本项目是 sqlc 的 fork 版本,在原始项目基础上增加了以下功能:
支持通过 SQL 查询名(方法名)来重载参数和返回值类型,复用 column 字段,不增加额外配置字段。
配置示例:
version: "2"
sql:
- engine: postgresql
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: db
out: db
overrides:
# 重载 GetAuthorByCreatedAt 查询的 created_at 参数类型
- column: "GetAuthorByCreatedAt.param.created_at"
go_type: "time.Time"
# 重载 ListAuthors 查询的 created_at 返回值类型
- column: "ListAuthors.return.created_at"
go_type: "time.Time"column 字段支持的格式:
| 格式 | 说明 | 示例 |
|---|---|---|
tablename.colname |
原有格式:表级别重载 | authors.id |
schema.tablename.colname |
原有格式:schema+表级别 | public.authors.id |
catalog.schema.tablename.colname |
原有格式:完整限定名 | mycat.public.authors.id |
queryname.param.colname |
新格式:查询参数重载 | GetAuthor.param.id |
queryname.return.colname |
新格式:查询返回值重载 | ListAuthors.return.name |
sqlc generates type-safe code from SQL. Here's how it works:
- You write queries in SQL.
- You run sqlc to generate code with type-safe interfaces to those queries.
- You write application code that calls the generated code.
Check out an interactive example to see it in action, and the introductory blog post for the motivation behind sqlc.
Additional languages can be added via plugins.
Development is possible thanks to our sponsors. If you would like to support sqlc, please consider sponsoring on GitHub.
Cyberax - NaNuNaNu - Stumble - WestfalNamur - alecthomas - cameronnewman - danielbprice - davherrmann - dvob - gilcrest - gzuidhof - jeffreylo - mmcloughlin - ryohei1216 - sgielen



