Skip to content

Codegen: add --format sqldelight (.sq schema generation)#73

Merged
AndroidPoet merged 1 commit into
mainfrom
codegen-sqldelight-format
Jun 22, 2026
Merged

Codegen: add --format sqldelight (.sq schema generation)#73
AndroidPoet merged 1 commit into
mainfrom
codegen-sqldelight-format

Conversation

@AndroidPoet

Copy link
Copy Markdown
Owner

What

Extends the codegen with a second output format so it can drive a local SQLDelight database that mirrors the Supabase schema.

SupabaseSqlDelightGenerator turns a PostgREST OpenAPI document into one .sq file per table:

  • CREATE TABLE IF NOT EXISTS with Postgres → SQLite storage classes (INTEGER / REAL / TEXT; booleanINTEGER, money/uuid/timestamps/arrays→TEXT)
  • NOT NULL from the schema's required columns
  • PRIMARY KEY detected from PostgREST's <pk/> description marker, falling back to an id column
  • standard selectAll / selectById / upsert / deleteById queries

SQLDelight's own Gradle plugin then compiles these .sq files into the type-safe Kotlin database — we only generate the schema half.

CLI

Main.kt gains --format kotlin|sqldelight:

  • kotlin (default, unchanged) — one @Serializable file per table/enum
  • sqldelight — one .sq per table

Each format clears its own stale output before writing.

Why

First step of the Supabase → SQLDelight offline-sync pipeline: our codegen produces the .sq, SQLDelight produces the typed DB. Read-only against the schema, like the existing generator.

Tests

SupabaseSqlDelightGeneratorTest covers file-per-table layout, storage-class mapping, NOT NULL + PRIMARY KEY, the standard queries, and PK fallback. :supabase-codegen:build green (tests + detekt + spotless).

Logged under Unreleased in the changelog — no version bump.

Adds SupabaseSqlDelightGenerator, which turns a PostgREST OpenAPI
document into one SQLDelight .sq file per table: a CREATE TABLE with
Postgres->SQLite storage classes, NOT NULL from required columns, the
primary key detected from PostgREST's <pk/> description marker (falling
back to an id column), plus standard selectAll/selectById/upsert/
deleteById queries. SQLDelight's own plugin then compiles these into a
type-safe Kotlin database.

The CLI gains --format kotlin|sqldelight (default kotlin, unchanged),
with format-specific stale-file cleanup before writing.
@AndroidPoet AndroidPoet merged commit 87b18ca into main Jun 22, 2026
6 of 8 checks passed
@AndroidPoet AndroidPoet deleted the codegen-sqldelight-format branch June 22, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant