Skip to content
 
 

Latest commit

 

History

1,834 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wicked-sqlc

A PostgreSQL-focused sqlc fork that generates type-safe Go code for wpgx and dcache. Write SQL; generate query methods with timeouts, optional caching, cache invalidation, replica access, and load/dump helpers for tests.

Architecture

We regularly rebase wicked-sqlc onto upstream sqlc releases. Our changes fall into two layers: compiler changes in the fork and a dedicated Go backend.

  1. Compiler — Parses SQL, resolves schema dependencies, and infers SQL types and parameter nullability. In wpgx mode, the first schema file owns the primary model; the remaining files supply dependencies and are analyzed first.
  2. Codegen contract — sqlc's GenerateRequest carries the catalog, typed queries, and comments. A small WickedMetadata extension adds the primary schema source, its relation, and top-level SELECT classification. Options such as timeout, cache, and invalidate travel as ordinary query comments, not custom compiler parameters.
  3. Wicked backendinternal/codegen/wicked maps SQL types to Go and renders the templates. It parses comment options and generates cache keys, timeout handling, invalidation hooks, replica APIs, and test helpers. The generated code uses wpgx and dcache at runtime.

The backend runs in-process, bundled in the sqlc binary. There is no separate plugin to install. sql_package: wpgx selects it; other Go configurations use upstream's standard Go backend.

Compiler fixes stay in this fork until validated with the full wicked stack, then can be proposed upstream independently. Generation-specific conventions stay in the wicked backend.

Use it

Build the current main branch with the Go version specified in go.mod:

git clone https://github.com/Stumble/sqlc.git
cd sqlc
make install

Select the backend in sqlc.yaml:

version: '2'
sql:
  - engine: postgresql
    schema: books/schema.sql
    queries: books/query.sql
    gen:
      go:
        sql_package: wpgx
        package: books
        out: books

Every query requires a timeout. Caching is opt-in:

-- name: GetBook :one
-- -- timeout: 500ms
-- -- cache: 10m
SELECT * FROM books WHERE id = @id;

Run sqlc generate to generate code, or sqlc diff to check that it is up to date. Existing wicked projects keep the same configuration and commands.

See the guide for schema conventions, query options, and runtime setup, or bookstore for a working example. Upstream documentation covers standard sqlc features.


The original upstream README is preserved below.

sqlc: A SQL Compiler

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 (a wicked fork)

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages