bun-query-builder 0.1.8 → 0.1.10
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 +5 -9
- package/dist/actions/cache.d.ts +14 -2
- package/dist/actions/console.d.ts +6 -0
- package/dist/actions/data.d.ts +13 -3
- package/dist/actions/db-info.d.ts +9 -4
- package/dist/actions/db-optimize.d.ts +5 -4
- package/dist/actions/db-wipe.d.ts +5 -4
- package/dist/actions/file.d.ts +1 -2
- package/dist/actions/index.d.ts +25 -25
- package/dist/actions/inspect.d.ts +9 -3
- package/dist/actions/introspect.d.ts +1 -2
- package/dist/actions/make-model.d.ts +5 -3
- package/dist/actions/migrate-generate.d.ts +5 -4
- package/dist/actions/migrate-rollback.d.ts +11 -4
- package/dist/actions/migrate-status.d.ts +9 -5
- package/dist/actions/migrate.d.ts +20 -12
- package/dist/actions/model-show.d.ts +5 -3
- package/dist/actions/query-explain-all.d.ts +5 -3
- package/dist/actions/relation-diagram.d.ts +5 -5
- package/dist/actions/seed.d.ts +17 -7
- package/dist/actions/sql.d.ts +1 -2
- package/dist/actions/unsafe.d.ts +1 -2
- package/dist/actions/validate.d.ts +9 -4
- package/dist/actions/wait-ready.d.ts +1 -2
- package/dist/client.d.ts +189 -199
- package/dist/config.d.ts +1 -1
- package/dist/db.d.ts +9 -8
- package/dist/drivers/index.d.ts +6 -8
- package/dist/drivers/mysql.d.ts +19 -169
- package/dist/drivers/postgres.d.ts +19 -155
- package/dist/drivers/sqlite.d.ts +19 -157
- package/dist/factory.d.ts +6 -3
- package/dist/index.d.ts +11 -11
- package/dist/index.js +1 -1
- package/dist/loader.d.ts +2 -3
- package/dist/meta.d.ts +2 -3
- package/dist/migrations.d.ts +47 -42
- package/dist/schema.d.ts +177 -30
- package/dist/seeder.d.ts +17 -12
- package/dist/types.d.ts +143 -42
- package/package.json +1 -1
package/dist/migrations.d.ts
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
import type { ModelRecord } from './schema';
|
|
2
2
|
import type { SupportedDialect } from './types';
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
3
|
+
export declare function buildMigrationPlan(models: ModelRecord, options: InferenceOptions): MigrationPlan;
|
|
4
|
+
export declare function generateSql(plan: MigrationPlan): string[];
|
|
5
|
+
/**
|
|
6
|
+
* Helper function to convert SQL statements array to a single string (for backward compatibility)
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateSqlString(plan: MigrationPlan): string;
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to convert diff SQL statements array to a single string (for backward compatibility)
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateDiffSqlString(previous: MigrationPlan | undefined, next: MigrationPlan): string;
|
|
13
|
+
/**
|
|
14
|
+
* Compute a stable hash for a migration plan. Useful for snapshotting.
|
|
15
|
+
*/
|
|
16
|
+
export declare function hashMigrationPlan(plan: MigrationPlan): string;
|
|
17
|
+
/**
|
|
18
|
+
* Generate comprehensive SQL to migrate from a previous plan to a new plan.
|
|
19
|
+
* - Creates new tables
|
|
20
|
+
* - Drops removed tables
|
|
21
|
+
* - Adds new columns
|
|
22
|
+
* - Drops removed columns
|
|
23
|
+
* - Adds new indexes
|
|
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 {
|
|
24
31
|
name: string
|
|
25
32
|
type: NormalizedColumnType
|
|
26
33
|
isPrimaryKey: boolean
|
|
@@ -31,35 +38,33 @@ export interface ColumnPlan {
|
|
|
31
38
|
references?: { table: string, column: string }
|
|
32
39
|
enumValues?: string[]
|
|
33
40
|
}
|
|
34
|
-
|
|
35
|
-
export interface IndexPlan {
|
|
41
|
+
export declare interface IndexPlan {
|
|
36
42
|
name: string
|
|
37
43
|
columns: string[]
|
|
38
44
|
type: 'index' | 'unique'
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
export interface TablePlan {
|
|
46
|
+
export declare interface TablePlan {
|
|
42
47
|
table: string
|
|
43
48
|
columns: ColumnPlan[]
|
|
44
49
|
indexes: IndexPlan[]
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
export interface MigrationPlan {
|
|
51
|
+
export declare interface MigrationPlan {
|
|
48
52
|
dialect: SupportedDialect
|
|
49
53
|
tables: TablePlan[]
|
|
50
54
|
}
|
|
51
|
-
declare
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
export declare interface InferenceOptions {
|
|
56
|
+
dialect: SupportedDialect
|
|
57
|
+
}
|
|
58
|
+
export type PrimitiveDefault = string | number | boolean | bigint | Date
|
|
59
|
+
export type NormalizedColumnType = | 'string'
|
|
60
|
+
| 'text'
|
|
61
|
+
| 'boolean'
|
|
62
|
+
| 'integer'
|
|
63
|
+
| 'bigint'
|
|
64
|
+
| 'float'
|
|
65
|
+
| 'double'
|
|
66
|
+
| 'decimal'
|
|
67
|
+
| 'date'
|
|
68
|
+
| 'datetime'
|
|
69
|
+
| 'json'
|
|
70
|
+
| 'enum'
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,8 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* # `defineModel(model)`
|
|
3
|
+
*
|
|
4
|
+
* Freezes and returns a model definition with strong inference for attributes
|
|
5
|
+
* and options.
|
|
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 {
|
|
6
47
|
default?: string | number | boolean | Date
|
|
7
48
|
unique?: boolean
|
|
8
49
|
order?: number
|
|
@@ -15,33 +56,46 @@ export interface Attribute {
|
|
|
15
56
|
message?: ValidatorMessage
|
|
16
57
|
}
|
|
17
58
|
}
|
|
59
|
+
export declare interface AttributesElements {
|
|
18
60
|
|
|
19
|
-
export interface AttributesElements {
|
|
20
|
-
[key: string]: Attribute
|
|
21
61
|
}
|
|
22
|
-
|
|
23
|
-
|
|
62
|
+
/**
|
|
63
|
+
* # `CompositeIndex`
|
|
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 {
|
|
24
73
|
name: string
|
|
25
74
|
columns: string[]
|
|
26
75
|
}
|
|
76
|
+
export declare interface Base {
|
|
27
77
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* # `ModelOptions`
|
|
81
|
+
*
|
|
82
|
+
* Declarative model definition used to build a typed `DatabaseSchema`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const User = defineModel({
|
|
87
|
+
* name: 'User',
|
|
88
|
+
* table: 'users',
|
|
89
|
+
* primaryKey: 'id',
|
|
90
|
+
* attributes: {
|
|
91
|
+
* id: { validation: { rule: {} // isInt() } },
|
|
92
|
+
* email: { validation: { rule: {} // isEmail() }, unique: true },
|
|
93
|
+
* },
|
|
94
|
+
* indexes: [{ name: 'users_email_unique', columns: ['email'] }],
|
|
95
|
+
* })
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare interface ModelOptions extends Base {
|
|
45
99
|
name: string
|
|
46
100
|
description?: string
|
|
47
101
|
table?: string
|
|
@@ -71,9 +125,102 @@ export interface ModelOptions extends Base {
|
|
|
71
125
|
[key: string]: (value: any) => any
|
|
72
126
|
}
|
|
73
127
|
}
|
|
74
|
-
|
|
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>
|
|
75
159
|
export type ModelDefinition = Readonly<ModelOptions>
|
|
76
|
-
|
|
160
|
+
/**
|
|
161
|
+
* # `ModelRecord`
|
|
162
|
+
*
|
|
163
|
+
* Collection of models keyed by model name. Kept flexible to preserve literal
|
|
164
|
+
* attribute keys and value types.
|
|
165
|
+
*/
|
|
77
166
|
export type ModelRecord = Record<string, any>
|
|
78
|
-
|
|
79
|
-
|
|
167
|
+
/**
|
|
168
|
+
* # `InferAttributes<M>`
|
|
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
|
+
}
|
package/dist/seeder.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get description(): string | undefined {
|
|
9
|
-
return undefined
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to create a seeder
|
|
3
|
+
*/
|
|
4
|
+
export declare function defineSeeder(seederClass: new () => Seeder): new () => Seeder;
|
|
5
|
+
/**
|
|
6
|
+
* Seeder configuration options
|
|
7
|
+
*/
|
|
12
8
|
export declare interface SeederConfig {
|
|
13
9
|
seedersDir?: string
|
|
14
10
|
seeders?: string[]
|
|
15
11
|
verbose?: boolean
|
|
16
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for running seeders
|
|
15
|
+
*/
|
|
17
16
|
export declare interface RunSeederOptions {
|
|
18
17
|
class?: string
|
|
19
18
|
verbose?: boolean
|
|
20
19
|
}
|
|
21
|
-
|
|
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
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,49 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* # `TransactionBackoffConfig`
|
|
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 {
|
|
4
15
|
baseMs: number
|
|
5
16
|
factor: number
|
|
6
17
|
maxMs: number
|
|
7
18
|
jitter: boolean
|
|
8
19
|
}
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
/**
|
|
21
|
+
* # `TransactionDefaultsConfig`
|
|
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 {
|
|
11
35
|
retries: number
|
|
12
36
|
isolation?: 'read committed' | 'repeatable read' | 'serializable'
|
|
13
37
|
sqlStates: string[]
|
|
14
38
|
backoff: TransactionBackoffConfig
|
|
15
39
|
}
|
|
16
|
-
|
|
17
|
-
|
|
40
|
+
/**
|
|
41
|
+
* # `TimestampConfig`
|
|
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 {
|
|
18
50
|
createdAt: string
|
|
19
51
|
updatedAt: string
|
|
20
52
|
defaultOrderColumn: string
|
|
21
53
|
}
|
|
22
|
-
|
|
23
|
-
|
|
54
|
+
/**
|
|
55
|
+
* # `PaginationConfig`
|
|
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 {
|
|
24
63
|
defaultPerPage: number
|
|
25
64
|
cursorColumn: string
|
|
26
65
|
}
|
|
27
|
-
|
|
28
|
-
|
|
66
|
+
/**
|
|
67
|
+
* # `AliasingConfig`
|
|
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 {
|
|
29
77
|
relationColumnAliasFormat: 'table_column' | 'table.dot.column' | 'camelCase'
|
|
30
78
|
}
|
|
31
|
-
|
|
32
|
-
|
|
79
|
+
/**
|
|
80
|
+
* # `RelationsConfig`
|
|
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 {
|
|
33
92
|
foreignKeyFormat: 'singularParent_id' | 'parentId'
|
|
34
93
|
singularizeStrategy?: 'stripTrailingS' | 'none'
|
|
35
94
|
maxDepth?: number
|
|
36
95
|
maxEagerLoad?: number
|
|
37
96
|
detectCycles?: boolean
|
|
38
97
|
}
|
|
39
|
-
|
|
40
|
-
|
|
98
|
+
/**
|
|
99
|
+
* # `SqlConfig`
|
|
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 {
|
|
41
114
|
randomFunction?: 'RANDOM()' | 'RAND()'
|
|
42
115
|
sharedLockSyntax?: 'FOR SHARE' | 'LOCK IN SHARE MODE'
|
|
43
116
|
jsonContainsMode?: 'operator' | 'function'
|
|
44
117
|
}
|
|
45
|
-
|
|
46
|
-
|
|
118
|
+
/**
|
|
119
|
+
* # `QueryHooks`
|
|
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 {
|
|
47
125
|
onQueryStart?: (event: { sql: string, params?: any[], kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
|
|
48
126
|
onQueryEnd?: (event: { sql: string, params?: any[], durationMs: number, rowCount?: number, kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
|
|
49
127
|
onQueryError?: (event: { sql: string, params?: any[], error: any, durationMs: number, kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
|
|
@@ -55,12 +133,17 @@ export interface QueryHooks {
|
|
|
55
133
|
beforeDelete?: (event: { table: string, where?: any }) => void | Promise<void>
|
|
56
134
|
afterDelete?: (event: { table: string, where?: any, result: any }) => void | Promise<void>
|
|
57
135
|
}
|
|
58
|
-
|
|
59
|
-
|
|
136
|
+
/**
|
|
137
|
+
* # `FeatureToggles`
|
|
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 {
|
|
60
144
|
distinctOn: boolean
|
|
61
145
|
}
|
|
62
|
-
|
|
63
|
-
export interface DatabaseConfig {
|
|
146
|
+
export declare interface DatabaseConfig {
|
|
64
147
|
database: string
|
|
65
148
|
username: string
|
|
66
149
|
password: string
|
|
@@ -68,13 +151,26 @@ export interface DatabaseConfig {
|
|
|
68
151
|
url?: string
|
|
69
152
|
port: number
|
|
70
153
|
}
|
|
71
|
-
|
|
72
|
-
|
|
154
|
+
/**
|
|
155
|
+
* # `QueryBuilderConfig`
|
|
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 {
|
|
73
171
|
verbose: boolean
|
|
74
172
|
dialect: SupportedDialect
|
|
75
|
-
|
|
76
173
|
database: DatabaseConfig
|
|
77
|
-
|
|
78
174
|
timestamps: TimestampConfig
|
|
79
175
|
pagination: PaginationConfig
|
|
80
176
|
aliasing: AliasingConfig
|
|
@@ -83,51 +179,56 @@ export interface QueryBuilderConfig {
|
|
|
83
179
|
sql: SqlConfig
|
|
84
180
|
features: FeatureToggles
|
|
85
181
|
debug?: {
|
|
182
|
+
/** When true, capture query text for debugging via `toText()`. */
|
|
86
183
|
captureText: boolean
|
|
87
184
|
}
|
|
88
185
|
hooks?: QueryHooks
|
|
89
186
|
softDeletes?: {
|
|
187
|
+
/** When true, apply a default `WHERE deleted_at IS NULL` filter. */
|
|
90
188
|
enabled: boolean
|
|
189
|
+
/** Column name used for soft delete flag/timestamp. */
|
|
91
190
|
column: string
|
|
191
|
+
/** When true, default filter is applied unless `.withTrashed()` is called. */
|
|
92
192
|
defaultFilter: boolean
|
|
93
193
|
}
|
|
94
194
|
}
|
|
95
|
-
|
|
96
|
-
export interface CliOption {
|
|
195
|
+
export declare interface CliOption {
|
|
97
196
|
verbose: boolean
|
|
98
197
|
}
|
|
99
|
-
|
|
100
|
-
export interface SqlOptions {
|
|
198
|
+
export declare interface SqlOptions {
|
|
101
199
|
limit?: number
|
|
102
200
|
}
|
|
103
|
-
|
|
104
|
-
export interface WaitReadyOptions {
|
|
201
|
+
export declare interface WaitReadyOptions {
|
|
105
202
|
attempts?: number
|
|
106
203
|
delay?: number
|
|
107
204
|
}
|
|
108
|
-
|
|
109
|
-
export interface FileOptions {
|
|
205
|
+
export declare interface FileOptions {
|
|
110
206
|
params?: string
|
|
111
207
|
}
|
|
112
|
-
|
|
113
|
-
export interface IntrospectOptions {
|
|
208
|
+
export declare interface IntrospectOptions {
|
|
114
209
|
verbose?: boolean
|
|
115
210
|
}
|
|
116
|
-
|
|
117
|
-
export interface MigrateOptions {
|
|
211
|
+
export declare interface MigrateOptions {
|
|
118
212
|
dialect?: SupportedDialect
|
|
119
213
|
state?: string
|
|
120
214
|
apply?: boolean
|
|
121
215
|
full?: boolean
|
|
122
216
|
}
|
|
123
|
-
|
|
124
|
-
export interface GenerateMigrationResult {
|
|
217
|
+
export declare interface GenerateMigrationResult {
|
|
125
218
|
sql: string
|
|
126
219
|
sqlStatements: string[]
|
|
127
220
|
hasChanges: boolean
|
|
128
221
|
plan: any
|
|
129
222
|
}
|
|
130
|
-
|
|
131
|
-
export interface UnsafeOptions {
|
|
223
|
+
export declare interface UnsafeOptions {
|
|
132
224
|
params?: string
|
|
133
|
-
}
|
|
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'
|
package/package.json
CHANGED