bun-query-builder 0.2.6 → 0.2.7
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 +23 -9
- package/dist/drivers/vitess.d.ts +7 -4
- package/dist/src/index.js +22 -8
- package/dist/types.d.ts +9 -4
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -11701,6 +11701,9 @@ function applyConfig(userConfig) {
|
|
|
11701
11701
|
if (userConfig.softDeletes) {
|
|
11702
11702
|
config5.softDeletes = { ...config5.softDeletes, ...userConfig.softDeletes };
|
|
11703
11703
|
}
|
|
11704
|
+
if (userConfig.vitess) {
|
|
11705
|
+
config5.vitess = { ...config5.vitess, ...userConfig.vitess };
|
|
11706
|
+
}
|
|
11704
11707
|
}
|
|
11705
11708
|
function setConfig(userConfig) {
|
|
11706
11709
|
if (userConfig.dialect && _lastConfiguredDialect && userConfig.dialect !== _lastConfiguredDialect) {
|
|
@@ -11730,6 +11733,9 @@ var init_config = __esm(() => {
|
|
|
11730
11733
|
host: "localhost",
|
|
11731
11734
|
port: 5432
|
|
11732
11735
|
},
|
|
11736
|
+
vitess: {
|
|
11737
|
+
sharded: true
|
|
11738
|
+
},
|
|
11733
11739
|
timestamps: {
|
|
11734
11740
|
createdAt: "created_at",
|
|
11735
11741
|
updatedAt: "updated_at",
|
|
@@ -17970,7 +17976,7 @@ function parseMysqlEnum(columnType) {
|
|
|
17970
17976
|
return;
|
|
17971
17977
|
return m[1].split(",").map((s) => s.trim().replace(/^'(.*)'$/s, "$1").replace(/''/g, "'")).filter((s) => s.length > 0);
|
|
17972
17978
|
}
|
|
17973
|
-
function groupPhysicalIndexes(
|
|
17979
|
+
function groupPhysicalIndexes(_table, rows) {
|
|
17974
17980
|
const byName = new Map;
|
|
17975
17981
|
for (const r of rows) {
|
|
17976
17982
|
if (r.isPrimary)
|
|
@@ -18531,11 +18537,16 @@ var VitessDriver;
|
|
|
18531
18537
|
var init_vitess = __esm(() => {
|
|
18532
18538
|
init_mysql();
|
|
18533
18539
|
VitessDriver = class VitessDriver extends MySQLDriver {
|
|
18534
|
-
|
|
18535
|
-
|
|
18540
|
+
sharded;
|
|
18541
|
+
constructor(sharded = true) {
|
|
18542
|
+
super();
|
|
18543
|
+
this.sharded = sharded;
|
|
18544
|
+
}
|
|
18545
|
+
getAutoIncrementClause(column) {
|
|
18546
|
+
return this.sharded ? "" : super.getAutoIncrementClause(column);
|
|
18536
18547
|
}
|
|
18537
18548
|
renderColumn(column) {
|
|
18538
|
-
if (!column.references)
|
|
18549
|
+
if (!this.sharded || !column.references)
|
|
18539
18550
|
return super.renderColumn(column);
|
|
18540
18551
|
const { references: _references, ...withoutReference } = column;
|
|
18541
18552
|
return super.renderColumn(withoutReference);
|
|
@@ -18543,10 +18554,12 @@ var init_vitess = __esm(() => {
|
|
|
18543
18554
|
createTable(table) {
|
|
18544
18555
|
return super.createTable(table);
|
|
18545
18556
|
}
|
|
18546
|
-
addForeignKey() {
|
|
18547
|
-
return "";
|
|
18557
|
+
addForeignKey(...args) {
|
|
18558
|
+
return this.sharded ? "" : super.addForeignKey(...args);
|
|
18548
18559
|
}
|
|
18549
18560
|
createMigrationsTable() {
|
|
18561
|
+
if (!this.sharded)
|
|
18562
|
+
return super.createMigrationsTable();
|
|
18550
18563
|
return `CREATE TABLE IF NOT EXISTS migrations (
|
|
18551
18564
|
migration VARCHAR(255) NOT NULL PRIMARY KEY,
|
|
18552
18565
|
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
@@ -18767,7 +18780,7 @@ function getDialectDriver(dialect) {
|
|
|
18767
18780
|
case "singlestore":
|
|
18768
18781
|
return new SingleStoreDriver;
|
|
18769
18782
|
case "vitess":
|
|
18770
|
-
return new VitessDriver;
|
|
18783
|
+
return new VitessDriver(config5.vitess?.sharded ?? true);
|
|
18771
18784
|
case "sqlite":
|
|
18772
18785
|
return new SQLiteDriver;
|
|
18773
18786
|
default:
|
|
@@ -18775,6 +18788,7 @@ function getDialectDriver(dialect) {
|
|
|
18775
18788
|
}
|
|
18776
18789
|
}
|
|
18777
18790
|
var init_drivers = __esm(() => {
|
|
18791
|
+
init_config();
|
|
18778
18792
|
init_mysql();
|
|
18779
18793
|
init_postgres();
|
|
18780
18794
|
init_singlestore();
|
|
@@ -29272,7 +29286,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
29272
29286
|
if (preserveUnknownColumns && removedCols.length > 0) {
|
|
29273
29287
|
const preserved = removedCols.map((name) => prevCols[name]);
|
|
29274
29288
|
const preservedNames = new Set(removedCols);
|
|
29275
|
-
const keptIndexes = prev.indexes.filter((idx) => idx.columns.some((c2) => preservedNames.has(c2)) && !currIdx[indexKey(idx)]);
|
|
29289
|
+
const keptIndexes = prev.indexes.filter((idx) => idx.columns.some((c2) => preservedNames.has(c2)) && !currIdx[indexKey(idx, prev.table)]);
|
|
29276
29290
|
info2(`-- Keeping ${preserved.length} column(s) on "${curr.table}" no model declares: ${removedCols.join(", ")} \u2014 reconciled from the database, where an undeclared column is out of scope rather than removed`);
|
|
29277
29291
|
curr = { ...curr, columns: [...curr.columns, ...preserved], indexes: [...curr.indexes, ...keptIndexes] };
|
|
29278
29292
|
currCols = mapColumnsByName(curr.columns);
|
|
@@ -31514,7 +31528,7 @@ function getPrefix() {
|
|
|
31514
31528
|
}
|
|
31515
31529
|
var prefix = getPrefix();
|
|
31516
31530
|
// package.json
|
|
31517
|
-
var version2 = "0.2.
|
|
31531
|
+
var version2 = "0.2.7";
|
|
31518
31532
|
|
|
31519
31533
|
// bin/cli.ts
|
|
31520
31534
|
init_actions();
|
package/dist/drivers/vitess.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ import type { ColumnPlan, TablePlan } from '../migrations';
|
|
|
6
6
|
* Vitess shards MySQL behind vtgate, which speaks the MySQL wire protocol, so
|
|
7
7
|
* runtime DML (placeholders, backtick quoting, `ON DUPLICATE KEY UPDATE`,
|
|
8
8
|
* `LAST_INSERT_ID`) is identical — see `isMysqlLike` in `config.ts`. Only DDL
|
|
9
|
-
* diverges
|
|
10
|
-
*
|
|
9
|
+
* diverges only when the keyspace is sharded. An unsharded keyspace retains
|
|
10
|
+
* normal MySQL AUTO_INCREMENT and foreign-key support, so this driver takes
|
|
11
|
+
* the topology explicitly instead of conflating "behind vtgate" with
|
|
12
|
+
* "distributed across shards".
|
|
11
13
|
*
|
|
12
14
|
* - **No foreign keys.** Enforcing one would need a cross-shard read on every
|
|
13
15
|
* write, so vtgate rejects them in a sharded keyspace. Both forms are
|
|
@@ -30,9 +32,10 @@ import type { ColumnPlan, TablePlan } from '../migrations';
|
|
|
30
32
|
* driver needs to know how a table is sharded.
|
|
31
33
|
*/
|
|
32
34
|
export declare class VitessDriver extends MySQLDriver {
|
|
33
|
-
|
|
35
|
+
constructor(sharded?: boolean);
|
|
36
|
+
protected getAutoIncrementClause(column: ColumnPlan): string;
|
|
34
37
|
protected renderColumn(column: ColumnPlan): string;
|
|
35
38
|
createTable(table: TablePlan): string;
|
|
36
|
-
addForeignKey(): string;
|
|
39
|
+
addForeignKey(...args: Parameters<MySQLDriver['addForeignKey']>): string;
|
|
37
40
|
createMigrationsTable(): string;
|
|
38
41
|
}
|
package/dist/src/index.js
CHANGED
|
@@ -11700,6 +11700,9 @@ function applyConfig(userConfig) {
|
|
|
11700
11700
|
if (userConfig.softDeletes) {
|
|
11701
11701
|
config5.softDeletes = { ...config5.softDeletes, ...userConfig.softDeletes };
|
|
11702
11702
|
}
|
|
11703
|
+
if (userConfig.vitess) {
|
|
11704
|
+
config5.vitess = { ...config5.vitess, ...userConfig.vitess };
|
|
11705
|
+
}
|
|
11703
11706
|
}
|
|
11704
11707
|
function setConfig(userConfig) {
|
|
11705
11708
|
if (userConfig.dialect && _lastConfiguredDialect && userConfig.dialect !== _lastConfiguredDialect) {
|
|
@@ -11729,6 +11732,9 @@ var init_config = __esm(() => {
|
|
|
11729
11732
|
host: "localhost",
|
|
11730
11733
|
port: 5432
|
|
11731
11734
|
},
|
|
11735
|
+
vitess: {
|
|
11736
|
+
sharded: true
|
|
11737
|
+
},
|
|
11732
11738
|
timestamps: {
|
|
11733
11739
|
createdAt: "created_at",
|
|
11734
11740
|
updatedAt: "updated_at",
|
|
@@ -17969,7 +17975,7 @@ function parseMysqlEnum(columnType) {
|
|
|
17969
17975
|
return;
|
|
17970
17976
|
return m[1].split(",").map((s) => s.trim().replace(/^'(.*)'$/s, "$1").replace(/''/g, "'")).filter((s) => s.length > 0);
|
|
17971
17977
|
}
|
|
17972
|
-
function groupPhysicalIndexes(
|
|
17978
|
+
function groupPhysicalIndexes(_table, rows) {
|
|
17973
17979
|
const byName = new Map;
|
|
17974
17980
|
for (const r of rows) {
|
|
17975
17981
|
if (r.isPrimary)
|
|
@@ -18530,11 +18536,16 @@ var VitessDriver;
|
|
|
18530
18536
|
var init_vitess = __esm(() => {
|
|
18531
18537
|
init_mysql();
|
|
18532
18538
|
VitessDriver = class VitessDriver extends MySQLDriver {
|
|
18533
|
-
|
|
18534
|
-
|
|
18539
|
+
sharded;
|
|
18540
|
+
constructor(sharded = true) {
|
|
18541
|
+
super();
|
|
18542
|
+
this.sharded = sharded;
|
|
18543
|
+
}
|
|
18544
|
+
getAutoIncrementClause(column) {
|
|
18545
|
+
return this.sharded ? "" : super.getAutoIncrementClause(column);
|
|
18535
18546
|
}
|
|
18536
18547
|
renderColumn(column) {
|
|
18537
|
-
if (!column.references)
|
|
18548
|
+
if (!this.sharded || !column.references)
|
|
18538
18549
|
return super.renderColumn(column);
|
|
18539
18550
|
const { references: _references, ...withoutReference } = column;
|
|
18540
18551
|
return super.renderColumn(withoutReference);
|
|
@@ -18542,10 +18553,12 @@ var init_vitess = __esm(() => {
|
|
|
18542
18553
|
createTable(table) {
|
|
18543
18554
|
return super.createTable(table);
|
|
18544
18555
|
}
|
|
18545
|
-
addForeignKey() {
|
|
18546
|
-
return "";
|
|
18556
|
+
addForeignKey(...args) {
|
|
18557
|
+
return this.sharded ? "" : super.addForeignKey(...args);
|
|
18547
18558
|
}
|
|
18548
18559
|
createMigrationsTable() {
|
|
18560
|
+
if (!this.sharded)
|
|
18561
|
+
return super.createMigrationsTable();
|
|
18549
18562
|
return `CREATE TABLE IF NOT EXISTS migrations (
|
|
18550
18563
|
migration VARCHAR(255) NOT NULL PRIMARY KEY,
|
|
18551
18564
|
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
@@ -18766,7 +18779,7 @@ function getDialectDriver(dialect) {
|
|
|
18766
18779
|
case "singlestore":
|
|
18767
18780
|
return new SingleStoreDriver;
|
|
18768
18781
|
case "vitess":
|
|
18769
|
-
return new VitessDriver;
|
|
18782
|
+
return new VitessDriver(config5.vitess?.sharded ?? true);
|
|
18770
18783
|
case "sqlite":
|
|
18771
18784
|
return new SQLiteDriver;
|
|
18772
18785
|
default:
|
|
@@ -18774,6 +18787,7 @@ function getDialectDriver(dialect) {
|
|
|
18774
18787
|
}
|
|
18775
18788
|
}
|
|
18776
18789
|
var init_drivers = __esm(() => {
|
|
18790
|
+
init_config();
|
|
18777
18791
|
init_mysql();
|
|
18778
18792
|
init_postgres();
|
|
18779
18793
|
init_singlestore();
|
|
@@ -29271,7 +29285,7 @@ function generateDiffOperations(previous, next, opts = {}) {
|
|
|
29271
29285
|
if (preserveUnknownColumns && removedCols.length > 0) {
|
|
29272
29286
|
const preserved = removedCols.map((name) => prevCols[name]);
|
|
29273
29287
|
const preservedNames = new Set(removedCols);
|
|
29274
|
-
const keptIndexes = prev.indexes.filter((idx) => idx.columns.some((c2) => preservedNames.has(c2)) && !currIdx[indexKey(idx)]);
|
|
29288
|
+
const keptIndexes = prev.indexes.filter((idx) => idx.columns.some((c2) => preservedNames.has(c2)) && !currIdx[indexKey(idx, prev.table)]);
|
|
29275
29289
|
info2(`-- Keeping ${preserved.length} column(s) on "${curr.table}" no model declares: ${removedCols.join(", ")} \u2014 reconciled from the database, where an undeclared column is out of scope rather than removed`);
|
|
29276
29290
|
curr = { ...curr, columns: [...curr.columns, ...preserved], indexes: [...curr.indexes, ...keptIndexes] };
|
|
29277
29291
|
currCols = mapColumnsByName(curr.columns);
|
package/dist/types.d.ts
CHANGED
|
@@ -192,6 +192,10 @@ export declare interface DatabaseConfig {
|
|
|
192
192
|
ssl?: boolean
|
|
193
193
|
pool?: PoolConfig
|
|
194
194
|
}
|
|
195
|
+
/** Vitess topology controls that affect generated DDL. */
|
|
196
|
+
export declare interface VitessConfig {
|
|
197
|
+
sharded: boolean
|
|
198
|
+
}
|
|
195
199
|
/**
|
|
196
200
|
* # `BrowserConfig`
|
|
197
201
|
*
|
|
@@ -236,6 +240,7 @@ export declare interface QueryBuilderConfig {
|
|
|
236
240
|
transactionDefaults: TransactionDefaultsConfig
|
|
237
241
|
sql: SqlConfig
|
|
238
242
|
sqlite?: SqliteConfig
|
|
243
|
+
vitess?: VitessConfig
|
|
239
244
|
features: FeatureToggles
|
|
240
245
|
debug?: {
|
|
241
246
|
captureText: boolean
|
|
@@ -293,10 +298,10 @@ export declare interface UnsafeOptions {
|
|
|
293
298
|
* but its DDL adds distributed-table concepts (`SHARD KEY`, `SORT KEY`,
|
|
294
299
|
* `ROWSTORE`/columnstore) and drops foreign keys — handled by the dedicated
|
|
295
300
|
* `SingleStoreDriver`.
|
|
296
|
-
* - 'vitess':
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
301
|
+
* - 'vitess': MySQL behind vtgate. Shares MySQL's wire protocol and DML (see
|
|
302
|
+
* `isMysqlLike`). Unsharded keyspaces retain normal MySQL DDL, while a
|
|
303
|
+
* sharded keyspace rejects foreign keys and AUTO_INCREMENT; select that
|
|
304
|
+
* stricter profile with `vitess.sharded`.
|
|
300
305
|
* - 'sqlite': Lightweight engine; some features are limited or emulated
|
|
301
306
|
* - 'browser': Browser-compatible mode that uses fetch() API calls instead of direct database connections
|
|
302
307
|
*/
|
package/package.json
CHANGED