bun-query-builder 0.1.40 → 0.1.44
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/actions/migrate-rollback.d.ts +2 -1
- package/dist/bin/cli.js +214 -84
- package/dist/config.d.ts +10 -1
- package/dist/db.d.ts +1 -0
- package/dist/drivers/index.d.ts +2 -0
- package/dist/drivers/mysql.d.ts +6 -0
- package/dist/drivers/singlestore.d.ts +28 -0
- package/dist/drivers/sqlite.d.ts +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/migrations.d.ts +5 -0
- package/dist/sqlite-pragmas.d.ts +30 -0
- package/dist/src/index.js +218 -83
- package/dist/types.d.ts +27 -1
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type { QueryBuilderConfig } from './types';
|
|
1
|
+
import type { QueryBuilderConfig, SupportedDialect } from './types';
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isMysqlLike(dialect?: SupportedDialect): boolean;
|
|
2
11
|
/**
|
|
3
12
|
* Get the placeholder format for the current dialect.
|
|
4
13
|
* PostgreSQL uses $1, $2, $3... while MySQL and SQLite use ?
|
package/dist/db.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Database } from 'bun:sqlite';
|
|
2
2
|
import { SQL } from 'bun';
|
|
3
3
|
import type { PoolConfig } from './types';
|
|
4
|
+
export declare function splitSqlStatements(sql: string): string[];
|
|
4
5
|
/**
|
|
5
6
|
* Map the qb-level `pool` config (ms-based, ergonomic) onto the Bun SQL
|
|
6
7
|
* driver's native option names (second resolution). Only the knobs Bun's
|
package/dist/drivers/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MySQLDriver } from './mysql';
|
|
2
2
|
import { PostgresDriver } from './postgres';
|
|
3
|
+
import { SingleStoreDriver } from './singlestore';
|
|
3
4
|
import { SQLiteDriver } from './sqlite';
|
|
4
5
|
import type { DialectDriver } from './postgres';
|
|
5
6
|
import type { SupportedDialect } from '../types';
|
|
@@ -29,6 +30,7 @@ export type {
|
|
|
29
30
|
export declare function getDialectDriver(dialect: SupportedDialect): DialectDriver;
|
|
30
31
|
export { MySQLDriver } from './mysql';
|
|
31
32
|
export { PostgresDriver } from './postgres';
|
|
33
|
+
export { SingleStoreDriver } from './singlestore';
|
|
32
34
|
export { SQLiteDriver } from './sqlite';
|
|
33
35
|
// DynamoDB driver (NoSQL)
|
|
34
36
|
export {
|
package/dist/drivers/mysql.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ export declare interface DialectDriver {
|
|
|
18
18
|
recordMigrationQuery: () => string
|
|
19
19
|
}
|
|
20
20
|
export declare class MySQLDriver implements DialectDriver {
|
|
21
|
+
protected quoteIdentifier(id: string): string;
|
|
22
|
+
protected getColumnType(column: ColumnPlan): string;
|
|
23
|
+
protected getPrimaryKeyType(column: ColumnPlan): string;
|
|
24
|
+
protected getAutoIncrementClause(column: ColumnPlan): string;
|
|
25
|
+
protected getDefaultValue(column: ColumnPlan): string;
|
|
21
26
|
createEnumType(_enumTypeName: string, _values: string[]): string;
|
|
22
27
|
createTable(table: TablePlan): string;
|
|
23
28
|
createIndex(tableName: string, index: IndexPlan): string;
|
|
@@ -34,4 +39,5 @@ export declare class MySQLDriver implements DialectDriver {
|
|
|
34
39
|
createMigrationsTable(): string;
|
|
35
40
|
getExecutedMigrationsQuery(): string;
|
|
36
41
|
recordMigrationQuery(): string;
|
|
42
|
+
protected renderColumn(column: ColumnPlan): string;
|
|
37
43
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MySQLDriver } from './mysql';
|
|
2
|
+
import type { IndexPlan, TablePlan } from '../migrations';
|
|
3
|
+
/**
|
|
4
|
+
* SingleStore DDL driver.
|
|
5
|
+
*
|
|
6
|
+
* SingleStore (formerly MemSQL) speaks the MySQL wire protocol, so runtime DML
|
|
7
|
+
* (placeholders, backtick quoting, `ON DUPLICATE KEY UPDATE`, `LAST_INSERT_ID`)
|
|
8
|
+
* is identical — see `isMysqlLike` in `config.ts`. Only the DDL diverges, which
|
|
9
|
+
* is what this driver customizes:
|
|
10
|
+
*
|
|
11
|
+
* - **Distributed tables.** Rows are hash-partitioned across leaf nodes by a
|
|
12
|
+
* `SHARD KEY`. When a model declares `shardKey`, we emit it; otherwise
|
|
13
|
+
* SingleStore shards on the primary key (or a random key for columnstore),
|
|
14
|
+
* so a plain MySQL-shaped `CREATE TABLE` still works.
|
|
15
|
+
* - **Storage engine.** `tableKind: 'columnstore'` (default for analytics
|
|
16
|
+
* workloads) emits `SORT KEY (...)`; `'rowstore'` emits `ROWSTORE`;
|
|
17
|
+
* `'reference'` emits a `REFERENCE` table (fully replicated, no shard key —
|
|
18
|
+
* ideal for small dimension tables that get JOINed everywhere).
|
|
19
|
+
* - **No foreign keys.** SingleStore does not support `FOREIGN KEY`
|
|
20
|
+
* constraints, so `addForeignKey` is a no-op (referential integrity is an
|
|
21
|
+
* application concern). This mirrors how the MySQL driver already treats
|
|
22
|
+
* enums (`createEnumType` → '').
|
|
23
|
+
*/
|
|
24
|
+
export declare class SingleStoreDriver extends MySQLDriver {
|
|
25
|
+
createTable(table: TablePlan): string;
|
|
26
|
+
addForeignKey(): string;
|
|
27
|
+
createIndex(tableName: string, index: IndexPlan): string;
|
|
28
|
+
}
|
package/dist/drivers/sqlite.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { ColumnPlan, IndexPlan, RebuildTableSpec, TablePlan } from '../migrations';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a plan type belongs to the numeric family. Used by the `_id`
|
|
4
|
+
* safety net (numeric ids must store as INTEGER on SQLite) — non-numeric
|
|
5
|
+
* declared types must never be coerced by the name heuristic.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isNumericPlanType(type: string | undefined): boolean;
|
|
2
8
|
export declare interface DialectDriver {
|
|
3
9
|
createEnumType: (enumTypeName: string, values: string[]) => string
|
|
4
10
|
createTable: (table: TablePlan) => string
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export * from './pivot';
|
|
|
40
40
|
export * from './orm';
|
|
41
41
|
export * from './schema';
|
|
42
42
|
export * from './seeder';
|
|
43
|
+
export * from './sqlite-pragmas';
|
|
43
44
|
export * from './type-inference';
|
|
44
45
|
export * from './types';
|
|
45
46
|
export { type ModelDefinition, defineModel } from './model';
|
package/dist/migrations.d.ts
CHANGED
|
@@ -61,6 +61,8 @@ export declare interface ColumnPlan {
|
|
|
61
61
|
defaultValue?: PrimitiveDefault
|
|
62
62
|
references?: { table: string, column: string, onDelete?: OnForeignKeyAction, onUpdate?: OnForeignKeyAction }
|
|
63
63
|
enumValues?: string[]
|
|
64
|
+
maxLength?: number
|
|
65
|
+
enumTypeName?: string
|
|
64
66
|
}
|
|
65
67
|
export declare interface IndexPlan {
|
|
66
68
|
name: string
|
|
@@ -72,6 +74,9 @@ export declare interface TablePlan {
|
|
|
72
74
|
table: string
|
|
73
75
|
columns: ColumnPlan[]
|
|
74
76
|
indexes: IndexPlan[]
|
|
77
|
+
shardKey?: string[]
|
|
78
|
+
sortKey?: string[]
|
|
79
|
+
tableKind?: 'rowstore' | 'columnstore' | 'reference'
|
|
75
80
|
}
|
|
76
81
|
export declare interface MigrationPlan {
|
|
77
82
|
dialect: SupportedDialect
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Database } from 'bun:sqlite';
|
|
2
|
+
/** The pragma list currently in effect: the config override, or the defaults. */
|
|
3
|
+
export declare function resolveSqlitePragmas(): readonly string[];
|
|
4
|
+
/**
|
|
5
|
+
* Apply the bootstrap pragmas to a freshly-opened `bun:sqlite` Database.
|
|
6
|
+
*
|
|
7
|
+
* Fail-open per pragma: a single rejected pragma (e.g. a dialect-specific
|
|
8
|
+
* one in a custom list) must not take down connection creation — matching
|
|
9
|
+
* the long-standing behavior of the WAL pragma this generalizes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function applySqliteBootstrapPragmas(db: Database): void;
|
|
12
|
+
/**
|
|
13
|
+
* Bootstrap pragmas applied to every sqlite connection the library opens.
|
|
14
|
+
*
|
|
15
|
+
* SQLite scopes these settings to the CONNECTION, not the database file, and
|
|
16
|
+
* ships with unsafe defaults on every fresh connection: `foreign_keys` is OFF
|
|
17
|
+
* (so `REFERENCES ... ON DELETE CASCADE` in the schema is silently inert and
|
|
18
|
+
* orphan rows insert without error) and there is no busy timeout (concurrent
|
|
19
|
+
* writers surface as immediate `SQLITE_BUSY` failures). They therefore have
|
|
20
|
+
* to be re-applied on every connection the library creates — historically
|
|
21
|
+
* only the query-builder connection got `journal_mode = WAL` while the
|
|
22
|
+
* model-layer executor (the connection `Model.create()/save()/delete()`
|
|
23
|
+
* writes through) got nothing at all, leaving FK enforcement off on the
|
|
24
|
+
* exact connection performing the writes.
|
|
25
|
+
*
|
|
26
|
+
* Override via `setConfig({ sqlite: { pragmas: [...] } })` — the custom list
|
|
27
|
+
* REPLACES this one. Caller-supplied `Database` instances
|
|
28
|
+
* (`configureOrm({ database: db })`) are never touched.
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_SQLITE_PRAGMAS: readonly string[];
|