Skip to content

Commit b621468

Browse files
committed
Add DoSqliteDriver, typegres/core + do-sqlite entries, codegen fixes
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). Update basic/sqlite example table imports.
1 parent 2f33ae7 commit b621468

21 files changed

Lines changed: 242 additions & 103 deletions

examples/basic/src/tables/collars.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { db } from "../db";
2-
import { expose } from "typegres";
2+
import { expose } from "typegres/core";
33
import { Int8, Text } from "typegres/postgres";
44
import { Dogs } from "./dogs";
55

examples/basic/src/tables/dogs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { db } from "../db";
2-
import { expose, sql } from "typegres";
2+
import { expose, sql } from "typegres/core";
33
import { Int8, Text, Timestamptz } from "typegres/postgres";
44
import { Teams } from "./teams";
55
import { Collars } from "./collars";

examples/basic/src/tables/microchips.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { db } from "../db";
2-
import { expose } from "typegres";
2+
import { expose } from "typegres/core";
33
import { Int8, Text } from "typegres/postgres";
44
import { Dogs } from "./dogs";
55

examples/basic/src/tables/teams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { db } from "../db";
2-
import { expose } from "typegres";
2+
import { expose } from "typegres/core";
33
import { Int8, Text } from "typegres/postgres";
44
import { Dogs } from "./dogs";
55

examples/basic/src/tables/toys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { db } from "../db";
2-
import { expose } from "typegres";
2+
import { expose } from "typegres/core";
33
import { Int8, Text } from "typegres/postgres";
44
import { Dogs } from "./dogs";
55

examples/sqlite/src/tables/dogs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { db } from "../db";
2-
import { expose } from "typegres";
2+
import { expose } from "typegres/core";
33
import { Integer, Text } from "typegres/sqlite";
44
import { Teams } from "./teams";
55

examples/sqlite/src/tables/teams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { db } from "../db";
2-
import { expose } from "typegres";
2+
import { expose } from "typegres/core";
33
import { Integer, Text } from "typegres/sqlite";
44
import { Dogs } from "./dogs";
55

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
"./exoeval": {
2929
"import": "./dist/exoeval/index.mjs",
3030
"types": "./dist/exoeval/index.d.mts"
31+
},
32+
"./capnweb": {
33+
"import": "./dist/capnweb/shim.mjs",
34+
"types": "./dist/capnweb/shim.d.mts"
35+
},
36+
"./do-sqlite": {
37+
"import": "./dist/driver-do-sqlite.mjs",
38+
"types": "./dist/driver-do-sqlite.d.mts"
39+
},
40+
"./core": {
41+
"import": "./dist/core.mjs",
42+
"types": "./dist/core.d.mts"
3143
}
3244
},
3345
"bin": {
@@ -38,14 +50,18 @@
3850
],
3951
"peerDependencies": {
4052
"@electric-sql/pglite": "^0.4.4",
41-
"pg": "^8.20.0"
53+
"pg": "^8.20.0",
54+
"better-sqlite3": "^12.11.1"
4255
},
4356
"peerDependenciesMeta": {
4457
"@electric-sql/pglite": {
4558
"optional": true
4659
},
4760
"pg": {
4861
"optional": true
62+
},
63+
"better-sqlite3": {
64+
"optional": true
4965
}
5066
},
5167
"engines": {
@@ -54,7 +70,7 @@
5470
"scripts": {
5571
"build": "tsdown",
5672
"codegen": "node --experimental-strip-types src/types/postgres/emit.ts && node --experimental-strip-types src/types/sqlite/emit.ts",
57-
"codegen:check": "tmp=$(mktemp -d) && node --experimental-strip-types src/types/postgres/emit.ts --out-dir \"$tmp/pg\" && { diff -r \"$tmp/pg\" src/types/postgres/generated || { echo 'src/types/postgres/generated is stale \u2014 run `npm run codegen` and commit.' >&2; rm -rf \"$tmp\"; exit 1; }; } && node --experimental-strip-types src/types/sqlite/emit.ts --out-dir \"$tmp/sqlite\" && { diff -r \"$tmp/sqlite/generated\" src/types/sqlite/generated || { echo 'src/types/sqlite/generated is stale \u2014 run `npm run codegen` and commit.' >&2; rm -rf \"$tmp\"; exit 1; }; } && rm -rf \"$tmp\"",
73+
"codegen:check": "tmp=$(mktemp -d) && node --experimental-strip-types src/types/postgres/emit.ts --out-dir \"$tmp/pg\" && { diff -r \"$tmp/pg\" src/types/postgres/generated || { echo 'src/types/postgres/generated is stale run `npm run codegen` and commit.' >&2; rm -rf \"$tmp\"; exit 1; }; } && node --experimental-strip-types src/types/sqlite/emit.ts --out-dir \"$tmp/sqlite\" && { diff -r \"$tmp/sqlite/generated\" src/types/sqlite/generated || { echo 'src/types/sqlite/generated is stale run `npm run codegen` and commit.' >&2; rm -rf \"$tmp\"; exit 1; }; } && rm -rf \"$tmp\"",
5874
"lint": "eslint src",
5975
"typecheck": "tsgo --noEmit",
6076
"format": "prettier --write src",

site/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ public/demo.ts.static
1010
public/events-*.js
1111
public/chunk-*.js
1212
public/lib-*.js
13+
public/rolldown-runtime-*.js

src/core.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Side-effect-free runtime surface: schema, SQL, tables, @expose — no
2+
// optional peer drivers. Prefer this entry (or selective subpaths) from
3+
// workerd / Durable Object bundles so pg / better-sqlite3 / pglite never
4+
// enter the module graph. Node apps can keep using `typegres` root.
5+
6+
export { Database, Connection } from "./database";
7+
export type { TransactionIsolation, TransactionOptions } from "./database";
8+
export { Table } from "./table";
9+
export { sql, Sql } from "./builder/sql";
10+
export { QueryBuilder } from "./builder/query";
11+
export { expose } from "./exoeval/tool";
12+
export type { ToolFunction } from "./exoeval/tool";
13+
export type { Driver, ExecuteFn, QueryResult } from "./driver-shared";

0 commit comments

Comments
 (0)