bun-query-builder 0.2.46 → 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
CHANGED
|
@@ -15600,6 +15600,10 @@ function createQueryBuilder(state) {
|
|
|
15600
15600
|
const newBase = fromIdx !== -1 ? `${baseText2.slice(0, fromIdx)}, ${frag}${baseText2.slice(fromIdx)}` : `${baseText2}, ${frag}`;
|
|
15601
15601
|
return makeSub(newBase, terms, params, tail);
|
|
15602
15602
|
},
|
|
15603
|
+
$call(callback) {
|
|
15604
|
+
const next = callback(this);
|
|
15605
|
+
return next ?? this;
|
|
15606
|
+
},
|
|
15603
15607
|
where(expr, op, value) {
|
|
15604
15608
|
return withTerm("AND", expr, op, value);
|
|
15605
15609
|
},
|
|
@@ -18638,14 +18642,26 @@ class MySQLDriver {
|
|
|
18638
18642
|
${columns}
|
|
18639
18643
|
);`;
|
|
18640
18644
|
}
|
|
18641
|
-
|
|
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) {
|
|
18642
18654
|
if (index.where) {
|
|
18643
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}`);
|
|
18644
18656
|
}
|
|
18645
18657
|
const kind = index.type === "unique" ? "UNIQUE " : "";
|
|
18646
18658
|
const idxName = qualifiedIndexName(tableName, index.name);
|
|
18647
|
-
const
|
|
18648
|
-
|
|
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});`;
|
|
18649
18665
|
}
|
|
18650
18666
|
addForeignKey(tableName, columnName, refTable, refColumn, onDelete, onUpdate, existingConstraintNames = []) {
|
|
18651
18667
|
const fkName = `${tableName}_${columnName}_fk`;
|
|
@@ -19024,11 +19040,11 @@ var init_singlestore = __esm(() => {
|
|
|
19024
19040
|
addForeignKey() {
|
|
19025
19041
|
return "";
|
|
19026
19042
|
}
|
|
19027
|
-
createIndex(tableName, index) {
|
|
19043
|
+
createIndex(tableName, index, columns) {
|
|
19028
19044
|
if (index.where) {
|
|
19029
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}`);
|
|
19030
19046
|
}
|
|
19031
|
-
return super.createIndex(tableName, index);
|
|
19047
|
+
return super.createIndex(tableName, index, columns);
|
|
19032
19048
|
}
|
|
19033
19049
|
};
|
|
19034
19050
|
});
|
|
@@ -29714,7 +29730,7 @@ function generateSql(plan, opts = {}) {
|
|
|
29714
29730
|
const createTableStatement = driver.createTable(t2);
|
|
29715
29731
|
tableStatements.push(createTableStatement);
|
|
29716
29732
|
for (const idx of t2.indexes)
|
|
29717
|
-
tableStatements.push(driver.createIndex(t2.table, idx));
|
|
29733
|
+
tableStatements.push(driver.createIndex(t2.table, idx, t2.columns));
|
|
29718
29734
|
if (tableIndex === tables.length - 1) {
|
|
29719
29735
|
for (const deferredTable of tables) {
|
|
29720
29736
|
for (const column of deferredTable.columns) {
|
|
@@ -30049,7 +30065,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30049
30065
|
const createTableStatement = driver.createTable(t2);
|
|
30050
30066
|
tableStatements.push(createTableStatement);
|
|
30051
30067
|
for (const idx of t2.indexes) {
|
|
30052
|
-
const createIndexStatement = driver.createIndex(t2.table, idx);
|
|
30068
|
+
const createIndexStatement = driver.createIndex(t2.table, idx, t2.columns);
|
|
30053
30069
|
tableStatements.push(createIndexStatement);
|
|
30054
30070
|
operations.push({ kind: "create_index", table: t2.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
30055
30071
|
}
|
|
@@ -30253,7 +30269,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30253
30269
|
for (const key of Object.keys(currIdx)) {
|
|
30254
30270
|
if (!prevIdx[key]) {
|
|
30255
30271
|
const idx = currIdx[key];
|
|
30256
|
-
const createIndexStatement = driver.createIndex(curr.table, idx);
|
|
30272
|
+
const createIndexStatement = driver.createIndex(curr.table, idx, curr.columns);
|
|
30257
30273
|
tableChanges.push(createIndexStatement);
|
|
30258
30274
|
chunks.push(createIndexStatement);
|
|
30259
30275
|
operations.push({ kind: "create_index", table: curr.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
@@ -32544,7 +32560,7 @@ function getPrefix() {
|
|
|
32544
32560
|
}
|
|
32545
32561
|
var prefix = getPrefix();
|
|
32546
32562
|
// package.json
|
|
32547
|
-
var version2 = "0.2.
|
|
32563
|
+
var version2 = "0.2.47";
|
|
32548
32564
|
|
|
32549
32565
|
// bin/cli.ts
|
|
32550
32566
|
init_actions();
|
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
|
@@ -15599,6 +15599,10 @@ function createQueryBuilder(state) {
|
|
|
15599
15599
|
const newBase = fromIdx !== -1 ? `${baseText2.slice(0, fromIdx)}, ${frag}${baseText2.slice(fromIdx)}` : `${baseText2}, ${frag}`;
|
|
15600
15600
|
return makeSub(newBase, terms, params, tail);
|
|
15601
15601
|
},
|
|
15602
|
+
$call(callback) {
|
|
15603
|
+
const next = callback(this);
|
|
15604
|
+
return next ?? this;
|
|
15605
|
+
},
|
|
15602
15606
|
where(expr, op, value) {
|
|
15603
15607
|
return withTerm("AND", expr, op, value);
|
|
15604
15608
|
},
|
|
@@ -18637,14 +18641,26 @@ class MySQLDriver {
|
|
|
18637
18641
|
${columns}
|
|
18638
18642
|
);`;
|
|
18639
18643
|
}
|
|
18640
|
-
|
|
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) {
|
|
18641
18653
|
if (index.where) {
|
|
18642
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}`);
|
|
18643
18655
|
}
|
|
18644
18656
|
const kind = index.type === "unique" ? "UNIQUE " : "";
|
|
18645
18657
|
const idxName = qualifiedIndexName(tableName, index.name);
|
|
18646
|
-
const
|
|
18647
|
-
|
|
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});`;
|
|
18648
18664
|
}
|
|
18649
18665
|
addForeignKey(tableName, columnName, refTable, refColumn, onDelete, onUpdate, existingConstraintNames = []) {
|
|
18650
18666
|
const fkName = `${tableName}_${columnName}_fk`;
|
|
@@ -19023,11 +19039,11 @@ var init_singlestore = __esm(() => {
|
|
|
19023
19039
|
addForeignKey() {
|
|
19024
19040
|
return "";
|
|
19025
19041
|
}
|
|
19026
|
-
createIndex(tableName, index) {
|
|
19042
|
+
createIndex(tableName, index, columns) {
|
|
19027
19043
|
if (index.where) {
|
|
19028
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}`);
|
|
19029
19045
|
}
|
|
19030
|
-
return super.createIndex(tableName, index);
|
|
19046
|
+
return super.createIndex(tableName, index, columns);
|
|
19031
19047
|
}
|
|
19032
19048
|
};
|
|
19033
19049
|
});
|
|
@@ -29713,7 +29729,7 @@ function generateSql(plan, opts = {}) {
|
|
|
29713
29729
|
const createTableStatement = driver.createTable(t2);
|
|
29714
29730
|
tableStatements.push(createTableStatement);
|
|
29715
29731
|
for (const idx of t2.indexes)
|
|
29716
|
-
tableStatements.push(driver.createIndex(t2.table, idx));
|
|
29732
|
+
tableStatements.push(driver.createIndex(t2.table, idx, t2.columns));
|
|
29717
29733
|
if (tableIndex === tables.length - 1) {
|
|
29718
29734
|
for (const deferredTable of tables) {
|
|
29719
29735
|
for (const column of deferredTable.columns) {
|
|
@@ -30048,7 +30064,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30048
30064
|
const createTableStatement = driver.createTable(t2);
|
|
30049
30065
|
tableStatements.push(createTableStatement);
|
|
30050
30066
|
for (const idx of t2.indexes) {
|
|
30051
|
-
const createIndexStatement = driver.createIndex(t2.table, idx);
|
|
30067
|
+
const createIndexStatement = driver.createIndex(t2.table, idx, t2.columns);
|
|
30052
30068
|
tableStatements.push(createIndexStatement);
|
|
30053
30069
|
operations.push({ kind: "create_index", table: t2.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
30054
30070
|
}
|
|
@@ -30252,7 +30268,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
30252
30268
|
for (const key of Object.keys(currIdx)) {
|
|
30253
30269
|
if (!prevIdx[key]) {
|
|
30254
30270
|
const idx = currIdx[key];
|
|
30255
|
-
const createIndexStatement = driver.createIndex(curr.table, idx);
|
|
30271
|
+
const createIndexStatement = driver.createIndex(curr.table, idx, curr.columns);
|
|
30256
30272
|
tableChanges.push(createIndexStatement);
|
|
30257
30273
|
chunks.push(createIndexStatement);
|
|
30258
30274
|
operations.push({ kind: "create_index", table: curr.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
package/package.json
CHANGED