bun-query-builder 0.2.15 → 0.2.17

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.
@@ -13,6 +13,11 @@ export declare function generateModelSource(table: string, columns: Introspected
13
13
  export declare function introspectDatabase(opts?: { tables?: string[] }): Promise<IntrospectedModel[]>;
14
14
  /** Map a raw SQL column type back to a normalized model column type. */
15
15
  export declare function sqlTypeToNormalized(rawType: string, dialect: SupportedDialect, ctx?: { enumValues?: string[] }): NormalizedColumnType;
16
+ /**
17
+ * Normalize a MySQL information_schema column without discarding physical
18
+ * details carried only by COLUMN_TYPE (for example TINYINT(1) and VARCHAR(n)).
19
+ */
20
+ export declare function mysqlColumnType(dataType: unknown, columnType: unknown, enumValues?: string[]): NormalizedColumnType;
16
21
  /**
17
22
  * The plan type for one Postgres column, given what the catalogue knows.
18
23
  *
package/dist/bin/cli.js CHANGED
@@ -17764,6 +17764,9 @@ function sqlTypeToNormalized(rawType, dialect, ctx) {
17764
17764
  return "enum";
17765
17765
  return "string";
17766
17766
  }
17767
+ function mysqlColumnType(dataType, columnType, enumValues) {
17768
+ return sqlTypeToNormalized(String(columnType || dataType || ""), "mysql", { enumValues });
17769
+ }
17767
17770
  function asAction(raw2) {
17768
17771
  const v = String(raw2 ?? "").toLowerCase().trim();
17769
17772
  if (v === "cascade" || v === "restrict" || v === "set null")
@@ -17959,7 +17962,7 @@ async function buildMysqlTable(qb, table) {
17959
17962
  const hasDefault = rawDefault != null;
17960
17963
  return {
17961
17964
  name,
17962
- type: sqlTypeToNormalized(String(r.data_type ?? r.DATA_TYPE ?? columnType), "mysql", { enumValues }),
17965
+ type: mysqlColumnType(r.data_type ?? r.DATA_TYPE, columnType, enumValues),
17963
17966
  isPrimaryKey,
17964
17967
  isUnique: uniqueColumns.has(name),
17965
17968
  isNullable: isPrimaryKey ? false : String(r.is_nullable ?? r.IS_NULLABLE).toUpperCase() === "YES",
@@ -28885,6 +28888,20 @@ function buildMigrationPlan2(models, options) {
28885
28888
  ensureTable({ table: pivotTable, columns: cols, indexes: idx });
28886
28889
  }
28887
28890
  }
28891
+ const tablesByName = new Map(tables.map((table) => [table.table, table]));
28892
+ for (const table of tables) {
28893
+ for (const column of table.columns) {
28894
+ if (!column.references)
28895
+ continue;
28896
+ const referenced = tablesByName.get(column.references.table)?.columns.find((candidate) => candidate.name === column.references.column);
28897
+ if (!referenced || column.type === referenced.type)
28898
+ continue;
28899
+ column.type = referenced.type;
28900
+ column.maxLength = referenced.maxLength;
28901
+ column.enumValues = referenced.enumValues;
28902
+ column.enumTypeName = referenced.enumTypeName;
28903
+ }
28904
+ }
28888
28905
  return { dialect: options.dialect, vitessSharded: options.vitessSharded, tables };
28889
28906
  }
28890
28907
  function generateSql(plan, opts = {}) {
@@ -31548,7 +31565,7 @@ function getPrefix() {
31548
31565
  }
31549
31566
  var prefix = getPrefix();
31550
31567
  // package.json
31551
- var version2 = "0.2.15";
31568
+ var version2 = "0.2.17";
31552
31569
 
31553
31570
  // bin/cli.ts
31554
31571
  init_actions();
package/dist/src/index.js CHANGED
@@ -17763,6 +17763,9 @@ function sqlTypeToNormalized(rawType, dialect, ctx) {
17763
17763
  return "enum";
17764
17764
  return "string";
17765
17765
  }
17766
+ function mysqlColumnType(dataType, columnType, enumValues) {
17767
+ return sqlTypeToNormalized(String(columnType || dataType || ""), "mysql", { enumValues });
17768
+ }
17766
17769
  function asAction(raw2) {
17767
17770
  const v = String(raw2 ?? "").toLowerCase().trim();
17768
17771
  if (v === "cascade" || v === "restrict" || v === "set null")
@@ -17958,7 +17961,7 @@ async function buildMysqlTable(qb, table) {
17958
17961
  const hasDefault = rawDefault != null;
17959
17962
  return {
17960
17963
  name,
17961
- type: sqlTypeToNormalized(String(r.data_type ?? r.DATA_TYPE ?? columnType), "mysql", { enumValues }),
17964
+ type: mysqlColumnType(r.data_type ?? r.DATA_TYPE, columnType, enumValues),
17962
17965
  isPrimaryKey,
17963
17966
  isUnique: uniqueColumns.has(name),
17964
17967
  isNullable: isPrimaryKey ? false : String(r.is_nullable ?? r.IS_NULLABLE).toUpperCase() === "YES",
@@ -28884,6 +28887,20 @@ function buildMigrationPlan2(models, options) {
28884
28887
  ensureTable({ table: pivotTable, columns: cols, indexes: idx });
28885
28888
  }
28886
28889
  }
28890
+ const tablesByName = new Map(tables.map((table) => [table.table, table]));
28891
+ for (const table of tables) {
28892
+ for (const column of table.columns) {
28893
+ if (!column.references)
28894
+ continue;
28895
+ const referenced = tablesByName.get(column.references.table)?.columns.find((candidate) => candidate.name === column.references.column);
28896
+ if (!referenced || column.type === referenced.type)
28897
+ continue;
28898
+ column.type = referenced.type;
28899
+ column.maxLength = referenced.maxLength;
28900
+ column.enumValues = referenced.enumValues;
28901
+ column.enumTypeName = referenced.enumTypeName;
28902
+ }
28903
+ }
28887
28904
  return { dialect: options.dialect, vitessSharded: options.vitessSharded, tables };
28888
28905
  }
28889
28906
  function generateSql(plan, opts = {}) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.15",
4
+ "version": "0.2.17",
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",