bun-query-builder 0.2.45 → 0.2.47
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/bin/cli.js +53 -16
- package/dist/client.d.ts +1 -0
- package/dist/drivers/mysql.d.ts +4 -2
- package/dist/drivers/postgres.d.ts +1 -1
- package/dist/drivers/singlestore.d.ts +2 -2
- package/dist/drivers/sqlite.d.ts +1 -1
- package/dist/src/index.js +52 -15
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -14944,6 +14944,10 @@ function createQueryBuilder(state) {
|
|
|
14944
14944
|
built = null;
|
|
14945
14945
|
return this;
|
|
14946
14946
|
},
|
|
14947
|
+
$call(callback) {
|
|
14948
|
+
callback(this);
|
|
14949
|
+
return this;
|
|
14950
|
+
},
|
|
14947
14951
|
union(other) {
|
|
14948
14952
|
appendSetOp("UNION", other);
|
|
14949
14953
|
return this;
|
|
@@ -15596,6 +15600,10 @@ function createQueryBuilder(state) {
|
|
|
15596
15600
|
const newBase = fromIdx !== -1 ? `${baseText2.slice(0, fromIdx)}, ${frag}${baseText2.slice(fromIdx)}` : `${baseText2}, ${frag}`;
|
|
15597
15601
|
return makeSub(newBase, terms, params, tail);
|
|
15598
15602
|
},
|
|
15603
|
+
$call(callback) {
|
|
15604
|
+
const next = callback(this);
|
|
15605
|
+
return next ?? this;
|
|
15606
|
+
},
|
|
15599
15607
|
where(expr, op, value) {
|
|
15600
15608
|
return withTerm("AND", expr, op, value);
|
|
15601
15609
|
},
|
|
@@ -18634,14 +18642,26 @@ class MySQLDriver {
|
|
|
18634
18642
|
${columns}
|
|
18635
18643
|
);`;
|
|
18636
18644
|
}
|
|
18637
|
-
|
|
18645
|
+
static KEY_PREFIX_CHARACTERS = 255;
|
|
18646
|
+
needsKeyPrefix(column) {
|
|
18647
|
+
const rendered = this.getColumnType(column).toLowerCase();
|
|
18648
|
+
if (rendered.includes("text") || rendered.includes("blob") || rendered === "json")
|
|
18649
|
+
return true;
|
|
18650
|
+
const width = rendered.match(/^(?:var)?char\((\d+)\)$/)?.[1];
|
|
18651
|
+
return width !== undefined && Number(width) >= 768;
|
|
18652
|
+
}
|
|
18653
|
+
createIndex(tableName, index, columns) {
|
|
18638
18654
|
if (index.where) {
|
|
18639
18655
|
throw new Error(`[migrations] Partial indexes (CompositeIndex.where) are not supported on MySQL. Index '${index.name}' on table '${tableName}' uses WHERE clause: ${index.where}`);
|
|
18640
18656
|
}
|
|
18641
18657
|
const kind = index.type === "unique" ? "UNIQUE " : "";
|
|
18642
18658
|
const idxName = qualifiedIndexName(tableName, index.name);
|
|
18643
|
-
const
|
|
18644
|
-
|
|
18659
|
+
const keyParts = index.columns.map((name) => {
|
|
18660
|
+
const column = columns?.find((one) => one.name === name);
|
|
18661
|
+
const quoted = this.quoteIdentifier(name);
|
|
18662
|
+
return column && this.needsKeyPrefix(column) ? `${quoted}(${MySQLDriver.KEY_PREFIX_CHARACTERS})` : quoted;
|
|
18663
|
+
}).join(", ");
|
|
18664
|
+
return `CREATE ${kind}INDEX ${this.quoteIdentifier(idxName)} ON ${this.quoteIdentifier(tableName)} (${keyParts});`;
|
|
18645
18665
|
}
|
|
18646
18666
|
addForeignKey(tableName, columnName, refTable, refColumn, onDelete, onUpdate, existingConstraintNames = []) {
|
|
18647
18667
|
const fkName = `${tableName}_${columnName}_fk`;
|
|
@@ -19020,11 +19040,11 @@ var init_singlestore = __esm(() => {
|
|
|
19020
19040
|
addForeignKey() {
|
|
19021
19041
|
return "";
|
|
19022
19042
|
}
|
|
19023
|
-
createIndex(tableName, index) {
|
|
19043
|
+
createIndex(tableName, index, columns) {
|
|
19024
19044
|
if (index.where) {
|
|
19025
19045
|
throw new Error(`[migrations] Partial indexes (CompositeIndex.where) are not supported on SingleStore. Index '${index.name}' on table '${tableName}' uses WHERE clause: ${index.where}`);
|
|
19026
19046
|
}
|
|
19027
|
-
return super.createIndex(tableName, index);
|
|
19047
|
+
return super.createIndex(tableName, index, columns);
|
|
19028
19048
|
}
|
|
19029
19049
|
};
|
|
19030
19050
|
});
|
|
@@ -26792,6 +26812,18 @@ class ModelQueryBuilder {
|
|
|
26792
26812
|
return "";
|
|
26793
26813
|
return this._trashed === "only" ? `${SOFT_DELETE_COLUMN} IS NOT NULL` : `${SOFT_DELETE_COLUMN} IS NULL`;
|
|
26794
26814
|
}
|
|
26815
|
+
assertNoUnappliedClauses(method) {
|
|
26816
|
+
const ignored = [];
|
|
26817
|
+
if (this._limit !== undefined)
|
|
26818
|
+
ignored.push("limit()");
|
|
26819
|
+
if (this._offset !== undefined)
|
|
26820
|
+
ignored.push("offset()");
|
|
26821
|
+
if (this._orderBy.length > 0)
|
|
26822
|
+
ignored.push("orderBy()");
|
|
26823
|
+
if (ignored.length > 0) {
|
|
26824
|
+
throw new TypeError(`[orm] ${method}() cannot apply ${ignored.join(", ")} \u2014 an UPDATE/DELETE takes no ORDER BY or LIMIT on every supported dialect. ` + `Previously these were ignored, so the statement affected every matching row. Narrow it with where() instead.`);
|
|
26825
|
+
}
|
|
26826
|
+
}
|
|
26795
26827
|
composeWhere(params) {
|
|
26796
26828
|
const userClause = this._wheres.length > 0 ? this.buildWhereClauses(params) : "";
|
|
26797
26829
|
const sd = this.softDeleteClause();
|
|
@@ -27041,6 +27073,7 @@ class ModelQueryBuilder {
|
|
|
27041
27073
|
}
|
|
27042
27074
|
async increment(column, amount = 1) {
|
|
27043
27075
|
assertValidIdentifier(column, "increment(column)");
|
|
27076
|
+
this.assertNoUnappliedClauses("increment");
|
|
27044
27077
|
const exec = getExecutor();
|
|
27045
27078
|
const params = [amount];
|
|
27046
27079
|
const incCol = sqlColumn(column);
|
|
@@ -27049,9 +27082,9 @@ class ModelQueryBuilder {
|
|
|
27049
27082
|
sql2 += `, updated_at = ?`;
|
|
27050
27083
|
params.push(formatNow());
|
|
27051
27084
|
}
|
|
27052
|
-
|
|
27053
|
-
|
|
27054
|
-
sql2 += ` WHERE ${
|
|
27085
|
+
const whereBody = this.composeWhere(params);
|
|
27086
|
+
if (whereBody) {
|
|
27087
|
+
sql2 += ` WHERE ${whereBody}`;
|
|
27055
27088
|
}
|
|
27056
27089
|
return (await exec.run(sql2, params)).changes;
|
|
27057
27090
|
}
|
|
@@ -27150,15 +27183,18 @@ class ModelQueryBuilder {
|
|
|
27150
27183
|
return Number(await this.aggregate("SUM", column) ?? 0) || 0;
|
|
27151
27184
|
}
|
|
27152
27185
|
async delete() {
|
|
27186
|
+
this.assertNoUnappliedClauses("delete");
|
|
27153
27187
|
const exec = getExecutor();
|
|
27154
27188
|
const params = [];
|
|
27155
27189
|
let sql2 = `DELETE FROM ${this._definition.table}`;
|
|
27156
|
-
|
|
27157
|
-
|
|
27190
|
+
const whereBody = this.composeWhere(params);
|
|
27191
|
+
if (whereBody) {
|
|
27192
|
+
sql2 += ` WHERE ${whereBody}`;
|
|
27158
27193
|
}
|
|
27159
27194
|
return (await exec.run(sql2, params)).changes;
|
|
27160
27195
|
}
|
|
27161
27196
|
async update(data) {
|
|
27197
|
+
this.assertNoUnappliedClauses("update");
|
|
27162
27198
|
const exec = getExecutor();
|
|
27163
27199
|
const entries = Object.entries(data);
|
|
27164
27200
|
const sets = entries.map(([k2]) => `${sqlColumn(k2)} = ?`).join(", ");
|
|
@@ -27167,8 +27203,9 @@ class ModelQueryBuilder {
|
|
|
27167
27203
|
params.push(formatNow());
|
|
27168
27204
|
}
|
|
27169
27205
|
let sql2 = `UPDATE ${this._definition.table} SET ${sets}${timestampsEnabled(this._definition) ? ", updated_at = ?" : ""}`;
|
|
27170
|
-
|
|
27171
|
-
|
|
27206
|
+
const whereBody = this.composeWhere(params);
|
|
27207
|
+
if (whereBody) {
|
|
27208
|
+
sql2 += ` WHERE ${whereBody}`;
|
|
27172
27209
|
}
|
|
27173
27210
|
return (await exec.run(sql2, params)).changes;
|
|
27174
27211
|
}
|
|
@@ -29693,7 +29730,7 @@ function generateSql(plan, opts = {}) {
|
|
|
29693
29730
|
const createTableStatement = driver.createTable(t2);
|
|
29694
29731
|
tableStatements.push(createTableStatement);
|
|
29695
29732
|
for (const idx of t2.indexes)
|
|
29696
|
-
tableStatements.push(driver.createIndex(t2.table, idx));
|
|
29733
|
+
tableStatements.push(driver.createIndex(t2.table, idx, t2.columns));
|
|
29697
29734
|
if (tableIndex === tables.length - 1) {
|
|
29698
29735
|
for (const deferredTable of tables) {
|
|
29699
29736
|
for (const column of deferredTable.columns) {
|
|
@@ -30028,7 +30065,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30028
30065
|
const createTableStatement = driver.createTable(t2);
|
|
30029
30066
|
tableStatements.push(createTableStatement);
|
|
30030
30067
|
for (const idx of t2.indexes) {
|
|
30031
|
-
const createIndexStatement = driver.createIndex(t2.table, idx);
|
|
30068
|
+
const createIndexStatement = driver.createIndex(t2.table, idx, t2.columns);
|
|
30032
30069
|
tableStatements.push(createIndexStatement);
|
|
30033
30070
|
operations.push({ kind: "create_index", table: t2.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
30034
30071
|
}
|
|
@@ -30232,7 +30269,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30232
30269
|
for (const key of Object.keys(currIdx)) {
|
|
30233
30270
|
if (!prevIdx[key]) {
|
|
30234
30271
|
const idx = currIdx[key];
|
|
30235
|
-
const createIndexStatement = driver.createIndex(curr.table, idx);
|
|
30272
|
+
const createIndexStatement = driver.createIndex(curr.table, idx, curr.columns);
|
|
30236
30273
|
tableChanges.push(createIndexStatement);
|
|
30237
30274
|
chunks.push(createIndexStatement);
|
|
30238
30275
|
operations.push({ kind: "create_index", table: curr.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
@@ -32523,7 +32560,7 @@ function getPrefix() {
|
|
|
32523
32560
|
}
|
|
32524
32561
|
var prefix = getPrefix();
|
|
32525
32562
|
// package.json
|
|
32526
|
-
var version2 = "0.2.
|
|
32563
|
+
var version2 = "0.2.47";
|
|
32527
32564
|
|
|
32528
32565
|
// bin/cli.ts
|
|
32529
32566
|
init_actions();
|
package/dist/client.d.ts
CHANGED
|
@@ -180,6 +180,7 @@ export declare interface BaseSelectQueryBuilder<DB extends AnyDatabaseSchema, TT
|
|
|
180
180
|
}
|
|
181
181
|
selectAll?: () => SelectQueryBuilder<DB, TTable, DB[TTable]['columns'], TJoined>
|
|
182
182
|
orderByRaw: (fragment: SqlFragment) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
|
|
183
|
+
$call: (callback: (query: SelectQueryBuilder<DB, TTable, TSelected, TJoined>) => unknown) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
|
|
183
184
|
union: (other: { toSQL: () => string }) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
|
|
184
185
|
unionAll: (other: { toSQL: () => string }) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
|
|
185
186
|
forPage: (page: number, perPage: number) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
|
package/dist/drivers/mysql.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { DateBucketGrain } from './postgres';
|
|
|
3
3
|
export declare interface DialectDriver {
|
|
4
4
|
createEnumType: (enumTypeName: string, values: string[]) => string
|
|
5
5
|
createTable: (table: TablePlan) => string
|
|
6
|
-
createIndex: (tableName: string, index: IndexPlan) => string
|
|
6
|
+
createIndex: (tableName: string, index: IndexPlan, columns?: readonly ColumnPlan[]) => string
|
|
7
7
|
addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string, existingConstraintNames?: string[]) => string
|
|
8
8
|
addColumn: (tableName: string, column: ColumnPlan) => string
|
|
9
9
|
modifyColumn: (tableName: string, column: ColumnPlan) => string
|
|
@@ -26,7 +26,9 @@ export declare class MySQLDriver implements DialectDriver {
|
|
|
26
26
|
protected getDefaultValue(column: ColumnPlan): string;
|
|
27
27
|
createEnumType(_enumTypeName: string, _values: string[]): string;
|
|
28
28
|
createTable(table: TablePlan): string;
|
|
29
|
-
|
|
29
|
+
protected static readonly KEY_PREFIX_CHARACTERS: 255;
|
|
30
|
+
protected needsKeyPrefix(column: ColumnPlan): boolean;
|
|
31
|
+
createIndex(tableName: string, index: IndexPlan, columns?: readonly ColumnPlan[]): string;
|
|
30
32
|
addForeignKey(tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string, existingConstraintNames?: string[]): string;
|
|
31
33
|
addColumn(tableName: string, column: ColumnPlan): string;
|
|
32
34
|
modifyColumn(tableName: string, column: ColumnPlan): string;
|
|
@@ -9,7 +9,7 @@ export declare const DATE_BUCKET_FORMAT: 'YYYY-MM-DDTHH:MM:SS.000Z';
|
|
|
9
9
|
export declare interface DialectDriver {
|
|
10
10
|
createEnumType: (enumTypeName: string, values: string[]) => string
|
|
11
11
|
createTable: (table: TablePlan) => string
|
|
12
|
-
createIndex: (tableName: string, index: IndexPlan) => string
|
|
12
|
+
createIndex: (tableName: string, index: IndexPlan, columns?: readonly ColumnPlan[]) => string
|
|
13
13
|
addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string, existingConstraintNames?: string[]) => string
|
|
14
14
|
addColumn: (tableName: string, column: ColumnPlan) => string
|
|
15
15
|
modifyColumn: (tableName: string, column: ColumnPlan) => string
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MySQLDriver } from './mysql';
|
|
2
|
-
import type { IndexPlan, TablePlan } from '../migrations';
|
|
2
|
+
import type { ColumnPlan, IndexPlan, TablePlan } from '../migrations';
|
|
3
3
|
/**
|
|
4
4
|
* SingleStore DDL driver.
|
|
5
5
|
*
|
|
@@ -24,5 +24,5 @@ import type { IndexPlan, TablePlan } from '../migrations';
|
|
|
24
24
|
export declare class SingleStoreDriver extends MySQLDriver {
|
|
25
25
|
createTable(table: TablePlan): string;
|
|
26
26
|
addForeignKey(): string;
|
|
27
|
-
createIndex(tableName: string, index: IndexPlan): string;
|
|
27
|
+
createIndex(tableName: string, index: IndexPlan, columns?: readonly ColumnPlan[]): string;
|
|
28
28
|
}
|
package/dist/drivers/sqlite.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { DateBucketGrain } from './postgres';
|
|
|
4
4
|
export declare interface DialectDriver {
|
|
5
5
|
createEnumType: (enumTypeName: string, values: string[]) => string
|
|
6
6
|
createTable: (table: TablePlan) => string
|
|
7
|
-
createIndex: (tableName: string, index: IndexPlan) => string
|
|
7
|
+
createIndex: (tableName: string, index: IndexPlan, columns?: readonly ColumnPlan[]) => string
|
|
8
8
|
addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string) => string
|
|
9
9
|
addColumn: (tableName: string, column: ColumnPlan) => string
|
|
10
10
|
modifyColumn: (tableName: string, column: ColumnPlan) => string
|
package/dist/src/index.js
CHANGED
|
@@ -14943,6 +14943,10 @@ function createQueryBuilder(state) {
|
|
|
14943
14943
|
built = null;
|
|
14944
14944
|
return this;
|
|
14945
14945
|
},
|
|
14946
|
+
$call(callback) {
|
|
14947
|
+
callback(this);
|
|
14948
|
+
return this;
|
|
14949
|
+
},
|
|
14946
14950
|
union(other) {
|
|
14947
14951
|
appendSetOp("UNION", other);
|
|
14948
14952
|
return this;
|
|
@@ -15595,6 +15599,10 @@ function createQueryBuilder(state) {
|
|
|
15595
15599
|
const newBase = fromIdx !== -1 ? `${baseText2.slice(0, fromIdx)}, ${frag}${baseText2.slice(fromIdx)}` : `${baseText2}, ${frag}`;
|
|
15596
15600
|
return makeSub(newBase, terms, params, tail);
|
|
15597
15601
|
},
|
|
15602
|
+
$call(callback) {
|
|
15603
|
+
const next = callback(this);
|
|
15604
|
+
return next ?? this;
|
|
15605
|
+
},
|
|
15598
15606
|
where(expr, op, value) {
|
|
15599
15607
|
return withTerm("AND", expr, op, value);
|
|
15600
15608
|
},
|
|
@@ -18633,14 +18641,26 @@ class MySQLDriver {
|
|
|
18633
18641
|
${columns}
|
|
18634
18642
|
);`;
|
|
18635
18643
|
}
|
|
18636
|
-
|
|
18644
|
+
static KEY_PREFIX_CHARACTERS = 255;
|
|
18645
|
+
needsKeyPrefix(column) {
|
|
18646
|
+
const rendered = this.getColumnType(column).toLowerCase();
|
|
18647
|
+
if (rendered.includes("text") || rendered.includes("blob") || rendered === "json")
|
|
18648
|
+
return true;
|
|
18649
|
+
const width = rendered.match(/^(?:var)?char\((\d+)\)$/)?.[1];
|
|
18650
|
+
return width !== undefined && Number(width) >= 768;
|
|
18651
|
+
}
|
|
18652
|
+
createIndex(tableName, index, columns) {
|
|
18637
18653
|
if (index.where) {
|
|
18638
18654
|
throw new Error(`[migrations] Partial indexes (CompositeIndex.where) are not supported on MySQL. Index '${index.name}' on table '${tableName}' uses WHERE clause: ${index.where}`);
|
|
18639
18655
|
}
|
|
18640
18656
|
const kind = index.type === "unique" ? "UNIQUE " : "";
|
|
18641
18657
|
const idxName = qualifiedIndexName(tableName, index.name);
|
|
18642
|
-
const
|
|
18643
|
-
|
|
18658
|
+
const keyParts = index.columns.map((name) => {
|
|
18659
|
+
const column = columns?.find((one) => one.name === name);
|
|
18660
|
+
const quoted = this.quoteIdentifier(name);
|
|
18661
|
+
return column && this.needsKeyPrefix(column) ? `${quoted}(${MySQLDriver.KEY_PREFIX_CHARACTERS})` : quoted;
|
|
18662
|
+
}).join(", ");
|
|
18663
|
+
return `CREATE ${kind}INDEX ${this.quoteIdentifier(idxName)} ON ${this.quoteIdentifier(tableName)} (${keyParts});`;
|
|
18644
18664
|
}
|
|
18645
18665
|
addForeignKey(tableName, columnName, refTable, refColumn, onDelete, onUpdate, existingConstraintNames = []) {
|
|
18646
18666
|
const fkName = `${tableName}_${columnName}_fk`;
|
|
@@ -19019,11 +19039,11 @@ var init_singlestore = __esm(() => {
|
|
|
19019
19039
|
addForeignKey() {
|
|
19020
19040
|
return "";
|
|
19021
19041
|
}
|
|
19022
|
-
createIndex(tableName, index) {
|
|
19042
|
+
createIndex(tableName, index, columns) {
|
|
19023
19043
|
if (index.where) {
|
|
19024
19044
|
throw new Error(`[migrations] Partial indexes (CompositeIndex.where) are not supported on SingleStore. Index '${index.name}' on table '${tableName}' uses WHERE clause: ${index.where}`);
|
|
19025
19045
|
}
|
|
19026
|
-
return super.createIndex(tableName, index);
|
|
19046
|
+
return super.createIndex(tableName, index, columns);
|
|
19027
19047
|
}
|
|
19028
19048
|
};
|
|
19029
19049
|
});
|
|
@@ -26791,6 +26811,18 @@ class ModelQueryBuilder {
|
|
|
26791
26811
|
return "";
|
|
26792
26812
|
return this._trashed === "only" ? `${SOFT_DELETE_COLUMN} IS NOT NULL` : `${SOFT_DELETE_COLUMN} IS NULL`;
|
|
26793
26813
|
}
|
|
26814
|
+
assertNoUnappliedClauses(method) {
|
|
26815
|
+
const ignored = [];
|
|
26816
|
+
if (this._limit !== undefined)
|
|
26817
|
+
ignored.push("limit()");
|
|
26818
|
+
if (this._offset !== undefined)
|
|
26819
|
+
ignored.push("offset()");
|
|
26820
|
+
if (this._orderBy.length > 0)
|
|
26821
|
+
ignored.push("orderBy()");
|
|
26822
|
+
if (ignored.length > 0) {
|
|
26823
|
+
throw new TypeError(`[orm] ${method}() cannot apply ${ignored.join(", ")} \u2014 an UPDATE/DELETE takes no ORDER BY or LIMIT on every supported dialect. ` + `Previously these were ignored, so the statement affected every matching row. Narrow it with where() instead.`);
|
|
26824
|
+
}
|
|
26825
|
+
}
|
|
26794
26826
|
composeWhere(params) {
|
|
26795
26827
|
const userClause = this._wheres.length > 0 ? this.buildWhereClauses(params) : "";
|
|
26796
26828
|
const sd = this.softDeleteClause();
|
|
@@ -27040,6 +27072,7 @@ class ModelQueryBuilder {
|
|
|
27040
27072
|
}
|
|
27041
27073
|
async increment(column, amount = 1) {
|
|
27042
27074
|
assertValidIdentifier(column, "increment(column)");
|
|
27075
|
+
this.assertNoUnappliedClauses("increment");
|
|
27043
27076
|
const exec = getExecutor();
|
|
27044
27077
|
const params = [amount];
|
|
27045
27078
|
const incCol = sqlColumn(column);
|
|
@@ -27048,9 +27081,9 @@ class ModelQueryBuilder {
|
|
|
27048
27081
|
sql2 += `, updated_at = ?`;
|
|
27049
27082
|
params.push(formatNow());
|
|
27050
27083
|
}
|
|
27051
|
-
|
|
27052
|
-
|
|
27053
|
-
sql2 += ` WHERE ${
|
|
27084
|
+
const whereBody = this.composeWhere(params);
|
|
27085
|
+
if (whereBody) {
|
|
27086
|
+
sql2 += ` WHERE ${whereBody}`;
|
|
27054
27087
|
}
|
|
27055
27088
|
return (await exec.run(sql2, params)).changes;
|
|
27056
27089
|
}
|
|
@@ -27149,15 +27182,18 @@ class ModelQueryBuilder {
|
|
|
27149
27182
|
return Number(await this.aggregate("SUM", column) ?? 0) || 0;
|
|
27150
27183
|
}
|
|
27151
27184
|
async delete() {
|
|
27185
|
+
this.assertNoUnappliedClauses("delete");
|
|
27152
27186
|
const exec = getExecutor();
|
|
27153
27187
|
const params = [];
|
|
27154
27188
|
let sql2 = `DELETE FROM ${this._definition.table}`;
|
|
27155
|
-
|
|
27156
|
-
|
|
27189
|
+
const whereBody = this.composeWhere(params);
|
|
27190
|
+
if (whereBody) {
|
|
27191
|
+
sql2 += ` WHERE ${whereBody}`;
|
|
27157
27192
|
}
|
|
27158
27193
|
return (await exec.run(sql2, params)).changes;
|
|
27159
27194
|
}
|
|
27160
27195
|
async update(data) {
|
|
27196
|
+
this.assertNoUnappliedClauses("update");
|
|
27161
27197
|
const exec = getExecutor();
|
|
27162
27198
|
const entries = Object.entries(data);
|
|
27163
27199
|
const sets = entries.map(([k2]) => `${sqlColumn(k2)} = ?`).join(", ");
|
|
@@ -27166,8 +27202,9 @@ class ModelQueryBuilder {
|
|
|
27166
27202
|
params.push(formatNow());
|
|
27167
27203
|
}
|
|
27168
27204
|
let sql2 = `UPDATE ${this._definition.table} SET ${sets}${timestampsEnabled(this._definition) ? ", updated_at = ?" : ""}`;
|
|
27169
|
-
|
|
27170
|
-
|
|
27205
|
+
const whereBody = this.composeWhere(params);
|
|
27206
|
+
if (whereBody) {
|
|
27207
|
+
sql2 += ` WHERE ${whereBody}`;
|
|
27171
27208
|
}
|
|
27172
27209
|
return (await exec.run(sql2, params)).changes;
|
|
27173
27210
|
}
|
|
@@ -29692,7 +29729,7 @@ function generateSql(plan, opts = {}) {
|
|
|
29692
29729
|
const createTableStatement = driver.createTable(t2);
|
|
29693
29730
|
tableStatements.push(createTableStatement);
|
|
29694
29731
|
for (const idx of t2.indexes)
|
|
29695
|
-
tableStatements.push(driver.createIndex(t2.table, idx));
|
|
29732
|
+
tableStatements.push(driver.createIndex(t2.table, idx, t2.columns));
|
|
29696
29733
|
if (tableIndex === tables.length - 1) {
|
|
29697
29734
|
for (const deferredTable of tables) {
|
|
29698
29735
|
for (const column of deferredTable.columns) {
|
|
@@ -30027,7 +30064,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30027
30064
|
const createTableStatement = driver.createTable(t2);
|
|
30028
30065
|
tableStatements.push(createTableStatement);
|
|
30029
30066
|
for (const idx of t2.indexes) {
|
|
30030
|
-
const createIndexStatement = driver.createIndex(t2.table, idx);
|
|
30067
|
+
const createIndexStatement = driver.createIndex(t2.table, idx, t2.columns);
|
|
30031
30068
|
tableStatements.push(createIndexStatement);
|
|
30032
30069
|
operations.push({ kind: "create_index", table: t2.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
30033
30070
|
}
|
|
@@ -30231,7 +30268,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30231
30268
|
for (const key of Object.keys(currIdx)) {
|
|
30232
30269
|
if (!prevIdx[key]) {
|
|
30233
30270
|
const idx = currIdx[key];
|
|
30234
|
-
const createIndexStatement = driver.createIndex(curr.table, idx);
|
|
30271
|
+
const createIndexStatement = driver.createIndex(curr.table, idx, curr.columns);
|
|
30235
30272
|
tableChanges.push(createIndexStatement);
|
|
30236
30273
|
chunks.push(createIndexStatement);
|
|
30237
30274
|
operations.push({ kind: "create_index", table: curr.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
package/package.json
CHANGED