bun-query-builder 0.2.20 → 0.2.22
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 +19 -15
- package/dist/src/index.js +18 -14
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -17890,20 +17890,23 @@ async function buildPgTable(qb, table, enumLabels) {
|
|
|
17890
17890
|
WHERE t.relname = $1 AND t.relkind = 'r'
|
|
17891
17891
|
ORDER BY i.relname, ord`, [table]);
|
|
17892
17892
|
const fkRows = await qb.unsafe(`SELECT kcu.column_name, ccu.table_name AS ref_table, ccu.column_name AS ref_column,
|
|
17893
|
-
tc.constraint_name, rc.delete_rule, rc.update_rule
|
|
17894
|
-
(SELECT COUNT(*) FROM information_schema.key_column_usage count_kcu
|
|
17895
|
-
WHERE count_kcu.constraint_name = tc.constraint_name
|
|
17896
|
-
AND count_kcu.constraint_schema = tc.constraint_schema) AS constraint_column_count
|
|
17893
|
+
tc.constraint_name, rc.delete_rule, rc.update_rule
|
|
17897
17894
|
FROM information_schema.table_constraints tc
|
|
17898
17895
|
JOIN information_schema.key_column_usage kcu ON kcu.constraint_name = tc.constraint_name
|
|
17899
17896
|
JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name
|
|
17900
17897
|
JOIN information_schema.referential_constraints rc ON rc.constraint_name = tc.constraint_name
|
|
17901
17898
|
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = $1 AND tc.table_schema = 'public'`, [table]);
|
|
17902
17899
|
const fkByColumn = new Map;
|
|
17900
|
+
const fkColumnCounts = new Map;
|
|
17901
|
+
for (const fk of fkRows) {
|
|
17902
|
+
const constraintName = String(fk.constraint_name);
|
|
17903
|
+
fkColumnCounts.set(constraintName, (fkColumnCounts.get(constraintName) ?? 0) + 1);
|
|
17904
|
+
}
|
|
17903
17905
|
for (const fk of fkRows) {
|
|
17904
17906
|
const name = String(fk.column_name);
|
|
17905
17907
|
const existing = fkByColumn.get(name);
|
|
17906
|
-
const
|
|
17908
|
+
const constraintName = String(fk.constraint_name);
|
|
17909
|
+
const constraintNames = fkColumnCounts.get(constraintName) === 1 ? [...new Set([...existing?.constraintNames ?? [], constraintName])] : existing?.constraintNames;
|
|
17907
17910
|
fkByColumn.set(name, existing ? { ...existing, constraintNames } : {
|
|
17908
17911
|
table: String(fk.ref_table),
|
|
17909
17912
|
column: String(fk.ref_column ?? "id"),
|
|
@@ -17948,21 +17951,22 @@ async function buildMysqlTable(qb, table) {
|
|
|
17948
17951
|
WHERE table_name = ? AND table_schema = DATABASE()
|
|
17949
17952
|
ORDER BY index_name, seq_in_index`, [table]);
|
|
17950
17953
|
const fkRows = await qb.unsafe(`SELECT kcu.column_name, kcu.referenced_table_name AS ref_table, kcu.referenced_column_name AS ref_column,
|
|
17951
|
-
kcu.constraint_name, rc.delete_rule, rc.update_rule
|
|
17952
|
-
(SELECT COUNT(*) FROM information_schema.key_column_usage count_kcu
|
|
17953
|
-
WHERE count_kcu.constraint_name = kcu.constraint_name
|
|
17954
|
-
AND count_kcu.constraint_schema = kcu.constraint_schema) AS constraint_column_count
|
|
17954
|
+
kcu.constraint_name, rc.delete_rule, rc.update_rule
|
|
17955
17955
|
FROM information_schema.key_column_usage kcu
|
|
17956
17956
|
JOIN information_schema.referential_constraints rc
|
|
17957
17957
|
ON rc.constraint_name = kcu.constraint_name AND rc.constraint_schema = kcu.table_schema
|
|
17958
17958
|
WHERE kcu.table_name = ? AND kcu.table_schema = DATABASE() AND kcu.referenced_table_name IS NOT NULL`, [table]);
|
|
17959
17959
|
const fkByColumn = new Map;
|
|
17960
|
+
const fkColumnCounts = new Map;
|
|
17961
|
+
for (const fk of fkRows) {
|
|
17962
|
+
const constraintName = String(fk.constraint_name ?? fk.CONSTRAINT_NAME);
|
|
17963
|
+
fkColumnCounts.set(constraintName, (fkColumnCounts.get(constraintName) ?? 0) + 1);
|
|
17964
|
+
}
|
|
17960
17965
|
for (const fk of fkRows) {
|
|
17961
17966
|
const name = String(fk.column_name ?? fk.COLUMN_NAME);
|
|
17962
17967
|
const existing = fkByColumn.get(name);
|
|
17963
|
-
const columnCount = Number(fk.constraint_column_count ?? fk.CONSTRAINT_COLUMN_COUNT);
|
|
17964
17968
|
const constraintName = String(fk.constraint_name ?? fk.CONSTRAINT_NAME);
|
|
17965
|
-
const constraintNames =
|
|
17969
|
+
const constraintNames = fkColumnCounts.get(constraintName) === 1 ? [...new Set([...existing?.constraintNames ?? [], constraintName])] : existing?.constraintNames;
|
|
17966
17970
|
fkByColumn.set(name, existing ? { ...existing, constraintNames } : {
|
|
17967
17971
|
table: String(fk.ref_table ?? fk.REF_TABLE),
|
|
17968
17972
|
column: String(fk.ref_column ?? fk.REF_COLUMN ?? "id"),
|
|
@@ -28591,7 +28595,7 @@ function buildMigrationPlan2(models, options) {
|
|
|
28591
28595
|
const column = rel.foreignKey ?? `${snakeCase(rel.model)}_id`;
|
|
28592
28596
|
const table2 = meta.modelToTable[rel.model];
|
|
28593
28597
|
if (table2)
|
|
28594
|
-
declaredFkTargets.set(column, table2);
|
|
28598
|
+
declaredFkTargets.set(column, { table: table2, onDelete: rel.onDelete });
|
|
28595
28599
|
}
|
|
28596
28600
|
for (const attrName of Object.keys(attrs)) {
|
|
28597
28601
|
const attr = attrs[attrName];
|
|
@@ -28660,10 +28664,10 @@ function buildMigrationPlan2(models, options) {
|
|
|
28660
28664
|
const declared = declaredFkTargets.get(columnName);
|
|
28661
28665
|
const base = columnName.replace(/_id$/, "");
|
|
28662
28666
|
const maybeModel = base.replace(/(^|_)([a-z])/g, (_2, __, c2) => c2.toUpperCase());
|
|
28663
|
-
const refTable = declared ?? (declaresBelongsTo ? undefined : meta.modelToTable[maybeModel]);
|
|
28667
|
+
const refTable = declared?.table ?? (declaresBelongsTo ? undefined : meta.modelToTable[maybeModel]);
|
|
28664
28668
|
if (refTable) {
|
|
28665
28669
|
const refPk = meta.primaryKeys[refTable] ?? "id";
|
|
28666
|
-
col.references = { table: refTable, column: refPk };
|
|
28670
|
+
col.references = { table: refTable, column: refPk, onDelete: declared?.onDelete };
|
|
28667
28671
|
}
|
|
28668
28672
|
}
|
|
28669
28673
|
}
|
|
@@ -31630,7 +31634,7 @@ function getPrefix() {
|
|
|
31630
31634
|
}
|
|
31631
31635
|
var prefix = getPrefix();
|
|
31632
31636
|
// package.json
|
|
31633
|
-
var version2 = "0.2.
|
|
31637
|
+
var version2 = "0.2.22";
|
|
31634
31638
|
|
|
31635
31639
|
// bin/cli.ts
|
|
31636
31640
|
init_actions();
|
package/dist/src/index.js
CHANGED
|
@@ -17889,20 +17889,23 @@ async function buildPgTable(qb, table, enumLabels) {
|
|
|
17889
17889
|
WHERE t.relname = $1 AND t.relkind = 'r'
|
|
17890
17890
|
ORDER BY i.relname, ord`, [table]);
|
|
17891
17891
|
const fkRows = await qb.unsafe(`SELECT kcu.column_name, ccu.table_name AS ref_table, ccu.column_name AS ref_column,
|
|
17892
|
-
tc.constraint_name, rc.delete_rule, rc.update_rule
|
|
17893
|
-
(SELECT COUNT(*) FROM information_schema.key_column_usage count_kcu
|
|
17894
|
-
WHERE count_kcu.constraint_name = tc.constraint_name
|
|
17895
|
-
AND count_kcu.constraint_schema = tc.constraint_schema) AS constraint_column_count
|
|
17892
|
+
tc.constraint_name, rc.delete_rule, rc.update_rule
|
|
17896
17893
|
FROM information_schema.table_constraints tc
|
|
17897
17894
|
JOIN information_schema.key_column_usage kcu ON kcu.constraint_name = tc.constraint_name
|
|
17898
17895
|
JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name
|
|
17899
17896
|
JOIN information_schema.referential_constraints rc ON rc.constraint_name = tc.constraint_name
|
|
17900
17897
|
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = $1 AND tc.table_schema = 'public'`, [table]);
|
|
17901
17898
|
const fkByColumn = new Map;
|
|
17899
|
+
const fkColumnCounts = new Map;
|
|
17900
|
+
for (const fk of fkRows) {
|
|
17901
|
+
const constraintName = String(fk.constraint_name);
|
|
17902
|
+
fkColumnCounts.set(constraintName, (fkColumnCounts.get(constraintName) ?? 0) + 1);
|
|
17903
|
+
}
|
|
17902
17904
|
for (const fk of fkRows) {
|
|
17903
17905
|
const name = String(fk.column_name);
|
|
17904
17906
|
const existing = fkByColumn.get(name);
|
|
17905
|
-
const
|
|
17907
|
+
const constraintName = String(fk.constraint_name);
|
|
17908
|
+
const constraintNames = fkColumnCounts.get(constraintName) === 1 ? [...new Set([...existing?.constraintNames ?? [], constraintName])] : existing?.constraintNames;
|
|
17906
17909
|
fkByColumn.set(name, existing ? { ...existing, constraintNames } : {
|
|
17907
17910
|
table: String(fk.ref_table),
|
|
17908
17911
|
column: String(fk.ref_column ?? "id"),
|
|
@@ -17947,21 +17950,22 @@ async function buildMysqlTable(qb, table) {
|
|
|
17947
17950
|
WHERE table_name = ? AND table_schema = DATABASE()
|
|
17948
17951
|
ORDER BY index_name, seq_in_index`, [table]);
|
|
17949
17952
|
const fkRows = await qb.unsafe(`SELECT kcu.column_name, kcu.referenced_table_name AS ref_table, kcu.referenced_column_name AS ref_column,
|
|
17950
|
-
kcu.constraint_name, rc.delete_rule, rc.update_rule
|
|
17951
|
-
(SELECT COUNT(*) FROM information_schema.key_column_usage count_kcu
|
|
17952
|
-
WHERE count_kcu.constraint_name = kcu.constraint_name
|
|
17953
|
-
AND count_kcu.constraint_schema = kcu.constraint_schema) AS constraint_column_count
|
|
17953
|
+
kcu.constraint_name, rc.delete_rule, rc.update_rule
|
|
17954
17954
|
FROM information_schema.key_column_usage kcu
|
|
17955
17955
|
JOIN information_schema.referential_constraints rc
|
|
17956
17956
|
ON rc.constraint_name = kcu.constraint_name AND rc.constraint_schema = kcu.table_schema
|
|
17957
17957
|
WHERE kcu.table_name = ? AND kcu.table_schema = DATABASE() AND kcu.referenced_table_name IS NOT NULL`, [table]);
|
|
17958
17958
|
const fkByColumn = new Map;
|
|
17959
|
+
const fkColumnCounts = new Map;
|
|
17960
|
+
for (const fk of fkRows) {
|
|
17961
|
+
const constraintName = String(fk.constraint_name ?? fk.CONSTRAINT_NAME);
|
|
17962
|
+
fkColumnCounts.set(constraintName, (fkColumnCounts.get(constraintName) ?? 0) + 1);
|
|
17963
|
+
}
|
|
17959
17964
|
for (const fk of fkRows) {
|
|
17960
17965
|
const name = String(fk.column_name ?? fk.COLUMN_NAME);
|
|
17961
17966
|
const existing = fkByColumn.get(name);
|
|
17962
|
-
const columnCount = Number(fk.constraint_column_count ?? fk.CONSTRAINT_COLUMN_COUNT);
|
|
17963
17967
|
const constraintName = String(fk.constraint_name ?? fk.CONSTRAINT_NAME);
|
|
17964
|
-
const constraintNames =
|
|
17968
|
+
const constraintNames = fkColumnCounts.get(constraintName) === 1 ? [...new Set([...existing?.constraintNames ?? [], constraintName])] : existing?.constraintNames;
|
|
17965
17969
|
fkByColumn.set(name, existing ? { ...existing, constraintNames } : {
|
|
17966
17970
|
table: String(fk.ref_table ?? fk.REF_TABLE),
|
|
17967
17971
|
column: String(fk.ref_column ?? fk.REF_COLUMN ?? "id"),
|
|
@@ -28590,7 +28594,7 @@ function buildMigrationPlan2(models, options) {
|
|
|
28590
28594
|
const column = rel.foreignKey ?? `${snakeCase(rel.model)}_id`;
|
|
28591
28595
|
const table2 = meta.modelToTable[rel.model];
|
|
28592
28596
|
if (table2)
|
|
28593
|
-
declaredFkTargets.set(column, table2);
|
|
28597
|
+
declaredFkTargets.set(column, { table: table2, onDelete: rel.onDelete });
|
|
28594
28598
|
}
|
|
28595
28599
|
for (const attrName of Object.keys(attrs)) {
|
|
28596
28600
|
const attr = attrs[attrName];
|
|
@@ -28659,10 +28663,10 @@ function buildMigrationPlan2(models, options) {
|
|
|
28659
28663
|
const declared = declaredFkTargets.get(columnName);
|
|
28660
28664
|
const base = columnName.replace(/_id$/, "");
|
|
28661
28665
|
const maybeModel = base.replace(/(^|_)([a-z])/g, (_2, __, c2) => c2.toUpperCase());
|
|
28662
|
-
const refTable = declared ?? (declaresBelongsTo ? undefined : meta.modelToTable[maybeModel]);
|
|
28666
|
+
const refTable = declared?.table ?? (declaresBelongsTo ? undefined : meta.modelToTable[maybeModel]);
|
|
28663
28667
|
if (refTable) {
|
|
28664
28668
|
const refPk = meta.primaryKeys[refTable] ?? "id";
|
|
28665
|
-
col.references = { table: refTable, column: refPk };
|
|
28669
|
+
col.references = { table: refTable, column: refPk, onDelete: declared?.onDelete };
|
|
28666
28670
|
}
|
|
28667
28671
|
}
|
|
28668
28672
|
}
|
package/package.json
CHANGED