Skip to content
 
 

Repository files navigation

sqlc: A SQL Compiler

Fork 变更说明

本项目是 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

go Go Report Card

sqlc generates type-safe code from SQL. Here's how it works:

  1. You write queries in SQL.
  2. You run sqlc to generate code with type-safe interfaces to those queries.
  3. 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.

Overview

Supported languages

Additional languages can be added via plugins.

Sponsors

Development is possible thanks to our sponsors. If you would like to support sqlc, please consider sponsoring on GitHub.

Riza.io

Coder.com Mint.fun Mux.com

Cyberax - NaNuNaNu - Stumble - WestfalNamur - alecthomas - cameronnewman - danielbprice - davherrmann - dvob - gilcrest - gzuidhof - jeffreylo - mmcloughlin - ryohei1216 - sgielen

About

Generate type-safe code from SQL

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages