bun-query-builder 0.2.2 → 0.2.3

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
@@ -28759,10 +28759,20 @@ function buildMigrationPlan2(models, options) {
28759
28759
  const pivotTable = cfg.table || [parentSingular, relatedSingular].sort().join("_");
28760
28760
  const fkParent = cfg.foreignKey || `${parentSingular}_id`;
28761
28761
  const fkRelated = cfg.relatedKey || `${relatedSingular}_id`;
28762
+ const pivotColumnNames = new Set([fkParent, fkRelated, ...Object.keys(pivotCfg.columns ?? {})]);
28763
+ const pivotPolymorphic = new Set;
28764
+ for (const column of pivotColumnNames) {
28765
+ if (!column.endsWith("_type"))
28766
+ continue;
28767
+ const idColumn = `${column.slice(0, -"_type".length)}_id`;
28768
+ if (pivotColumnNames.has(idColumn))
28769
+ pivotPolymorphic.add(idColumn);
28770
+ }
28771
+ const referenceTo = (column, table) => pivotPolymorphic.has(column) ? undefined : { table, column: "id" };
28762
28772
  const cols = [
28763
28773
  { name: "id", type: "bigint", isPrimaryKey: true, isUnique: false, isNullable: false, hasDefault: false },
28764
- { name: fkParent, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: { table: parentTable, column: "id" } },
28765
- { name: fkRelated, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: { table: relatedTable, column: "id" } }
28774
+ { name: fkParent, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: referenceTo(fkParent, parentTable) },
28775
+ { name: fkRelated, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: referenceTo(fkRelated, relatedTable) }
28766
28776
  ];
28767
28777
  if (pivotCfg.columns) {
28768
28778
  for (const [name, attr] of Object.entries(pivotCfg.columns)) {
@@ -31452,7 +31462,7 @@ function getPrefix() {
31452
31462
  }
31453
31463
  var prefix = getPrefix();
31454
31464
  // package.json
31455
- var version2 = "0.2.2";
31465
+ var version2 = "0.2.3";
31456
31466
 
31457
31467
  // bin/cli.ts
31458
31468
  init_actions();
package/dist/src/index.js CHANGED
@@ -28758,10 +28758,20 @@ function buildMigrationPlan2(models, options) {
28758
28758
  const pivotTable = cfg.table || [parentSingular, relatedSingular].sort().join("_");
28759
28759
  const fkParent = cfg.foreignKey || `${parentSingular}_id`;
28760
28760
  const fkRelated = cfg.relatedKey || `${relatedSingular}_id`;
28761
+ const pivotColumnNames = new Set([fkParent, fkRelated, ...Object.keys(pivotCfg.columns ?? {})]);
28762
+ const pivotPolymorphic = new Set;
28763
+ for (const column of pivotColumnNames) {
28764
+ if (!column.endsWith("_type"))
28765
+ continue;
28766
+ const idColumn = `${column.slice(0, -"_type".length)}_id`;
28767
+ if (pivotColumnNames.has(idColumn))
28768
+ pivotPolymorphic.add(idColumn);
28769
+ }
28770
+ const referenceTo = (column, table) => pivotPolymorphic.has(column) ? undefined : { table, column: "id" };
28761
28771
  const cols = [
28762
28772
  { name: "id", type: "bigint", isPrimaryKey: true, isUnique: false, isNullable: false, hasDefault: false },
28763
- { name: fkParent, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: { table: parentTable, column: "id" } },
28764
- { name: fkRelated, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: { table: relatedTable, column: "id" } }
28773
+ { name: fkParent, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: referenceTo(fkParent, parentTable) },
28774
+ { name: fkRelated, type: "bigint", isPrimaryKey: false, isUnique: false, isNullable: false, hasDefault: false, references: referenceTo(fkRelated, relatedTable) }
28765
28775
  ];
28766
28776
  if (pivotCfg.columns) {
28767
28777
  for (const [name, attr] of Object.entries(pivotCfg.columns)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.2.3",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",