{"id":14974937,"url":"https://github.com/rexshijaku/sql-to-laravel-builder","last_synced_at":"2025-04-05T13:06:52.334Z","repository":{"id":47842736,"uuid":"367907876","full_name":"rexshijaku/sql-to-laravel-builder","owner":"rexshijaku","description":"SQL to Laravel Query Builder","archived":false,"fork":false,"pushed_at":"2023-04-23T20:52:53.000Z","size":110,"stargazers_count":190,"open_issues_count":4,"forks_count":29,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T12:06:04.055Z","etag":null,"topics":["laravel","laravel-builder","laravel8","query-builder","sql-query"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rexshijaku.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-16T14:45:40.000Z","updated_at":"2025-03-20T02:57:15.000Z","dependencies_parsed_at":"2024-11-22T05:01:59.286Z","dependency_job_id":null,"html_url":"https://github.com/rexshijaku/sql-to-laravel-builder","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"b0bbe11a7c7fb9b6cf9a328e2027c65ed42d6eec"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexshijaku%2Fsql-to-laravel-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexshijaku%2Fsql-to-laravel-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexshijaku%2Fsql-to-laravel-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexshijaku%2Fsql-to-laravel-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rexshijaku","download_url":"https://codeload.github.com/rexshijaku/sql-to-laravel-builder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339155,"owners_count":20923014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-builder","laravel8","query-builder","sql-query"],"created_at":"2024-09-24T13:51:17.411Z","updated_at":"2025-04-05T13:06:52.316Z","avatar_url":"https://github.com/rexshijaku.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/rexshijaku"],"categories":[],"sub_categories":[],"readme":"# Marwan - SQL To Laravel Builder\nSQL to Laravel Query Builder, A Converter written in PHP\n\n## Support\n\n\u003ca href=\"https://www.buymeacoffee.com/rexshijaku\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"50\" width=\"180\"\u003e\u003c/a\u003e\n\n### Features\n- Converts SQL Queries to Laravel Query Builder.\n- Assists on building queries as instructed in Laravel Documentation. \n- Provides options to interact with, for generating different results.\n\n### Supports \nLaravel 8\n\n### Demo\n\n##### Online demo\nLive demo and free usage is available \u003ca href='http://152.70.176.144/sql-to-laravel-builder/'\u003ehere\u003c/a\u003e.\n\n### Get Started\n##### Install by manual download: \nDownload the repository and install required packages by composer.json :\n\n##### Packagist\nYou can also install it from packagist by running the following command :\n```html\ncomposer require rexshijaku/sql-to-laravel-builder\n```\n\n### Usage\n##### Simple example\n#\n```php\n\u003c?php\n\nuse RexShijaku\\SQLToLaravelBuilder\\SQLToLaravelBuilder;\n\nrequire_once dirname(__FILE__) . './vendor/autoload.php';\n\n$options = array('facade' =\u003e 'DB::');\n$converter = new SQLToLaravelBuilder($options);\n\n$sql = \"SELECT COUNT(*) FROM members\";\necho $converter-\u003econvert($sql);\n```\nThis will produce the following result: \n```php\nDB::table('members')-\u003ecount();\n```\n##### A more complex example :\n\n```php\n$sql = \"SELECT\n                department_id,\n                count(*) \n            FROM\n                members\n                LEFT JOIN details AS d ON d.member_id = members.member_id \n            WHERE\n                ( age = 25 OR ( salary = 2000 AND gender = 'm' ) ) \n                AND id \u003e 15 \n            GROUP BY\n                department_id \n            HAVING\n                height \u003e 1.60\";\necho $converter-\u003econvert($sql);\n```\nand this will generate the result below :\n```php\nDB::table('members')\n    -\u003eselect('department_id', DB::raw('count(*)'))\n    -\u003eleftJoin('details AS d', 'd.member_id', '=', 'members.member_id')\n    -\u003ewhere(function ($query) {\n        $query-\u003ewhere('age', '=', 25)\n              -\u003eorWhere(function ($query) {\n                            $query-\u003ewhere('salary', '=', 2000)\n                                  -\u003ewhere('gender', '=', 'm');\n        });\n    })\n    -\u003ewhere('id', '\u003e', 15)\n    -\u003egroupBy('department_id')\n    -\u003ehaving('height', '\u003e', 1.60)\n    -\u003eget();\n```\n##### Notice \nIf you need to change options, or get more comprehensive understanding of provided options then see the following section of Options.\nThere are dozens of examples for every use case explained in the Query Builder documentation of Laravel 8, which are located in the \u003ca href=\"https://github.com/rexshijaku/sql-to-laravel-builder/tree/main/examples\" target=\"_blank\"\u003eexamples\u003c/a\u003e folder.\n\n### Options\nSome important options are briefly explained below:\n| Argument  | DataType    | Default  | Description |\n| ----- |:----------:| -----:| -----:|\n| facade  |  string | DB:: | Facade which allows the access to the Database functionality. |\n| group  |  boolean | true | Whether it should group key value pairs into a php array, or generate separate commands for each pair. See an example \u003ca href=\"https://github.com/rexshijaku/sql-to-laravel-builder/tree/main/examples/where.php\" target=\"_blank\"\u003ehere\u003c/a\u003e. |\n\n\n### How does it works ?\nSQL-To-Laravel-Builder is built on top of \u003ca href=\"hhttps://github.com/greenlion/PHP-SQL-Parser\"\u003ePHP-SQL-Parser\u003c/a\u003e. While \u003ca href=\"hhttps://github.com/greenlion/PHP-SQL-Parser\"\u003ePHP-SQL-Parser\u003c/a\u003e is responsible for parsing the given SQL Query as input. The result of the  \u003ca href=\"hhttps://github.com/greenlion/PHP-SQL-Parser\"\u003ePHP-SQL-Parser\u003c/a\u003e is the input of SQL-To-Laravel-Builder.\n\nThe structure has three main parts : \n1) Extractors classes - which help to pull out SQL Query parts in a way which are more understandable and processable by Builders. \n2) Builder classes - which help to construct Query Builder methods.\n3) Creator - which orchestrates the process between Extractors and Builders in order to produce parts of Query Builder.\n\n### Known issues\n- It is not tested in all cases.\n- Poor error handling.\n\n### Contributions \nFeel free to contribute on development, testing or eventual bug reporting.\n\n### Support\nFor general questions about Marwan - SQL-To-Laravel-Builder, tweet at @rexshijaku or write me an email on rexhepshijaku@gmail.com.\nTo have a quick tutorial check the  \u003ca href=\"https://github.com/rexshijaku/sql-to-laravel-builder/tree/main/examples\" target=\"_blank\"\u003eexamples\u003c/a\u003e folder provided in the repository.\n\n### Author\n##### Rexhep Shijaku\n - Email : rexhepshijaku@gmail.com\n - Twitter : https://twitter.com/rexshijaku\n \n### Thank you\nAll contributors who created and are continuously improving \u003ca href=\"hhttps://github.com/greenlion/PHP-SQL-Parser\"\u003ePHP-SQL-Parser\u003c/a\u003e, without it, this project would be much harder to be realized. \n\n### In memoriam\nFor the innocent lives lost (including Marwan al-Masri, aged just six) during the 2021 Israel–Palestine crisis.\n\n### License\nMIT License\n\nCopyright (c) 2021 | Rexhep Shijaku\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frexshijaku%2Fsql-to-laravel-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frexshijaku%2Fsql-to-laravel-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frexshijaku%2Fsql-to-laravel-builder/lists"}