Add DoSqliteDriver, typegres/core + do-sqlite entries, codegen fixes - #87
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR restructures Typegres’ packaging to better support worker-safe consumption by introducing a side-effect-free typegres/core entrypoint and a Durable Object-friendly SQLite driver (typegres/do-sqlite), while updating codegen and examples to import runtime helpers from typegres/core. It also fixes SQLite introspection around rowid-alias detection for composite primary keys and adds regression tests.
Changes:
- Add
typegres/core,typegres/do-sqlite, andtypegres/capnwebsubpath exports; update build entries to emit them. - Introduce
DoSqliteDriver+ shared driver contract utilities indriver-shared.tsto avoid pulling optional Node-only peers into worker bundles. - Update codegen + tests/examples to import
expose/sqlfromtypegres/core, and adjust SQLite introspection + tests for composite PK rowid-alias behavior.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tsdown.config.ts | Adds new entrypoints and externalizes capnweb to support new subpath exports. |
| src/tables/sqlite.ts | Refines SQLite rowid-alias detection for composite PKs and threads PK column count through introspection. |
| src/tables/sqlite.test.ts | Updates generated snapshots to use typegres/core and adds composite-PK regression assertions. |
| src/tables/postgres.test.ts | Updates generated snapshots to use typegres/core for runtime imports. |
| src/tables/generate.ts | Switches codegen runtime imports from typegres to typegres/core. |
| src/tables/generate.test.ts | Updates codegen unit snapshots/fixtures to reflect typegres/core runtime import changes. |
| src/index.ts | Exposes DoSqliteDriver, switches Driver type export to driver-shared, and documents worker-safe subpaths. |
| src/driver.ts | Moves shared driver types/helpers out to driver-shared and re-exports DoSqliteDriver. |
| src/driver-shared.ts | New shared driver contract + SQLite row normalization without optional peer imports. |
| src/driver-do-sqlite.ts | New Durable Object SqlStorage-backed SQLite driver implementation. |
| src/database.ts | Avoids importing ./driver (and its optional peers) by using driver-shared types. |
| src/core.ts | New worker-safe runtime surface entrypoint (typegres/core). |
| site/.gitignore | Ignores new rolldown runtime chunk naming pattern. |
| package.json | Adds ./core, ./do-sqlite, ./capnweb exports and makes better-sqlite3 an optional peer. |
| examples/sqlite/src/tables/teams.ts | Updates runtime import to typegres/core. |
| examples/sqlite/src/tables/dogs.ts | Updates runtime import to typegres/core. |
| examples/basic/src/tables/toys.ts | Updates runtime import to typegres/core. |
| examples/basic/src/tables/teams.ts | Updates runtime import to typegres/core. |
| examples/basic/src/tables/microchips.ts | Updates runtime import to typegres/core. |
| examples/basic/src/tables/dogs.ts | Updates runtime import to typegres/core. |
| examples/basic/src/tables/collars.ts | Updates runtime import to typegres/core. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+96
to
99
| const toColumnInfo = (r: TableInfoRow, pkColCount: number): ColumnInfo => { | ||
| const rowid = isRowidAlias(r.type, r.pk, pkColCount); | ||
| return { | ||
| name: r.name, |
Comment on lines
+164
to
167
| const isRowid = localCol ? isRowidAlias(localCol.type, localCol.pk, pkColCount) : false; | ||
| out.push({ | ||
| from_table: tableName, | ||
| from_column: fk.from, |
Comment on lines
+30
to
+36
| execute: ExecuteFn = ({ text, values }: CompiledSql): Promise<QueryResult> => { | ||
| const query = stripMatchedOuterParens(text); | ||
| // SqlStorage rejects BigInt; typegres emits 0n/1n for booleans. | ||
| const bound = values.map((v) => (typeof v === "bigint" ? Number(v) : v)); | ||
| const rows = this.sql.exec(query, ...bound).toArray().map(normalizeRow); | ||
| return Promise.resolve({ rows }); | ||
| }; |
Comment on lines
92
to
94
| const existing = `import { db } from "../db"; | ||
| import { Int8, Text } from "typegres"; | ||
| import { Int8, Text } from "typegres/core"; | ||
|
|
Comment on lines
+24
to
+26
| const query = stripMatchedOuterParens(text); | ||
| const bound = values.map((v) => (typeof v === "bigint" ? Number(v) : v)); | ||
| const rows = this.sql.exec(query, ...bound).toArray().map(normalizeRow); |
Comment on lines
+23
to
27
| entry: ["src/index.ts", "src/config.ts", "src/builder/sql.ts", "src/types/postgres/index.ts", "src/types/sqlite/index.ts", "src/cli.ts", "src/exoeval/index.ts", "src/capnweb/shim.ts", "src/drivers/do.ts", "src/drivers/pg.ts", "src/drivers/pglite.ts", "src/drivers/sqlite.ts"], | ||
| format: ["esm"], | ||
| clean: true, | ||
| deps: { neverBundle: ["pg", "@electric-sql/pglite", "better-sqlite3"] }, | ||
| deps: { neverBundle: ["pg", "@electric-sql/pglite", "better-sqlite3", "capnweb"] }, | ||
| plugins: [swcPlugin()], |
ryanrasti
force-pushed
the
ryan_do_sqlite_packaging
branch
from
July 17, 2026 23:24
32ba10f to
004c70f
Compare
ryanrasti
force-pushed
the
ryan_do_sqlite_packaging
branch
from
July 17, 2026 23:26
004c70f to
306ee30
Compare
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.
Worker-safe packaging: DoSqliteDriver on typegres/do-sqlite, schema/runtime on typegres/core (no optional node peers). Make better-sqlite3 an optional peer; export typegres/capnweb. Codegen emits typegres/core imports. SQLite introspector only marks single-column INTEGER PRIMARY KEY as generated (composite PKs are not rowid aliases). Document usage in guidelines.md and access-context.md; update basic/sqlite example table imports.