bun-query-builder 0.2.9 → 0.2.11

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
@@ -18772,7 +18772,7 @@ class SQLiteDriver {
18772
18772
  var init_sqlite = () => {};
18773
18773
 
18774
18774
  // src/drivers/index.ts
18775
- function getDialectDriver(dialect) {
18775
+ function getDialectDriver(dialect, options = {}) {
18776
18776
  switch (dialect) {
18777
18777
  case "postgres":
18778
18778
  return new PostgresDriver;
@@ -18781,7 +18781,7 @@ function getDialectDriver(dialect) {
18781
18781
  case "singlestore":
18782
18782
  return new SingleStoreDriver;
18783
18783
  case "vitess":
18784
- return new VitessDriver(config5.vitess?.sharded ?? true);
18784
+ return new VitessDriver(options.vitessSharded ?? config5.vitess?.sharded ?? true);
18785
18785
  case "sqlite":
18786
18786
  return new SQLiteDriver;
18787
18787
  default:
@@ -18941,7 +18941,7 @@ async function generateMigration(dir, opts = {}) {
18941
18941
  const dialect = opts.dialect || config5.dialect || "postgres";
18942
18942
  const workspaceRoot = getWorkspaceRoot();
18943
18943
  const models = await loadModels({ modelsDir: dir });
18944
- const plan = buildMigrationPlan2(models, { dialect });
18944
+ const plan = buildMigrationPlan2(models, { dialect, vitessSharded: opts.vitessSharded });
18945
18945
  let previous;
18946
18946
  let reconciledFromDatabase = false;
18947
18947
  if (!opts.full) {
@@ -28347,6 +28347,9 @@ ${statement}`);
28347
28347
  existingCorpusBodies?.add(body);
28348
28348
  return true;
28349
28349
  }
28350
+ function isLosslessTypeChange(from, to) {
28351
+ return from === "integer" && to === "bigint" || from === "string" && to === "text";
28352
+ }
28350
28353
  function guessTypeFromName(columnName) {
28351
28354
  if (columnName.endsWith("_id"))
28352
28355
  return "bigint";
@@ -28879,7 +28882,7 @@ function buildMigrationPlan2(models, options) {
28879
28882
  ensureTable({ table: pivotTable, columns: cols, indexes: idx });
28880
28883
  }
28881
28884
  }
28882
- return { dialect: options.dialect, tables };
28885
+ return { dialect: options.dialect, vitessSharded: options.vitessSharded, tables };
28883
28886
  }
28884
28887
  function generateSql(plan, opts = {}) {
28885
28888
  migrationCounter = 0;
@@ -28890,7 +28893,7 @@ function generateSql(plan, opts = {}) {
28890
28893
  useDeterministicNames = true;
28891
28894
  const emit = opts.dryRun ? () => false : createMigrationFile;
28892
28895
  const statements = [];
28893
- const driver = getDialectDriver(plan.dialect);
28896
+ const driver = getDialectDriver(plan.dialect, { vitessSharded: plan.vitessSharded });
28894
28897
  const { tables, deferredForeignKeys } = orderTablesForCreate(plan.tables, plan.dialect);
28895
28898
  for (const [tableIndex, originalTable] of tables.entries()) {
28896
28899
  const t2 = {
@@ -29179,7 +29182,7 @@ function generateDiffOperations(previous, next, opts = {}) {
29179
29182
  useDeterministicNames = false;
29180
29183
  const chunks = [];
29181
29184
  const operations = [];
29182
- const driver = getDialectDriver(next.dialect);
29185
+ const driver = getDialectDriver(next.dialect, { vitessSharded: next.vitessSharded });
29183
29186
  const dialect = next.dialect;
29184
29187
  const prevTables = mapTablesByName(previous.tables);
29185
29188
  const nextTables = mapTablesByName(next.tables);
@@ -29376,7 +29379,7 @@ function generateDiffOperations(previous, next, opts = {}) {
29376
29379
  kind: "modify_column",
29377
29380
  table: curr.table,
29378
29381
  column: colName,
29379
- destructive: prevCol.type !== currCol.type,
29382
+ destructive: prevCol.type !== currCol.type && !isLosslessTypeChange(prevCol.type, currCol.type),
29380
29383
  sql: modifyColumnStatement
29381
29384
  });
29382
29385
  info2(`-- Detected column change: ${curr.table}.${colName} (${prevCol.type} -> ${currCol.type})`);
@@ -31536,7 +31539,7 @@ function getPrefix() {
31536
31539
  }
31537
31540
  var prefix = getPrefix();
31538
31541
  // package.json
31539
- var version2 = "0.2.9";
31542
+ var version2 = "0.2.11";
31540
31543
 
31541
31544
  // bin/cli.ts
31542
31545
  init_actions();
@@ -28,7 +28,7 @@ export type {
28
28
  DynamoDBUpdateItemParams,
29
29
  SingleTableEntityMapping,
30
30
  } from './dynamodb';
31
- export declare function getDialectDriver(dialect: SupportedDialect): DialectDriver;
31
+ export declare function getDialectDriver(dialect: SupportedDialect, options?: { vitessSharded?: boolean }): DialectDriver;
32
32
  export { MySQLDriver } from './mysql';
33
33
  export { PostgresDriver } from './postgres';
34
34
  export { SingleStoreDriver } from './singlestore';
@@ -10,6 +10,13 @@ export declare function isGeneratedMigrationSql(sql: string): boolean;
10
10
  * the same thing to the schema, whatever they are called.
11
11
  */
12
12
  export declare function migrationBody(sql: string): string;
13
+ /**
14
+ * Whether changing a normalized physical type can preserve every existing
15
+ * value. Keep this deliberately conservative: integer-to-bigint widens the
16
+ * numeric range, and varchar-to-text removes a length ceiling. The reverse
17
+ * directions remain destructive and still require explicit confirmation.
18
+ */
19
+ export declare function isLosslessTypeChange(from: NormalizedColumnType, to: NormalizedColumnType): boolean;
13
20
  export declare function buildMigrationPlan(models: ModelRecord, options: InferenceOptions): MigrationPlan;
14
21
  export declare function generateSql(plan: MigrationPlan, opts?: { dryRun?: boolean }): string[];
15
22
  /**
@@ -105,6 +112,7 @@ export declare interface TablePlan {
105
112
  }
106
113
  export declare interface MigrationPlan {
107
114
  dialect: SupportedDialect
115
+ vitessSharded?: boolean
108
116
  tables: TablePlan[]
109
117
  }
110
118
  /**
@@ -142,6 +150,7 @@ export declare interface DiffResult {
142
150
  }
143
151
  export declare interface InferenceOptions {
144
152
  dialect: SupportedDialect
153
+ vitessSharded?: boolean
145
154
  }
146
155
  export declare interface DiffOptions {
147
156
  applyRenames?: boolean
package/dist/src/index.js CHANGED
@@ -18771,7 +18771,7 @@ class SQLiteDriver {
18771
18771
  var init_sqlite = () => {};
18772
18772
 
18773
18773
  // src/drivers/index.ts
18774
- function getDialectDriver(dialect) {
18774
+ function getDialectDriver(dialect, options = {}) {
18775
18775
  switch (dialect) {
18776
18776
  case "postgres":
18777
18777
  return new PostgresDriver;
@@ -18780,7 +18780,7 @@ function getDialectDriver(dialect) {
18780
18780
  case "singlestore":
18781
18781
  return new SingleStoreDriver;
18782
18782
  case "vitess":
18783
- return new VitessDriver(config5.vitess?.sharded ?? true);
18783
+ return new VitessDriver(options.vitessSharded ?? config5.vitess?.sharded ?? true);
18784
18784
  case "sqlite":
18785
18785
  return new SQLiteDriver;
18786
18786
  default:
@@ -18940,7 +18940,7 @@ async function generateMigration(dir, opts = {}) {
18940
18940
  const dialect = opts.dialect || config5.dialect || "postgres";
18941
18941
  const workspaceRoot = getWorkspaceRoot();
18942
18942
  const models = await loadModels({ modelsDir: dir });
18943
- const plan = buildMigrationPlan2(models, { dialect });
18943
+ const plan = buildMigrationPlan2(models, { dialect, vitessSharded: opts.vitessSharded });
18944
18944
  let previous;
18945
18945
  let reconciledFromDatabase = false;
18946
18946
  if (!opts.full) {
@@ -28346,6 +28346,9 @@ ${statement}`);
28346
28346
  existingCorpusBodies?.add(body);
28347
28347
  return true;
28348
28348
  }
28349
+ function isLosslessTypeChange(from, to) {
28350
+ return from === "integer" && to === "bigint" || from === "string" && to === "text";
28351
+ }
28349
28352
  function guessTypeFromName(columnName) {
28350
28353
  if (columnName.endsWith("_id"))
28351
28354
  return "bigint";
@@ -28878,7 +28881,7 @@ function buildMigrationPlan2(models, options) {
28878
28881
  ensureTable({ table: pivotTable, columns: cols, indexes: idx });
28879
28882
  }
28880
28883
  }
28881
- return { dialect: options.dialect, tables };
28884
+ return { dialect: options.dialect, vitessSharded: options.vitessSharded, tables };
28882
28885
  }
28883
28886
  function generateSql(plan, opts = {}) {
28884
28887
  migrationCounter = 0;
@@ -28889,7 +28892,7 @@ function generateSql(plan, opts = {}) {
28889
28892
  useDeterministicNames = true;
28890
28893
  const emit = opts.dryRun ? () => false : createMigrationFile;
28891
28894
  const statements = [];
28892
- const driver = getDialectDriver(plan.dialect);
28895
+ const driver = getDialectDriver(plan.dialect, { vitessSharded: plan.vitessSharded });
28893
28896
  const { tables, deferredForeignKeys } = orderTablesForCreate(plan.tables, plan.dialect);
28894
28897
  for (const [tableIndex, originalTable] of tables.entries()) {
28895
28898
  const t2 = {
@@ -29178,7 +29181,7 @@ function generateDiffOperations(previous, next, opts = {}) {
29178
29181
  useDeterministicNames = false;
29179
29182
  const chunks = [];
29180
29183
  const operations = [];
29181
- const driver = getDialectDriver(next.dialect);
29184
+ const driver = getDialectDriver(next.dialect, { vitessSharded: next.vitessSharded });
29182
29185
  const dialect = next.dialect;
29183
29186
  const prevTables = mapTablesByName(previous.tables);
29184
29187
  const nextTables = mapTablesByName(next.tables);
@@ -29375,7 +29378,7 @@ function generateDiffOperations(previous, next, opts = {}) {
29375
29378
  kind: "modify_column",
29376
29379
  table: curr.table,
29377
29380
  column: colName,
29378
- destructive: prevCol.type !== currCol.type,
29381
+ destructive: prevCol.type !== currCol.type && !isLosslessTypeChange(prevCol.type, currCol.type),
29379
29382
  sql: modifyColumnStatement
29380
29383
  });
29381
29384
  info2(`-- Detected column change: ${curr.table}.${colName} (${prevCol.type} -> ${currCol.type})`);
@@ -29552,6 +29555,7 @@ export {
29552
29555
  lastCreatedMigrationFiles,
29553
29556
  iterateAllPivots,
29554
29557
  isMysqlLike,
29558
+ isLosslessTypeChange,
29555
29559
  isGeneratedMigrationSql,
29556
29560
  isDefinitionEqual,
29557
29561
  isBrowser,
package/dist/types.d.ts CHANGED
@@ -271,6 +271,7 @@ export declare interface IntrospectOptions {
271
271
  }
272
272
  export declare interface MigrateOptions {
273
273
  dialect?: SupportedDialect
274
+ vitessSharded?: boolean
274
275
  state?: string
275
276
  apply?: boolean
276
277
  full?: boolean
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.9",
4
+ "version": "0.2.11",
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",