{"id":13600269,"url":"https://github.com/kesonan/sqlgen","last_synced_at":"2025-10-25T14:17:00.923Z","repository":{"id":56805741,"uuid":"517882851","full_name":"kesonan/sqlgen","owner":"kesonan","description":"A tool to generate bun, gorm, sql, sqlx and xorm sql code.","archived":false,"fork":false,"pushed_at":"2023-06-29T14:29:20.000Z","size":168,"stargazers_count":85,"open_issues_count":1,"forks_count":9,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-10T21:38:26.506Z","etag":null,"topics":["codegen","database","generator","golang","mysql","sqlgen","sqlgenerate","sqlgenerator"],"latest_commit_sha":null,"homepage":"","language":"Go","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/kesonan.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":"2022-07-26T02:13:39.000Z","updated_at":"2025-03-29T21:05:18.000Z","dependencies_parsed_at":"2024-05-06T06:30:58.431Z","dependency_job_id":null,"html_url":"https://github.com/kesonan/sqlgen","commit_stats":null,"previous_names":["kesonan/sqlgen","anqiansong/sqlgen"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kesonan/sqlgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kesonan%2Fsqlgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kesonan%2Fsqlgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kesonan%2Fsqlgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kesonan%2Fsqlgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kesonan","download_url":"https://codeload.github.com/kesonan/sqlgen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kesonan%2Fsqlgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270923614,"owners_count":24668582,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["codegen","database","generator","golang","mysql","sqlgen","sqlgenerate","sqlgenerator"],"created_at":"2024-08-01T18:00:33.848Z","updated_at":"2025-10-25T14:16:55.598Z","avatar_url":"https://github.com/kesonan.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# sqlgen\n\nEnglish | [中文](README_cn.md)\n\n[![Go](https://github.com/anqiansong/sqlgen/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/anqiansong/sqlgen/actions/workflows/go.yml)\n[![codecov](https://codecov.io/gh/anqiansong/sqlgen/branch/main/graph/badge.svg?token=8mLCFUqD2l)](https://codecov.io/gh/anqiansong/sqlgen)\n[![Go Reference](https://pkg.go.dev/badge/github.com/anqiansong/sqlgen.svg)](https://pkg.go.dev/github.com/anqiansong/sqlgen)\n[![Go Report Card](https://goreportcard.com/badge/github.com/anqiansong/sqlgen)](https://goreportcard.com/report/github.com/anqiansong/sqlgen)\n[![Release](https://img.shields.io/github/v/release/anqiansong/sqlgen.svg?style=flat-square)](https://github.com/anqiansong/sqlgen)\n[![GitHub license](https://img.shields.io/github/license/anqiansong/sqlgen?style=flat-square)](https://github.com/anqiansong/sqlgen/blob/main/LICENSE)\n\nsqlgen is a tool to generate **bun**, **gorm**, **sql**, **sqlx** and **xorm** sql code from SQL\nfile which is inspired by\n\n- [go-zero](https://github.com/zeromicro/go-zero)\n- [goctl](https://github.com/zeromicro/go-zero/tree/master/tools/goctl)\n- [sqlc](https://github.com/kyleconroy/sqlc).\n\n# Installation\n\n```bash\ngo install github.com/anqiansong/sqlgen@latest\n```\n\n# Example\n\nSee [example](https://github.com/anqiansong/sqlgen/tree/main/example)\n\n# Queries rule\n\n## 1. Function Name\n\nYou can define a function via `fn` keyword in line comment, for example:\n\n```sql\n-- fn: my_func\nSELECT *\nFROM user;\n```\n\nit will be generated as:\n\n```go\nfunc (m *UserModel) my_func (...) {\n...\n}\n```\n\n## 2. Get One Record\n\nThe expression `limit 1` must be explicitly defined if you want to get only one record, for example:\n\n```sql\n-- fn: FindOne\nselect *\nfrom user\nwhere id = ? limit 1;\n```\n\n## 3. Marker or Values?\n\nFor arguments of SQL, you can use `?` or explicitly values to mark them, in sqlgen, the arguments\nwill be converted into variables, for example, the following query are equivalent:\n\n\u003e NOTES: It does not apply to rule 2\n\n```sql\n-- fn: FindLimit\nselect *\nfrom user\nwhere id = ?;\n\n-- fn: FindLimit\nselect *\nfrom user\nwhere id = 1;\n\n```\n\n## 4. SQL Function\n\nsqlgen supports aggregate function queries in sql, other than that, other functions are not\nsupported so far. All the aggregate function query expressions must contain AS expression, for\nexample:\n\n```sql\n-- fn: CountAll\nselect count(*) as count\nfrom user;\n```\n\nFor most query cases, you can\nsee [example.sql](https://github.com/anqiansong/sqlgen/blob/main/example/example.sql) for details.\n\n# How it works\n\n1. Create a SQL file\n2. Write your SQL code in the SQL file\n3. Run `sqlgen` to generate code\n\n# Notes\n\n1. Only support MYSQL code generation.\n3. Do not support multiple tables in one SQL file.\n4. Do not support join query.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkesonan%2Fsqlgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkesonan%2Fsqlgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkesonan%2Fsqlgen/lists"}