sqlite-zod-orm 3.20.0 → 3.21.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/dist/index.js +13 -1
- package/package.json +1 -1
- package/src/builder.ts +30 -0
- package/src/database.ts +1 -1
- package/src/types.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -4572,6 +4572,17 @@ class QueryBuilder {
|
|
|
4572
4572
|
const aggSql = selectSql.replace(/^SELECT .+? FROM/, `SELECT ${groupCols}, COUNT(*) as count FROM`);
|
|
4573
4573
|
return this.executor(aggSql, params, true);
|
|
4574
4574
|
}
|
|
4575
|
+
pluck(column) {
|
|
4576
|
+
const { sql: selectSql, params } = compileIQO(this.tableName, this.iqo);
|
|
4577
|
+
const pluckSql = selectSql.replace(/^SELECT .+? FROM/, `SELECT "${column}" FROM`);
|
|
4578
|
+
const results = this.executor(pluckSql, params, true);
|
|
4579
|
+
return results.map((r) => r[column]);
|
|
4580
|
+
}
|
|
4581
|
+
clone() {
|
|
4582
|
+
const cloned = new QueryBuilder(this.tableName, this.executor, this.singleExecutor, this.joinResolver, this.conditionResolver, this.eagerLoader);
|
|
4583
|
+
cloned.iqo = JSON.parse(JSON.stringify(this.iqo));
|
|
4584
|
+
return cloned;
|
|
4585
|
+
}
|
|
4575
4586
|
updateAll(data) {
|
|
4576
4587
|
const { sql: selectSql, params } = compileIQO(this.tableName, this.iqo);
|
|
4577
4588
|
const whereMatch = selectSql.match(/WHERE (.+?)(?:\s+ORDER|\s+LIMIT|\s+GROUP|\s+HAVING|$)/s);
|
|
@@ -5235,7 +5246,8 @@ class _Database {
|
|
|
5235
5246
|
_pollInterval;
|
|
5236
5247
|
constructor(dbFile, schemas, options = {}) {
|
|
5237
5248
|
this.db = new SqliteDatabase(dbFile);
|
|
5238
|
-
|
|
5249
|
+
if (options.wal !== false)
|
|
5250
|
+
this.db.run("PRAGMA journal_mode = WAL");
|
|
5239
5251
|
this.db.run("PRAGMA foreign_keys = ON");
|
|
5240
5252
|
this.schemas = schemas;
|
|
5241
5253
|
this.options = options;
|
package/package.json
CHANGED
package/src/builder.ts
CHANGED
|
@@ -465,6 +465,36 @@ export class QueryBuilder<T extends Record<string, any>, TResult extends Record<
|
|
|
465
465
|
return this.executor(aggSql, params, true) as any;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
// ---------- Convenience Methods ----------
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Return a flat array of values for a single column.
|
|
472
|
+
* ```ts
|
|
473
|
+
* db.users.select().pluck('name') // → ['Alice', 'Bob', 'Charlie']
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
pluck(column: keyof T & string): any[] {
|
|
477
|
+
const { sql: selectSql, params } = compileIQO(this.tableName, this.iqo);
|
|
478
|
+
const pluckSql = selectSql.replace(/^SELECT .+? FROM/, `SELECT "${column}" FROM`);
|
|
479
|
+
const results = this.executor(pluckSql, params, true);
|
|
480
|
+
return results.map((r: any) => r[column]);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** Clone this QueryBuilder so you can fork a query. */
|
|
484
|
+
clone(): QueryBuilder<T, TResult> {
|
|
485
|
+
const cloned = new QueryBuilder<T, TResult>(
|
|
486
|
+
this.tableName,
|
|
487
|
+
this.executor,
|
|
488
|
+
this.singleExecutor,
|
|
489
|
+
this.joinResolver,
|
|
490
|
+
this.conditionResolver,
|
|
491
|
+
this.eagerLoader,
|
|
492
|
+
);
|
|
493
|
+
// Deep-copy the IQO state
|
|
494
|
+
(cloned as any).iqo = JSON.parse(JSON.stringify(this.iqo));
|
|
495
|
+
return cloned;
|
|
496
|
+
}
|
|
497
|
+
|
|
468
498
|
// ---------- Batch Mutations ----------
|
|
469
499
|
|
|
470
500
|
/**
|
package/src/database.ts
CHANGED
|
@@ -65,7 +65,7 @@ class _Database<Schemas extends SchemaMap> {
|
|
|
65
65
|
|
|
66
66
|
constructor(dbFile: string, schemas: Schemas, options: DatabaseOptions = {}) {
|
|
67
67
|
this.db = new SqliteDatabase(dbFile);
|
|
68
|
-
this.db.run('PRAGMA journal_mode = WAL');
|
|
68
|
+
if (options.wal !== false) this.db.run('PRAGMA journal_mode = WAL');
|
|
69
69
|
this.db.run('PRAGMA foreign_keys = ON');
|
|
70
70
|
this.schemas = schemas;
|
|
71
71
|
this.options = options;
|
package/src/types.ts
CHANGED
|
@@ -75,6 +75,12 @@ export type DatabaseOptions<R extends RelationsConfig = RelationsConfig> = {
|
|
|
75
75
|
* Default: `false`.
|
|
76
76
|
*/
|
|
77
77
|
debug?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Enable WAL (Write-Ahead Logging) journal mode for better
|
|
80
|
+
* concurrent read/write performance. Recommended for production.
|
|
81
|
+
* Default: `false`.
|
|
82
|
+
*/
|
|
83
|
+
wal?: boolean;
|
|
78
84
|
/**
|
|
79
85
|
* Lifecycle hooks per table. Each hook receives data and can transform it.
|
|
80
86
|
*
|