bun-query-builder 0.1.63 → 0.2.2
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/introspect-db.d.ts +9 -0
- 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 +624 -331
- package/dist/client.d.ts +2 -2
- package/dist/config.d.ts +13 -0
- package/dist/db.d.ts +12 -0
- package/dist/drivers/index-name.d.ts +1 -0
- package/dist/inflect.d.ts +17 -0
- package/dist/migrations.d.ts +26 -0
- package/dist/src/index.js +611 -315
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -236,8 +236,8 @@ export declare interface InsertQueryBuilder<DB extends DatabaseSchema<any>, TTab
|
|
|
236
236
|
executeTakeFirstOrThrow: () => Promise<DB[TTable]['columns']>
|
|
237
237
|
}
|
|
238
238
|
export declare interface UpdateQueryBuilder<DB extends DatabaseSchema<any>, TTable extends keyof DB & string> {
|
|
239
|
-
set: (values: Partial<DB[TTable]['columns']>) => UpdateQueryBuilder<DB, TTable>
|
|
240
|
-
where: (expr: WhereExpression<DB[TTable]['columns']> | string, op?: WhereOperator, value?: any) => UpdateQueryBuilder<DB, TTable>
|
|
239
|
+
set: (values: Partial<{ [K in keyof DB[TTable]['columns']]: DB[TTable]['columns'][K] | SqlFragment }>) => UpdateQueryBuilder<DB, TTable>
|
|
240
|
+
where: (expr: WhereExpression<DB[TTable]['columns']> | string | SqlFragment, op?: WhereOperator, value?: any) => UpdateQueryBuilder<DB, TTable>
|
|
241
241
|
returning: <K extends keyof DB[TTable]['columns'] & string>(...cols: K[]) => SelectQueryBuilder<DB, TTable, Pick<DB[TTable]['columns'], K>>
|
|
242
242
|
toSQL: () => string
|
|
243
243
|
execute: () => Promise<number>
|
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 ?
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function qualifiedIndexName(tableName: string, indexName: string): string;
|
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'
|