bun-query-builder 0.1.62 → 0.2.0
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 +10 -2
- package/dist/actions/migrate-status.d.ts +1 -1
- package/dist/actions/migrate.d.ts +4 -0
- package/dist/actions/seed.d.ts +8 -1
- package/dist/bin/cli.js +432 -293
- package/dist/config.d.ts +30 -3
- package/dist/db.d.ts +18 -0
- package/dist/inflect.d.ts +17 -0
- package/dist/migrations.d.ts +26 -0
- package/dist/src/index.js +419 -277
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -8,6 +8,19 @@ import type { QueryBuilderConfig, SupportedDialect } from './types';
|
|
|
8
8
|
* same behavior; only DDL (see `SingleStoreDriver`) diverges.
|
|
9
9
|
*/
|
|
10
10
|
export declare function isMysqlLike(dialect?: SupportedDialect): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The dialect a command should operate on.
|
|
13
|
+
*
|
|
14
|
+
* `explicit` is what the user asked for on the command line — only honoured
|
|
15
|
+
* when they actually said something. Every CLI command used to declare
|
|
16
|
+
* `--dialect` with `{ default: 'postgres' }` and pass the result straight
|
|
17
|
+
* through, so the "default" arrived as an explicit choice and beat the
|
|
18
|
+
* project's own configuration: a SQLite app running `qb migrate` generated
|
|
19
|
+
* Postgres DDL, and `db:wipe` looked for `pg_tables`, unless every single
|
|
20
|
+
* invocation repeated `--dialect sqlite`. The fallbacks the actions already
|
|
21
|
+
* carried were unreachable.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveDialect(explicit?: string | null): SupportedDialect;
|
|
11
24
|
/**
|
|
12
25
|
* Get the placeholder format for the current dialect.
|
|
13
26
|
* PostgreSQL uses $1, $2, $3... while MySQL and SQLite use ?
|
|
@@ -35,9 +48,23 @@ export declare function getPlaceholders(count: number, startIndex?: number): str
|
|
|
35
48
|
* It is intentionally explicit/async: the builder otherwise runs purely off the
|
|
36
49
|
* synchronous `config` singleton (defaults + any `setConfig`), which keeps
|
|
37
50
|
* `bun --compile` and test behavior deterministic — auto-loading a file in the
|
|
38
|
-
* background would make early queries race the load.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
51
|
+
* background would make early queries race the load.
|
|
52
|
+
*
|
|
53
|
+
* Precedence is `defaults < config file < setConfig()`. bunfig returns a fully
|
|
54
|
+
* populated object (defaults merged with the file and env), which is fine for
|
|
55
|
+
* every key the caller has not spoken for — re-applying a default on top of the
|
|
56
|
+
* singleton that already holds that default is a no-op. It is NOT fine for keys
|
|
57
|
+
* an embedder set through `setConfig()`: those came back as library defaults and
|
|
58
|
+
* silently overwrote the embedder's choice. `setConfig({ snapshotDir })`
|
|
59
|
+
* followed by a `generateMigration()` (which calls this) reverted the snapshot
|
|
60
|
+
* to `.qb` and wrote generated state into the project root.
|
|
61
|
+
*
|
|
62
|
+
* So the loaded object is applied with those keys filtered out — an explicit API
|
|
63
|
+
* call is a stronger signal than a file that may not know the embedder exists.
|
|
64
|
+
*
|
|
65
|
+
* Note the load MUST pass `defaultConfig`: bunfig derives the environment
|
|
66
|
+
* variable names it recognises (`QUERY_BUILDER_*`) from the shape of the
|
|
67
|
+
* defaults, so passing an empty object silently drops env-var support.
|
|
41
68
|
*/
|
|
42
69
|
export declare function getConfig(): Promise<QueryBuilderConfig>;
|
|
43
70
|
export declare function setConfig(userConfig: Partial<QueryBuilderConfig>): void;
|
package/dist/db.d.ts
CHANGED
|
@@ -9,6 +9,18 @@ export declare function splitSqlStatements(sql: string): string[];
|
|
|
9
9
|
* unit tests — the same pattern as `resolvePoolOptions`/`splitSqlStatements`.
|
|
10
10
|
* It is not re-exported from `src/index.ts`, so it stays internal.
|
|
11
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* The database the library is actually connected to.
|
|
14
|
+
*
|
|
15
|
+
* Resolved the same way `createConnectionString` resolves it: the configured
|
|
16
|
+
* name, with `DB_DATABASE` taking precedence, quotes stripped. The
|
|
17
|
+
* information_schema lookups in `db:wipe` and `db:optimize` used to read
|
|
18
|
+
* `process.env.DB_NAME` — a variable this library neither documents nor reads
|
|
19
|
+
* anywhere else — and fall back to the literal `'test'`, so on MySQL they
|
|
20
|
+
* listed the tables of whatever database happened to be called `test` and
|
|
21
|
+
* silently did nothing to the real one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveDatabaseName(dbConfig?: DatabaseConfig): string;
|
|
12
24
|
export declare function createConnectionString(dialect: SupportedDialect, dbConfig: DatabaseConfig): string;
|
|
13
25
|
/**
|
|
14
26
|
* Map the qb-level `pool` config (ms-based, ergonomic) onto the Bun SQL
|
|
@@ -38,6 +50,12 @@ export declare function getOrCreateBunSql(forceNew?: boolean): SQL;
|
|
|
38
50
|
export declare function resetConnection(): void;
|
|
39
51
|
/**
|
|
40
52
|
* Inject a custom SQL instance. Useful for tests or custom connection setups.
|
|
53
|
+
*
|
|
54
|
+
* The signature is stamped alongside it so `getOrCreateBunSql()` treats the
|
|
55
|
+
* injected instance as current: leaving it null would read as "config changed"
|
|
56
|
+
* on the very next call and the injection would be discarded before it was ever
|
|
57
|
+
* used. It also means a later `setConfig()` that changes the connection still
|
|
58
|
+
* invalidates the injected instance, which is the point of the signature.
|
|
41
59
|
*/
|
|
42
60
|
export declare function setSqlInstance(sql: SQL): void;
|
|
43
61
|
// Wrapper that catches "Connection closed" errors and retries with a fresh connection
|
package/dist/inflect.d.ts
CHANGED
|
@@ -16,6 +16,23 @@
|
|
|
16
16
|
* live schemas, so `'stripTrailingS'` remains the default and the corrected
|
|
17
17
|
* behavior is opt-in via `relations.singularizeStrategy: 'inflect'`.
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* The conventional table name for a model that does not declare one.
|
|
21
|
+
*
|
|
22
|
+
* The ORM has always resolved this properly — snake_case, then the same
|
|
23
|
+
* pluralization rules `inflectSingular` inverts — while the schema, meta and
|
|
24
|
+
* migration layers each fell back to `name.toLowerCase() + 's'`. For any model
|
|
25
|
+
* whose name is not a bare-`s` plural that is a silent split: the generator
|
|
26
|
+
* created `categorys` and `blogposts` while the ORM read and wrote
|
|
27
|
+
* `categories` and `blog_posts`, so the migration built a table the runtime
|
|
28
|
+
* never touched.
|
|
29
|
+
*
|
|
30
|
+
* `OrderItem` -> `order_items`, `Category` -> `categories`,
|
|
31
|
+
* `Address` -> `addresses`, `Box` -> `boxes`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function toTableName(modelName: string): string;
|
|
34
|
+
/** The table a model definition resolves to: its own `table`, or the convention. */
|
|
35
|
+
export declare function tableNameFor(model: { table?: unknown, name?: unknown }): string;
|
|
19
36
|
/** Naive trailing-`s` strip — the historical default. */
|
|
20
37
|
export declare function stripTrailingS(name: string): string;
|
|
21
38
|
/**
|
package/dist/migrations.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { ModelRecord, OnForeignKeyAction } from './schema';
|
|
2
2
|
import type { SupportedDialect } from './types';
|
|
3
|
+
/** The files written by the most recent generate run, in creation order. */
|
|
4
|
+
export declare function lastCreatedMigrationFiles(): string[];
|
|
5
|
+
/** True when this SQL was written by the generator rather than by a person. */
|
|
6
|
+
export declare function isGeneratedMigrationSql(sql: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The comparable body of a migration: its statements, with the provenance
|
|
9
|
+
* header, comments and whitespace taken out. Two files with the same body do
|
|
10
|
+
* the same thing to the schema, whatever they are called.
|
|
11
|
+
*/
|
|
12
|
+
export declare function migrationBody(sql: string): string;
|
|
3
13
|
export declare function buildMigrationPlan(models: ModelRecord, options: InferenceOptions): MigrationPlan;
|
|
4
14
|
export declare function generateSql(plan: MigrationPlan, opts?: { dryRun?: boolean }): string[];
|
|
5
15
|
/**
|
|
@@ -51,6 +61,21 @@ export declare function generateDiffOperations(previous: MigrationPlan | undefin
|
|
|
51
61
|
* callers that only need the raw statements.
|
|
52
62
|
*/
|
|
53
63
|
export declare function generateDiffSql(previous: MigrationPlan | undefined, next: MigrationPlan, opts?: DiffOptions): string[];
|
|
64
|
+
/**
|
|
65
|
+
* Header stamped onto every migration file this generator writes.
|
|
66
|
+
*
|
|
67
|
+
* Provenance, not decoration. The runner treats generated ALTER migrations as
|
|
68
|
+
* transient — replayed rather than recorded, and deleted once applied — and it
|
|
69
|
+
* used to decide that from the FILENAME. A hand-written
|
|
70
|
+
* `0000000131-alter-farms-table.sql` is a perfectly natural name for a person
|
|
71
|
+
* to choose, and it was deleted off their disk the first time they migrated.
|
|
72
|
+
* A marker the generator writes and a human does not is the only signal that
|
|
73
|
+
* actually distinguishes the two.
|
|
74
|
+
*
|
|
75
|
+
* Files without it are treated as authored, which is the safe reading: they
|
|
76
|
+
* are recorded, run once, and never removed.
|
|
77
|
+
*/
|
|
78
|
+
export declare const GENERATED_MARKER: '-- qb:generated';
|
|
54
79
|
export declare interface ColumnPlan {
|
|
55
80
|
name: string
|
|
56
81
|
type: NormalizedColumnType
|
|
@@ -121,6 +146,7 @@ export declare interface InferenceOptions {
|
|
|
121
146
|
export declare interface DiffOptions {
|
|
122
147
|
applyRenames?: boolean
|
|
123
148
|
dryRun?: boolean
|
|
149
|
+
preserveUnknownColumns?: boolean
|
|
124
150
|
}
|
|
125
151
|
export type PrimitiveDefault = string | number | boolean | bigint | Date;
|
|
126
152
|
export type NormalizedColumnType = | 'string'
|