bun-query-builder 0.1.51 → 0.1.53
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 +58 -59
- package/dist/src/index.js +57 -58
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -15917,7 +15917,7 @@ function createQueryBuilder(state) {
|
|
|
15917
15917
|
return false;
|
|
15918
15918
|
},
|
|
15919
15919
|
unsafe(query, params) {
|
|
15920
|
-
return
|
|
15920
|
+
return _sql.unsafe(query, params);
|
|
15921
15921
|
},
|
|
15922
15922
|
file(path, params) {
|
|
15923
15923
|
return bunSql.file(path, params);
|
|
@@ -28327,7 +28327,7 @@ function generateSql(plan, opts = {}) {
|
|
|
28327
28327
|
const statements = [];
|
|
28328
28328
|
const driver = getDialectDriver(plan.dialect);
|
|
28329
28329
|
const { tables, deferredForeignKeys } = orderTablesForCreate(plan.tables, plan.dialect);
|
|
28330
|
-
for (const originalTable of tables) {
|
|
28330
|
+
for (const [tableIndex, originalTable] of tables.entries()) {
|
|
28331
28331
|
const t2 = {
|
|
28332
28332
|
...originalTable,
|
|
28333
28333
|
columns: originalTable.columns.map((column) => deferredForeignKeys.has(foreignKeyKey(originalTable.table, column.name)) ? { ...column, references: undefined } : column)
|
|
@@ -28351,23 +28351,23 @@ function generateSql(plan, opts = {}) {
|
|
|
28351
28351
|
tableStatements.push(createTableStatement);
|
|
28352
28352
|
for (const idx of t2.indexes)
|
|
28353
28353
|
tableStatements.push(driver.createIndex(t2.table, idx));
|
|
28354
|
+
if (tableIndex === tables.length - 1) {
|
|
28355
|
+
for (const deferredTable of tables) {
|
|
28356
|
+
for (const column of deferredTable.columns) {
|
|
28357
|
+
if (!column.references || !deferredForeignKeys.has(foreignKeyKey(deferredTable.table, column.name)))
|
|
28358
|
+
continue;
|
|
28359
|
+
const addForeignKey = driver.addForeignKey(deferredTable.table, column.name, column.references.table, column.references.column, column.references.onDelete, column.references.onUpdate);
|
|
28360
|
+
if (addForeignKey)
|
|
28361
|
+
tableStatements.push(addForeignKey);
|
|
28362
|
+
}
|
|
28363
|
+
}
|
|
28364
|
+
}
|
|
28354
28365
|
statements.push(...tableStatements);
|
|
28355
28366
|
const combinedStatement = tableStatements.join(`
|
|
28356
28367
|
|
|
28357
28368
|
`);
|
|
28358
28369
|
emit(combinedStatement, `create-${t2.table}-table`);
|
|
28359
28370
|
}
|
|
28360
|
-
for (const t2 of tables) {
|
|
28361
|
-
for (const c2 of t2.columns) {
|
|
28362
|
-
if (c2.references && deferredForeignKeys.has(foreignKeyKey(t2.table, c2.name))) {
|
|
28363
|
-
const alterTableStatement = driver.addForeignKey(t2.table, c2.name, c2.references.table, c2.references.column, c2.references.onDelete, c2.references.onUpdate);
|
|
28364
|
-
if (!alterTableStatement)
|
|
28365
|
-
continue;
|
|
28366
|
-
statements.push(alterTableStatement);
|
|
28367
|
-
emit(alterTableStatement, `alter-${t2.table}-${c2.name}`);
|
|
28368
|
-
}
|
|
28369
|
-
}
|
|
28370
|
-
}
|
|
28371
28371
|
const totalChanges = migrationsCreatedCount + migrationsUpdatedCount;
|
|
28372
28372
|
if (totalChanges === 0) {
|
|
28373
28373
|
info2("-- Nothing to migrate");
|
|
@@ -28622,59 +28622,58 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
28622
28622
|
info2(`-- Detected dropped table: ${tableName}`);
|
|
28623
28623
|
}
|
|
28624
28624
|
}
|
|
28625
|
-
|
|
28626
|
-
|
|
28627
|
-
|
|
28628
|
-
|
|
28629
|
-
|
|
28630
|
-
|
|
28631
|
-
|
|
28632
|
-
|
|
28633
|
-
|
|
28634
|
-
|
|
28635
|
-
|
|
28636
|
-
|
|
28637
|
-
|
|
28638
|
-
|
|
28639
|
-
|
|
28625
|
+
const newTablePlans = Object.keys(nextTables).filter((tableName) => !prevTables[tableName]).map((tableName) => nextTables[tableName]);
|
|
28626
|
+
const { tables: orderedNewTables, deferredForeignKeys } = orderTablesForCreate(newTablePlans, dialect);
|
|
28627
|
+
for (const [tableIndex, originalTable] of orderedNewTables.entries()) {
|
|
28628
|
+
const t2 = {
|
|
28629
|
+
...originalTable,
|
|
28630
|
+
columns: originalTable.columns.map((column) => deferredForeignKeys.has(foreignKeyKey(originalTable.table, column.name)) ? { ...column, references: undefined } : column)
|
|
28631
|
+
};
|
|
28632
|
+
const tableStatements = [];
|
|
28633
|
+
const enumTypes2 = new Set;
|
|
28634
|
+
for (const c2 of t2.columns) {
|
|
28635
|
+
if (c2.type === "enum" && c2.enumValues && c2.enumValues.length > 0) {
|
|
28636
|
+
const enumTypeName = `${t2.table}_${c2.name}_type`;
|
|
28637
|
+
c2.enumTypeName = enumTypeName;
|
|
28638
|
+
if (!enumTypes2.has(enumTypeName)) {
|
|
28639
|
+
const createEnumStatement = driver.createEnumType(enumTypeName, c2.enumValues);
|
|
28640
|
+
if (createEnumStatement) {
|
|
28641
|
+
tableStatements.push(createEnumStatement);
|
|
28640
28642
|
}
|
|
28643
|
+
enumTypes2.add(enumTypeName);
|
|
28641
28644
|
}
|
|
28642
28645
|
}
|
|
28643
|
-
const createTableStatement = driver.createTable(t2);
|
|
28644
|
-
tableStatements.push(createTableStatement);
|
|
28645
|
-
chunks.push(...tableStatements);
|
|
28646
|
-
operations.push({ kind: "create_table", table: t2.table, destructive: false, sql: createTableStatement });
|
|
28647
|
-
const combinedStatement = tableStatements.join(`
|
|
28648
|
-
|
|
28649
|
-
`);
|
|
28650
|
-
emit(combinedStatement, `create-${t2.table}-table`);
|
|
28651
28646
|
}
|
|
28652
|
-
|
|
28653
|
-
|
|
28654
|
-
|
|
28655
|
-
const
|
|
28656
|
-
|
|
28657
|
-
|
|
28658
|
-
|
|
28659
|
-
|
|
28660
|
-
|
|
28661
|
-
|
|
28662
|
-
}
|
|
28663
|
-
|
|
28664
|
-
|
|
28665
|
-
|
|
28666
|
-
|
|
28667
|
-
for (const c2 of t2.columns) {
|
|
28668
|
-
if (c2.references) {
|
|
28669
|
-
const alterTableStatement = driver.addForeignKey(t2.table, c2.name, c2.references.table, c2.references.column, c2.references.onDelete, c2.references.onUpdate);
|
|
28670
|
-
if (!alterTableStatement)
|
|
28647
|
+
const createTableStatement = driver.createTable(t2);
|
|
28648
|
+
tableStatements.push(createTableStatement);
|
|
28649
|
+
for (const idx of t2.indexes) {
|
|
28650
|
+
const createIndexStatement = driver.createIndex(t2.table, idx);
|
|
28651
|
+
tableStatements.push(createIndexStatement);
|
|
28652
|
+
operations.push({ kind: "create_index", table: t2.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
28653
|
+
}
|
|
28654
|
+
for (const column of originalTable.columns) {
|
|
28655
|
+
if (column.references && !deferredForeignKeys.has(foreignKeyKey(originalTable.table, column.name)))
|
|
28656
|
+
operations.push({ kind: "add_foreign_key", table: originalTable.table, column: column.name, destructive: false, sql: createTableStatement });
|
|
28657
|
+
}
|
|
28658
|
+
if (tableIndex === orderedNewTables.length - 1) {
|
|
28659
|
+
for (const deferredTable of orderedNewTables) {
|
|
28660
|
+
for (const column of deferredTable.columns) {
|
|
28661
|
+
if (!column.references || !deferredForeignKeys.has(foreignKeyKey(deferredTable.table, column.name)))
|
|
28671
28662
|
continue;
|
|
28672
|
-
|
|
28673
|
-
|
|
28674
|
-
|
|
28663
|
+
const addForeignKey = driver.addForeignKey(deferredTable.table, column.name, column.references.table, column.references.column, column.references.onDelete, column.references.onUpdate);
|
|
28664
|
+
if (!addForeignKey)
|
|
28665
|
+
continue;
|
|
28666
|
+
tableStatements.push(addForeignKey);
|
|
28667
|
+
operations.push({ kind: "add_foreign_key", table: deferredTable.table, column: column.name, destructive: false, sql: addForeignKey });
|
|
28675
28668
|
}
|
|
28676
28669
|
}
|
|
28677
28670
|
}
|
|
28671
|
+
chunks.push(...tableStatements);
|
|
28672
|
+
operations.push({ kind: "create_table", table: t2.table, destructive: false, sql: createTableStatement });
|
|
28673
|
+
const combinedStatement = tableStatements.join(`
|
|
28674
|
+
|
|
28675
|
+
`);
|
|
28676
|
+
emit(combinedStatement, `create-${t2.table}-table`);
|
|
28678
28677
|
}
|
|
28679
28678
|
const enumTypes = new Set;
|
|
28680
28679
|
for (const tableName of Object.keys(nextTables)) {
|
|
@@ -30952,7 +30951,7 @@ function getPrefix() {
|
|
|
30952
30951
|
}
|
|
30953
30952
|
var prefix = getPrefix();
|
|
30954
30953
|
// package.json
|
|
30955
|
-
var version2 = "0.1.
|
|
30954
|
+
var version2 = "0.1.53";
|
|
30956
30955
|
|
|
30957
30956
|
// bin/cli.ts
|
|
30958
30957
|
init_actions();
|
package/dist/src/index.js
CHANGED
|
@@ -15916,7 +15916,7 @@ function createQueryBuilder(state) {
|
|
|
15916
15916
|
return false;
|
|
15917
15917
|
},
|
|
15918
15918
|
unsafe(query, params) {
|
|
15919
|
-
return
|
|
15919
|
+
return _sql.unsafe(query, params);
|
|
15920
15920
|
},
|
|
15921
15921
|
file(path, params) {
|
|
15922
15922
|
return bunSql.file(path, params);
|
|
@@ -28326,7 +28326,7 @@ function generateSql(plan, opts = {}) {
|
|
|
28326
28326
|
const statements = [];
|
|
28327
28327
|
const driver = getDialectDriver(plan.dialect);
|
|
28328
28328
|
const { tables, deferredForeignKeys } = orderTablesForCreate(plan.tables, plan.dialect);
|
|
28329
|
-
for (const originalTable of tables) {
|
|
28329
|
+
for (const [tableIndex, originalTable] of tables.entries()) {
|
|
28330
28330
|
const t2 = {
|
|
28331
28331
|
...originalTable,
|
|
28332
28332
|
columns: originalTable.columns.map((column) => deferredForeignKeys.has(foreignKeyKey(originalTable.table, column.name)) ? { ...column, references: undefined } : column)
|
|
@@ -28350,23 +28350,23 @@ function generateSql(plan, opts = {}) {
|
|
|
28350
28350
|
tableStatements.push(createTableStatement);
|
|
28351
28351
|
for (const idx of t2.indexes)
|
|
28352
28352
|
tableStatements.push(driver.createIndex(t2.table, idx));
|
|
28353
|
+
if (tableIndex === tables.length - 1) {
|
|
28354
|
+
for (const deferredTable of tables) {
|
|
28355
|
+
for (const column of deferredTable.columns) {
|
|
28356
|
+
if (!column.references || !deferredForeignKeys.has(foreignKeyKey(deferredTable.table, column.name)))
|
|
28357
|
+
continue;
|
|
28358
|
+
const addForeignKey = driver.addForeignKey(deferredTable.table, column.name, column.references.table, column.references.column, column.references.onDelete, column.references.onUpdate);
|
|
28359
|
+
if (addForeignKey)
|
|
28360
|
+
tableStatements.push(addForeignKey);
|
|
28361
|
+
}
|
|
28362
|
+
}
|
|
28363
|
+
}
|
|
28353
28364
|
statements.push(...tableStatements);
|
|
28354
28365
|
const combinedStatement = tableStatements.join(`
|
|
28355
28366
|
|
|
28356
28367
|
`);
|
|
28357
28368
|
emit(combinedStatement, `create-${t2.table}-table`);
|
|
28358
28369
|
}
|
|
28359
|
-
for (const t2 of tables) {
|
|
28360
|
-
for (const c2 of t2.columns) {
|
|
28361
|
-
if (c2.references && deferredForeignKeys.has(foreignKeyKey(t2.table, c2.name))) {
|
|
28362
|
-
const alterTableStatement = driver.addForeignKey(t2.table, c2.name, c2.references.table, c2.references.column, c2.references.onDelete, c2.references.onUpdate);
|
|
28363
|
-
if (!alterTableStatement)
|
|
28364
|
-
continue;
|
|
28365
|
-
statements.push(alterTableStatement);
|
|
28366
|
-
emit(alterTableStatement, `alter-${t2.table}-${c2.name}`);
|
|
28367
|
-
}
|
|
28368
|
-
}
|
|
28369
|
-
}
|
|
28370
28370
|
const totalChanges = migrationsCreatedCount + migrationsUpdatedCount;
|
|
28371
28371
|
if (totalChanges === 0) {
|
|
28372
28372
|
info2("-- Nothing to migrate");
|
|
@@ -28621,59 +28621,58 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
28621
28621
|
info2(`-- Detected dropped table: ${tableName}`);
|
|
28622
28622
|
}
|
|
28623
28623
|
}
|
|
28624
|
-
|
|
28625
|
-
|
|
28626
|
-
|
|
28627
|
-
|
|
28628
|
-
|
|
28629
|
-
|
|
28630
|
-
|
|
28631
|
-
|
|
28632
|
-
|
|
28633
|
-
|
|
28634
|
-
|
|
28635
|
-
|
|
28636
|
-
|
|
28637
|
-
|
|
28638
|
-
|
|
28624
|
+
const newTablePlans = Object.keys(nextTables).filter((tableName) => !prevTables[tableName]).map((tableName) => nextTables[tableName]);
|
|
28625
|
+
const { tables: orderedNewTables, deferredForeignKeys } = orderTablesForCreate(newTablePlans, dialect);
|
|
28626
|
+
for (const [tableIndex, originalTable] of orderedNewTables.entries()) {
|
|
28627
|
+
const t2 = {
|
|
28628
|
+
...originalTable,
|
|
28629
|
+
columns: originalTable.columns.map((column) => deferredForeignKeys.has(foreignKeyKey(originalTable.table, column.name)) ? { ...column, references: undefined } : column)
|
|
28630
|
+
};
|
|
28631
|
+
const tableStatements = [];
|
|
28632
|
+
const enumTypes2 = new Set;
|
|
28633
|
+
for (const c2 of t2.columns) {
|
|
28634
|
+
if (c2.type === "enum" && c2.enumValues && c2.enumValues.length > 0) {
|
|
28635
|
+
const enumTypeName = `${t2.table}_${c2.name}_type`;
|
|
28636
|
+
c2.enumTypeName = enumTypeName;
|
|
28637
|
+
if (!enumTypes2.has(enumTypeName)) {
|
|
28638
|
+
const createEnumStatement = driver.createEnumType(enumTypeName, c2.enumValues);
|
|
28639
|
+
if (createEnumStatement) {
|
|
28640
|
+
tableStatements.push(createEnumStatement);
|
|
28639
28641
|
}
|
|
28642
|
+
enumTypes2.add(enumTypeName);
|
|
28640
28643
|
}
|
|
28641
28644
|
}
|
|
28642
|
-
const createTableStatement = driver.createTable(t2);
|
|
28643
|
-
tableStatements.push(createTableStatement);
|
|
28644
|
-
chunks.push(...tableStatements);
|
|
28645
|
-
operations.push({ kind: "create_table", table: t2.table, destructive: false, sql: createTableStatement });
|
|
28646
|
-
const combinedStatement = tableStatements.join(`
|
|
28647
|
-
|
|
28648
|
-
`);
|
|
28649
|
-
emit(combinedStatement, `create-${t2.table}-table`);
|
|
28650
28645
|
}
|
|
28651
|
-
|
|
28652
|
-
|
|
28653
|
-
|
|
28654
|
-
const
|
|
28655
|
-
|
|
28656
|
-
|
|
28657
|
-
|
|
28658
|
-
|
|
28659
|
-
|
|
28660
|
-
|
|
28661
|
-
}
|
|
28662
|
-
|
|
28663
|
-
|
|
28664
|
-
|
|
28665
|
-
|
|
28666
|
-
for (const c2 of t2.columns) {
|
|
28667
|
-
if (c2.references) {
|
|
28668
|
-
const alterTableStatement = driver.addForeignKey(t2.table, c2.name, c2.references.table, c2.references.column, c2.references.onDelete, c2.references.onUpdate);
|
|
28669
|
-
if (!alterTableStatement)
|
|
28646
|
+
const createTableStatement = driver.createTable(t2);
|
|
28647
|
+
tableStatements.push(createTableStatement);
|
|
28648
|
+
for (const idx of t2.indexes) {
|
|
28649
|
+
const createIndexStatement = driver.createIndex(t2.table, idx);
|
|
28650
|
+
tableStatements.push(createIndexStatement);
|
|
28651
|
+
operations.push({ kind: "create_index", table: t2.table, column: idx.name, destructive: false, sql: createIndexStatement });
|
|
28652
|
+
}
|
|
28653
|
+
for (const column of originalTable.columns) {
|
|
28654
|
+
if (column.references && !deferredForeignKeys.has(foreignKeyKey(originalTable.table, column.name)))
|
|
28655
|
+
operations.push({ kind: "add_foreign_key", table: originalTable.table, column: column.name, destructive: false, sql: createTableStatement });
|
|
28656
|
+
}
|
|
28657
|
+
if (tableIndex === orderedNewTables.length - 1) {
|
|
28658
|
+
for (const deferredTable of orderedNewTables) {
|
|
28659
|
+
for (const column of deferredTable.columns) {
|
|
28660
|
+
if (!column.references || !deferredForeignKeys.has(foreignKeyKey(deferredTable.table, column.name)))
|
|
28670
28661
|
continue;
|
|
28671
|
-
|
|
28672
|
-
|
|
28673
|
-
|
|
28662
|
+
const addForeignKey = driver.addForeignKey(deferredTable.table, column.name, column.references.table, column.references.column, column.references.onDelete, column.references.onUpdate);
|
|
28663
|
+
if (!addForeignKey)
|
|
28664
|
+
continue;
|
|
28665
|
+
tableStatements.push(addForeignKey);
|
|
28666
|
+
operations.push({ kind: "add_foreign_key", table: deferredTable.table, column: column.name, destructive: false, sql: addForeignKey });
|
|
28674
28667
|
}
|
|
28675
28668
|
}
|
|
28676
28669
|
}
|
|
28670
|
+
chunks.push(...tableStatements);
|
|
28671
|
+
operations.push({ kind: "create_table", table: t2.table, destructive: false, sql: createTableStatement });
|
|
28672
|
+
const combinedStatement = tableStatements.join(`
|
|
28673
|
+
|
|
28674
|
+
`);
|
|
28675
|
+
emit(combinedStatement, `create-${t2.table}-table`);
|
|
28677
28676
|
}
|
|
28678
28677
|
const enumTypes = new Set;
|
|
28679
28678
|
for (const tableName of Object.keys(nextTables)) {
|
package/package.json
CHANGED