{"id":13615159,"url":"https://github.com/doctrine/sql-formatter","last_synced_at":"2025-05-10T06:16:53.764Z","repository":{"id":37033175,"uuid":"249204709","full_name":"doctrine/sql-formatter","owner":"doctrine","description":"A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.","archived":false,"fork":false,"pushed_at":"2025-03-10T23:40:47.000Z","size":832,"stargazers_count":1772,"open_issues_count":11,"forks_count":26,"subscribers_count":8,"default_branch":"1.5.x","last_synced_at":"2025-05-08T20:58:34.645Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HTML","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/doctrine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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":"2020-03-22T14:47:48.000Z","updated_at":"2025-05-06T08:14:33.000Z","dependencies_parsed_at":"2022-06-29T10:33:54.090Z","dependency_job_id":"9d739ebf-4896-457e-8a16-d477dc708f2c","html_url":"https://github.com/doctrine/sql-formatter","commit_stats":{"total_commits":265,"total_committers":37,"mean_commits":7.162162162162162,"dds":0.7320754716981133,"last_synced_commit":"1e04414f21f24483e95f48e6455aa7e67274decc"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doctrine%2Fsql-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doctrine%2Fsql-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doctrine%2Fsql-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doctrine%2Fsql-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doctrine","download_url":"https://codeload.github.com/doctrine/sql-formatter/tar.gz/refs/heads/1.5.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253157561,"owners_count":21863134,"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":[],"created_at":"2024-08-01T20:01:10.080Z","updated_at":"2025-05-08T22:30:44.599Z","avatar_url":"https://github.com/doctrine.png","language":"HTML","funding_links":[],"categories":["HTML"],"sub_categories":[],"readme":"# SqlFormatter\n\nA lightweight php package for formatting sql statements.\n\nIt can automatically indent and add line breaks in addition to syntax\nhighlighting.\n\n## History\n\nThis package is a fork from https://github.com/jdorn/sql-formatter\nHere is what the original History section says:\n\n\u003e I found myself having to debug auto-generated SQL statements all the time and\n\u003e wanted some way to easily output formatted HTML without having to include a\n\u003e huge library or copy and paste into online formatters.\n\n\u003e I was originally planning to extract the formatting code from PhpMyAdmin,\n\u003e but that was 10,000+ lines of code and used global variables.\n\n\u003e I saw that other people had the same problem and used Stack Overflow user\n\u003e losif's answer as a starting point.  http://stackoverflow.com/a/3924147\n\n― @jdorn\n\n## Usage\n\nThe `SqlFormatter` class has a method `format` which takes an SQL string as\ninput and returns a formatted block.\n\nSample usage:\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse Doctrine\\SqlFormatter\\SqlFormatter;\n\n$query = \"SELECT count(*),`Column1`,`Testing`, `Testing Three` FROM `Table1`\n    WHERE Column1 = 'testing' AND ( (`Column2` = `Column3` OR Column4 \u003e= NOW()) )\n    GROUP BY Column1 ORDER BY Column3 DESC LIMIT 5,10\";\n\necho (new SqlFormatter())-\u003eformat($query);\n```\n\nOutput:\n\n\u003cimg src=\"examples/readme_format_html.svg\" width=\"600\" height=\"450\" alt=\"formatted output with HTML Highlight\"\u003e\n\nWhen you run php under cli and instantiated `SqlFormatter` without argument, highlighted with `CliHighlighter`.\n\nSqlFormatter constructor takes `Highlighter` implementations. `HtmlHighlighter` etc.\n\n\n### Formatting Only\n\nIf you don't want syntax highlighting and only want the indentations and\nline breaks, pass in a `NullHighlighter` instance as the second parameter.\n\nThis is useful for outputting to error logs or other non-html formats.\n\n```php\n\u003c?php\n\nuse Doctrine\\SqlFormatter\\NullHighlighter;\nuse Doctrine\\SqlFormatter\\SqlFormatter;\n\necho (new SqlFormatter(new NullHighlighter()))-\u003eformat($query);\n```\n\nOutput:\n\n```\nSELECT\n  count(*),\n  `Column1`,\n  `Testing`,\n  `Testing Three`\nFROM\n  `Table1`\nWHERE\n  Column1 = 'testing'\n  AND (\n    (\n      `Column2` = `Column3`\n      OR Column4 \u003e= NOW()\n    )\n  )\nGROUP BY\n  Column1\nORDER BY\n  Column3 DESC\nLIMIT\n  5, 10\n```\n\n### Syntax Highlighting Only\n\nThere is a separate method `highlight` that preserves all original whitespace\nand just adds syntax highlighting.\n\nThis is useful for sql that is already well formatted and just needs to be a\nlittle easier to read.\n\n```php\n\u003c?php\necho (new SqlFormatter())-\u003ehighlight($query);\n```\n\nOutput:\n\n\u003cimg src=\"examples/readme_highlight_html.svg\" width=\"800\" height=\"150\" alt=\"HTML Highlight output\"\u003e\n\n### Compress Query\n\nThe `compress` method removes all comments and compresses whitespace.\n\nThis is useful for outputting queries that can be copy pasted to the command\nline easily.\n\n```sql\n-- This is a comment\n    SELECT\n    /* This is another comment\n    On more than one line */\n    Id #This is one final comment\n    as temp, DateCreated as Created FROM MyTable;\n```\n\n```php\necho (new SqlFormatter())-\u003ecompress($query);\n```\n\nOutput:\n\n```sql\nSELECT Id as temp, DateCreated as Created FROM MyTable;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoctrine%2Fsql-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoctrine%2Fsql-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoctrine%2Fsql-formatter/lists"}