Codegen: add --format sqldelight (.sq schema generation)#73
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extends the codegen with a second output format so it can drive a local SQLDelight database that mirrors the Supabase schema.
SupabaseSqlDelightGeneratorturns a PostgREST OpenAPI document into one.sqfile per table:CREATE TABLE IF NOT EXISTSwith Postgres → SQLite storage classes (INTEGER/REAL/TEXT;boolean→INTEGER,money/uuid/timestamps/arrays→TEXT)NOT NULLfrom the schema's required columnsPRIMARY KEYdetected from PostgREST's<pk/>description marker, falling back to anidcolumnselectAll/selectById/upsert/deleteByIdqueriesSQLDelight's own Gradle plugin then compiles these
.sqfiles into the type-safe Kotlin database — we only generate the schema half.CLI
Main.ktgains--format kotlin|sqldelight:kotlin(default, unchanged) — one@Serializablefile per table/enumsqldelight— one.sqper tableEach 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
SupabaseSqlDelightGeneratorTestcovers file-per-table layout, storage-class mapping, NOT NULL + PRIMARY KEY, the standard queries, and PK fallback.:supabase-codegen:buildgreen (tests + detekt + spotless).Logged under Unreleased in the changelog — no version bump.