Skip to content

Parse JSON-defined business intelligence queries into SQL using Laravel. Build flexible, dynamic reporting and dashboard features with ease.

License

Notifications You must be signed in to change notification settings

Jnyawach/laravel-query-translator

Repository files navigation

Laravel BI Query Translator

Latest Version on Packagist GitHub Tests Action Status Downloads

Documentation, Installation, and Usage

Please visit the Documentation for detailed instructions on how to install and use this package.

What It Does

This package allows you to quickly generate SQL queries from a JSON-based query structure. It is particularly useful for building Business Intelligence (BI) tools, where users can create complex queries through a user-friendly JSON without needing to write SQL code manually. Once installed you can be able to convert a JSON query structure into a SQL query string. See the example below:

use Nyawach\LaravelQueryTranslator\Facades\QueryTranslator;

$query=[
  "table" => "lunar_orders"
  "joins" => []
  "filters" => []
  "summary" => [
    "summarizations" =>  [
       [
        "summarization_operator" => "SUM"
        "summarization_column" => "sub_total"
      ]
       [
        "summarization_operator" => "COUNT"
        "summarization_column" => "id"
      ]
    ]
    "group_by" => [
      [
        "group_by_column" => "status"
      ]
    ]
  ]
  "sort" => []
];

return QueryTranslator::execute($request->all());
// and get
[
    {
        "SUM_sub_total": "130000",
        "COUNT_id": 2,
        "status": "dispatched"
    },
    {
        "SUM_sub_total": "225000",
        "COUNT_id": 3,
        "status": "order-cancelled"
    },
    {
        "SUM_sub_total": "130000",
        "COUNT_id": 2,
        "status": "order-delivered"
    },
    {
        "SUM_sub_total": "910000",
        "COUNT_id": 1,
        "status": "payment-offline"
    },
    {
        "SUM_sub_total": "485000",
        "COUNT_id": 7,
        "status": "payment-received"
    }
]

Change Log

Please see CHANGELOG for more information recent changes.

Contributing

Please see CONTRIBUTING for details.

Testing

To run the tests, execute the following command in your terminal:

composer test

Security & Vulnerabilities

If you discover any security related issues, please email [email protected]

Credits

This package has been highly inspired by Metabase a querying and visualization layer for your databases

License

The MIT License (MIT). Please see LICENSE for more information.

About

Parse JSON-defined business intelligence queries into SQL using Laravel. Build flexible, dynamic reporting and dashboard features with ease.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages