bun-query-builder 0.2.18 → 0.2.19

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.
@@ -18,6 +18,8 @@ export declare function sqlTypeToNormalized(rawType: string, dialect: SupportedD
18
18
  * details carried only by COLUMN_TYPE (for example TINYINT(1) and VARCHAR(n)).
19
19
  */
20
20
  export declare function mysqlColumnType(dataType: unknown, columnType: unknown, enumValues?: string[]): NormalizedColumnType;
21
+ /** Preserve the physical bound of a MySQL VARCHAR column for round-trip diffs. */
22
+ export declare function mysqlColumnMaxLength(columnType: unknown): number | undefined;
21
23
  /**
22
24
  * The plan type for one Postgres column, given what the catalogue knows.
23
25
  *
package/dist/bin/cli.js CHANGED
@@ -17740,6 +17740,8 @@ function sqlTypeToNormalized(rawType, dialect, ctx) {
17740
17740
  if (/^(?:varchar|character varying|nvarchar|nchar|char|character|bpchar)/.test(base)) {
17741
17741
  const m = t.match(/\((\d+)\)/);
17742
17742
  const len = m ? Number(m[1]) : undefined;
17743
+ if (isMysqlLike(dialect))
17744
+ return "string";
17743
17745
  return len !== undefined && len > 255 ? "text" : "string";
17744
17746
  }
17745
17747
  if (/text|clob/.test(base))
@@ -17767,6 +17769,13 @@ function sqlTypeToNormalized(rawType, dialect, ctx) {
17767
17769
  function mysqlColumnType(dataType, columnType, enumValues) {
17768
17770
  return sqlTypeToNormalized(String(columnType || dataType || ""), "mysql", { enumValues });
17769
17771
  }
17772
+ function mysqlColumnMaxLength(columnType) {
17773
+ const match = String(columnType || "").trim().match(/^varchar\((\d+)\)/i);
17774
+ if (!match)
17775
+ return;
17776
+ const length = Number(match[1]);
17777
+ return Number.isSafeInteger(length) && length > 0 ? length : undefined;
17778
+ }
17770
17779
  function asAction(raw2) {
17771
17780
  const v = String(raw2 ?? "").toLowerCase().trim();
17772
17781
  if (v === "cascade" || v === "restrict" || v === "set null")
@@ -17969,6 +17978,7 @@ async function buildMysqlTable(qb, table) {
17969
17978
  hasDefault,
17970
17979
  defaultValue: hasDefault ? normalizeRawDefault(rawDefault) : undefined,
17971
17980
  enumValues,
17981
+ maxLength: mysqlColumnMaxLength(columnType),
17972
17982
  references: fkByColumn.get(name)
17973
17983
  };
17974
17984
  });
@@ -29124,6 +29134,37 @@ function canonicalStorageType(col, dialect) {
29124
29134
  return "TEXT";
29125
29135
  }
29126
29136
  }
29137
+ if (dialect === "mysql" || dialect === "vitess" || dialect === "singlestore") {
29138
+ switch (col.type) {
29139
+ case "string":
29140
+ return `VARCHAR(${col.maxLength ?? 255})`;
29141
+ case "text":
29142
+ return "TEXT";
29143
+ case "boolean":
29144
+ return "TINYINT(1)";
29145
+ case "integer":
29146
+ return "INTEGER";
29147
+ case "bigint":
29148
+ return "BIGINT";
29149
+ case "float":
29150
+ return "REAL";
29151
+ case "double":
29152
+ return "DOUBLE";
29153
+ case "decimal":
29154
+ return "DECIMAL";
29155
+ case "date":
29156
+ return "DATE";
29157
+ case "datetime":
29158
+ case "timestamptz":
29159
+ return "DATETIME";
29160
+ case "json":
29161
+ return "JSON";
29162
+ case "enum":
29163
+ return "ENUM";
29164
+ default:
29165
+ return col.type;
29166
+ }
29167
+ }
29127
29168
  return col.type;
29128
29169
  }
29129
29170
  function canonicalizeDefault(col) {
@@ -31627,7 +31668,7 @@ function getPrefix() {
31627
31668
  }
31628
31669
  var prefix = getPrefix();
31629
31670
  // package.json
31630
- var version2 = "0.2.18";
31671
+ var version2 = "0.2.19";
31631
31672
 
31632
31673
  // bin/cli.ts
31633
31674
  init_actions();
package/dist/src/index.js CHANGED
@@ -17739,6 +17739,8 @@ function sqlTypeToNormalized(rawType, dialect, ctx) {
17739
17739
  if (/^(?:varchar|character varying|nvarchar|nchar|char|character|bpchar)/.test(base)) {
17740
17740
  const m = t.match(/\((\d+)\)/);
17741
17741
  const len = m ? Number(m[1]) : undefined;
17742
+ if (isMysqlLike(dialect))
17743
+ return "string";
17742
17744
  return len !== undefined && len > 255 ? "text" : "string";
17743
17745
  }
17744
17746
  if (/text|clob/.test(base))
@@ -17766,6 +17768,13 @@ function sqlTypeToNormalized(rawType, dialect, ctx) {
17766
17768
  function mysqlColumnType(dataType, columnType, enumValues) {
17767
17769
  return sqlTypeToNormalized(String(columnType || dataType || ""), "mysql", { enumValues });
17768
17770
  }
17771
+ function mysqlColumnMaxLength(columnType) {
17772
+ const match = String(columnType || "").trim().match(/^varchar\((\d+)\)/i);
17773
+ if (!match)
17774
+ return;
17775
+ const length = Number(match[1]);
17776
+ return Number.isSafeInteger(length) && length > 0 ? length : undefined;
17777
+ }
17769
17778
  function asAction(raw2) {
17770
17779
  const v = String(raw2 ?? "").toLowerCase().trim();
17771
17780
  if (v === "cascade" || v === "restrict" || v === "set null")
@@ -17968,6 +17977,7 @@ async function buildMysqlTable(qb, table) {
17968
17977
  hasDefault,
17969
17978
  defaultValue: hasDefault ? normalizeRawDefault(rawDefault) : undefined,
17970
17979
  enumValues,
17980
+ maxLength: mysqlColumnMaxLength(columnType),
17971
17981
  references: fkByColumn.get(name)
17972
17982
  };
17973
17983
  });
@@ -29123,6 +29133,37 @@ function canonicalStorageType(col, dialect) {
29123
29133
  return "TEXT";
29124
29134
  }
29125
29135
  }
29136
+ if (dialect === "mysql" || dialect === "vitess" || dialect === "singlestore") {
29137
+ switch (col.type) {
29138
+ case "string":
29139
+ return `VARCHAR(${col.maxLength ?? 255})`;
29140
+ case "text":
29141
+ return "TEXT";
29142
+ case "boolean":
29143
+ return "TINYINT(1)";
29144
+ case "integer":
29145
+ return "INTEGER";
29146
+ case "bigint":
29147
+ return "BIGINT";
29148
+ case "float":
29149
+ return "REAL";
29150
+ case "double":
29151
+ return "DOUBLE";
29152
+ case "decimal":
29153
+ return "DECIMAL";
29154
+ case "date":
29155
+ return "DATE";
29156
+ case "datetime":
29157
+ case "timestamptz":
29158
+ return "DATETIME";
29159
+ case "json":
29160
+ return "JSON";
29161
+ case "enum":
29162
+ return "ENUM";
29163
+ default:
29164
+ return col.type;
29165
+ }
29166
+ }
29126
29167
  return col.type;
29127
29168
  }
29128
29169
  function canonicalizeDefault(col) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.18",
4
+ "version": "0.2.19",
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",