Skip to content

Codegen: emit offline-sync adapters + paged queries, read spec from file#74

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

Codegen: emit offline-sync adapters + paged queries, read spec from file#74
AndroidPoet merged 1 commit into
mainfrom
codegen-sqldelight-adapters

Conversation

@AndroidPoet

Copy link
Copy Markdown
Owner

What

Closes the Supabase → typed local DB loop so the whole thing generates from one OpenAPI document.

.sq schema — pagination

Generated tables now also emit countAll, offset page, and keyset pageAfter queries (alongside the existing selectAll/selectById/upsert/deleteById).

New: offline-sync adapter generation

SupabaseSqlDelightAdapterGenerator emits a SupabaseAdapters.kt with a supabaseAdapters(driver) factory that wires each generated table into an offline-sync LocalStore as its single source of truth. Each entry is a generic SqlDelightTableAdapter configured by a column descriptor (storage kind + nullability) and primary key — no per-table conversion code is generated, because that logic lives once in the offline-sync runtime. Enable with --format sqldelight --adapters true.

New: read the spec from a file

--spec <openapi.json> reads the schema from disk — no network, no key. --url/--key still work.

Verified live

Ran against a checked-in sample (supabase-codegen/sample/openapi.json):

✓ Wrote .../ChatRooms.sq
✓ Wrote .../ChatMessages.sq
✓ Wrote .../SupabaseAdapters.kt

The generated SupabaseAdapters.kt compiles cleanly against the offline-sync runtime (core + store-sqldelight + SQLDelight runtime) — column kinds (BOOL/INTEGER/REAL/JSON/TEXT), nullability, and pk all resolved from the spec.

Tests

SupabaseSqlDelightAdapterGeneratorTest covers the factory shape, runtime imports, pk wiring, every column-kind classification, and the new paged .sq queries. :supabase-codegen:build green (tests + detekt + spotless).

Logged under Unreleased — no version bump.

Extends the SQLDelight codegen so the whole Supabase -> typed local DB
chain generates from one OpenAPI document:

- .sq tables gain countAll + offset page + keyset pageAfter queries.
- New SupabaseSqlDelightAdapterGenerator emits SupabaseAdapters.kt: a
  supabaseAdapters(driver) factory wiring each table into an offline-sync
  LocalStore as its source of truth. Each entry is a generic
  SqlDelightTableAdapter configured by a column descriptor (kind +
  nullability) and primary key — no per-table conversion code is
  generated. Enabled with --format sqldelight --adapters true.
- --spec <openapi.json> reads the schema from a local file (no network,
  no key); --url/--key still work.

Verified live against supabase-codegen/sample/openapi.json: generates
the .sq files + SupabaseAdapters.kt, and the generated adapters compile
against the offline-sync runtime. Logged under Unreleased.
@AndroidPoet AndroidPoet merged commit 383ab6f into main Jun 22, 2026
@AndroidPoet AndroidPoet deleted the codegen-sqldelight-adapters branch June 22, 2026 09:36
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