From the Piko project ↗

Plain SQL, typed Go.

Write queries in .sql files. Seagull checks them against your migrations and generates type-safe Go, from SQLite to ClickHouse, in pure Go with zero cgo.

Open source · Apache 2.0 · Pre-release · Will steal your chips

SQL in, Go outWalk through it →
db/migrations/0001_users.up.sql
CREATE TABLE users (
    id         SERIAL PRIMARY KEY,
    name       TEXT NOT NULL,
    email      VARCHAR(255),
    age        INTEGER,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
db/queries/users.sql
-- sgl.query(GetUser, one)
SELECT id, name, email, age, created_at
FROM users WHERE id = $1;
internal/store/users.sql.go
// Code generated by sgl. DO NOT EDIT.

type GetUserRow struct {
	ID        int32
	Name      string
	Email     *string
	Age       *int32
	CreatedAt time.Time
}

func (queries *Queries) GetUser(
	ctx context.Context, id int32,
) (GetUserRow, error)

* email and age can be NULL, so they are pointers. The others never are.

$ sgl generatewrote internal/store: models.go querier.go users.sql.go
Two ways to use it

On the command line.
Inside your build.

Run sgl as a Go tool in your module, or call the generator from your own program. The analysis is the same either way.

The command line

One binary, every step

Generate, check in CI, format directives and run migrations. sgl vet reports in text, JSON, GitHub annotations or SARIF.

$ go get -tool seagull.sh/seagull/cmd/sgl
$ go tool sgl generate
$ go tool sgl vet --format github
$ go tool sgl migrate up
Explore the CLI →
The Go library

Generate from your own code

Give the generator a dialect and your files; get Go files and diagnostics back. Plug in your own emitter, preset or type overrides.

gen, err := seagull.New(postgres.New())
if err != nil {
    return err
}
result, err := gen.Generate(ctx, seagull.Input{
    Package:    "store",
    Migrations: db, MigrationDir: "migrations",
    Queries:    db, QueryDir:     "queries",
})
Use it from Go →
Learn by example

53 ideas.
Every engine.

214 small programs across 8 engines, from a first query to the runtime query builder. Each shows the SQL you write, the Go sgl generates, and the code that calls it, and each one runs in CI.

Browse every example →
Screams at your queries

So production
doesn't have to.

Every query is analysed against the schema your migrations build, before a line of Go is written. Typos, missing columns, the wrong command and bad directives come back with a code, a caret and a fix.

Browse every diagnostic →
db/queries/example.sql:1:27: error[Q028]: invalid value "mnay" for keyword argument "command"; allowed: one, many, exec, execresult, execrows, batch, stream, copyfrom, asyncexec
help: did you mean "many"?

The same report in your terminal, as a GitHub annotation, or as SARIF for code scanning.

Checked against your migrations

Seagull replays your migrations to build its catalogue of tables, views, types and functions. Queries are checked against the schema you ship, not a copy kept by hand.

How migrations feed the catalogue →

Nullability you can trust

Nullability is followed through joins, expressions, subqueries and CTEs. A column that can be NULL becomes a pointer; one that cannot, never does.

Override a column's type →

Dynamic queries, closed allow-lists

dynamic: runtime generates a builder for filters, ordering and paging. Columns and operators are checked against the query's own select list, and values are always bound.

Build queries at runtime →

Migrations and seeds included

Run the same .sql files with sgl migrate: in order, checksummed, and locked where your database has a lock, so two deploys do not migrate at once.

Run migrations →
Eight dialects

One grammar.
Every database's types.

The same directives work everywhere. Each dialect brings its own parser, types and built-in functions, so the Go you get matches the database you run.

sgl and the code it writes are pure Go. DuckDB is the exception at run time: its driver needs cgo, so connect to it from a custom build.

How we check it

Tested against the real thing.

Seagull is pre-release, but its analyser is not new. These are the checks it runs.

332 golden cases

Every dialect's analysis is pinned by golden tests: the catalogue, the analysed query and its diagnostics, across eight dialects.

See the dialects →

Real databases

Integration suites generate code, build it and run it against real PostgreSQL, CockroachDB, TimescaleDB, MariaDB, SQLite, DuckDB and ClickHouse.

Read the suites ↗

Born in production

Seagull is the querier that generates the data layer of Piko applications, moved into its own repository. Piko keeps using it, with its own piko. directives.

Meet Piko ↗

Codes that never change

Diagnostics have stable codes, from Q001 up. A number is never reused, so CI scripts, editors and code scanning can rely on them.

Browse the codes →

Part of the
Piko project.

Seagull began as the querier inside the Piko web framework, the sibling of Pipit, Piko's Go interpreter. Now it has its own home, for any Go project. This website is built with Piko.

Meet Piko ↗
Get started

Point sgl at your migrations and queries.

Read getting started →