sql-builder

Lingua Tungga → TypeScript, Python, Go

What is sql-builder

A SQL builder and schema codegen with one source of truth, verified byte-for-byte against drizzle-orm 0.44.4 across three dialects and three target languages.

experimentalFor developers evaluating or adopting the libraryMarkdown

Before this page: basic TypeScript, familiarity with Drizzle or another SQL builder

sql-builder is two things that share one pipeline:

  1. A SQL builder whose TypeScript surface reads and behaves like Drizzle.
  2. A schema codegen that turns a Prisma DMMF document into typed table modules.

Both are written once in Lingua Tungga, a small statically typed language, and emitted as TypeScript, Python, and Go. The emitted builders produce the same SQL text and the same bound parameters as drizzle-orm@0.44.4 for the same input.

That last sentence is the whole design constraint. It is not a compatibility claim in the marketing sense; it is a gate. If a query renders differently by one byte, the build fails.

The two halves

Half Input Output
Schema codegen Prisma DMMF, via prisma db pull schema.json (IR v3), then .lt table modules
SQL builder A query written against those tables SQL text and a parameter list, per dialect

schema.json is the canonical intermediate representation. It is deliberately smaller than Prisma's model: columns, defaults, indexes, enums, and foreign keys, with the naming rules codegen needs. Anything DMMF exposes that the IR cannot represent is recorded in unsupported.json instead of being silently dropped.

Why a single source

Maintaining three implementations of a query builder means three places for a bug to live. Here the semantics live in .lt, and each emitter is a rendering of that semantics with the host language's conventions:

  • TypeScript gets camelCase and delete_ for reserved words.
  • Python gets snake_case and from_.
  • Go gets PascalCase and explicit error returns.

The naming differences are the point. The behaviour is not supposed to differ at all, and the parity suite is what keeps that honest.

What "compatible" means here

Comparisons are made on the rendered SQL string plus the ordered parameter list, case by case, for Postgres, MySQL, and SQLite:

// TypeScript
db.select().from(users).where(eq(users.id, 1));

// Postgres
select "id" from "users" where "users"."id" = $1
// params: [1]

Two properties matter more than they look:

  • Parameters stay parameters. Values are bound, never inlined, so the shape of the SQL does not depend on the data.
  • Dialect quirks are reproduced, not improved. Identifier quoting, placeholder syntax, and column qualification follow Drizzle exactly, including the cases where its choice looks arbitrary.

Note

Compatibility is with drizzle-orm@0.44.4 specifically. Drizzle moves; this port pins a version and records its output as a fixture, so an upstream change shows up as a failing case rather than a quiet behavioural drift.

How it is verified

Three layers, each with a different failure mode:

  1. Differential fixtures — recorded Drizzle output for a fixed case set, hashed and checked in.
  2. Database roundtrip — the same statements executed against Postgres and MySQL, compared on real rows.
  3. Static gallery — every case rendered for all three targets and all three dialects, published as evidence.

The gallery is generated from the same fixtures the gates use, so it cannot describe a state the repository is not in.

What this documentation covers

These pages document the public surface: the schema pipeline, the builder's concepts and operators, the CLI, and the known limits. Internal planning notes stay out of the published site.

Status

The package is pre-1.0 (0.0.1). The builder and schema pipeline are feature complete for the cases in the parity suite; the emitted Python and Go packages are held to the same fixture set but have fewer human users.

Warning

Treat the API as stable enough to build against and not yet stable enough to freeze. Breaking changes before 1.0 are recorded in the changelog, and each one names the fixture that motivated it.