turbine-orm 0.50.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -66
- package/dist/adapters/cockroachdb.d.ts +5 -5
- package/dist/adapters/cockroachdb.js +10 -10
- package/dist/adapters/index.d.ts +5 -5
- package/dist/adapters/index.js +7 -7
- package/dist/adapters/yugabytedb.d.ts +7 -7
- package/dist/adapters/yugabytedb.js +10 -10
- package/dist/cjs/adapters/cockroachdb.d.ts +5 -5
- package/dist/cjs/adapters/cockroachdb.js +10 -10
- package/dist/cjs/adapters/index.d.ts +5 -5
- package/dist/cjs/adapters/index.js +7 -7
- package/dist/cjs/adapters/yugabytedb.d.ts +7 -7
- package/dist/cjs/adapters/yugabytedb.js +10 -10
- package/dist/cjs/cli/config.d.ts +13 -2
- package/dist/cjs/cli/config.js +3 -2
- package/dist/cjs/cli/destructive.d.ts +1 -1
- package/dist/cjs/cli/destructive.js +1 -1
- package/dist/cjs/cli/index.d.ts +10 -10
- package/dist/cjs/cli/index.js +49 -45
- package/dist/cjs/cli/loader.d.ts +7 -7
- package/dist/cjs/cli/loader.js +9 -9
- package/dist/cjs/cli/mcp.js +4 -4
- package/dist/cjs/cli/migrate.d.ts +5 -5
- package/dist/cjs/cli/migrate.js +11 -11
- package/dist/cjs/cli/studio-ui.generated.js +1 -1
- package/dist/cjs/cli/ui.d.ts +2 -2
- package/dist/cjs/cli/ui.js +2 -2
- package/dist/cjs/client.d.ts +49 -38
- package/dist/cjs/client.js +57 -56
- package/dist/cjs/dialect.d.ts +62 -18
- package/dist/cjs/dialect.js +40 -2
- package/dist/cjs/errors.d.ts +5 -5
- package/dist/cjs/errors.js +11 -11
- package/dist/cjs/generate.d.ts +6 -6
- package/dist/cjs/generate.js +31 -29
- package/dist/cjs/index-advisor.d.ts +5 -5
- package/dist/cjs/index-advisor.js +0 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/introspect.d.ts +35 -9
- package/dist/cjs/introspect.js +83 -32
- package/dist/cjs/mssql.d.ts +11 -11
- package/dist/cjs/mssql.js +64 -29
- package/dist/cjs/mysql.d.ts +8 -8
- package/dist/cjs/mysql.js +61 -23
- package/dist/cjs/nested-write.d.ts +21 -2
- package/dist/cjs/nested-write.js +51 -14
- package/dist/cjs/optional-peer-import.cjs +7 -7
- package/dist/cjs/optional-peer-import.d.cts +7 -7
- package/dist/cjs/pipeline-submittable.d.ts +2 -2
- package/dist/cjs/pipeline-submittable.js +6 -6
- package/dist/cjs/pipeline.d.ts +1 -1
- package/dist/cjs/pipeline.js +4 -4
- package/dist/cjs/powdb-introspect.d.ts +1 -1
- package/dist/cjs/powdb-introspect.js +1 -1
- package/dist/cjs/powdb.d.ts +28 -28
- package/dist/cjs/powdb.js +66 -66
- package/dist/cjs/powql.d.ts +27 -27
- package/dist/cjs/powql.js +73 -52
- package/dist/cjs/query/aggregates.d.ts +1 -1
- package/dist/cjs/query/aggregates.js +5 -5
- package/dist/cjs/query/batched-loader.d.ts +11 -11
- package/dist/cjs/query/batched-loader.js +24 -24
- package/dist/cjs/query/builder.d.ts +39 -21
- package/dist/cjs/query/builder.js +99 -57
- package/dist/cjs/query/compound-unique.d.ts +1 -1
- package/dist/cjs/query/compound-unique.js +0 -0
- package/dist/cjs/query/deferred.d.ts +12 -6
- package/dist/cjs/query/deferred.js +1 -1
- package/dist/cjs/query/filters.d.ts +31 -11
- package/dist/cjs/query/filters.js +67 -14
- package/dist/cjs/query/index.d.ts +1 -1
- package/dist/cjs/query/index.js +1 -1
- package/dist/cjs/query/relations.d.ts +9 -9
- package/dist/cjs/query/relations.js +164 -57
- package/dist/cjs/query/types.d.ts +86 -35
- package/dist/cjs/query/types.js +1 -1
- package/dist/cjs/query/utils.d.ts +27 -10
- package/dist/cjs/query/utils.js +86 -14
- package/dist/cjs/query/where.d.ts +47 -28
- package/dist/cjs/query/where.js +130 -31
- package/dist/cjs/query/writes.d.ts +24 -5
- package/dist/cjs/query/writes.js +102 -13
- package/dist/cjs/realtime.d.ts +7 -7
- package/dist/cjs/realtime.js +9 -9
- package/dist/cjs/schema-builder.d.ts +18 -7
- package/dist/cjs/schema-builder.js +17 -10
- package/dist/cjs/schema-metadata.d.ts +3 -3
- package/dist/cjs/schema-metadata.js +9 -9
- package/dist/cjs/schema-sql.d.ts +9 -9
- package/dist/cjs/schema-sql.js +20 -20
- package/dist/cjs/schema.d.ts +19 -9
- package/dist/cjs/schema.js +6 -6
- package/dist/cjs/serverless.d.ts +15 -15
- package/dist/cjs/serverless.js +16 -16
- package/dist/cjs/sqlite.d.ts +8 -8
- package/dist/cjs/sqlite.js +53 -22
- package/dist/cjs/typed-sql.d.ts +4 -4
- package/dist/cjs/typed-sql.js +5 -5
- package/dist/cli/config.d.ts +13 -2
- package/dist/cli/config.js +3 -2
- package/dist/cli/destructive.d.ts +1 -1
- package/dist/cli/destructive.js +1 -1
- package/dist/cli/index.d.ts +10 -10
- package/dist/cli/index.js +49 -45
- package/dist/cli/loader.d.ts +7 -7
- package/dist/cli/loader.js +9 -9
- package/dist/cli/mcp.js +4 -4
- package/dist/cli/migrate.d.ts +5 -5
- package/dist/cli/migrate.js +11 -11
- package/dist/cli/studio-ui.generated.js +1 -1
- package/dist/cli/ui.d.ts +2 -2
- package/dist/cli/ui.js +2 -2
- package/dist/client.d.ts +49 -38
- package/dist/client.js +57 -56
- package/dist/dialect.d.ts +62 -18
- package/dist/dialect.js +40 -2
- package/dist/errors.d.ts +5 -5
- package/dist/errors.js +11 -11
- package/dist/generate.d.ts +6 -6
- package/dist/generate.js +31 -29
- package/dist/index-advisor.d.ts +5 -5
- package/dist/index-advisor.js +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/dist/introspect.d.ts +35 -9
- package/dist/introspect.js +82 -32
- package/dist/mssql.d.ts +11 -11
- package/dist/mssql.js +64 -29
- package/dist/mysql.d.ts +8 -8
- package/dist/mysql.js +61 -23
- package/dist/nested-write.d.ts +21 -2
- package/dist/nested-write.js +51 -14
- package/dist/optional-peer-import.cjs +7 -7
- package/dist/optional-peer-import.d.cts +7 -7
- package/dist/pipeline-submittable.d.ts +2 -2
- package/dist/pipeline-submittable.js +6 -6
- package/dist/pipeline.d.ts +1 -1
- package/dist/pipeline.js +4 -4
- package/dist/powdb-introspect.d.ts +1 -1
- package/dist/powdb-introspect.js +1 -1
- package/dist/powdb.d.ts +28 -28
- package/dist/powdb.js +66 -66
- package/dist/powql.d.ts +27 -27
- package/dist/powql.js +73 -52
- package/dist/query/aggregates.d.ts +1 -1
- package/dist/query/aggregates.js +5 -5
- package/dist/query/batched-loader.d.ts +11 -11
- package/dist/query/batched-loader.js +24 -24
- package/dist/query/builder.d.ts +39 -21
- package/dist/query/builder.js +100 -58
- package/dist/query/compound-unique.d.ts +1 -1
- package/dist/query/compound-unique.js +0 -0
- package/dist/query/deferred.d.ts +12 -6
- package/dist/query/deferred.js +1 -1
- package/dist/query/filters.d.ts +31 -11
- package/dist/query/filters.js +66 -13
- package/dist/query/index.d.ts +1 -1
- package/dist/query/index.js +1 -1
- package/dist/query/relations.d.ts +9 -9
- package/dist/query/relations.js +165 -58
- package/dist/query/types.d.ts +86 -35
- package/dist/query/types.js +1 -1
- package/dist/query/utils.d.ts +27 -10
- package/dist/query/utils.js +84 -14
- package/dist/query/where.d.ts +47 -28
- package/dist/query/where.js +129 -32
- package/dist/query/writes.d.ts +24 -5
- package/dist/query/writes.js +101 -13
- package/dist/realtime.d.ts +7 -7
- package/dist/realtime.js +9 -9
- package/dist/schema-builder.d.ts +18 -7
- package/dist/schema-builder.js +17 -10
- package/dist/schema-metadata.d.ts +3 -3
- package/dist/schema-metadata.js +9 -9
- package/dist/schema-sql.d.ts +9 -9
- package/dist/schema-sql.js +20 -20
- package/dist/schema.d.ts +19 -9
- package/dist/schema.js +6 -6
- package/dist/serverless.d.ts +15 -15
- package/dist/serverless.js +16 -16
- package/dist/sqlite.d.ts +8 -8
- package/dist/sqlite.js +53 -22
- package/dist/typed-sql.d.ts +4 -4
- package/dist/typed-sql.js +5 -5
- package/package.json +2 -2
package/dist/cjs/schema-sql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* turbine-orm
|
|
2
|
+
* turbine-orm, Schema SQL Generator
|
|
3
3
|
*
|
|
4
4
|
* Converts a SchemaDef (from defineSchema) into executable DDL statements.
|
|
5
5
|
* Also provides diff and push commands for syncing schema to a live database.
|
|
@@ -15,7 +15,7 @@ export interface SchemaSqlOptions {
|
|
|
15
15
|
/**
|
|
16
16
|
* How to handle the pgvector extension when the schema contains a `vector`
|
|
17
17
|
* column. `'auto'` (default) prepends `CREATE EXTENSION IF NOT EXISTS vector;`
|
|
18
|
-
*
|
|
18
|
+
* - appropriate for `push`. `'manual'` emits a leading comment only, so the
|
|
19
19
|
* generated `.sql` migration doesn't silently require superuser privileges.
|
|
20
20
|
*/
|
|
21
21
|
extensions?: 'auto' | 'manual';
|
|
@@ -72,11 +72,11 @@ export interface AlterDef {
|
|
|
72
72
|
columns: AlterColumnDef[];
|
|
73
73
|
}
|
|
74
74
|
export interface DiffResult {
|
|
75
|
-
/** Tables that exist in schema but not in DB
|
|
75
|
+
/** Tables that exist in schema but not in DB, need CREATE TABLE */
|
|
76
76
|
create: TableDef[];
|
|
77
|
-
/** Tables that exist in both but differ
|
|
77
|
+
/** Tables that exist in both but differ, need ALTER TABLE */
|
|
78
78
|
alter: AlterDef[];
|
|
79
|
-
/** Table names that exist in DB but not in schema
|
|
79
|
+
/** Table names that exist in DB but not in schema, would need DROP TABLE */
|
|
80
80
|
drop: string[];
|
|
81
81
|
/** SQL statements to execute the diff (UP direction) */
|
|
82
82
|
statements: string[];
|
|
@@ -85,7 +85,7 @@ export interface DiffResult {
|
|
|
85
85
|
/**
|
|
86
86
|
* Human-readable warnings for changes the diff detected but refuses to apply
|
|
87
87
|
* automatically because they are destructive or otherwise unsafe (enum value
|
|
88
|
-
* removal/reorder, etc.). Never executed
|
|
88
|
+
* removal/reorder, etc.). Never executed, surfaced for the operator.
|
|
89
89
|
*/
|
|
90
90
|
warnings?: string[];
|
|
91
91
|
}
|
|
@@ -106,7 +106,7 @@ export interface DbForeignKey {
|
|
|
106
106
|
export declare function buildAddForeignKeyStatement(table: string, constraintName: string, column: string, targetTable: string, targetColumn: string, onDelete: ReferentialAction, onUpdate: ReferentialAction, dialect?: Dialect): string;
|
|
107
107
|
/**
|
|
108
108
|
* Decide whether a FK's referential actions changed. When they differ, returns
|
|
109
|
-
* the DROP + ADD CONSTRAINT statements (and their reverse)
|
|
109
|
+
* the DROP + ADD CONSTRAINT statements (and their reverse), Postgres has no
|
|
110
110
|
* `ALTER CONSTRAINT` for referential actions, so drop-and-recreate is the only
|
|
111
111
|
* path. Returns null when the actions already match.
|
|
112
112
|
*/
|
|
@@ -117,7 +117,7 @@ export declare function diffReferentialAction(table: string, db: DbForeignKey, s
|
|
|
117
117
|
/**
|
|
118
118
|
* Compute append-only enum value changes. Returns `ALTER TYPE ... ADD VALUE`
|
|
119
119
|
* statements for labels present in the schema but not the DB (in order), plus a
|
|
120
|
-
* destructive warning for any DB label the schema dropped or any reorder
|
|
120
|
+
* destructive warning for any DB label the schema dropped or any reorder -
|
|
121
121
|
* Postgres cannot remove or reorder enum values without recreating the type.
|
|
122
122
|
*/
|
|
123
123
|
export declare function diffEnumValues(enumName: string, schemaLabels: readonly string[], dbLabels: readonly string[], dialect?: Dialect): {
|
|
@@ -147,7 +147,7 @@ export interface CheckSpec {
|
|
|
147
147
|
* Diff a table's CHECK constraints (matched by name). Adds constraints missing
|
|
148
148
|
* from the DB, drops DB constraints absent from the schema, and drop+adds when a
|
|
149
149
|
* same-named constraint's expression changed. Expression comparison is a naive
|
|
150
|
-
* whitespace-insensitive match
|
|
150
|
+
* whitespace-insensitive match, semantically-equal-but-different-spelled
|
|
151
151
|
* expressions may re-emit (documented; harmless drop+add).
|
|
152
152
|
*/
|
|
153
153
|
export declare function diffCheckConstraints(table: string, schemaChecks: readonly CheckSpec[], dbChecks: readonly CheckSpec[], dialect?: Dialect): {
|
package/dist/cjs/schema-sql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* turbine-orm
|
|
3
|
+
* turbine-orm, Schema SQL Generator
|
|
4
4
|
*
|
|
5
5
|
* Converts a SchemaDef (from defineSchema) into executable DDL statements.
|
|
6
6
|
* Also provides diff and push commands for syncing schema to a live database.
|
|
@@ -51,7 +51,7 @@ function quoteEnumLabel(label) {
|
|
|
51
51
|
/**
|
|
52
52
|
* Whether a resolved column type is an auto-increment pseudo-type (SERIAL /
|
|
53
53
|
* BIGSERIAL). These carry an implicit sequence default and NOT NULL, and their
|
|
54
|
-
* underlying integer width (int4 vs int8) is never auto-migrated by diff
|
|
54
|
+
* underlying integer width (int4 vs int8) is never auto-migrated by diff, a
|
|
55
55
|
* width change on a live PK is destructive and must be done by hand.
|
|
56
56
|
*/
|
|
57
57
|
function isSerialType(type) {
|
|
@@ -74,7 +74,7 @@ function generateCreateEnumType(enumName, labels, dialect) {
|
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Resolve the DDL type token for a column: an enum type name, a `vector(n)`
|
|
77
|
-
* literal, or the dialect's scalar type
|
|
77
|
+
* literal, or the dialect's scalar type, with a trailing `[]` for arrays.
|
|
78
78
|
*
|
|
79
79
|
* `vectorDimensions` is the one number interpolated into the type token, so it
|
|
80
80
|
* is validated here as a positive integer within pgvector's limit rather than
|
|
@@ -99,7 +99,7 @@ function resolveDdlType(config, dialect, columnName) {
|
|
|
99
99
|
return config.isArray ? `${base}[]` : base;
|
|
100
100
|
}
|
|
101
101
|
// ---------------------------------------------------------------------------
|
|
102
|
-
// SQL Generation
|
|
102
|
+
// SQL Generation, SchemaDef → CREATE TABLE statements
|
|
103
103
|
// ---------------------------------------------------------------------------
|
|
104
104
|
/**
|
|
105
105
|
* Convert a SchemaDef into an ordered array of SQL DDL statements.
|
|
@@ -114,7 +114,7 @@ function schemaToSQL(schema, options) {
|
|
|
114
114
|
// Topologically sort tables by their foreign key references
|
|
115
115
|
const sorted = topologicalSort(schema);
|
|
116
116
|
const resolveRef = makeRefResolver(schema);
|
|
117
|
-
// pgvector extension line
|
|
117
|
+
// pgvector extension line, only when a vector column exists. Postgres-only:
|
|
118
118
|
// a dialect that can't do pgvector must not silently emit broken DDL.
|
|
119
119
|
if (schemaHasVectorColumn(schema)) {
|
|
120
120
|
if (!dialect.supportsVector) {
|
|
@@ -198,7 +198,7 @@ function topologicalSort(schema) {
|
|
|
198
198
|
if (resolved.has(name))
|
|
199
199
|
return;
|
|
200
200
|
if (visiting.has(name)) {
|
|
201
|
-
// Circular reference
|
|
201
|
+
// Circular reference, just add it
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
204
|
visiting.add(name);
|
|
@@ -268,7 +268,7 @@ function generateCreateTable(table, resolveRef, dialect = dialect_js_1.postgresD
|
|
|
268
268
|
*/
|
|
269
269
|
function generateColumnDef(fieldName, config, resolveRef, dialect = dialect_js_1.postgresDialect) {
|
|
270
270
|
const snakeName = (0, schema_js_1.camelToSnake)(fieldName);
|
|
271
|
-
// NOT NULL
|
|
271
|
+
// NOT NULL, serial types are implicitly NOT NULL, but explicit is fine.
|
|
272
272
|
// A column is NOT NULL if:
|
|
273
273
|
// 1. Explicitly marked .notNull(), OR
|
|
274
274
|
// 2. Is a serial (BIGSERIAL implies NOT NULL), OR
|
|
@@ -282,7 +282,7 @@ function generateColumnDef(fieldName, config, resolveRef, dialect = dialect_js_1
|
|
|
282
282
|
if (config.defaultValue != null) {
|
|
283
283
|
defaultValue = normalizeDefault(config.defaultValue);
|
|
284
284
|
}
|
|
285
|
-
// REFERENCES
|
|
285
|
+
// REFERENCES, resolve the raw table name through the optional resolver so
|
|
286
286
|
// both camelCase accessor names and snake_case DDL names work.
|
|
287
287
|
let references;
|
|
288
288
|
if (config.referencesTarget) {
|
|
@@ -511,7 +511,7 @@ function buildAddForeignKeyStatement(table, constraintName, column, targetTable,
|
|
|
511
511
|
}
|
|
512
512
|
/**
|
|
513
513
|
* Decide whether a FK's referential actions changed. When they differ, returns
|
|
514
|
-
* the DROP + ADD CONSTRAINT statements (and their reverse)
|
|
514
|
+
* the DROP + ADD CONSTRAINT statements (and their reverse), Postgres has no
|
|
515
515
|
* `ALTER CONSTRAINT` for referential actions, so drop-and-recreate is the only
|
|
516
516
|
* path. Returns null when the actions already match.
|
|
517
517
|
*/
|
|
@@ -527,7 +527,7 @@ function diffReferentialAction(table, db, schemaOnDelete, schemaOnUpdate, dialec
|
|
|
527
527
|
/**
|
|
528
528
|
* Compute append-only enum value changes. Returns `ALTER TYPE ... ADD VALUE`
|
|
529
529
|
* statements for labels present in the schema but not the DB (in order), plus a
|
|
530
|
-
* destructive warning for any DB label the schema dropped or any reorder
|
|
530
|
+
* destructive warning for any DB label the schema dropped or any reorder -
|
|
531
531
|
* Postgres cannot remove or reorder enum values without recreating the type.
|
|
532
532
|
*/
|
|
533
533
|
function diffEnumValues(enumName, schemaLabels, dbLabels, dialect = dialect_js_1.postgresDialect) {
|
|
@@ -543,7 +543,7 @@ function diffEnumValues(enumName, schemaLabels, dbLabels, dialect = dialect_js_1
|
|
|
543
543
|
const removed = dbLabels.filter((l) => !schemaSet.has(l));
|
|
544
544
|
if (removed.length > 0) {
|
|
545
545
|
warnings.push(`Enum "${enumName}": labels [${removed.join(', ')}] exist in the database but not the schema. ` +
|
|
546
|
-
`Postgres cannot remove enum values in place
|
|
546
|
+
`Postgres cannot remove enum values in place, recreate the type manually if intended.`);
|
|
547
547
|
}
|
|
548
548
|
return { statements, warnings };
|
|
549
549
|
}
|
|
@@ -551,7 +551,7 @@ function diffEnumValues(enumName, schemaLabels, dbLabels, dialect = dialect_js_1
|
|
|
551
551
|
* Diff a table's CHECK constraints (matched by name). Adds constraints missing
|
|
552
552
|
* from the DB, drops DB constraints absent from the schema, and drop+adds when a
|
|
553
553
|
* same-named constraint's expression changed. Expression comparison is a naive
|
|
554
|
-
* whitespace-insensitive match
|
|
554
|
+
* whitespace-insensitive match, semantically-equal-but-different-spelled
|
|
555
555
|
* expressions may re-emit (documented; harmless drop+add).
|
|
556
556
|
*/
|
|
557
557
|
function diffCheckConstraints(table, schemaChecks, dbChecks, dialect = dialect_js_1.postgresDialect) {
|
|
@@ -733,7 +733,7 @@ async function schemaDiff(schema, connectionString) {
|
|
|
733
733
|
result.statements.push(...fkIndexes);
|
|
734
734
|
// User-declared indexes on a brand-new table (reversed by the DROP TABLE).
|
|
735
735
|
result.statements.push(...generateDeclaredIndexes(tableDef, dialect));
|
|
736
|
-
// Reverse: DROP TABLE (with indexes
|
|
736
|
+
// Reverse: DROP TABLE (with indexes, they drop automatically)
|
|
737
737
|
result.reverseStatements.unshift(`DROP TABLE IF EXISTS ${dialect.quoteIdentifier(ddlName)} CASCADE;`);
|
|
738
738
|
}
|
|
739
739
|
}
|
|
@@ -757,7 +757,7 @@ async function schemaDiff(schema, connectionString) {
|
|
|
757
757
|
const snakeName = (0, schema_js_1.camelToSnake)(fieldName);
|
|
758
758
|
const dbCol = dbCols[snakeName];
|
|
759
759
|
if (!dbCol) {
|
|
760
|
-
// Column exists in schema but not in DB
|
|
760
|
+
// Column exists in schema but not in DB, ADD COLUMN
|
|
761
761
|
const colDef = generateColumnDef(fieldName, config, resolveRef, dialect);
|
|
762
762
|
const sql = `ALTER TABLE ${dialect.quoteIdentifier(tableName)} ADD COLUMN ${colDef};`;
|
|
763
763
|
const reverseSql = `ALTER TABLE ${dialect.quoteIdentifier(tableName)} DROP COLUMN ${dialect.quoteIdentifier(snakeName)};`;
|
|
@@ -770,10 +770,10 @@ async function schemaDiff(schema, connectionString) {
|
|
|
770
770
|
// underlying int4/int8 width must never be auto-altered on a live table
|
|
771
771
|
// (a downcast on a PK loses data / breaks the sequence). This also
|
|
772
772
|
// preserves back-compat for DBs whose `serial` columns were created as
|
|
773
|
-
// BIGSERIAL (int8) before 0.24.0
|
|
773
|
+
// BIGSERIAL (int8) before 0.24.0, `push` won't try to shrink them.
|
|
774
774
|
const expectedUdt = schemaTypeToUdt(config);
|
|
775
775
|
if (expectedUdt && !isSerialType(config.type) && dbCol.udtName !== expectedUdt) {
|
|
776
|
-
// resolveDdlType handles enum names, vector(n), arrays, and VARCHAR(n)
|
|
776
|
+
// resolveDdlType handles enum names, vector(n), arrays, and VARCHAR(n) -
|
|
777
777
|
// config.type alone would emit the internal ENUM/VECTOR sentinels here.
|
|
778
778
|
const sqlType = resolveDdlType(config, dialect, snakeName);
|
|
779
779
|
const oldSqlType = udtToSqlType(dbCol.udtName, dbCol.maxLength);
|
|
@@ -833,7 +833,7 @@ async function schemaDiff(schema, connectionString) {
|
|
|
833
833
|
result.reverseStatements.unshift(reverseSql);
|
|
834
834
|
}
|
|
835
835
|
}
|
|
836
|
-
// Check UNIQUE constraint mismatch (skip PKs
|
|
836
|
+
// Check UNIQUE constraint mismatch (skip PKs, they're implicitly unique)
|
|
837
837
|
if (!config.isPrimaryKey) {
|
|
838
838
|
const hasDbUnique = snakeName in tableUniques;
|
|
839
839
|
const wantsUnique = config.isUnique === true;
|
|
@@ -886,7 +886,7 @@ async function schemaDiff(schema, connectionString) {
|
|
|
886
886
|
const snakeName = (0, schema_js_1.camelToSnake)(fieldName);
|
|
887
887
|
const dbFk = tableFks[snakeName];
|
|
888
888
|
if (!dbFk)
|
|
889
|
-
continue; // FK not present in DB yet (or composite)
|
|
889
|
+
continue; // FK not present in DB yet (or composite), skip
|
|
890
890
|
const change = diffReferentialAction(tableName, dbFk, config.onDelete ?? 'no action', config.onUpdate ?? 'no action', dialect);
|
|
891
891
|
if (change) {
|
|
892
892
|
result.statements.push(...change.statements);
|
|
@@ -900,7 +900,7 @@ async function schemaDiff(schema, connectionString) {
|
|
|
900
900
|
// inline checks carry auto-generated names the code-first schema never
|
|
901
901
|
// sees), and we do NOT drop+add on expression mismatch: pg_get_constraintdef
|
|
902
902
|
// canonicalizes expressions (casts, ANY(ARRAY[...]) rewrites), so authored
|
|
903
|
-
// text almost never string-matches the stored form
|
|
903
|
+
// text almost never string-matches the stored form, comparing would emit a
|
|
904
904
|
// spurious full-table-revalidating drop+add on every diff. An apparent
|
|
905
905
|
// mismatch surfaces as a warning instead; rename the constraint to
|
|
906
906
|
// intentionally replace its expression. Unnamed schema checks are skipped
|
|
@@ -1078,7 +1078,7 @@ function defaultsMatch(schemaDefault, dbDefault) {
|
|
|
1078
1078
|
return a === b;
|
|
1079
1079
|
}
|
|
1080
1080
|
// ---------------------------------------------------------------------------
|
|
1081
|
-
// Schema Push
|
|
1081
|
+
// Schema Push, execute the diff against a live database
|
|
1082
1082
|
// ---------------------------------------------------------------------------
|
|
1083
1083
|
/**
|
|
1084
1084
|
* Scan a set of diff statements for data-destroying operations, using the same
|
package/dist/cjs/schema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* turbine-orm
|
|
2
|
+
* turbine-orm, Schema metadata types
|
|
3
3
|
*
|
|
4
4
|
* These types represent the introspected database schema at runtime.
|
|
5
5
|
* They're used by the query builder, code generator, and CLI.
|
|
@@ -70,7 +70,7 @@ export interface ColumnMetadata {
|
|
|
70
70
|
/**
|
|
71
71
|
* Schema the column's Postgres type lives in, recorded by introspection
|
|
72
72
|
* ONLY when it differs from the introspected schema (and isn't a
|
|
73
|
-
* `pg_catalog` builtin)
|
|
73
|
+
* `pg_catalog` builtin), e.g. an enum or domain owned by another schema.
|
|
74
74
|
* Consumers use it as a cross-schema guard: a same-named enum in another
|
|
75
75
|
* schema must not receive this schema's `::"enum"` cast (search_path would
|
|
76
76
|
* resolve it to the wrong type). Absent for same-schema types, builtins,
|
|
@@ -84,7 +84,7 @@ export interface ColumnMetadata {
|
|
|
84
84
|
/** Whether the column has a DEFAULT, is serial, or is generated */
|
|
85
85
|
hasDefault: boolean;
|
|
86
86
|
/**
|
|
87
|
-
* Whether the **database server** generates this column's value on insert
|
|
87
|
+
* Whether the **database server** generates this column's value on insert -
|
|
88
88
|
* a `serial`/`BIGSERIAL` sequence, an `IDENTITY` column, or PowDB's `auto`
|
|
89
89
|
* modifier. This is a strict subset of {@link hasDefault} (a server-generated
|
|
90
90
|
* column always reports `hasDefault: true`), but unlike a client-side default
|
|
@@ -96,8 +96,8 @@ export interface ColumnMetadata {
|
|
|
96
96
|
/**
|
|
97
97
|
* True when this is a Postgres **`GENERATED ALWAYS AS (expr) STORED`** column
|
|
98
98
|
* (`information_schema.columns.is_generated = 'ALWAYS'`). Distinct from
|
|
99
|
-
* {@link isGenerated}
|
|
100
|
-
* that a client MAY still override
|
|
99
|
+
* {@link isGenerated}, which flags a server-*assigned* identity/serial value
|
|
100
|
+
* that a client MAY still override, a STORED generated column's value is
|
|
101
101
|
* *computed from other columns* and can NEVER be supplied on insert/update
|
|
102
102
|
* (Postgres rejects it). Codegen therefore omits it from `*Create`/`*Update`
|
|
103
103
|
* input types, and the write builders reject any `data` containing it with a
|
|
@@ -120,6 +120,16 @@ export interface ColumnMetadata {
|
|
|
120
120
|
* Introspection never auto-tags PII (it is a code-first declaration).
|
|
121
121
|
*/
|
|
122
122
|
pii?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* True when this column should be set to the current time on every `update`
|
|
125
|
+
* that does not name it explicitly (Prisma's `@updatedAt`).
|
|
126
|
+
*
|
|
127
|
+
* A code-first declaration only (`defineSchema` `updatedAt: true` /
|
|
128
|
+
* `.updatedAt()`): introspection NEVER infers it from a column's name,
|
|
129
|
+
* because an application that already manages its own `updated_at` would
|
|
130
|
+
* silently have its writes changed. Untagged schemas emit byte-identical SQL.
|
|
131
|
+
*/
|
|
132
|
+
updatedAt?: boolean;
|
|
123
133
|
/** Whether this is an array column */
|
|
124
134
|
isArray: boolean;
|
|
125
135
|
/** Dialect-specific array/bulk-insert type token when needed. */
|
|
@@ -159,10 +169,10 @@ export interface RelationDef {
|
|
|
159
169
|
* For `manyToMany` relations only: the junction (join) table that links the
|
|
160
170
|
* source and target tables. The subquery JOINs the target through this table.
|
|
161
171
|
*
|
|
162
|
-
* - `table`
|
|
163
|
-
* - `sourceKey
|
|
172
|
+
* - `table` , junction table name (snake_case).
|
|
173
|
+
* - `sourceKey`, junction column(s) referencing the SOURCE table's
|
|
164
174
|
* {@link referenceKey} (typically the source PK).
|
|
165
|
-
* - `targetKey
|
|
175
|
+
* - `targetKey`, junction column(s) referencing the TARGET table's PK.
|
|
166
176
|
*
|
|
167
177
|
* Array forms support composite keys (paired positionally with the
|
|
168
178
|
* referenced columns). Omitted for non-m2m relations.
|
|
@@ -246,7 +256,7 @@ export declare function timeOfDayKind(dbType: string | undefined): 'time' | 'tim
|
|
|
246
256
|
* driver's local-offset serialization is CORRECT for it (Postgres converts the
|
|
247
257
|
* offset away). The two types here store the literal wall-clock fields they
|
|
248
258
|
* are given, so binding a JS `Date` through the driver stores the process's
|
|
249
|
-
* LOCAL calendar fields
|
|
259
|
+
* LOCAL calendar fields, in `America/Los_Angeles`, `2026-07-25T00:00:00Z`
|
|
250
260
|
* lands as `2026-07-24 17:00:00`. The read path already interprets an
|
|
251
261
|
* offset-less value as UTC (see `parseDbDate`), so the write path has to bind
|
|
252
262
|
* the UTC components for the round trip to be stable.
|
package/dist/cjs/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* turbine-orm
|
|
3
|
+
* turbine-orm, Schema metadata types
|
|
4
4
|
*
|
|
5
5
|
* These types represent the introspected database schema at runtime.
|
|
6
6
|
* They're used by the query builder, code generator, and CLI.
|
|
@@ -38,7 +38,7 @@ const PG_TO_TS = {
|
|
|
38
38
|
float4: 'number',
|
|
39
39
|
float8: 'number',
|
|
40
40
|
oid: 'number',
|
|
41
|
-
// Precision-sensitive
|
|
41
|
+
// Precision-sensitive, keep as string to avoid JS float issues
|
|
42
42
|
numeric: 'string',
|
|
43
43
|
money: 'string',
|
|
44
44
|
// Boolean
|
|
@@ -79,9 +79,9 @@ const PG_TO_TS = {
|
|
|
79
79
|
// TSVector
|
|
80
80
|
tsvector: 'string',
|
|
81
81
|
tsquery: 'string',
|
|
82
|
-
// pgvector
|
|
82
|
+
// pgvector, embeddings. Mapped to `number[]` for DX (the natural shape an app
|
|
83
83
|
// passes when inserting / comparing embeddings). NOTE: like `numeric` above,
|
|
84
|
-
// there is a runtime caveat
|
|
84
|
+
// there is a runtime caveat, pg has no built-in parser for the `vector` type,
|
|
85
85
|
// so over the wire a fetched vector arrives as a string literal like
|
|
86
86
|
// '[1,2,3]' unless the app registers its own parser (e.g. via pgvector's
|
|
87
87
|
// `registerType`). Turbine never auto-registers one (no side-effecting type
|
|
@@ -99,7 +99,7 @@ const DATE_TYPES = new Set(['timestamptz', 'timestamp', 'date']);
|
|
|
99
99
|
* `text`: the `text[]` fallback below then produces text-typed UNNEST output
|
|
100
100
|
* and Postgres refuses the insert with `42804 column "x" is of type <t> but
|
|
101
101
|
* expression is of type text`. `varchar` / `char` / `bpchar` deliberately keep
|
|
102
|
-
* the `text[]` cast
|
|
102
|
+
* the `text[]` cast, `text` assignment-casts to all three, and pinning them
|
|
103
103
|
* would change already-emitted SQL for no behavioral gain.
|
|
104
104
|
*/
|
|
105
105
|
const PG_TO_ARRAY = {
|
|
@@ -223,7 +223,7 @@ function timeOfDayKind(dbType) {
|
|
|
223
223
|
* driver's local-offset serialization is CORRECT for it (Postgres converts the
|
|
224
224
|
* offset away). The two types here store the literal wall-clock fields they
|
|
225
225
|
* are given, so binding a JS `Date` through the driver stores the process's
|
|
226
|
-
* LOCAL calendar fields
|
|
226
|
+
* LOCAL calendar fields, in `America/Los_Angeles`, `2026-07-25T00:00:00Z`
|
|
227
227
|
* lands as `2026-07-24 17:00:00`. The read path already interprets an
|
|
228
228
|
* offset-less value as UTC (see `parseDbDate`), so the write path has to bind
|
|
229
229
|
* the UTC components for the round trip to be stable.
|
package/dist/cjs/serverless.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* turbine-orm/serverless
|
|
2
|
+
* turbine-orm/serverless, edge / serverless driver integration
|
|
3
3
|
*
|
|
4
4
|
* Turbine runs on any Postgres driver that speaks the node-postgres API.
|
|
5
5
|
* This module exposes a thin factory (`turbineHttp`) that binds an external
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
* Any driver whose `Pool` satisfies `PgCompatPool` will work. The ones
|
|
13
13
|
* below are verified:
|
|
14
14
|
*
|
|
15
|
-
* - **Neon** (`@neondatabase/serverless`)
|
|
16
|
-
* - **Vercel Postgres** (`@vercel/postgres`)
|
|
17
|
-
* - **Cloudflare Hyperdrive
|
|
18
|
-
* - **Supabase
|
|
15
|
+
* - **Neon** (`@neondatabase/serverless`), HTTP and WebSocket transports
|
|
16
|
+
* - **Vercel Postgres** (`@vercel/postgres`), wraps Neon
|
|
17
|
+
* - **Cloudflare Hyperdrive**, exposes a pg-compatible driver
|
|
18
|
+
* - **Supabase**, use the regular `pg` package; Supabase is Postgres-native
|
|
19
19
|
*
|
|
20
|
-
* Turbine does NOT bundle any of these
|
|
20
|
+
* Turbine does NOT bundle any of these, install whichever you need and
|
|
21
21
|
* pass its pool directly.
|
|
22
22
|
*
|
|
23
23
|
* ## Limitations over HTTP
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
* If you call these on an HTTP pool the underlying driver will error.
|
|
28
28
|
* - **LISTEN/NOTIFY** is not available over HTTP.
|
|
29
29
|
* - **Transactions** are supported but each transaction holds an HTTP
|
|
30
|
-
* connection for its duration
|
|
30
|
+
* connection for its duration, keep them short.
|
|
31
31
|
*
|
|
32
|
-
* ## Example
|
|
32
|
+
* ## Example, Neon on Vercel Edge
|
|
33
33
|
*
|
|
34
34
|
* ```ts
|
|
35
35
|
* // app/api/users/route.ts
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* }
|
|
49
49
|
* ```
|
|
50
50
|
*
|
|
51
|
-
* ## Example
|
|
51
|
+
* ## Example, Supabase (direct Postgres, no HTTP proxy needed)
|
|
52
52
|
*
|
|
53
53
|
* ```ts
|
|
54
54
|
* import { TurbineClient } from 'turbine-orm';
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
* }, SCHEMA);
|
|
61
61
|
* ```
|
|
62
62
|
*
|
|
63
|
-
* ## Example
|
|
63
|
+
* ## Example, Cloudflare Workers
|
|
64
64
|
*
|
|
65
65
|
* ```ts
|
|
66
66
|
* // Use the Neon HTTP driver which works in Workers runtime
|
|
@@ -92,14 +92,14 @@ export interface TurbineHttpOptions extends Pick<TurbineConfig, 'logging' | 'def
|
|
|
92
92
|
*
|
|
93
93
|
* Use this for serverless/edge environments where Turbine should NOT
|
|
94
94
|
* manage its own `pg.Pool`. The caller retains ownership of the pool's
|
|
95
|
-
* lifecycle
|
|
95
|
+
* lifecycle, `db.disconnect()` is a no-op.
|
|
96
96
|
*
|
|
97
97
|
* ## Typed table accessors
|
|
98
98
|
*
|
|
99
99
|
* By default `turbineHttp` returns the base {@link TurbineClient}, so you
|
|
100
100
|
* reach tables through `db.table('users')`. To get the *generated*, fully
|
|
101
|
-
* typed accessors (`db.users.findMany()`)
|
|
102
|
-
* `turbine()` factory gives you
|
|
101
|
+
* typed accessors (`db.users.findMany()`), identical to what the TCP-path
|
|
102
|
+
* `turbine()` factory gives you, pass your generated client type as the
|
|
103
103
|
* `TClient` type argument. The runtime object is the same; the generated
|
|
104
104
|
* subclass only adds `declare readonly` accessor typings, and the base
|
|
105
105
|
* constructor already creates those accessors at runtime for every table in
|
|
@@ -116,7 +116,7 @@ export interface TurbineHttpOptions extends Pick<TurbineConfig, 'logging' | 'def
|
|
|
116
116
|
* @param options - Optional logging / defaultLimit / warnOnUnlimited
|
|
117
117
|
* @returns A TurbineClient instance (typed as `TClient`)
|
|
118
118
|
*
|
|
119
|
-
* @example Untyped (back-compat)
|
|
119
|
+
* @example Untyped (back-compat), reach tables via `db.table(...)`
|
|
120
120
|
* ```ts
|
|
121
121
|
* import { Pool } from '@neondatabase/serverless';
|
|
122
122
|
* import { turbineHttp } from 'turbine-orm/serverless';
|
|
@@ -127,7 +127,7 @@ export interface TurbineHttpOptions extends Pick<TurbineConfig, 'logging' | 'def
|
|
|
127
127
|
* const users = await db.table('users').findMany({ limit: 10 });
|
|
128
128
|
* ```
|
|
129
129
|
*
|
|
130
|
-
* @example Typed
|
|
130
|
+
* @example Typed, generated accessors, identical to the TCP client
|
|
131
131
|
* ```ts
|
|
132
132
|
* import { Pool } from '@neondatabase/serverless';
|
|
133
133
|
* import { turbineHttp } from 'turbine-orm/serverless';
|
package/dist/cjs/serverless.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* turbine-orm/serverless
|
|
3
|
+
* turbine-orm/serverless, edge / serverless driver integration
|
|
4
4
|
*
|
|
5
5
|
* Turbine runs on any Postgres driver that speaks the node-postgres API.
|
|
6
6
|
* This module exposes a thin factory (`turbineHttp`) that binds an external
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
* Any driver whose `Pool` satisfies `PgCompatPool` will work. The ones
|
|
14
14
|
* below are verified:
|
|
15
15
|
*
|
|
16
|
-
* - **Neon** (`@neondatabase/serverless`)
|
|
17
|
-
* - **Vercel Postgres** (`@vercel/postgres`)
|
|
18
|
-
* - **Cloudflare Hyperdrive
|
|
19
|
-
* - **Supabase
|
|
16
|
+
* - **Neon** (`@neondatabase/serverless`), HTTP and WebSocket transports
|
|
17
|
+
* - **Vercel Postgres** (`@vercel/postgres`), wraps Neon
|
|
18
|
+
* - **Cloudflare Hyperdrive**, exposes a pg-compatible driver
|
|
19
|
+
* - **Supabase**, use the regular `pg` package; Supabase is Postgres-native
|
|
20
20
|
*
|
|
21
|
-
* Turbine does NOT bundle any of these
|
|
21
|
+
* Turbine does NOT bundle any of these, install whichever you need and
|
|
22
22
|
* pass its pool directly.
|
|
23
23
|
*
|
|
24
24
|
* ## Limitations over HTTP
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
* If you call these on an HTTP pool the underlying driver will error.
|
|
29
29
|
* - **LISTEN/NOTIFY** is not available over HTTP.
|
|
30
30
|
* - **Transactions** are supported but each transaction holds an HTTP
|
|
31
|
-
* connection for its duration
|
|
31
|
+
* connection for its duration, keep them short.
|
|
32
32
|
*
|
|
33
|
-
* ## Example
|
|
33
|
+
* ## Example, Neon on Vercel Edge
|
|
34
34
|
*
|
|
35
35
|
* ```ts
|
|
36
36
|
* // app/api/users/route.ts
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
* }
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
|
-
* ## Example
|
|
52
|
+
* ## Example, Supabase (direct Postgres, no HTTP proxy needed)
|
|
53
53
|
*
|
|
54
54
|
* ```ts
|
|
55
55
|
* import { TurbineClient } from 'turbine-orm';
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
* }, SCHEMA);
|
|
62
62
|
* ```
|
|
63
63
|
*
|
|
64
|
-
* ## Example
|
|
64
|
+
* ## Example, Cloudflare Workers
|
|
65
65
|
*
|
|
66
66
|
* ```ts
|
|
67
67
|
* // Use the Neon HTTP driver which works in Workers runtime
|
|
@@ -87,14 +87,14 @@ const client_js_1 = require("./client.js");
|
|
|
87
87
|
*
|
|
88
88
|
* Use this for serverless/edge environments where Turbine should NOT
|
|
89
89
|
* manage its own `pg.Pool`. The caller retains ownership of the pool's
|
|
90
|
-
* lifecycle
|
|
90
|
+
* lifecycle, `db.disconnect()` is a no-op.
|
|
91
91
|
*
|
|
92
92
|
* ## Typed table accessors
|
|
93
93
|
*
|
|
94
94
|
* By default `turbineHttp` returns the base {@link TurbineClient}, so you
|
|
95
95
|
* reach tables through `db.table('users')`. To get the *generated*, fully
|
|
96
|
-
* typed accessors (`db.users.findMany()`)
|
|
97
|
-
* `turbine()` factory gives you
|
|
96
|
+
* typed accessors (`db.users.findMany()`), identical to what the TCP-path
|
|
97
|
+
* `turbine()` factory gives you, pass your generated client type as the
|
|
98
98
|
* `TClient` type argument. The runtime object is the same; the generated
|
|
99
99
|
* subclass only adds `declare readonly` accessor typings, and the base
|
|
100
100
|
* constructor already creates those accessors at runtime for every table in
|
|
@@ -111,7 +111,7 @@ const client_js_1 = require("./client.js");
|
|
|
111
111
|
* @param options - Optional logging / defaultLimit / warnOnUnlimited
|
|
112
112
|
* @returns A TurbineClient instance (typed as `TClient`)
|
|
113
113
|
*
|
|
114
|
-
* @example Untyped (back-compat)
|
|
114
|
+
* @example Untyped (back-compat), reach tables via `db.table(...)`
|
|
115
115
|
* ```ts
|
|
116
116
|
* import { Pool } from '@neondatabase/serverless';
|
|
117
117
|
* import { turbineHttp } from 'turbine-orm/serverless';
|
|
@@ -122,7 +122,7 @@ const client_js_1 = require("./client.js");
|
|
|
122
122
|
* const users = await db.table('users').findMany({ limit: 10 });
|
|
123
123
|
* ```
|
|
124
124
|
*
|
|
125
|
-
* @example Typed
|
|
125
|
+
* @example Typed, generated accessors, identical to the TCP client
|
|
126
126
|
* ```ts
|
|
127
127
|
* import { Pool } from '@neondatabase/serverless';
|
|
128
128
|
* import { turbineHttp } from 'turbine-orm/serverless';
|
|
@@ -138,6 +138,6 @@ function turbineHttp(pool, schema, options = {}) {
|
|
|
138
138
|
// The generated subclass only layers `declare readonly` accessor typings
|
|
139
139
|
// over the base client; the base constructor materializes those same
|
|
140
140
|
// accessors at runtime (Object.defineProperty per schema table). So the
|
|
141
|
-
// returned instance genuinely has TClient's shape
|
|
141
|
+
// returned instance genuinely has TClient's shape, the assertion is safe.
|
|
142
142
|
return new client_js_1.TurbineClient({ pool, ...options }, schema);
|
|
143
143
|
}
|
package/dist/cjs/sqlite.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* turbine-orm/sqlite
|
|
2
|
+
* turbine-orm/sqlite, zero-dependency SQLite engine
|
|
3
3
|
*
|
|
4
4
|
* Binds Turbine to SQLite via Node's built-in `node:sqlite` driver
|
|
5
5
|
* (`DatabaseSync`), so SQLite is a **zero new dependency** engine: the root
|
|
6
6
|
* package's runtime dependency stays exactly `pg`. This is the in-process
|
|
7
|
-
* test / edge / "try it in 10 seconds" engine
|
|
7
|
+
* test / edge / "try it in 10 seconds" engine, `:memory:` databases run
|
|
8
8
|
* entirely in-process with no service container.
|
|
9
9
|
*
|
|
10
10
|
* ## Driver
|
|
11
11
|
*
|
|
12
12
|
* - **Primary:** `node:sqlite` `DatabaseSync` (Node ≥ 22.5, experimental). Emits
|
|
13
|
-
* an `ExperimentalWarning
|
|
13
|
+
* an `ExperimentalWarning`, harmless. No native build, no extra dependency.
|
|
14
14
|
* - **Fallback:** `better-sqlite3` for Node < 22.5. Not bundled and not required;
|
|
15
15
|
* wrap a `better-sqlite3` handle in the same `PgCompatPool` shape if needed.
|
|
16
16
|
*
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* WAL` is enabled for file databases to allow concurrent readers.
|
|
25
25
|
* - **Unsupported (throw `UnsupportedFeatureError`):** pgvector distance ops,
|
|
26
26
|
* LISTEN/NOTIFY (`$listen` / `$notify`), RLS `sessionContext`. Advisory-lock
|
|
27
|
-
* migration locking is unavailable
|
|
27
|
+
* migration locking is unavailable, SQLite is single-writer, so migrations
|
|
28
28
|
* serialize naturally.
|
|
29
29
|
* - **Type affinity caveats:** SQLite has no native `BOOLEAN` (0/1 integers) or
|
|
30
30
|
* `DATE` (TEXT/INTEGER). Booleans bind as 1/0; `Date` values bind as ISO-8601
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* - **Case-insensitive matching** uses `COLLATE NOCASE`, which is **ASCII-only**
|
|
35
35
|
* (no Unicode case folding).
|
|
36
36
|
*
|
|
37
|
-
* ## Example
|
|
37
|
+
* ## Example, `:memory:` database
|
|
38
38
|
*
|
|
39
39
|
* ```ts
|
|
40
40
|
* import { turbineSqlite } from 'turbine-orm/sqlite';
|
|
@@ -58,12 +58,12 @@ type QueryArg = string | {
|
|
|
58
58
|
/**
|
|
59
59
|
* A `PgCompatPool` backed by a single `node:sqlite` `DatabaseSync` connection.
|
|
60
60
|
* SQLite is single-connection by nature (a `:memory:` database is per-handle),
|
|
61
|
-
* so `connect()` hands back a client over the **same** handle
|
|
61
|
+
* so `connect()` hands back a client over the **same** handle, transactions
|
|
62
62
|
* (`BEGIN`/`COMMIT`/`ROLLBACK`, `SAVEPOINT` nesting) just run on it. Queries are
|
|
63
63
|
* serialized; this is the documented single-writer model.
|
|
64
64
|
*/
|
|
65
65
|
export declare class SqlitePool implements PgCompatPool {
|
|
66
|
-
/** The underlying `node:sqlite` handle
|
|
66
|
+
/** The underlying `node:sqlite` handle, exposed as an escape hatch (seed/DDL). */
|
|
67
67
|
readonly db: DatabaseSync;
|
|
68
68
|
private closed;
|
|
69
69
|
constructor(db: DatabaseSync);
|
|
@@ -116,7 +116,7 @@ export interface TurbineSqliteOptions extends Pick<TurbineConfig, 'logging' | 'd
|
|
|
116
116
|
* Ignored for `':memory:'`. Default: `true`.
|
|
117
117
|
*/
|
|
118
118
|
wal?: boolean;
|
|
119
|
-
/** `PRAGMA busy_timeout` in ms
|
|
119
|
+
/** `PRAGMA busy_timeout` in ms, how long a writer waits on `SQLITE_BUSY`. Default: 5000. */
|
|
120
120
|
busyTimeoutMs?: number;
|
|
121
121
|
/** Enable `PRAGMA foreign_keys` enforcement. Default: `true`. */
|
|
122
122
|
foreignKeys?: boolean;
|