bun-query-builder 0.1.5 → 0.1.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/actions/benchmark.d.ts +9 -5
- package/dist/actions/cache.d.ts +2 -14
- package/dist/actions/console.d.ts +0 -6
- package/dist/actions/data.d.ts +3 -13
- package/dist/actions/db-info.d.ts +4 -9
- package/dist/actions/db-optimize.d.ts +4 -5
- package/dist/actions/db-wipe.d.ts +4 -5
- package/dist/actions/file.d.ts +2 -1
- package/dist/actions/index.d.ts +25 -25
- package/dist/actions/inspect.d.ts +3 -9
- package/dist/actions/introspect.d.ts +2 -1
- package/dist/actions/make-model.d.ts +3 -5
- package/dist/actions/migrate-generate.d.ts +4 -5
- package/dist/actions/migrate-rollback.d.ts +4 -11
- package/dist/actions/migrate-status.d.ts +5 -9
- package/dist/actions/migrate.d.ts +13 -21
- package/dist/actions/model-show.d.ts +3 -5
- package/dist/actions/query-explain-all.d.ts +3 -5
- package/dist/actions/relation-diagram.d.ts +5 -5
- package/dist/actions/seed.d.ts +7 -17
- package/dist/actions/sql.d.ts +2 -1
- package/dist/actions/unsafe.d.ts +2 -1
- package/dist/actions/validate.d.ts +4 -9
- package/dist/actions/wait-ready.d.ts +2 -1
- package/dist/client.d.ts +199 -189
- package/dist/config.d.ts +2 -1
- package/dist/db.d.ts +8 -9
- package/dist/drivers/index.d.ts +8 -6
- package/dist/drivers/mysql.d.ts +169 -19
- package/dist/drivers/postgres.d.ts +155 -19
- package/dist/drivers/sqlite.d.ts +157 -19
- package/dist/factory.d.ts +3 -6
- package/dist/index.d.ts +11 -11
- package/dist/index.js +3502 -299
- package/dist/loader.d.ts +3 -2
- package/dist/meta.d.ts +3 -2
- package/dist/migrations.d.ts +42 -47
- package/dist/schema.d.ts +30 -177
- package/dist/seeder.d.ts +12 -17
- package/dist/types.d.ts +42 -143
- package/package.json +5 -4
package/dist/loader.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ModelRecord } from './schema';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
export declare interface LoadModelsOptions {
|
|
4
4
|
cwd?: string
|
|
5
5
|
modelsDir: string
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
|
+
export declare function loadModels(options: LoadModelsOptions): Promise<ModelRecord>;
|
package/dist/meta.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelRecord } from './schema';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
export declare interface SchemaMeta {
|
|
4
4
|
modelToTable: Record<string, string>
|
|
5
5
|
tableToModel: Record<string, string>
|
|
@@ -18,4 +18,5 @@ export declare interface SchemaMeta {
|
|
|
18
18
|
morphedByMany?: Record<string, string>
|
|
19
19
|
}>
|
|
20
20
|
scopes?: Record<string, Record<string, (qb: any, value?: any) => any>>
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
|
+
export declare function buildSchemaMeta(models: ModelRecord): SchemaMeta;
|
package/dist/migrations.d.ts
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
import type { ModelRecord } from './schema';
|
|
2
2
|
import type { SupportedDialect } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* - Drops removed indexes
|
|
25
|
-
* - Adds new foreign keys for newly added columns
|
|
26
|
-
*
|
|
27
|
-
* If there is no previous plan or the dialect changed, generates full SQL.
|
|
28
|
-
*/
|
|
29
|
-
export declare function generateDiffSql(previous: MigrationPlan | undefined, next: MigrationPlan): string[];
|
|
30
|
-
export declare interface ColumnPlan {
|
|
3
|
+
|
|
4
|
+
declare function findWorkspaceRoot(startPath: string): string;
|
|
5
|
+
declare function ensureSqlDirectory(): string;
|
|
6
|
+
declare function createMigrationFile(statement: string, fileName: string): boolean;
|
|
7
|
+
export declare type PrimitiveDefault = string | number | boolean | bigint | Date
|
|
8
|
+
|
|
9
|
+
export type NormalizedColumnType =
|
|
10
|
+
| 'string'
|
|
11
|
+
| 'text'
|
|
12
|
+
| 'boolean'
|
|
13
|
+
| 'integer'
|
|
14
|
+
| 'bigint'
|
|
15
|
+
| 'float'
|
|
16
|
+
| 'double'
|
|
17
|
+
| 'decimal'
|
|
18
|
+
| 'date'
|
|
19
|
+
| 'datetime'
|
|
20
|
+
| 'json'
|
|
21
|
+
| 'enum'
|
|
22
|
+
|
|
23
|
+
export interface ColumnPlan {
|
|
31
24
|
name: string
|
|
32
25
|
type: NormalizedColumnType
|
|
33
26
|
isPrimaryKey: boolean
|
|
@@ -38,33 +31,35 @@ export declare interface ColumnPlan {
|
|
|
38
31
|
references?: { table: string, column: string }
|
|
39
32
|
enumValues?: string[]
|
|
40
33
|
}
|
|
41
|
-
|
|
34
|
+
|
|
35
|
+
export interface IndexPlan {
|
|
42
36
|
name: string
|
|
43
37
|
columns: string[]
|
|
44
38
|
type: 'index' | 'unique'
|
|
45
39
|
}
|
|
46
|
-
|
|
40
|
+
|
|
41
|
+
export interface TablePlan {
|
|
47
42
|
table: string
|
|
48
43
|
columns: ColumnPlan[]
|
|
49
44
|
indexes: IndexPlan[]
|
|
50
45
|
}
|
|
51
|
-
|
|
46
|
+
|
|
47
|
+
export interface MigrationPlan {
|
|
52
48
|
dialect: SupportedDialect
|
|
53
49
|
tables: TablePlan[]
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
| 'enum'
|
|
51
|
+
declare function guessTypeFromName(columnName: string): NormalizedColumnType | undefined;
|
|
52
|
+
declare function normalizeDefaultValue(value: unknown): PrimitiveDefault | undefined;
|
|
53
|
+
declare function detectEnumFromValidationRule(rule: unknown): string[] | undefined;
|
|
54
|
+
declare function detectTypeFromValidationRule(rule: unknown): NormalizedColumnType | undefined;
|
|
55
|
+
export declare function buildMigrationPlan(models: ModelRecord, options: InferenceOptions): MigrationPlan;
|
|
56
|
+
export declare function generateSql(plan: MigrationPlan): string[];
|
|
57
|
+
export declare function generateSqlString(plan: MigrationPlan): string;
|
|
58
|
+
export declare function generateDiffSqlString(previous: MigrationPlan | undefined, next: MigrationPlan): string;
|
|
59
|
+
export declare function hashMigrationPlan(plan: MigrationPlan): string;
|
|
60
|
+
declare function canonicalize(value: any): any;
|
|
61
|
+
declare function mapTablesByName(tables: TablePlan[]): Record<string, TablePlan>;
|
|
62
|
+
declare function mapColumnsByName(columns: ColumnPlan[]): Record<string, ColumnPlan>;
|
|
63
|
+
declare function columnsAreDifferent(col1: ColumnPlan, col2: ColumnPlan): boolean;
|
|
64
|
+
declare function mapIndexesByKey(indexes: IndexPlan[]): Record<string, IndexPlan>;
|
|
65
|
+
export declare function generateDiffSql(previous: MigrationPlan | undefined, next: MigrationPlan): string[];
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,49 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const Post = defineModel({
|
|
10
|
-
* name: 'Post',
|
|
11
|
-
* attributes: {
|
|
12
|
-
* title: { validation: { rule: {} // isLength({ min: 1 }) } },
|
|
13
|
-
* },
|
|
14
|
-
* })
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function defineModel<const T extends ModelDefinition>(model: T): T;
|
|
18
|
-
/**
|
|
19
|
-
* # `defineModels(models)`
|
|
20
|
-
*
|
|
21
|
-
* Freezes and returns a record of model definitions, preserving literal keys so
|
|
22
|
-
* downstream types (like `DatabaseSchema`) can map model names to table names.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const models = defineModels({ User, Post })
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function defineModels<const T extends ModelRecord>(models: T): T;
|
|
30
|
-
/**
|
|
31
|
-
* # `Attribute`
|
|
32
|
-
*
|
|
33
|
-
* Describes a model column and its validation/meta options.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const User = defineModel({
|
|
38
|
-
* name: 'User',
|
|
39
|
-
* attributes: {
|
|
40
|
-
* email: { validation: { rule: {} // isEmail() }, unique: true },
|
|
41
|
-
* age: { validation: { rule: {} // isInt({ min: 0 }) }, default: 0 },
|
|
42
|
-
* }
|
|
43
|
-
* })
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare interface Attribute {
|
|
1
|
+
export declare type ValidatorMessage = Record<string, string>
|
|
2
|
+
|
|
3
|
+
export type ValidationType = unknown
|
|
4
|
+
|
|
5
|
+
export interface Attribute {
|
|
47
6
|
default?: string | number | boolean | Date
|
|
48
7
|
unique?: boolean
|
|
49
8
|
order?: number
|
|
@@ -56,46 +15,33 @@ export declare interface Attribute {
|
|
|
56
15
|
message?: ValidatorMessage
|
|
57
16
|
}
|
|
58
17
|
}
|
|
59
|
-
export declare interface AttributesElements {
|
|
60
18
|
|
|
19
|
+
export interface AttributesElements {
|
|
20
|
+
[key: string]: Attribute
|
|
61
21
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
* Describes a named multi-column index.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* { name: 'user_email_unique', columns: ['email'] }
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export declare interface CompositeIndex {
|
|
22
|
+
|
|
23
|
+
export interface CompositeIndex {
|
|
73
24
|
name: string
|
|
74
25
|
columns: string[]
|
|
75
26
|
}
|
|
76
|
-
export declare interface Base {
|
|
77
27
|
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* })
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export declare interface ModelOptions extends Base {
|
|
28
|
+
export interface Base {}
|
|
29
|
+
|
|
30
|
+
export type ModelNames = string
|
|
31
|
+
|
|
32
|
+
export type HasOne<T extends string> = Record<string, T>
|
|
33
|
+
export type HasMany<T extends string> = Record<string, T>
|
|
34
|
+
export type BelongsTo<T extends string> = Record<string, T>
|
|
35
|
+
export type BelongsToMany<T extends string> = Record<string, T>
|
|
36
|
+
export type HasOneThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
37
|
+
export type HasManyThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
38
|
+
export type MorphOne<T extends string> = Record<string, T>
|
|
39
|
+
export type MorphMany<T extends string> = Record<string, T>
|
|
40
|
+
export type MorphTo = Record<string, unknown>
|
|
41
|
+
export type MorphToMany<T extends string> = Record<string, T>
|
|
42
|
+
export type MorphedByMany<T extends string> = Record<string, T>
|
|
43
|
+
|
|
44
|
+
export interface ModelOptions extends Base {
|
|
99
45
|
name: string
|
|
100
46
|
description?: string
|
|
101
47
|
table?: string
|
|
@@ -125,102 +71,9 @@ export declare interface ModelOptions extends Base {
|
|
|
125
71
|
[key: string]: (value: any) => any
|
|
126
72
|
}
|
|
127
73
|
}
|
|
128
|
-
|
|
129
|
-
* # `ValidatorMessage`
|
|
130
|
-
*
|
|
131
|
-
* Map of field identifiers to custom error messages returned by validators.
|
|
132
|
-
*/
|
|
133
|
-
export type ValidatorMessage = Record<string, string>
|
|
134
|
-
/**
|
|
135
|
-
* # `ValidationType`
|
|
136
|
-
*
|
|
137
|
-
* External validator rule type (compatible with ts-validation). Kept broad to
|
|
138
|
-
* avoid a hard dependency while still enabling type inference via rule shape.
|
|
139
|
-
*/
|
|
140
|
-
export type ValidationType = unknown
|
|
141
|
-
export type ModelNames = string
|
|
142
|
-
/**
|
|
143
|
-
* # Relationship helpers
|
|
144
|
-
*
|
|
145
|
-
* Lightweight relationship declarations for model definitions. Each helper is a
|
|
146
|
-
* record keyed by relation name with the related model name as value.
|
|
147
|
-
*/
|
|
148
|
-
export type HasOne<T extends string> = Record<string, T>
|
|
149
|
-
export type HasMany<T extends string> = Record<string, T>
|
|
150
|
-
export type BelongsTo<T extends string> = Record<string, T>
|
|
151
|
-
export type BelongsToMany<T extends string> = Record<string, T>
|
|
152
|
-
export type HasOneThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
153
|
-
export type HasManyThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
154
|
-
export type MorphOne<T extends string> = Record<string, T>
|
|
155
|
-
export type MorphMany<T extends string> = Record<string, T>
|
|
156
|
-
export type MorphTo = Record<string, unknown>
|
|
157
|
-
export type MorphToMany<T extends string> = Record<string, T>
|
|
158
|
-
export type MorphedByMany<T extends string> = Record<string, T>
|
|
74
|
+
|
|
159
75
|
export type ModelDefinition = Readonly<ModelOptions>
|
|
160
|
-
|
|
161
|
-
* # `ModelRecord`
|
|
162
|
-
*
|
|
163
|
-
* Collection of models keyed by model name. Kept flexible to preserve literal
|
|
164
|
-
* attribute keys and value types.
|
|
165
|
-
*/
|
|
76
|
+
|
|
166
77
|
export type ModelRecord = Record<string, any>
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
* Given a `ModelDefinition`, produces a record of attribute names to their
|
|
171
|
-
* inferred input type based on the validator rule shape.
|
|
172
|
-
*/
|
|
173
|
-
declare type ExtractRuleInput<R> = R extends { validate: (value: infer T) => any }
|
|
174
|
-
? T
|
|
175
|
-
: R extends { test: (value: infer T) => any }
|
|
176
|
-
? T
|
|
177
|
-
: R extends { getRules: () => Array<{ test: (value: infer T) => any }> }
|
|
178
|
-
? T
|
|
179
|
-
: unknown
|
|
180
|
-
export type InferAttributes<M extends ModelDefinition> = M extends {
|
|
181
|
-
attributes: infer A extends Record<string, { validation: { rule: any } }>
|
|
182
|
-
}
|
|
183
|
-
? { [K in keyof A & string]: ExtractRuleInput<A[K]['validation']['rule']> }
|
|
184
|
-
: Record<string, unknown>
|
|
185
|
-
/**
|
|
186
|
-
* # `InferPrimaryKey<M>`
|
|
187
|
-
*
|
|
188
|
-
* Extracts a model's primary key field name, defaulting to `'id'`.
|
|
189
|
-
*/
|
|
190
|
-
export type InferPrimaryKey<M extends ModelDefinition> = M extends {
|
|
191
|
-
primaryKey: infer K extends string
|
|
192
|
-
}
|
|
193
|
-
? K
|
|
194
|
-
: 'id'
|
|
195
|
-
/**
|
|
196
|
-
* # `InferTableName<M>`
|
|
197
|
-
*
|
|
198
|
-
* Resolves the table name from a model: uses `table` when provided, otherwise
|
|
199
|
-
* falls back to a simple pluralized form of the model name.
|
|
200
|
-
*/
|
|
201
|
-
export type InferTableName<M extends ModelDefinition> = M extends {
|
|
202
|
-
table: infer T extends string
|
|
203
|
-
}
|
|
204
|
-
? T
|
|
205
|
-
: M extends { name: infer N extends string }
|
|
206
|
-
? `${Lowercase<N>}s`
|
|
207
|
-
: string
|
|
208
|
-
/**
|
|
209
|
-
* # `DatabaseSchema<Models>`
|
|
210
|
-
*
|
|
211
|
-
* Maps model definitions to a concrete database schema shape containing the
|
|
212
|
-
* table columns and primary key. This is the primary input for the query
|
|
213
|
-
* builder's type-safety.
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* ```ts
|
|
217
|
-
* const models = defineModels({ User, Post })
|
|
218
|
-
* type Schema = DatabaseSchema<typeof models>
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
export type DatabaseSchema<MRecord extends ModelRecord> = {
|
|
222
|
-
[MName in keyof MRecord & string as InferTableName<MRecord[MName]>]: {
|
|
223
|
-
columns: InferAttributes<MRecord[MName]>
|
|
224
|
-
primaryKey: InferPrimaryKey<MRecord[MName]>
|
|
225
|
-
};
|
|
226
|
-
}
|
|
78
|
+
export declare function defineModel<const T extends ModelDefinition>(model: T): T;
|
|
79
|
+
export declare function defineModels<const T extends ModelRecord>(models: T): T;
|
package/dist/seeder.d.ts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export declare abstract class Seeder {
|
|
2
|
+
abstract run(qb: any): Promise<void>
|
|
3
|
+
|
|
4
|
+
get order(): number {
|
|
5
|
+
return 100
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get description(): string | undefined {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
11
|
+
}
|
|
8
12
|
export declare interface SeederConfig {
|
|
9
13
|
seedersDir?: string
|
|
10
14
|
seeders?: string[]
|
|
11
15
|
verbose?: boolean
|
|
12
16
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Options for running seeders
|
|
15
|
-
*/
|
|
16
17
|
export declare interface RunSeederOptions {
|
|
17
18
|
class?: string
|
|
18
19
|
verbose?: boolean
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
* Base seeder class that all seeders should extend.
|
|
22
|
-
* Provides access to query builder and faker for generating test data.
|
|
23
|
-
*/
|
|
24
|
-
export declare abstract class Seeder {
|
|
25
|
-
abstract run(qb: any): Promise<void>;
|
|
26
|
-
}
|
|
21
|
+
export declare function defineSeeder(seederClass?: new ()): new () => Seeder;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,127 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Controls exponential backoff between transaction retry attempts.
|
|
5
|
-
*
|
|
6
|
-
* - `baseMs`: Initial delay in milliseconds used for the first retry.
|
|
7
|
-
* - `factor`: Multiplicative growth factor applied per attempt (e.g., 2 = doubles).
|
|
8
|
-
* - `maxMs`: Maximum delay cap in milliseconds; backoff never exceeds this value.
|
|
9
|
-
* - `jitter`: When true, adds a small randomization to the delay to reduce thundering herds.
|
|
10
|
-
*
|
|
11
|
-
* The delay for attempt n (1-indexed) is roughly: min(maxMs, baseMs * factor^(n-1)),
|
|
12
|
-
* optionally adjusted by jitter.
|
|
13
|
-
*/
|
|
14
|
-
export declare interface TransactionBackoffConfig {
|
|
1
|
+
export declare type SupportedDialect = 'postgres' | 'mysql' | 'sqlite'
|
|
2
|
+
|
|
3
|
+
export interface TransactionBackoffConfig {
|
|
15
4
|
baseMs: number
|
|
16
5
|
factor: number
|
|
17
6
|
maxMs: number
|
|
18
7
|
jitter: boolean
|
|
19
8
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* Default settings applied to transactional operations.
|
|
24
|
-
*
|
|
25
|
-
* - `retries`: Number of times a transaction may be retried on retriable errors
|
|
26
|
-
* (e.g., deadlocks, serialization failures).
|
|
27
|
-
* - `isolation`: Transaction isolation level.
|
|
28
|
-
* - 'read committed': Prevents dirty reads; non-repeatable reads possible.
|
|
29
|
-
* - 'repeatable read': Ensures stable snapshot for a transaction; phantom reads may vary by DB.
|
|
30
|
-
* - 'serializable': Highest isolation; transactions appear to run one-by-one.
|
|
31
|
-
* - `sqlStates`: Additional vendor error codes considered retriable.
|
|
32
|
-
* - `backoff`: Backoff configuration applied between retries.
|
|
33
|
-
*/
|
|
34
|
-
export declare interface TransactionDefaultsConfig {
|
|
9
|
+
|
|
10
|
+
export interface TransactionDefaultsConfig {
|
|
35
11
|
retries: number
|
|
36
12
|
isolation?: 'read committed' | 'repeatable read' | 'serializable'
|
|
37
13
|
sqlStates: string[]
|
|
38
14
|
backoff: TransactionBackoffConfig
|
|
39
15
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
* Column naming conventions for timestamp fields used by helpers.
|
|
44
|
-
*
|
|
45
|
-
* - `createdAt`: Column name for row creation time (e.g., 'created_at').
|
|
46
|
-
* - `updatedAt`: Column name for last update time (e.g., 'updated_at').
|
|
47
|
-
* - `defaultOrderColumn`: Column used by helpers like `latest()`/`oldest()`.
|
|
48
|
-
*/
|
|
49
|
-
export declare interface TimestampConfig {
|
|
16
|
+
|
|
17
|
+
export interface TimestampConfig {
|
|
50
18
|
createdAt: string
|
|
51
19
|
updatedAt: string
|
|
52
20
|
defaultOrderColumn: string
|
|
53
21
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
* Defaults for result pagination helpers.
|
|
58
|
-
*
|
|
59
|
-
* - `defaultPerPage`: Default LIMIT used by paginate helpers when not specified.
|
|
60
|
-
* - `cursorColumn`: Default column used for cursor-based pagination (e.g., 'id').
|
|
61
|
-
*/
|
|
62
|
-
export declare interface PaginationConfig {
|
|
22
|
+
|
|
23
|
+
export interface PaginationConfig {
|
|
63
24
|
defaultPerPage: number
|
|
64
25
|
cursorColumn: string
|
|
65
26
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
* Controls how selected columns from joined relations are aliased.
|
|
70
|
-
*
|
|
71
|
-
* - `relationColumnAliasFormat`:
|
|
72
|
-
* - 'table_column': Aliases as `${table}_${column}` (e.g., `posts_title`).
|
|
73
|
-
* - 'table.dot.column': Aliases with dot notation (e.g., `posts.title`).
|
|
74
|
-
* - 'camelCase': Aliases as camelCase from `${table}_${column}` (e.g., `postsTitle`).
|
|
75
|
-
*/
|
|
76
|
-
export declare interface AliasingConfig {
|
|
27
|
+
|
|
28
|
+
export interface AliasingConfig {
|
|
77
29
|
relationColumnAliasFormat: 'table_column' | 'table.dot.column' | 'camelCase'
|
|
78
30
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
* Conventions for inferring foreign key names and singularization.
|
|
83
|
-
*
|
|
84
|
-
* - `foreignKeyFormat`:
|
|
85
|
-
* - 'singularParent_id': Uses `${singular(parent)}_id` (e.g., `user_id`).
|
|
86
|
-
* - 'parentId': Uses camelCase `parentId` (e.g., `userId`).
|
|
87
|
-
* - `singularizeStrategy`:
|
|
88
|
-
* - 'stripTrailingS': Naively remove trailing 's' when singularizing (default behavior when enabled elsewhere).
|
|
89
|
-
* - 'none': Do not singularize relation/table names.
|
|
90
|
-
*/
|
|
91
|
-
export declare interface RelationsConfig {
|
|
31
|
+
|
|
32
|
+
export interface RelationsConfig {
|
|
92
33
|
foreignKeyFormat: 'singularParent_id' | 'parentId'
|
|
93
34
|
singularizeStrategy?: 'stripTrailingS' | 'none'
|
|
94
35
|
maxDepth?: number
|
|
95
36
|
maxEagerLoad?: number
|
|
96
37
|
detectCycles?: boolean
|
|
97
38
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
* Dialect-specific SQL toggles.
|
|
102
|
-
*
|
|
103
|
-
* - `randomFunction`:
|
|
104
|
-
* - 'RANDOM()': PostgreSQL/SQLite style function for random ordering.
|
|
105
|
-
* - 'RAND()': MySQL style function for random ordering.
|
|
106
|
-
* - `sharedLockSyntax`:
|
|
107
|
-
* - 'FOR SHARE': PostgreSQL style shared lock.
|
|
108
|
-
* - 'LOCK IN SHARE MODE': MySQL style shared lock.
|
|
109
|
-
* - `jsonContainsMode`:
|
|
110
|
-
* - 'operator': Use native operators when available (e.g., Postgres `@>`).
|
|
111
|
-
* - 'function': Use a function-based approach (e.g., `json_contains`) when operators are not available.
|
|
112
|
-
*/
|
|
113
|
-
export declare interface SqlConfig {
|
|
39
|
+
|
|
40
|
+
export interface SqlConfig {
|
|
114
41
|
randomFunction?: 'RANDOM()' | 'RAND()'
|
|
115
42
|
sharedLockSyntax?: 'FOR SHARE' | 'LOCK IN SHARE MODE'
|
|
116
43
|
jsonContainsMode?: 'operator' | 'function'
|
|
117
44
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
* Optional lifecycle hooks around query execution. These are invoked for any
|
|
122
|
-
* statement executed through the builder (select/insert/update/delete/raw).
|
|
123
|
-
*/
|
|
124
|
-
export declare interface QueryHooks {
|
|
45
|
+
|
|
46
|
+
export interface QueryHooks {
|
|
125
47
|
onQueryStart?: (event: { sql: string, params?: any[], kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
|
|
126
48
|
onQueryEnd?: (event: { sql: string, params?: any[], durationMs: number, rowCount?: number, kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
|
|
127
49
|
onQueryError?: (event: { sql: string, params?: any[], error: any, durationMs: number, kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
|
|
@@ -133,17 +55,12 @@ export declare interface QueryHooks {
|
|
|
133
55
|
beforeDelete?: (event: { table: string, where?: any }) => void | Promise<void>
|
|
134
56
|
afterDelete?: (event: { table: string, where?: any, result: any }) => void | Promise<void>
|
|
135
57
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*
|
|
139
|
-
* Optional features that may be enabled per instance.
|
|
140
|
-
*
|
|
141
|
-
* - `distinctOn`: Enables PostgreSQL-like `DISTINCT ON (...)` behavior in builders.
|
|
142
|
-
*/
|
|
143
|
-
export declare interface FeatureToggles {
|
|
58
|
+
|
|
59
|
+
export interface FeatureToggles {
|
|
144
60
|
distinctOn: boolean
|
|
145
61
|
}
|
|
146
|
-
|
|
62
|
+
|
|
63
|
+
export interface DatabaseConfig {
|
|
147
64
|
database: string
|
|
148
65
|
username: string
|
|
149
66
|
password: string
|
|
@@ -151,26 +68,13 @@ export declare interface DatabaseConfig {
|
|
|
151
68
|
url?: string
|
|
152
69
|
port: number
|
|
153
70
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*
|
|
157
|
-
* Global configuration for the query builder.
|
|
158
|
-
*
|
|
159
|
-
* - `verbose`: Enables extra logging/diagnostics from the builder.
|
|
160
|
-
* - `dialect`: Target SQL dialect. See `SupportedDialect` for details.
|
|
161
|
-
* - `timestamps`: Timestamp column naming conventions.
|
|
162
|
-
* - `pagination`: Defaults for pagination helpers.
|
|
163
|
-
* - `aliasing`: How relation columns are aliased in SELECT lists.
|
|
164
|
-
* - `relations`: Foreign key naming and singularization conventions.
|
|
165
|
-
* - `transactionDefaults`: Default retry/backoff/isolation behavior for transactions.
|
|
166
|
-
* - `sql`: Dialect-specific SQL toggles.
|
|
167
|
-
* - `features`: Optional feature flags.
|
|
168
|
-
* - `debug.captureText`: When true, the builder exposes a `toText()` method to capture SQL text in memory for debugging.
|
|
169
|
-
*/
|
|
170
|
-
export declare interface QueryBuilderConfig {
|
|
71
|
+
|
|
72
|
+
export interface QueryBuilderConfig {
|
|
171
73
|
verbose: boolean
|
|
172
74
|
dialect: SupportedDialect
|
|
75
|
+
|
|
173
76
|
database: DatabaseConfig
|
|
77
|
+
|
|
174
78
|
timestamps: TimestampConfig
|
|
175
79
|
pagination: PaginationConfig
|
|
176
80
|
aliasing: AliasingConfig
|
|
@@ -179,56 +83,51 @@ export declare interface QueryBuilderConfig {
|
|
|
179
83
|
sql: SqlConfig
|
|
180
84
|
features: FeatureToggles
|
|
181
85
|
debug?: {
|
|
182
|
-
/** When true, capture query text for debugging via `toText()`. */
|
|
183
86
|
captureText: boolean
|
|
184
87
|
}
|
|
185
88
|
hooks?: QueryHooks
|
|
186
89
|
softDeletes?: {
|
|
187
|
-
/** When true, apply a default `WHERE deleted_at IS NULL` filter. */
|
|
188
90
|
enabled: boolean
|
|
189
|
-
/** Column name used for soft delete flag/timestamp. */
|
|
190
91
|
column: string
|
|
191
|
-
/** When true, default filter is applied unless `.withTrashed()` is called. */
|
|
192
92
|
defaultFilter: boolean
|
|
193
93
|
}
|
|
194
94
|
}
|
|
195
|
-
|
|
95
|
+
|
|
96
|
+
export interface CliOption {
|
|
196
97
|
verbose: boolean
|
|
197
98
|
}
|
|
198
|
-
|
|
99
|
+
|
|
100
|
+
export interface SqlOptions {
|
|
199
101
|
limit?: number
|
|
200
102
|
}
|
|
201
|
-
|
|
103
|
+
|
|
104
|
+
export interface WaitReadyOptions {
|
|
202
105
|
attempts?: number
|
|
203
106
|
delay?: number
|
|
204
107
|
}
|
|
205
|
-
|
|
108
|
+
|
|
109
|
+
export interface FileOptions {
|
|
206
110
|
params?: string
|
|
207
111
|
}
|
|
208
|
-
|
|
112
|
+
|
|
113
|
+
export interface IntrospectOptions {
|
|
209
114
|
verbose?: boolean
|
|
210
115
|
}
|
|
211
|
-
|
|
116
|
+
|
|
117
|
+
export interface MigrateOptions {
|
|
212
118
|
dialect?: SupportedDialect
|
|
213
119
|
state?: string
|
|
214
120
|
apply?: boolean
|
|
215
121
|
full?: boolean
|
|
216
122
|
}
|
|
217
|
-
|
|
123
|
+
|
|
124
|
+
export interface GenerateMigrationResult {
|
|
218
125
|
sql: string
|
|
219
126
|
sqlStatements: string[]
|
|
220
127
|
hasChanges: boolean
|
|
221
128
|
plan: any
|
|
222
129
|
}
|
|
223
|
-
|
|
130
|
+
|
|
131
|
+
export interface UnsafeOptions {
|
|
224
132
|
params?: string
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* # `SupportedDialect`
|
|
228
|
-
*
|
|
229
|
-
* The SQL dialect used to tailor generated SQL and certain features.
|
|
230
|
-
* - 'postgres': Uses `RANDOM()`, supports JSON operators (e.g. `@>`), `FOR SHARE`, `FOR UPDATE`, CTEs
|
|
231
|
-
* - 'mysql': Uses `RAND()`, shared locks via `LOCK IN SHARE MODE`
|
|
232
|
-
* - 'sqlite': Lightweight engine; some features are limited or emulated
|
|
233
|
-
*/
|
|
234
|
-
export type SupportedDialect = 'postgres' | 'mysql' | 'sqlite'
|
|
133
|
+
}
|