@vertz/db 0.2.12 → 0.2.13
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 +65 -4
- package/dist/d1/index.d.ts +3 -11
- package/dist/d1/index.js +1 -1
- package/dist/index.d.ts +73 -72
- package/dist/index.js +188 -663
- package/dist/internals.d.ts +41 -12
- package/dist/internals.js +3 -1
- package/dist/shared/chunk-1x9z0p5e.js +977 -0
- package/dist/shared/chunk-8v70x3hq.js +105 -0
- package/dist/shared/{chunk-pnk6yzjv.js → chunk-ndxe1h28.js} +1 -1
- package/dist/shared/{chunk-sfmyxz6r.js → chunk-pkv8w501.js} +3 -2
- package/dist/shared/{chunk-0e1vy9qd.js → chunk-pxjcpnpx.js} +4 -85
- package/dist/sql/index.js +2 -2
- package/dist/sqlite/index.d.ts +3 -11
- package/dist/sqlite/index.js +1 -1
- package/package.json +3 -3
- package/dist/shared/chunk-agyds4jw.js +0 -302
- package/dist/shared/chunk-v2qm94qp.js +0 -23
package/dist/internals.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The query function type expected by the migration runner.
|
|
3
|
+
*/
|
|
4
|
+
type MigrationQueryFn = (sql: string, params: readonly unknown[]) => Promise<{
|
|
5
|
+
rows: readonly Record<string, unknown>[];
|
|
6
|
+
rowCount: number;
|
|
7
|
+
}>;
|
|
1
8
|
interface JsonbValidator<T> {
|
|
2
9
|
parse(value: unknown): T;
|
|
3
10
|
}
|
|
@@ -10,11 +17,6 @@ interface ColumnMetadata {
|
|
|
10
17
|
readonly _annotations: Record<string, true>;
|
|
11
18
|
readonly isReadOnly: boolean;
|
|
12
19
|
readonly isAutoUpdate: boolean;
|
|
13
|
-
readonly isTenant: boolean;
|
|
14
|
-
readonly references: {
|
|
15
|
-
readonly table: string;
|
|
16
|
-
readonly column: string;
|
|
17
|
-
} | null;
|
|
18
20
|
readonly check: string | null;
|
|
19
21
|
readonly defaultValue?: unknown;
|
|
20
22
|
readonly format?: string;
|
|
@@ -65,18 +67,15 @@ interface ColumnBuilder<
|
|
|
65
67
|
check(sql: string): ColumnBuilder<TType, Omit<TMeta, "check"> & {
|
|
66
68
|
readonly check: string;
|
|
67
69
|
}>;
|
|
68
|
-
references(table: string, column?: string): ColumnBuilder<TType, Omit<TMeta, "references"> & {
|
|
69
|
-
readonly references: {
|
|
70
|
-
readonly table: string;
|
|
71
|
-
readonly column: string;
|
|
72
|
-
};
|
|
73
|
-
}>;
|
|
74
70
|
}
|
|
75
71
|
type InferColumnType<C> = C extends ColumnBuilder<infer T, ColumnMetadata> ? T : never;
|
|
72
|
+
type IndexType = "btree" | "hash" | "gin" | "gist" | "brin";
|
|
76
73
|
interface IndexDef {
|
|
77
74
|
readonly columns: readonly string[];
|
|
78
75
|
readonly name?: string;
|
|
79
76
|
readonly unique?: boolean;
|
|
77
|
+
readonly type?: IndexType;
|
|
78
|
+
readonly where?: string;
|
|
80
79
|
}
|
|
81
80
|
/** A record of column builders -- the shape passed to d.table(). */
|
|
82
81
|
type ColumnRecord = Record<string, ColumnBuilder<unknown, ColumnMetadata>>;
|
|
@@ -170,6 +169,8 @@ interface IndexSnapshot {
|
|
|
170
169
|
columns: string[];
|
|
171
170
|
name?: string;
|
|
172
171
|
unique?: boolean;
|
|
172
|
+
type?: IndexType;
|
|
173
|
+
where?: string;
|
|
173
174
|
}
|
|
174
175
|
interface ForeignKeySnapshot {
|
|
175
176
|
column: string;
|
|
@@ -196,6 +197,34 @@ interface SnapshotStorage {
|
|
|
196
197
|
save(key: string, snapshot: SchemaSnapshot): Promise<void>;
|
|
197
198
|
}
|
|
198
199
|
/**
|
|
200
|
+
* Options for autoMigrate.
|
|
201
|
+
*/
|
|
202
|
+
interface AutoMigrateOptions {
|
|
203
|
+
/** The current schema snapshot (from d.table() definitions). */
|
|
204
|
+
currentSchema: SchemaSnapshot;
|
|
205
|
+
/** Key for snapshot persistence (file path for NodeSnapshotStorage, or any string key for custom backends). */
|
|
206
|
+
snapshotPath: string;
|
|
207
|
+
/** Database dialect - currently only 'sqlite' is supported. */
|
|
208
|
+
dialect: "sqlite";
|
|
209
|
+
/** Database connection that can execute SQL queries. */
|
|
210
|
+
db: MigrationQueryFn;
|
|
211
|
+
/** Optional storage adapter. Defaults to NodeSnapshotStorage. */
|
|
212
|
+
storage?: SnapshotStorage;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Auto-migrate the database schema.
|
|
216
|
+
*
|
|
217
|
+
* This function:
|
|
218
|
+
* 1. Loads the previous snapshot from disk (if any)
|
|
219
|
+
* 2. Compares against the current schema
|
|
220
|
+
* 3. Generates and applies migration SQL
|
|
221
|
+
* 4. Logs warnings for destructive changes
|
|
222
|
+
* 5. Saves the updated snapshot
|
|
223
|
+
*
|
|
224
|
+
* @param options - Migration options
|
|
225
|
+
*/
|
|
226
|
+
declare function autoMigrate(options: AutoMigrateOptions): Promise<void>;
|
|
227
|
+
/**
|
|
199
228
|
* Node.js filesystem implementation of SnapshotStorage.
|
|
200
229
|
* Uses node:fs/promises for file I/O and node:path for directory creation.
|
|
201
230
|
*/
|
|
@@ -290,4 +319,4 @@ declare function mapRow<T>(row: Record<string, unknown>): T;
|
|
|
290
319
|
* Convert an array of rows from snake_case to camelCase.
|
|
291
320
|
*/
|
|
292
321
|
declare function mapRows<T>(rows: readonly Record<string, unknown>[]): T[];
|
|
293
|
-
export { resolveSelectColumns, mapRows, mapRow, getTimestampColumns, getPrimaryKeyColumns, getDefaultColumns, getColumnsWithoutAnnotations, getColumnNames, executeQuery, QueryFn, NodeSnapshotStorage, GroupByArgs, ExecutorResult, CountArgs, AggregateArgs };
|
|
322
|
+
export { resolveSelectColumns, mapRows, mapRow, getTimestampColumns, getPrimaryKeyColumns, getDefaultColumns, getColumnsWithoutAnnotations, getColumnNames, executeQuery, autoMigrate, QueryFn, NodeSnapshotStorage, GroupByArgs, ExecutorResult, CountArgs, AutoMigrateOptions, AggregateArgs };
|
package/dist/internals.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
autoMigrate,
|
|
2
3
|
executeQuery,
|
|
3
4
|
getColumnNames,
|
|
4
5
|
getColumnsWithoutAnnotations,
|
|
@@ -8,7 +9,7 @@ import {
|
|
|
8
9
|
mapRow,
|
|
9
10
|
mapRows,
|
|
10
11
|
resolveSelectColumns
|
|
11
|
-
} from "./shared/chunk-
|
|
12
|
+
} from "./shared/chunk-1x9z0p5e.js";
|
|
12
13
|
import {
|
|
13
14
|
NodeSnapshotStorage
|
|
14
15
|
} from "./shared/chunk-kb4tnn2k.js";
|
|
@@ -22,5 +23,6 @@ export {
|
|
|
22
23
|
getColumnsWithoutAnnotations,
|
|
23
24
|
getColumnNames,
|
|
24
25
|
executeQuery,
|
|
26
|
+
autoMigrate,
|
|
25
27
|
NodeSnapshotStorage
|
|
26
28
|
};
|