Skip to content

Add DoSqliteDriver, typegres/core + do-sqlite entries, codegen fixes - #87

Merged
ryanrasti merged 1 commit into
mainfrom
ryan_do_sqlite_packaging
Jul 17, 2026
Merged

Add DoSqliteDriver, typegres/core + do-sqlite entries, codegen fixes#87
ryanrasti merged 1 commit into
mainfrom
ryan_do_sqlite_packaging

Conversation

@ryanrasti

Copy link
Copy Markdown
Owner

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and typegres/capnweb subpath exports; update build entries to emit them.
  • Introduce DoSqliteDriver + shared driver contract utilities in driver-shared.ts to avoid pulling optional Node-only peers into worker bundles.
  • Update codegen + tests/examples to import expose/sql from typegres/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 thread src/tables/sqlite.ts
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 thread src/tables/sqlite.ts
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 thread src/drivers/do.ts
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";

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Comment thread src/drivers/do.ts Outdated
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 thread tsdown.config.ts
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
ryanrasti force-pushed the ryan_do_sqlite_packaging branch from 32ba10f to 004c70f Compare July 17, 2026 23:24
@ryanrasti
ryanrasti force-pushed the ryan_do_sqlite_packaging branch from 004c70f to 306ee30 Compare July 17, 2026 23:26
@ryanrasti
ryanrasti merged commit 4bc9a71 into main Jul 17, 2026
3 checks passed
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.

2 participants