{"id":15490438,"url":"https://github.com/myconsciousness/sql-formatter","last_synced_at":"2025-04-22T19:10:22.864Z","repository":{"id":118166410,"uuid":"285017147","full_name":"myConsciousness/sql-formatter","owner":"myConsciousness","description":"Lightweight, Extensible and Flexible formatter for SQL based on Java.","archived":false,"fork":false,"pushed_at":"2021-01-26T10:35:03.000Z","size":246,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T09:17:59.898Z","etag":null,"topics":["formatter","java","sql","sql-formatter"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/myConsciousness.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-04T15:13:21.000Z","updated_at":"2024-05-29T17:41:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"59d21759-7f51-43e8-a7ac-e417842f880d","html_url":"https://github.com/myConsciousness/sql-formatter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myConsciousness%2Fsql-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myConsciousness%2Fsql-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myConsciousness%2Fsql-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myConsciousness%2Fsql-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/myConsciousness","download_url":"https://codeload.github.com/myConsciousness/sql-formatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306638,"owners_count":21408926,"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":["formatter","java","sql","sql-formatter"],"created_at":"2024-10-02T07:21:19.825Z","updated_at":"2025-04-22T19:10:22.858Z","avatar_url":"https://github.com/myConsciousness.png","language":"Java","readme":"# SQL Formatter\n\n## What is it?\n\n**_This is a formatter for SQL queries such as DDL and DML._**\n\n`SQL Formatter` is specialized in formatting DDL and DML queries that do not use regular expressions and has no functions other than formatting. **_Therefore it is extremely lightweight besides can be expanded to meet user needs._**\n\nThe following syntaxes of ORACLE SQL are supported. I have not checked for compatibility with other RDBMS, sorry!\n\n- **_DDL Statement_**\n\n  - `CREATE`\n  - `ALTER`\n  - `DROP`\n  - `COMMENT`\n\n- **_DML Statement_**\n  - `SELECT`\n  - `INSERT`\n  - `UPDATE`\n  - `DELETE`\n\n## How To Use\n\n### 1. Add the dependencies\n\n\u003e Note:\u003cbr\u003e\n\u003e Replace version you want to use. Check the latest [Packages](https://github.com/myConsciousness/sql-formatter/packages).\u003cbr\u003e\n\u003e Please contact me for a token to download the package.\n\n**_Maven_**\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.thinkit.formatter\u003c/groupId\u003e\n  \u003cartifactId\u003esql-formatter\u003c/artifactId\u003e\n  \u003cversion\u003ev1.0.0-1-g22b76d8\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003cservers\u003e\n  \u003cserver\u003e\n    \u003cid\u003egithub\u003c/id\u003e\n    \u003cusername\u003emyConsciousness\u003c/username\u003e\n    \u003cpassword\u003exxxxxxxxxxxxxxxxxx\u003c/password\u003e\n  \u003c/server\u003e\n\u003c/servers\u003e\n```\n\n**_Gradle_**\n\n```gradle\nrepositories {\n    maven {\n        name = \"GitHubPackages\"\n        url = uri(\"https://maven.pkg.github.com/myConsciousness/sql-formatter\")\n        credentials {\n          username = \"myConsciousness\"\n          password = \"xxxxxxxxxxxxxxxxxx\"\n        }\n    }\n}\n\ndependencies {\n    implementation 'org.thinkit.formatter:sql-formatter:v1.0.4'\n}\n```\n\n### 2. Add an import for [**_SQL Fomratter_**](https://github.com/myConsciousness/sql-formatter/blob/master/src/main/java/org/thinkit/formatter/SqlFormatter.java)\n\n```java\nimport org.thinkit.formatter.SqlFormatter;\n```\n\n### 3. Create a instance\n\n```java\nFormatter formatter = SqlFormatter.of();\n```\n\nYou can also create an instance with a specific number of indents as following.\n\n\u003e _Note:_\u003cbr\u003e\n\u003e If a negative indentation is passed at instantiation time, the initial value defined in the [content file](https://github.com/myConsciousness/json-formatter/blob/master/src/main/resources/content/formatter/json/SqlDefaultIndentItem.json) takes precedence.\n\n```java\nFormatter formatter = SqlFormatter.withIndent(indent);\n```\n\n### 4. Format!\n\n```java\nFormatter formatter = SqlFormatter.withIndent(indent);\nString formattedSql = formatter.format(sql);\n```\n\n## Demonstrate I/O\n\nI have prepared the following unformatted select query for input/output reference. It's very simple query but it's hard to see without any spaces or line breaks.\n\n```sql\n      select t.foo, h.foo, t.foo from foo t, foo as hoge order by something desc left outer join foo h on t.foo = h.foo and t.foo = h.foo where name like '%foofoofoo' and test in ('foo', 'foo', 'foo', 'foo');\n```\n\nLet's run `SQL Formatter` with the SQL query of above template as an argument.\n\n```java\nSqlFormatter.of().format(sql);\n```\n\nThe output is as follows.\n\n\u003e _Note:_\u003cbr\u003e\n\u003e Whitespace in the JSON string before formatting is trimmed during the formatting process, so no pre-processing is required.\n\n```sql\nselect\n    t.foo,\n    h.foo,\n    t.foo\nfrom\n    foo t,\n    foo as hoge\norder by\n    something desc\nleft outer join\n    foo h\n        on t.foo = h.foo\n        and t.foo = h.foo\n    where\n        name like '%foofoofoo'\n        and test in (\n            'foo', 'foo', 'foo', 'foo'\n        )\n;\n```\n\n## License\n\n```\nCopyright 2020 Kato Shinya.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except\nin compliance with the License. You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License\nis distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\nor implied. See the License for the specific language governing permissions and limitations under\nthe License.\n```\n\n## More Information\n\n`SQL Formatter` was designed and implemented by Kato Shinya, who works as a freelance developer from Japan.\n\nRegardless of the means or content of communication, I would love to hear from you if you have any questions or concerns. I do not check my email box very often so a response may be delayed, anyway thank you for your interest!\n\n- [Creator Profile](https://github.com/myConsciousness)\n- [License](https://github.com/myConsciousness/sql-formatter/blob/master/LICENSE)\n- [Release Note](https://github.com/myConsciousness/sql-formatter/releases)\n- [Package](https://github.com/myConsciousness/sql-formatter/packages)\n- [File a Bug](https://github.com/myConsciousness/sql-formatter/issues)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyconsciousness%2Fsql-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmyconsciousness%2Fsql-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyconsciousness%2Fsql-formatter/lists"}