bun-query-builder 0.2.5 → 0.2.6

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
@@ -11643,7 +11643,7 @@ var init_dist = __esm(() => {
11643
11643
  // src/config.ts
11644
11644
  import process19 from "process";
11645
11645
  function isMysqlLike(dialect = config5.dialect) {
11646
- return dialect === "mysql" || dialect === "singlestore";
11646
+ return dialect === "mysql" || dialect === "singlestore" || dialect === "vitess";
11647
11647
  }
11648
11648
  function resolveDialect(explicit) {
11649
11649
  if (explicit)
@@ -12094,7 +12094,7 @@ function resolveDatabaseName(dbConfig = config5.database) {
12094
12094
  return String(raw).replace(/^['"]|['"]$/g, "");
12095
12095
  }
12096
12096
  function createConnectionString(dialect, dbConfig) {
12097
- if ((dialect === "postgres" || dialect === "mysql" || dialect === "singlestore") && process21.env.DB_CONNECTION === dialect) {
12097
+ if ((dialect === "postgres" || dialect === "mysql" || dialect === "singlestore" || dialect === "vitess") && process21.env.DB_CONNECTION === dialect) {
12098
12098
  const e = process21.env;
12099
12099
  const envDb = (e.DB_DATABASE || dbConfig.database || "").replace(/^['"]|['"]$/g, "");
12100
12100
  const envUser = e.DB_USERNAME || dbConfig.username;
@@ -12115,6 +12115,7 @@ function createConnectionString(dialect, dbConfig) {
12115
12115
  return `postgres://${username}:${password}@${host}${port ? `:${port}` : ""}/${database}${sslQ}`;
12116
12116
  case "mysql":
12117
12117
  case "singlestore":
12118
+ case "vitess":
12118
12119
  return `mysql://${username}:${password}@${host}${port ? `:${port}` : ""}/${database}${sslQ}`;
12119
12120
  case "sqlite":
12120
12121
  if (database === ":memory:") {
@@ -18525,6 +18526,35 @@ var init_singlestore = __esm(() => {
18525
18526
  };
18526
18527
  });
18527
18528
 
18529
+ // src/drivers/vitess.ts
18530
+ var VitessDriver;
18531
+ var init_vitess = __esm(() => {
18532
+ init_mysql();
18533
+ VitessDriver = class VitessDriver extends MySQLDriver {
18534
+ getAutoIncrementClause(_column) {
18535
+ return "";
18536
+ }
18537
+ renderColumn(column) {
18538
+ if (!column.references)
18539
+ return super.renderColumn(column);
18540
+ const { references: _references, ...withoutReference } = column;
18541
+ return super.renderColumn(withoutReference);
18542
+ }
18543
+ createTable(table) {
18544
+ return super.createTable(table);
18545
+ }
18546
+ addForeignKey() {
18547
+ return "";
18548
+ }
18549
+ createMigrationsTable() {
18550
+ return `CREATE TABLE IF NOT EXISTS migrations (
18551
+ migration VARCHAR(255) NOT NULL PRIMARY KEY,
18552
+ executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
18553
+ )`;
18554
+ }
18555
+ };
18556
+ });
18557
+
18528
18558
  // src/drivers/sqlite.ts
18529
18559
  function isNumericPlanType(type) {
18530
18560
  return type === "integer" || type === "bigint" || type === "float" || type === "double" || type === "decimal";
@@ -18736,6 +18766,8 @@ function getDialectDriver(dialect) {
18736
18766
  return new MySQLDriver;
18737
18767
  case "singlestore":
18738
18768
  return new SingleStoreDriver;
18769
+ case "vitess":
18770
+ return new VitessDriver;
18739
18771
  case "sqlite":
18740
18772
  return new SQLiteDriver;
18741
18773
  default:
@@ -18746,11 +18778,13 @@ var init_drivers = __esm(() => {
18746
18778
  init_mysql();
18747
18779
  init_postgres();
18748
18780
  init_singlestore();
18781
+ init_vitess();
18749
18782
  init_sqlite();
18750
18783
  init_mysql();
18751
18784
  init_postgres();
18752
18785
  init_singlestore();
18753
18786
  init_sqlite();
18787
+ init_vitess();
18754
18788
  });
18755
18789
 
18756
18790
  // src/workspace.ts
@@ -31480,7 +31514,7 @@ function getPrefix() {
31480
31514
  }
31481
31515
  var prefix = getPrefix();
31482
31516
  // package.json
31483
- var version2 = "0.2.5";
31517
+ var version2 = "0.2.6";
31484
31518
 
31485
31519
  // bin/cli.ts
31486
31520
  init_actions();
package/dist/config.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { QueryBuilderConfig, SupportedDialect } from './types';
2
2
  /**
3
- * Whether a dialect belongs to the MySQL wire-protocol family (MySQL itself or
4
- * SingleStore). These share `?` placeholders, backtick identifier quoting,
5
- * `ON DUPLICATE KEY UPDATE` upserts, `LAST_INSERT_ID()` id recovery, and the
6
- * `YYYY-MM-DD HH:MM:SS` datetime literal shape. Runtime DML branches should key
7
- * off this helper rather than `dialect === 'mysql'` so SingleStore inherits the
8
- * same behavior; only DDL (see `SingleStoreDriver`) diverges.
3
+ * Whether a dialect belongs to the MySQL wire-protocol family (MySQL itself,
4
+ * SingleStore, or Vitess). These share `?` placeholders, backtick identifier
5
+ * quoting, `ON DUPLICATE KEY UPDATE` upserts, `LAST_INSERT_ID()` id recovery,
6
+ * and the `YYYY-MM-DD HH:MM:SS` datetime literal shape. Runtime DML branches
7
+ * should key off this helper rather than `dialect === 'mysql'` so the
8
+ * distributed dialects inherit the same behavior; only DDL (see
9
+ * `SingleStoreDriver` / `VitessDriver`) diverges.
9
10
  */
10
11
  export declare function isMysqlLike(dialect?: SupportedDialect): boolean;
11
12
  /**
@@ -2,6 +2,7 @@ import { MySQLDriver } from './mysql';
2
2
  import { PostgresDriver } from './postgres';
3
3
  import { SingleStoreDriver } from './singlestore';
4
4
  import { SQLiteDriver } from './sqlite';
5
+ import { VitessDriver } from './vitess';
5
6
  import type { DialectDriver } from './postgres';
6
7
  import type { SupportedDialect } from '../types';
7
8
  export type { DialectDriver } from './postgres';
@@ -32,6 +33,7 @@ export { MySQLDriver } from './mysql';
32
33
  export { PostgresDriver } from './postgres';
33
34
  export { SingleStoreDriver } from './singlestore';
34
35
  export { SQLiteDriver } from './sqlite';
36
+ export { VitessDriver } from './vitess';
35
37
  // DynamoDB driver (NoSQL)
36
38
  export {
37
39
  createDynamoDBDriver,
@@ -0,0 +1,38 @@
1
+ import { MySQLDriver } from './mysql';
2
+ import type { ColumnPlan, TablePlan } from '../migrations';
3
+ /**
4
+ * Vitess DDL driver.
5
+ *
6
+ * Vitess shards MySQL behind vtgate, which speaks the MySQL wire protocol, so
7
+ * runtime DML (placeholders, backtick quoting, `ON DUPLICATE KEY UPDATE`,
8
+ * `LAST_INSERT_ID`) is identical — see `isMysqlLike` in `config.ts`. Only DDL
9
+ * diverges, and every divergence below follows from one fact: a keyspace is
10
+ * split across shards that share nothing.
11
+ *
12
+ * - **No foreign keys.** Enforcing one would need a cross-shard read on every
13
+ * write, so vtgate rejects them in a sharded keyspace. Both forms are
14
+ * suppressed: the `ALTER TABLE … ADD CONSTRAINT` statement (`addForeignKey`)
15
+ * and the inline `REFERENCES` clause the MySQL driver emits inside a column
16
+ * definition. Missing the inline form would be the subtler bug — the table
17
+ * plan carries the reference on the column, so a `CREATE TABLE` would fail
18
+ * on its own without any FK statement being generated.
19
+ * - **No AUTO_INCREMENT.** Each shard would independently hand out the same
20
+ * values and collide. This is not a parse error, which makes it worse than
21
+ * one: the DDL succeeds and the collisions appear later, under load, as
22
+ * duplicate-key failures on inserts that were previously fine. Primary keys
23
+ * must come from the application or from a sequence table in an unsharded
24
+ * keyspace, declared in the VSchema.
25
+ *
26
+ * **Sharding is not expressed in DDL.** Unlike SingleStore, where the shard key
27
+ * is a `CREATE TABLE` clause, Vitess keeps the topology in a separate VSchema
28
+ * document that maps each table's sharding column to a vindex. So `createTable`
29
+ * here is plain MySQL minus the two constructs above, and nothing in this
30
+ * driver needs to know how a table is sharded.
31
+ */
32
+ export declare class VitessDriver extends MySQLDriver {
33
+ protected getAutoIncrementClause(_column: ColumnPlan): string;
34
+ protected renderColumn(column: ColumnPlan): string;
35
+ createTable(table: TablePlan): string;
36
+ addForeignKey(): string;
37
+ createMigrationsTable(): string;
38
+ }
package/dist/src/index.js CHANGED
@@ -11642,7 +11642,7 @@ var init_dist = __esm(() => {
11642
11642
  // src/config.ts
11643
11643
  import process19 from "process";
11644
11644
  function isMysqlLike(dialect = config5.dialect) {
11645
- return dialect === "mysql" || dialect === "singlestore";
11645
+ return dialect === "mysql" || dialect === "singlestore" || dialect === "vitess";
11646
11646
  }
11647
11647
  function resolveDialect(explicit) {
11648
11648
  if (explicit)
@@ -12093,7 +12093,7 @@ function resolveDatabaseName(dbConfig = config5.database) {
12093
12093
  return String(raw).replace(/^['"]|['"]$/g, "");
12094
12094
  }
12095
12095
  function createConnectionString(dialect, dbConfig) {
12096
- if ((dialect === "postgres" || dialect === "mysql" || dialect === "singlestore") && process21.env.DB_CONNECTION === dialect) {
12096
+ if ((dialect === "postgres" || dialect === "mysql" || dialect === "singlestore" || dialect === "vitess") && process21.env.DB_CONNECTION === dialect) {
12097
12097
  const e = process21.env;
12098
12098
  const envDb = (e.DB_DATABASE || dbConfig.database || "").replace(/^['"]|['"]$/g, "");
12099
12099
  const envUser = e.DB_USERNAME || dbConfig.username;
@@ -12114,6 +12114,7 @@ function createConnectionString(dialect, dbConfig) {
12114
12114
  return `postgres://${username}:${password}@${host}${port ? `:${port}` : ""}/${database}${sslQ}`;
12115
12115
  case "mysql":
12116
12116
  case "singlestore":
12117
+ case "vitess":
12117
12118
  return `mysql://${username}:${password}@${host}${port ? `:${port}` : ""}/${database}${sslQ}`;
12118
12119
  case "sqlite":
12119
12120
  if (database === ":memory:") {
@@ -18524,6 +18525,35 @@ var init_singlestore = __esm(() => {
18524
18525
  };
18525
18526
  });
18526
18527
 
18528
+ // src/drivers/vitess.ts
18529
+ var VitessDriver;
18530
+ var init_vitess = __esm(() => {
18531
+ init_mysql();
18532
+ VitessDriver = class VitessDriver extends MySQLDriver {
18533
+ getAutoIncrementClause(_column) {
18534
+ return "";
18535
+ }
18536
+ renderColumn(column) {
18537
+ if (!column.references)
18538
+ return super.renderColumn(column);
18539
+ const { references: _references, ...withoutReference } = column;
18540
+ return super.renderColumn(withoutReference);
18541
+ }
18542
+ createTable(table) {
18543
+ return super.createTable(table);
18544
+ }
18545
+ addForeignKey() {
18546
+ return "";
18547
+ }
18548
+ createMigrationsTable() {
18549
+ return `CREATE TABLE IF NOT EXISTS migrations (
18550
+ migration VARCHAR(255) NOT NULL PRIMARY KEY,
18551
+ executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
18552
+ )`;
18553
+ }
18554
+ };
18555
+ });
18556
+
18527
18557
  // src/drivers/sqlite.ts
18528
18558
  function isNumericPlanType(type) {
18529
18559
  return type === "integer" || type === "bigint" || type === "float" || type === "double" || type === "decimal";
@@ -18735,6 +18765,8 @@ function getDialectDriver(dialect) {
18735
18765
  return new MySQLDriver;
18736
18766
  case "singlestore":
18737
18767
  return new SingleStoreDriver;
18768
+ case "vitess":
18769
+ return new VitessDriver;
18738
18770
  case "sqlite":
18739
18771
  return new SQLiteDriver;
18740
18772
  default:
@@ -18745,11 +18777,13 @@ var init_drivers = __esm(() => {
18745
18777
  init_mysql();
18746
18778
  init_postgres();
18747
18779
  init_singlestore();
18780
+ init_vitess();
18748
18781
  init_sqlite();
18749
18782
  init_mysql();
18750
18783
  init_postgres();
18751
18784
  init_singlestore();
18752
18785
  init_sqlite();
18786
+ init_vitess();
18753
18787
  });
18754
18788
 
18755
18789
  // src/workspace.ts
@@ -29580,6 +29614,7 @@ export {
29580
29614
  browserQuery,
29581
29615
  browserAuth,
29582
29616
  applySqliteBootstrapPragmas,
29617
+ VitessDriver,
29583
29618
  SingleTableRepository,
29584
29619
  SingleTableQueryBuilder,
29585
29620
  SingleTablePatterns,
package/dist/types.d.ts CHANGED
@@ -293,7 +293,11 @@ export declare interface UnsafeOptions {
293
293
  * but its DDL adds distributed-table concepts (`SHARD KEY`, `SORT KEY`,
294
294
  * `ROWSTORE`/columnstore) and drops foreign keys — handled by the dedicated
295
295
  * `SingleStoreDriver`.
296
+ * - 'vitess': Sharded MySQL behind vtgate. Shares MySQL's wire protocol and
297
+ * DML (see `isMysqlLike`), but a sharded keyspace rejects foreign keys and
298
+ * AUTO_INCREMENT, and its sharding topology lives in a separate VSchema
299
+ * document rather than in DDL — handled by the dedicated `VitessDriver`.
296
300
  * - 'sqlite': Lightweight engine; some features are limited or emulated
297
301
  * - 'browser': Browser-compatible mode that uses fetch() API calls instead of direct database connections
298
302
  */
299
- export type SupportedDialect = 'postgres' | 'mysql' | 'singlestore' | 'sqlite' | 'browser';
303
+ export type SupportedDialect = 'postgres' | 'mysql' | 'singlestore' | 'vitess' | 'sqlite' | 'browser';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.5",
4
+ "version": "0.2.6",
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",