A mapping language to compose SQL for Go.
README.md

StitchQL

StitchQL #

Write SQL. Share the pieces. Generate Go.

StitchQL generates typed Go queries for PostgreSQL. Reuse SELECT and RETURNING column lists, compose SQL predicates in Go, and optionally maintain your schema as reusable fragments beside your queries.

The aim is to reduce repetition while keeping SQL explicit. Your application owns connection pools, transactions, and business logic; StitchQL handles parameters, result types, and scanning through pgx.

Documentation · Installation · Getting started · Go API

Queries #

package store

columns bookColumns[b books] {
    b.id,
    b.title
}

predicate ByTitle[b books](title string) {
    b.title = {title}
}

query FindBooks(filter predicate[books]) {
    SELECT {bookColumns[b]}
    FROM books AS b
    WHERE {filter[b]}
    ORDER BY b.id
}

Generate with stitchql generate ./store, then call the query from Go:

books, err := store.FindBooks(store.ByTitle("Kindred")).Select(ctx, pool)

Schema and migrations #

Schema declarations are optional. Keep managing your schema externally, or place composable definitions in the same package:

fields Timestamps {
    created_at timestamptz NOT NULL DEFAULT now(),
    updated_at timestamptz NOT NULL DEFAULT now()
}

schema {
    CREATE TABLE books (
        id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
        title text NOT NULL,
        {Timestamps}
    );
}

With a development database configured, generate Go code and migrations from the declarations:

stitchql generate ./store
stitchql schema generate ./store > schema.sql
stitchql schema diff ./store --name create_books --dir ./migrations

Schema generation emits SQL. Migration generation writes a Goose migration for review and application through your deployment process. See Schema and migrations for the workflow.

StitchQL is under active development and currently targets Go 1.27.3+ and PostgreSQL 18. See SQL support for current limitations and the library example for a working application. To run the documentation site locally, see docs setup.

License #

MIT © 2026 Brandon Bennett.