@holo-js/db 0.1.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/index.d.ts +3789 -0
- package/dist/index.mjs +14319 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3789 @@
|
|
|
1
|
+
import { PoolConfig, QueryResult } from 'pg';
|
|
2
|
+
import { PoolOptions } from 'mysql2/promise';
|
|
3
|
+
|
|
4
|
+
type LogicalColumnKind = 'id' | 'integer' | 'bigInteger' | 'string' | 'text' | 'boolean' | 'real' | 'decimal' | 'date' | 'datetime' | 'timestamp' | 'json' | 'blob' | 'uuid' | 'ulid' | 'snowflake' | 'vector' | 'enum';
|
|
5
|
+
type ColumnDefaultKind = 'value' | 'now';
|
|
6
|
+
type IdGenerationStrategy = 'autoIncrement' | 'uuid' | 'ulid' | 'snowflake';
|
|
7
|
+
type VectorValue = readonly number[];
|
|
8
|
+
interface ForeignKeyReference {
|
|
9
|
+
table: string;
|
|
10
|
+
column: string;
|
|
11
|
+
constraintName?: string;
|
|
12
|
+
onDelete?: string;
|
|
13
|
+
onUpdate?: string;
|
|
14
|
+
}
|
|
15
|
+
interface ColumnDefinition<_TType = unknown, TNullable extends boolean = false, THasDefault extends boolean = false, TGenerated extends boolean = false> {
|
|
16
|
+
readonly kind: LogicalColumnKind;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly nullable: TNullable;
|
|
19
|
+
readonly hasDefault: THasDefault;
|
|
20
|
+
readonly generated: TGenerated;
|
|
21
|
+
readonly primaryKey: boolean;
|
|
22
|
+
readonly unique: boolean;
|
|
23
|
+
readonly defaultKind?: ColumnDefaultKind;
|
|
24
|
+
readonly defaultValue?: unknown;
|
|
25
|
+
readonly references?: ForeignKeyReference;
|
|
26
|
+
readonly idStrategy?: IdGenerationStrategy;
|
|
27
|
+
readonly enumValues?: readonly string[];
|
|
28
|
+
readonly vectorDimensions?: number;
|
|
29
|
+
}
|
|
30
|
+
type AnyColumnDefinition = ColumnDefinition<unknown, boolean, boolean, boolean>;
|
|
31
|
+
type TableColumnsShape = Record<string, AnyColumnDefinition>;
|
|
32
|
+
interface TableDefinition<TName extends string = string, TColumns extends TableColumnsShape = TableColumnsShape> {
|
|
33
|
+
readonly kind: 'table';
|
|
34
|
+
readonly tableName: TName;
|
|
35
|
+
readonly columns: TColumns;
|
|
36
|
+
readonly indexes: readonly TableIndexDefinition[];
|
|
37
|
+
}
|
|
38
|
+
interface TableIndexDefinition {
|
|
39
|
+
readonly name?: string;
|
|
40
|
+
readonly columns: readonly string[];
|
|
41
|
+
readonly unique: boolean;
|
|
42
|
+
}
|
|
43
|
+
type ColumnSelectType<TColumn extends AnyColumnDefinition> = TColumn extends ColumnDefinition<infer TValue, infer TNullable, boolean, boolean> ? TNullable extends true ? TValue | null : TValue : never;
|
|
44
|
+
type ColumnInsertType<TColumn extends AnyColumnDefinition> = TColumn extends ColumnDefinition<infer TValue, infer TNullable, boolean, boolean> ? TNullable extends true ? TValue | null : TValue : never;
|
|
45
|
+
type OptionalInsertKeys<TColumns extends TableColumnsShape> = {
|
|
46
|
+
[K in keyof TColumns]: TColumns[K] extends ColumnDefinition<unknown, boolean, infer THasDefault, infer TGenerated> ? THasDefault extends true ? K : TGenerated extends true ? K : never : never;
|
|
47
|
+
}[keyof TColumns];
|
|
48
|
+
type RequiredInsertKeys<TColumns extends TableColumnsShape> = Exclude<keyof TColumns, OptionalInsertKeys<TColumns>>;
|
|
49
|
+
type InferSelect<TTable extends TableDefinition> = {
|
|
50
|
+
[K in keyof TTable['columns']]: ColumnSelectType<TTable['columns'][K]>;
|
|
51
|
+
};
|
|
52
|
+
type InferInsert<TTable extends TableDefinition> = {
|
|
53
|
+
[K in RequiredInsertKeys<TTable['columns']>]: ColumnInsertType<TTable['columns'][K]>;
|
|
54
|
+
} & {
|
|
55
|
+
[K in OptionalInsertKeys<TTable['columns']>]?: ColumnInsertType<TTable['columns'][K]>;
|
|
56
|
+
};
|
|
57
|
+
type InferUpdate<TTable extends TableDefinition> = Partial<{
|
|
58
|
+
[K in keyof TTable['columns']]: ColumnInsertType<TTable['columns'][K]>;
|
|
59
|
+
}>;
|
|
60
|
+
|
|
61
|
+
type ColumnMetadata = {
|
|
62
|
+
kind: LogicalColumnKind;
|
|
63
|
+
name?: string;
|
|
64
|
+
nullable: boolean;
|
|
65
|
+
hasDefault: boolean;
|
|
66
|
+
generated: boolean;
|
|
67
|
+
primaryKey: boolean;
|
|
68
|
+
unique: boolean;
|
|
69
|
+
defaultKind?: ColumnDefaultKind;
|
|
70
|
+
defaultValue?: unknown;
|
|
71
|
+
references?: ForeignKeyReference;
|
|
72
|
+
referenceTable?: string;
|
|
73
|
+
inferReferenceTable?: boolean;
|
|
74
|
+
referenceColumn?: string;
|
|
75
|
+
referenceConstraintName?: string;
|
|
76
|
+
referenceOnDelete?: ForeignKeyReference['onDelete'];
|
|
77
|
+
referenceOnUpdate?: ForeignKeyReference['onUpdate'];
|
|
78
|
+
idStrategy?: IdGenerationStrategy;
|
|
79
|
+
enumValues?: readonly string[];
|
|
80
|
+
vectorDimensions?: number;
|
|
81
|
+
};
|
|
82
|
+
type VectorOptions = {
|
|
83
|
+
dimensions: number;
|
|
84
|
+
};
|
|
85
|
+
type ColumnBuildOptions = {
|
|
86
|
+
name: string;
|
|
87
|
+
};
|
|
88
|
+
declare class ColumnBuilder<TType, TNullable extends boolean = false, THasDefault extends boolean = false, TGenerated extends boolean = false> {
|
|
89
|
+
private readonly metadata;
|
|
90
|
+
constructor(kind: LogicalColumnKind, name?: string, metadata?: Partial<ColumnMetadata>);
|
|
91
|
+
notNull(): ColumnBuilder<TType, false, THasDefault, TGenerated>;
|
|
92
|
+
nullable(): ColumnBuilder<TType, true, THasDefault, TGenerated>;
|
|
93
|
+
default(value: unknown): ColumnBuilder<TType, TNullable, true, TGenerated>;
|
|
94
|
+
defaultNow(): ColumnBuilder<TType, TNullable, true, TGenerated>;
|
|
95
|
+
generated(): ColumnBuilder<TType, TNullable, THasDefault, true>;
|
|
96
|
+
primaryKey(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
97
|
+
unique(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
98
|
+
references(columnName: string): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
99
|
+
on(table: string): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
100
|
+
constraintName(name: string): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
101
|
+
constrained(table?: string, columnName?: string): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
102
|
+
onDelete(action: NonNullable<ForeignKeyReference['onDelete']>): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
103
|
+
onUpdate(action: NonNullable<ForeignKeyReference['onUpdate']>): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
104
|
+
cascadeOnDelete(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
105
|
+
restrictOnDelete(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
106
|
+
nullOnDelete(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
107
|
+
noActionOnDelete(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
108
|
+
cascadeOnUpdate(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
109
|
+
restrictOnUpdate(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
110
|
+
nullOnUpdate(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
111
|
+
noActionOnUpdate(): ColumnBuilder<TType, TNullable, THasDefault, TGenerated>;
|
|
112
|
+
toDefinition(options: ColumnBuildOptions): ColumnDefinition<TType, TNullable, THasDefault, TGenerated>;
|
|
113
|
+
private clone;
|
|
114
|
+
}
|
|
115
|
+
declare const column: {
|
|
116
|
+
id(name?: string): ColumnBuilder<number, false, false, true>;
|
|
117
|
+
autoIncrementId(name?: string): ColumnBuilder<number, false, false, true>;
|
|
118
|
+
integer(name?: string): ColumnBuilder<number, false, false, false>;
|
|
119
|
+
bigInteger(name?: string): ColumnBuilder<number, false, false, false>;
|
|
120
|
+
string(name?: string): ColumnBuilder<string, false, false, false>;
|
|
121
|
+
text(name?: string): ColumnBuilder<string, false, false, false>;
|
|
122
|
+
boolean(name?: string): ColumnBuilder<boolean, false, false, false>;
|
|
123
|
+
real(name?: string): ColumnBuilder<number, false, false, false>;
|
|
124
|
+
decimal(name?: string): ColumnBuilder<string, false, false, false>;
|
|
125
|
+
date(name?: string): ColumnBuilder<Date, false, false, false>;
|
|
126
|
+
datetime(name?: string): ColumnBuilder<Date, false, false, false>;
|
|
127
|
+
timestamp(name?: string): ColumnBuilder<Date, false, false, false>;
|
|
128
|
+
json<TValue = unknown>(name?: string): ColumnBuilder<TValue, false, false, false>;
|
|
129
|
+
blob(name?: string): ColumnBuilder<Uint8Array<ArrayBufferLike>, false, false, false>;
|
|
130
|
+
uuid(name?: string): ColumnBuilder<string, false, false, false>;
|
|
131
|
+
ulid(name?: string): ColumnBuilder<string, false, false, false>;
|
|
132
|
+
snowflake(name?: string): ColumnBuilder<string, false, false, false>;
|
|
133
|
+
foreignId(name?: string): ColumnBuilder<number, false, false, false>;
|
|
134
|
+
foreignUuid(name?: string): ColumnBuilder<string, false, false, false>;
|
|
135
|
+
foreignUlid(name?: string): ColumnBuilder<string, false, false, false>;
|
|
136
|
+
foreignSnowflake(name?: string): ColumnBuilder<string, false, false, false>;
|
|
137
|
+
vector(options: VectorOptions, name?: string): ColumnBuilder<VectorValue, false, false, false>;
|
|
138
|
+
enum<const TValues extends readonly string[]>(values: TValues, name?: string): ColumnBuilder<TValues[number], false, false, false>;
|
|
139
|
+
};
|
|
140
|
+
type AnyColumnBuilder = ColumnBuilder<unknown, boolean, boolean, boolean>;
|
|
141
|
+
type ColumnInput = AnyColumnBuilder | AnyColumnDefinition;
|
|
142
|
+
|
|
143
|
+
type ColumnShapeInput$2 = Record<string, ColumnInput>;
|
|
144
|
+
type ResolvedColumn<TColumn extends ColumnInput> = TColumn extends {
|
|
145
|
+
toDefinition(options: {
|
|
146
|
+
name: string;
|
|
147
|
+
}): infer TDefinition;
|
|
148
|
+
} ? TDefinition extends AnyColumnDefinition ? TDefinition : never : TColumn extends AnyColumnDefinition ? TColumn : never;
|
|
149
|
+
type BoundColumns<TColumns extends ColumnShapeInput$2> = {
|
|
150
|
+
[K in keyof TColumns]: ResolvedColumn<TColumns[K]>;
|
|
151
|
+
};
|
|
152
|
+
type BoundTableDefinition<TName extends string, TColumns extends ColumnShapeInput$2> = TableDefinition<TName, BoundColumns<TColumns>> & BoundColumns<TColumns>;
|
|
153
|
+
|
|
154
|
+
interface GeneratedSchemaTables {
|
|
155
|
+
}
|
|
156
|
+
type GeneratedSchemaTableName = Extract<keyof GeneratedSchemaTables, string>;
|
|
157
|
+
type GeneratedSchemaTable<TName extends string> = TName extends GeneratedSchemaTableName ? GeneratedSchemaTables[TName] : TableDefinition<TName, TableColumnsShape>;
|
|
158
|
+
declare function registerGeneratedTables<TTables extends Record<string, TableDefinition>>(tables: TTables): TTables;
|
|
159
|
+
declare function defineGeneratedTable<TName extends string, TColumns extends Record<string, ColumnInput>>(tableName: TName, columns: TColumns, options?: {
|
|
160
|
+
indexes?: readonly TableIndexDefinition[];
|
|
161
|
+
}): BoundTableDefinition<TName, TColumns>;
|
|
162
|
+
declare function clearGeneratedTables(): void;
|
|
163
|
+
declare function getGeneratedTableDefinition<TName extends string>(tableName: TName): GeneratedSchemaTable<TName> | undefined;
|
|
164
|
+
declare function resolveGeneratedTableDefinition<TTables extends Record<string, TableDefinition>, TName extends Extract<keyof TTables, string>>(tableName: TName, tables: TTables): TTables[TName];
|
|
165
|
+
declare function resolveGeneratedTableDefinition<TName extends string>(tableName: TName, tables: Partial<Record<string, TableDefinition>>): GeneratedSchemaTable<TName>;
|
|
166
|
+
declare function listGeneratedTableDefinitions(): readonly TableDefinition[];
|
|
167
|
+
declare function renderGeneratedSchemaPlaceholder(): string;
|
|
168
|
+
declare function renderGeneratedSchemaModule(tables: readonly TableDefinition[]): string;
|
|
169
|
+
|
|
170
|
+
type EntityConstructor = {
|
|
171
|
+
new <TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap>(repository: ModelRepositoryLike<TTable, EmptyScopeMap, TRelations>, attributes: Partial<ModelRecord<TTable>>, exists?: boolean): Entity<TTable, TRelations>;
|
|
172
|
+
prototype: EntityBase<TableDefinition, RelationMap>;
|
|
173
|
+
};
|
|
174
|
+
declare class EntityBase<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap> {
|
|
175
|
+
private readonly repository;
|
|
176
|
+
private attributes;
|
|
177
|
+
private original;
|
|
178
|
+
private changes;
|
|
179
|
+
private persisted;
|
|
180
|
+
private relations;
|
|
181
|
+
private relationLoads;
|
|
182
|
+
private peerCollection?;
|
|
183
|
+
private hiddenOverrides;
|
|
184
|
+
private visibleOverrides;
|
|
185
|
+
private visibleOnly;
|
|
186
|
+
private appendedOverrides;
|
|
187
|
+
constructor(repository: ModelRepositoryLike<TTable, EmptyScopeMap, TRelations>, attributes: Partial<ModelRecord<TTable>>, exists?: boolean);
|
|
188
|
+
getRepository(): ModelRepositoryLike<TTable>;
|
|
189
|
+
private getRepositoryRuntime;
|
|
190
|
+
is(other: unknown): boolean;
|
|
191
|
+
isNot(other: unknown): boolean;
|
|
192
|
+
exists(): boolean;
|
|
193
|
+
trashed(): boolean;
|
|
194
|
+
get<TKey extends Extract<keyof ModelRecord<TTable>, string>>(key: TKey): ModelRecord<TTable>[TKey];
|
|
195
|
+
set<TKey extends Extract<keyof ModelRecord<TTable>, string>>(key: TKey, value: ModelRecord<TTable>[TKey]): this;
|
|
196
|
+
fill(values: Partial<ModelRecord<TTable>>): this;
|
|
197
|
+
forceFill(values: Partial<ModelRecord<TTable>>): this;
|
|
198
|
+
isDirty(key?: Extract<keyof ModelRecord<TTable>, string>): boolean;
|
|
199
|
+
isClean(): boolean;
|
|
200
|
+
getDirty(): Partial<ModelUpdatePayload<TTable>>;
|
|
201
|
+
getChanges(): Partial<ModelUpdatePayload<TTable>>;
|
|
202
|
+
wasChanged(key?: Extract<keyof ModelRecord<TTable>, string>): boolean;
|
|
203
|
+
syncOriginal(): this;
|
|
204
|
+
syncChanges(): this;
|
|
205
|
+
syncPersisted(entity: EntityBase<TTable>, changes?: Record<string, unknown>): this;
|
|
206
|
+
bindPeerCollection(peers: readonly EntityBase<TTable, TRelations>[]): this;
|
|
207
|
+
getPeerCollection(): readonly EntityBase<TTable, TRelations>[] | undefined;
|
|
208
|
+
getPendingRelationLoad(name: string): Promise<unknown> | undefined;
|
|
209
|
+
setPendingRelationLoad(name: string, load: Promise<unknown>): this;
|
|
210
|
+
clearPendingRelationLoad(name: string): this;
|
|
211
|
+
toAttributes(): ModelRecord<TTable>;
|
|
212
|
+
setRelation(name: string, value: unknown): this;
|
|
213
|
+
setComputed(name: string, value: unknown): this;
|
|
214
|
+
makeHidden(...keys: readonly string[]): this;
|
|
215
|
+
makeVisible(...keys: readonly string[]): this;
|
|
216
|
+
setHidden(keys: readonly string[]): this;
|
|
217
|
+
setVisible(keys: readonly string[]): this;
|
|
218
|
+
append(...keys: readonly string[]): this;
|
|
219
|
+
setAppends(keys: readonly string[]): this;
|
|
220
|
+
withoutAppends(): this;
|
|
221
|
+
getRelation<TRelation = unknown>(name: string): TRelation;
|
|
222
|
+
hasRelation(name: string): boolean;
|
|
223
|
+
getLoadedRelations(): Readonly<Record<string, unknown>>;
|
|
224
|
+
getSerializationConfig(): {
|
|
225
|
+
readonly hidden: ReadonlySet<string>;
|
|
226
|
+
readonly visible: ReadonlySet<string>;
|
|
227
|
+
readonly visibleOnly: readonly string[] | null;
|
|
228
|
+
readonly appended: readonly string[] | null;
|
|
229
|
+
};
|
|
230
|
+
forgetRelation(name: string): this;
|
|
231
|
+
toJSON(): ModelRecord<TTable>;
|
|
232
|
+
save(): Promise<this>;
|
|
233
|
+
push(): Promise<this>;
|
|
234
|
+
saveQuietly(): Promise<this>;
|
|
235
|
+
delete(): Promise<void>;
|
|
236
|
+
deleteQuietly(): Promise<void>;
|
|
237
|
+
restore(): Promise<this>;
|
|
238
|
+
restoreQuietly(): Promise<this>;
|
|
239
|
+
forceDelete(): Promise<void>;
|
|
240
|
+
forceDeleteQuietly(): Promise<void>;
|
|
241
|
+
fresh(): Promise<Entity<TTable, TRelations> | undefined>;
|
|
242
|
+
refresh(): Promise<this>;
|
|
243
|
+
replicate(except?: readonly string[]): Entity<TTable, TRelations>;
|
|
244
|
+
load<TPaths extends readonly ModelRelationPath<TRelations>[]>(...relations: TPaths): Promise<this & ResolveEagerLoads<TRelations, TPaths> & (this extends {
|
|
245
|
+
toJSON(): infer R;
|
|
246
|
+
} ? {
|
|
247
|
+
toJSON(): R & SerializeLoaded<ResolveEagerLoads<TRelations, TPaths>>;
|
|
248
|
+
} : {
|
|
249
|
+
toJSON(): ModelRecord<TTable> & SerializeLoaded<ResolveEagerLoads<TRelations, TPaths>>;
|
|
250
|
+
})>;
|
|
251
|
+
loadMissing<TPaths extends readonly ModelRelationPath<TRelations>[]>(...relations: TPaths): Promise<this & ResolveEagerLoads<TRelations, TPaths> & (this extends {
|
|
252
|
+
toJSON(): infer R;
|
|
253
|
+
} ? {
|
|
254
|
+
toJSON(): R & SerializeLoaded<ResolveEagerLoads<TRelations, TPaths>>;
|
|
255
|
+
} : {
|
|
256
|
+
toJSON(): ModelRecord<TTable> & SerializeLoaded<ResolveEagerLoads<TRelations, TPaths>>;
|
|
257
|
+
})>;
|
|
258
|
+
loadMorph(relation: ModelRelationName<TRelations>, mapping: ModelMorphLoadMap): Promise<this>;
|
|
259
|
+
loadCount(...relations: readonly ModelRelationName<TRelations>[]): Promise<this>;
|
|
260
|
+
loadExists(...relations: readonly ModelRelationName<TRelations>[]): Promise<this>;
|
|
261
|
+
loadSum<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<this>;
|
|
262
|
+
loadAvg<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<this>;
|
|
263
|
+
loadMin<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<this>;
|
|
264
|
+
loadMax<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<this>;
|
|
265
|
+
associate<TRelated extends TableDefinition>(relation: string, related: Entity<TRelated> | null): this;
|
|
266
|
+
dissociate(relation: string): this;
|
|
267
|
+
saveRelated<TRelated extends TableDefinition>(relation: string, related: Entity<TRelated>): Promise<Entity<TRelated>>;
|
|
268
|
+
saveManyRelated<TRelated extends TableDefinition>(relation: string, related: readonly Entity<TRelated>[]): Promise<Entity<TRelated>[]>;
|
|
269
|
+
saveRelatedQuietly<TRelated extends TableDefinition>(relation: string, related: Entity<TRelated>): Promise<Entity<TRelated>>;
|
|
270
|
+
saveManyRelatedQuietly<TRelated extends TableDefinition>(relation: string, related: readonly Entity<TRelated>[]): Promise<Entity<TRelated>[]>;
|
|
271
|
+
createRelated(relation: string, values: Record<string, unknown>): Promise<Entity<TableDefinition>>;
|
|
272
|
+
createManyRelated(relation: string, values: readonly Record<string, unknown>[]): Promise<Entity<TableDefinition>[]>;
|
|
273
|
+
createRelatedQuietly(relation: string, values: Record<string, unknown>): Promise<Entity<TableDefinition>>;
|
|
274
|
+
createManyRelatedQuietly(relation: string, values: readonly Record<string, unknown>[]): Promise<Entity<TableDefinition>[]>;
|
|
275
|
+
attach(relation: string, ids: unknown, attributes?: Record<string, unknown>): Promise<void>;
|
|
276
|
+
detach(relation: string, ids?: unknown): Promise<number>;
|
|
277
|
+
sync(relation: string, ids: unknown): Promise<{
|
|
278
|
+
attached: unknown[];
|
|
279
|
+
detached: unknown[];
|
|
280
|
+
updated: unknown[];
|
|
281
|
+
}>;
|
|
282
|
+
syncWithoutDetaching(relation: string, ids: unknown): Promise<{
|
|
283
|
+
attached: unknown[];
|
|
284
|
+
detached: unknown[];
|
|
285
|
+
updated: unknown[];
|
|
286
|
+
}>;
|
|
287
|
+
updateExistingPivot(relation: string, id: unknown, attributes: Record<string, unknown>): Promise<number>;
|
|
288
|
+
toggle(relation: string, ids: unknown): Promise<{
|
|
289
|
+
attached: unknown[];
|
|
290
|
+
detached: unknown[];
|
|
291
|
+
}>;
|
|
292
|
+
private initializeModelProperties;
|
|
293
|
+
}
|
|
294
|
+
type Entity<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap> = EntityBase<TTable, TRelations> & ModelRecord<TTable>;
|
|
295
|
+
declare const Entity: EntityConstructor;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Capability flags exposed by a driver+dialect pair.
|
|
299
|
+
*
|
|
300
|
+
* The new architecture uses explicit capabilities instead of branching on
|
|
301
|
+
* driver names throughout the ORM.
|
|
302
|
+
*/
|
|
303
|
+
interface DatabaseCapabilities {
|
|
304
|
+
returning: boolean;
|
|
305
|
+
savepoints: boolean;
|
|
306
|
+
concurrentQueries: boolean;
|
|
307
|
+
workerThreadExecution: boolean;
|
|
308
|
+
lockForUpdate: boolean;
|
|
309
|
+
sharedLock: boolean;
|
|
310
|
+
jsonValueQuery: boolean;
|
|
311
|
+
jsonContains: boolean;
|
|
312
|
+
jsonLength: boolean;
|
|
313
|
+
schemaQualifiedIdentifiers: boolean;
|
|
314
|
+
nativeUpsert: boolean;
|
|
315
|
+
ddlAlterSupport: boolean;
|
|
316
|
+
introspection: boolean;
|
|
317
|
+
}
|
|
318
|
+
declare const DEFAULT_CAPABILITIES: DatabaseCapabilities;
|
|
319
|
+
declare function createCapabilities(overrides?: Partial<DatabaseCapabilities>): DatabaseCapabilities;
|
|
320
|
+
|
|
321
|
+
interface SecurityPolicy {
|
|
322
|
+
allowUnsafeRawSql: boolean;
|
|
323
|
+
debugSqlInLogs: boolean;
|
|
324
|
+
maxQueryComplexity?: number;
|
|
325
|
+
redactBindingsInLogs: boolean;
|
|
326
|
+
maxLoggedBindings: number;
|
|
327
|
+
}
|
|
328
|
+
declare const DEFAULT_SECURITY_POLICY: SecurityPolicy;
|
|
329
|
+
declare function createSecurityPolicy(overrides?: Partial<SecurityPolicy>): SecurityPolicy;
|
|
330
|
+
declare function redactBindings(bindings: readonly unknown[], policy: SecurityPolicy): unknown[];
|
|
331
|
+
declare function redactSql(sql: string, policy: SecurityPolicy): string;
|
|
332
|
+
|
|
333
|
+
declare class SchemaRegistry {
|
|
334
|
+
private readonly tables;
|
|
335
|
+
register<TTable extends TableDefinition>(table: TTable): TTable;
|
|
336
|
+
has(name: string): boolean;
|
|
337
|
+
replace<TTable extends TableDefinition>(table: TTable): TTable;
|
|
338
|
+
delete(name: string): void;
|
|
339
|
+
get<TTable extends TableDefinition = TableDefinition>(name: string): TTable | undefined;
|
|
340
|
+
list(): TableDefinition[];
|
|
341
|
+
clear(): void;
|
|
342
|
+
}
|
|
343
|
+
declare function createSchemaRegistry(): SchemaRegistry;
|
|
344
|
+
|
|
345
|
+
declare class ModelRegistry {
|
|
346
|
+
private readonly models;
|
|
347
|
+
register(reference: ModelDefinitionLike): AnyModelDefinition;
|
|
348
|
+
has(name: string): boolean;
|
|
349
|
+
get(name: string): AnyModelDefinition | undefined;
|
|
350
|
+
list(): readonly AnyModelDefinition[];
|
|
351
|
+
clear(): void;
|
|
352
|
+
}
|
|
353
|
+
declare function createModelRegistry(): ModelRegistry;
|
|
354
|
+
|
|
355
|
+
type SchedulingMode = 'concurrent' | 'serialized' | 'worker';
|
|
356
|
+
interface QuerySchedulerOptions {
|
|
357
|
+
connectionName: string;
|
|
358
|
+
supportsConcurrentQueries: boolean;
|
|
359
|
+
supportsWorkerThreads: boolean;
|
|
360
|
+
concurrency?: ConcurrencyOptions;
|
|
361
|
+
}
|
|
362
|
+
declare class QueryScheduler {
|
|
363
|
+
private readonly connectionName;
|
|
364
|
+
private readonly queueLimit;
|
|
365
|
+
private readonly supportsConcurrentQueries;
|
|
366
|
+
private readonly supportsWorkerThreads;
|
|
367
|
+
private readonly concurrentState;
|
|
368
|
+
private readonly serializedState;
|
|
369
|
+
private readonly workerState;
|
|
370
|
+
constructor(options: QuerySchedulerOptions);
|
|
371
|
+
schedule<T>(options: {
|
|
372
|
+
transactional: boolean;
|
|
373
|
+
preferWorkerThreads?: boolean;
|
|
374
|
+
}, callback: (schedulingMode: SchedulingMode) => Promise<T>): Promise<{
|
|
375
|
+
result: T;
|
|
376
|
+
schedulingMode: SchedulingMode;
|
|
377
|
+
}>;
|
|
378
|
+
preview(options: {
|
|
379
|
+
transactional: boolean;
|
|
380
|
+
preferWorkerThreads?: boolean;
|
|
381
|
+
}): SchedulingMode;
|
|
382
|
+
private resolveMode;
|
|
383
|
+
private resolveState;
|
|
384
|
+
}
|
|
385
|
+
declare function createQueryScheduler(options: QuerySchedulerOptions): QueryScheduler;
|
|
386
|
+
|
|
387
|
+
type DatabaseDriverName = 'sqlite' | 'postgres' | 'mysql' | string;
|
|
388
|
+
type TransactionScopeKind = 'root' | 'transaction' | 'savepoint';
|
|
389
|
+
interface ConcurrencyOptions {
|
|
390
|
+
maxConcurrentQueries?: number;
|
|
391
|
+
queueLimit?: number;
|
|
392
|
+
workerThreads?: boolean;
|
|
393
|
+
}
|
|
394
|
+
interface DatabaseOperationOptions {
|
|
395
|
+
signal?: AbortSignal;
|
|
396
|
+
timeoutMs?: number;
|
|
397
|
+
}
|
|
398
|
+
type TransactionCallback = () => void | Promise<void>;
|
|
399
|
+
interface UnsafeStatement {
|
|
400
|
+
unsafe: true;
|
|
401
|
+
sql: string;
|
|
402
|
+
bindings?: readonly unknown[];
|
|
403
|
+
source?: string;
|
|
404
|
+
}
|
|
405
|
+
type CompiledQueryKind = 'select' | 'insert' | 'update' | 'upsert' | 'delete';
|
|
406
|
+
type CompiledQueryResultMode = 'rows' | 'write';
|
|
407
|
+
type CompiledQueryIntent = 'read' | 'write';
|
|
408
|
+
type CompiledQueryStreamingMode = 'buffered';
|
|
409
|
+
type CompiledQueryTransactionAffinity = 'optional' | 'required';
|
|
410
|
+
interface CompiledStatementMetadata {
|
|
411
|
+
kind: CompiledQueryKind;
|
|
412
|
+
resultMode: CompiledQueryResultMode;
|
|
413
|
+
selectedShape: {
|
|
414
|
+
mode: 'all' | 'projection' | 'write';
|
|
415
|
+
columns: readonly string[];
|
|
416
|
+
aggregates: readonly string[];
|
|
417
|
+
hasRawSelections: boolean;
|
|
418
|
+
hasSubqueries: boolean;
|
|
419
|
+
};
|
|
420
|
+
safety: {
|
|
421
|
+
unsafe: boolean;
|
|
422
|
+
containsRawSql: boolean;
|
|
423
|
+
};
|
|
424
|
+
debug: {
|
|
425
|
+
tableName: string;
|
|
426
|
+
hasJoins: boolean;
|
|
427
|
+
hasUnions: boolean;
|
|
428
|
+
hasGrouping: boolean;
|
|
429
|
+
hasHaving: boolean;
|
|
430
|
+
complexity: number;
|
|
431
|
+
lockMode?: string;
|
|
432
|
+
intent: CompiledQueryIntent;
|
|
433
|
+
transactionAffinity: CompiledQueryTransactionAffinity;
|
|
434
|
+
streaming: CompiledQueryStreamingMode;
|
|
435
|
+
connectionName?: string;
|
|
436
|
+
scope?: TransactionScopeKind;
|
|
437
|
+
schedulingMode?: SchedulingMode;
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
interface CompiledStatement {
|
|
441
|
+
unsafe?: true;
|
|
442
|
+
sql: string;
|
|
443
|
+
bindings?: readonly unknown[];
|
|
444
|
+
source?: string;
|
|
445
|
+
metadata?: CompiledStatementMetadata;
|
|
446
|
+
}
|
|
447
|
+
interface DriverQueryResult<TRow extends Record<string, unknown> = Record<string, unknown>> {
|
|
448
|
+
rows: TRow[];
|
|
449
|
+
rowCount: number;
|
|
450
|
+
}
|
|
451
|
+
interface DriverExecutionResult {
|
|
452
|
+
affectedRows?: number;
|
|
453
|
+
lastInsertId?: number | string;
|
|
454
|
+
}
|
|
455
|
+
interface DriverAdapter {
|
|
456
|
+
initialize(): Promise<void>;
|
|
457
|
+
disconnect(): Promise<void>;
|
|
458
|
+
isConnected(): boolean;
|
|
459
|
+
runWithTransactionScope?<T>(callback: () => Promise<T>): Promise<T>;
|
|
460
|
+
introspect?<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[], options?: DatabaseOperationOptions): Promise<DriverQueryResult<TRow>>;
|
|
461
|
+
query<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[], options?: DatabaseOperationOptions): Promise<DriverQueryResult<TRow>>;
|
|
462
|
+
execute(sql: string, bindings?: readonly unknown[], options?: DatabaseOperationOptions): Promise<DriverExecutionResult>;
|
|
463
|
+
beginTransaction(options?: DatabaseOperationOptions): Promise<void>;
|
|
464
|
+
commit(options?: DatabaseOperationOptions): Promise<void>;
|
|
465
|
+
rollback(options?: DatabaseOperationOptions): Promise<void>;
|
|
466
|
+
createSavepoint?(name: string, options?: DatabaseOperationOptions): Promise<void>;
|
|
467
|
+
rollbackToSavepoint?(name: string, options?: DatabaseOperationOptions): Promise<void>;
|
|
468
|
+
releaseSavepoint?(name: string, options?: DatabaseOperationOptions): Promise<void>;
|
|
469
|
+
}
|
|
470
|
+
interface Dialect {
|
|
471
|
+
readonly name: string;
|
|
472
|
+
readonly capabilities: DatabaseCapabilities;
|
|
473
|
+
quoteIdentifier(identifier: string): string;
|
|
474
|
+
createPlaceholder(index: number): string;
|
|
475
|
+
}
|
|
476
|
+
interface QueryStartLog {
|
|
477
|
+
kind: 'query' | 'execute';
|
|
478
|
+
connectionName: string;
|
|
479
|
+
sql: string;
|
|
480
|
+
bindings: unknown[];
|
|
481
|
+
source?: string;
|
|
482
|
+
scope: TransactionScopeKind;
|
|
483
|
+
schedulingMode?: 'concurrent' | 'serialized' | 'worker';
|
|
484
|
+
}
|
|
485
|
+
interface QuerySuccessLog extends QueryStartLog {
|
|
486
|
+
durationMs: number;
|
|
487
|
+
rowCount?: number;
|
|
488
|
+
affectedRows?: number;
|
|
489
|
+
}
|
|
490
|
+
interface QueryErrorLog extends QueryStartLog {
|
|
491
|
+
durationMs: number;
|
|
492
|
+
error: unknown;
|
|
493
|
+
}
|
|
494
|
+
interface TransactionLog {
|
|
495
|
+
scope: Exclude<TransactionScopeKind, 'root'>;
|
|
496
|
+
depth: number;
|
|
497
|
+
savepointName?: string;
|
|
498
|
+
}
|
|
499
|
+
interface MigrationStartLog {
|
|
500
|
+
connectionName: string;
|
|
501
|
+
migrationName: string;
|
|
502
|
+
action: 'up' | 'down';
|
|
503
|
+
batch?: number;
|
|
504
|
+
}
|
|
505
|
+
interface MigrationSuccessLog extends MigrationStartLog {
|
|
506
|
+
durationMs: number;
|
|
507
|
+
}
|
|
508
|
+
interface MigrationErrorLog extends MigrationStartLog {
|
|
509
|
+
durationMs: number;
|
|
510
|
+
error: unknown;
|
|
511
|
+
}
|
|
512
|
+
interface SeederStartLog {
|
|
513
|
+
connectionName: string;
|
|
514
|
+
seederName: string;
|
|
515
|
+
quietly: boolean;
|
|
516
|
+
environment?: string;
|
|
517
|
+
}
|
|
518
|
+
interface SeederSuccessLog extends SeederStartLog {
|
|
519
|
+
durationMs: number;
|
|
520
|
+
}
|
|
521
|
+
interface SeederErrorLog extends SeederStartLog {
|
|
522
|
+
durationMs: number;
|
|
523
|
+
error: unknown;
|
|
524
|
+
}
|
|
525
|
+
interface DatabaseLogger {
|
|
526
|
+
onQueryStart?(entry: QueryStartLog): void | Promise<void>;
|
|
527
|
+
onQuerySuccess?(entry: QuerySuccessLog): void | Promise<void>;
|
|
528
|
+
onQueryError?(entry: QueryErrorLog): void | Promise<void>;
|
|
529
|
+
onTransactionStart?(entry: TransactionLog): void | Promise<void>;
|
|
530
|
+
onTransactionCommit?(entry: TransactionLog): void | Promise<void>;
|
|
531
|
+
onTransactionRollback?(entry: TransactionLog & {
|
|
532
|
+
error?: unknown;
|
|
533
|
+
}): void | Promise<void>;
|
|
534
|
+
onMigrationStart?(entry: MigrationStartLog): void | Promise<void>;
|
|
535
|
+
onMigrationSuccess?(entry: MigrationSuccessLog): void | Promise<void>;
|
|
536
|
+
onMigrationError?(entry: MigrationErrorLog): void | Promise<void>;
|
|
537
|
+
onSeederStart?(entry: SeederStartLog): void | Promise<void>;
|
|
538
|
+
onSeederSuccess?(entry: SeederSuccessLog): void | Promise<void>;
|
|
539
|
+
onSeederError?(entry: SeederErrorLog): void | Promise<void>;
|
|
540
|
+
}
|
|
541
|
+
interface DatabaseContextOptions {
|
|
542
|
+
connectionName?: string;
|
|
543
|
+
schemaName?: string;
|
|
544
|
+
adapter: DriverAdapter;
|
|
545
|
+
dialect: Dialect;
|
|
546
|
+
driver?: DatabaseDriverName;
|
|
547
|
+
logger?: DatabaseLogger;
|
|
548
|
+
security?: Partial<SecurityPolicy>;
|
|
549
|
+
concurrency?: ConcurrencyOptions;
|
|
550
|
+
schemaRegistry?: SchemaRegistry;
|
|
551
|
+
modelRegistry?: ModelRegistry;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
interface PaginationMeta {
|
|
555
|
+
readonly total: number;
|
|
556
|
+
readonly perPage: number;
|
|
557
|
+
readonly pageName: string;
|
|
558
|
+
readonly currentPage: number;
|
|
559
|
+
readonly lastPage: number;
|
|
560
|
+
readonly from: number | null;
|
|
561
|
+
readonly to: number | null;
|
|
562
|
+
readonly hasMorePages: boolean;
|
|
563
|
+
}
|
|
564
|
+
interface PaginatorMethods<T> {
|
|
565
|
+
items(): readonly T[];
|
|
566
|
+
firstItem(): number | null;
|
|
567
|
+
lastItem(): number | null;
|
|
568
|
+
hasPages(): boolean;
|
|
569
|
+
hasMorePages(): boolean;
|
|
570
|
+
getPageName(): string;
|
|
571
|
+
toJSON(): {
|
|
572
|
+
data: readonly T[];
|
|
573
|
+
meta: PaginationMeta;
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
interface SimplePaginationMeta {
|
|
577
|
+
readonly perPage: number;
|
|
578
|
+
readonly pageName: string;
|
|
579
|
+
readonly currentPage: number;
|
|
580
|
+
readonly from: number | null;
|
|
581
|
+
readonly to: number | null;
|
|
582
|
+
readonly hasMorePages: boolean;
|
|
583
|
+
}
|
|
584
|
+
interface SimplePaginatorMethods<T> {
|
|
585
|
+
items(): readonly T[];
|
|
586
|
+
firstItem(): number | null;
|
|
587
|
+
lastItem(): number | null;
|
|
588
|
+
hasPages(): boolean;
|
|
589
|
+
hasMorePages(): boolean;
|
|
590
|
+
getPageName(): string;
|
|
591
|
+
toJSON(): {
|
|
592
|
+
data: readonly T[];
|
|
593
|
+
meta: SimplePaginationMeta;
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
interface PaginatedResult<T> extends PaginatorMethods<T> {
|
|
597
|
+
readonly data: readonly T[];
|
|
598
|
+
readonly meta: PaginationMeta;
|
|
599
|
+
}
|
|
600
|
+
interface SimplePaginatedResult<T> extends SimplePaginatorMethods<T> {
|
|
601
|
+
readonly data: readonly T[];
|
|
602
|
+
readonly meta: SimplePaginationMeta;
|
|
603
|
+
}
|
|
604
|
+
interface CursorPaginatorMethods<T> {
|
|
605
|
+
items(): readonly T[];
|
|
606
|
+
hasMorePages(): boolean;
|
|
607
|
+
getCursorName(): string;
|
|
608
|
+
nextCursorToken(): string | null;
|
|
609
|
+
previousCursorToken(): string | null;
|
|
610
|
+
toJSON(): {
|
|
611
|
+
data: readonly T[];
|
|
612
|
+
perPage: number;
|
|
613
|
+
cursorName: string;
|
|
614
|
+
nextCursor: string | null;
|
|
615
|
+
prevCursor: string | null;
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
interface CursorPaginatedResult<T> extends CursorPaginatorMethods<T> {
|
|
619
|
+
readonly data: readonly T[];
|
|
620
|
+
readonly perPage: number;
|
|
621
|
+
readonly cursorName: string;
|
|
622
|
+
readonly nextCursor: string | null;
|
|
623
|
+
readonly prevCursor: string | null;
|
|
624
|
+
}
|
|
625
|
+
interface PaginationOptions {
|
|
626
|
+
readonly pageName?: string;
|
|
627
|
+
}
|
|
628
|
+
interface CursorPaginationOptions {
|
|
629
|
+
readonly cursorName?: string;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
type QueryOperator = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not in' | 'between' | 'not between' | 'like';
|
|
633
|
+
type QueryDirection = 'asc' | 'desc';
|
|
634
|
+
type QueryLockMode = 'update' | 'share';
|
|
635
|
+
type QueryJoinType = 'inner' | 'left' | 'right' | 'cross';
|
|
636
|
+
interface QuerySource {
|
|
637
|
+
readonly kind: 'table';
|
|
638
|
+
readonly tableName: string;
|
|
639
|
+
readonly alias?: string;
|
|
640
|
+
readonly table?: TableDefinition;
|
|
641
|
+
}
|
|
642
|
+
interface QueryColumnSelection {
|
|
643
|
+
readonly kind: 'column';
|
|
644
|
+
readonly column: string;
|
|
645
|
+
readonly alias?: string;
|
|
646
|
+
}
|
|
647
|
+
interface QueryAggregateSelection {
|
|
648
|
+
readonly kind: 'aggregate';
|
|
649
|
+
readonly aggregate: 'count' | 'sum' | 'avg' | 'min' | 'max';
|
|
650
|
+
readonly column: string | '*';
|
|
651
|
+
readonly alias: string;
|
|
652
|
+
}
|
|
653
|
+
interface QueryRawSelection {
|
|
654
|
+
readonly kind: 'raw';
|
|
655
|
+
readonly sql: string;
|
|
656
|
+
readonly bindings: readonly unknown[];
|
|
657
|
+
}
|
|
658
|
+
interface QuerySubquerySelection {
|
|
659
|
+
readonly kind: 'subquery';
|
|
660
|
+
readonly query: SelectQueryPlan;
|
|
661
|
+
readonly alias: string;
|
|
662
|
+
}
|
|
663
|
+
type QuerySelection = QueryColumnSelection | QueryAggregateSelection | QueryRawSelection | QuerySubquerySelection;
|
|
664
|
+
interface QueryJoinClause {
|
|
665
|
+
readonly type: QueryJoinType;
|
|
666
|
+
readonly table?: string;
|
|
667
|
+
readonly subquery?: SelectQueryPlan;
|
|
668
|
+
readonly alias?: string;
|
|
669
|
+
readonly lateral?: boolean;
|
|
670
|
+
readonly leftColumn?: string;
|
|
671
|
+
readonly operator?: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>;
|
|
672
|
+
readonly rightColumn?: string;
|
|
673
|
+
}
|
|
674
|
+
interface QueryUnionClause {
|
|
675
|
+
readonly all: boolean;
|
|
676
|
+
readonly query: SelectQueryPlan;
|
|
677
|
+
}
|
|
678
|
+
interface QueryHavingClause {
|
|
679
|
+
readonly expression: string;
|
|
680
|
+
readonly operator: Exclude<QueryOperator, 'in' | 'not in'>;
|
|
681
|
+
readonly value: unknown;
|
|
682
|
+
}
|
|
683
|
+
interface QueryPredicate {
|
|
684
|
+
readonly kind: 'comparison';
|
|
685
|
+
readonly boolean?: 'and' | 'or';
|
|
686
|
+
readonly column: string;
|
|
687
|
+
readonly operator: QueryOperator;
|
|
688
|
+
readonly value: unknown;
|
|
689
|
+
}
|
|
690
|
+
interface QueryColumnPredicate {
|
|
691
|
+
readonly kind: 'column';
|
|
692
|
+
readonly boolean?: 'and' | 'or';
|
|
693
|
+
readonly column: string;
|
|
694
|
+
readonly operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>;
|
|
695
|
+
readonly compareTo: string;
|
|
696
|
+
}
|
|
697
|
+
interface QueryNullPredicate {
|
|
698
|
+
readonly kind: 'null';
|
|
699
|
+
readonly boolean?: 'and' | 'or';
|
|
700
|
+
readonly column: string;
|
|
701
|
+
readonly negated: boolean;
|
|
702
|
+
}
|
|
703
|
+
type QueryDatePart = 'date' | 'month' | 'day' | 'year' | 'time';
|
|
704
|
+
interface QueryDatePredicate {
|
|
705
|
+
readonly kind: 'date';
|
|
706
|
+
readonly boolean?: 'and' | 'or';
|
|
707
|
+
readonly column: string;
|
|
708
|
+
readonly part: QueryDatePart;
|
|
709
|
+
readonly operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>;
|
|
710
|
+
readonly value: unknown;
|
|
711
|
+
}
|
|
712
|
+
type QueryJsonMode = 'value' | 'contains' | 'length';
|
|
713
|
+
type QueryFullTextMode = 'natural' | 'boolean';
|
|
714
|
+
interface QueryJsonPredicate {
|
|
715
|
+
readonly kind: 'json';
|
|
716
|
+
readonly boolean?: 'and' | 'or';
|
|
717
|
+
readonly column: string;
|
|
718
|
+
readonly path: readonly string[];
|
|
719
|
+
readonly jsonMode: QueryJsonMode;
|
|
720
|
+
readonly operator?: Exclude<QueryOperator, 'in' | 'not in'>;
|
|
721
|
+
readonly value: unknown;
|
|
722
|
+
}
|
|
723
|
+
interface QueryFullTextPredicate {
|
|
724
|
+
readonly kind: 'fulltext';
|
|
725
|
+
readonly boolean?: 'and' | 'or';
|
|
726
|
+
readonly columns: readonly string[];
|
|
727
|
+
readonly mode: QueryFullTextMode;
|
|
728
|
+
readonly value: string;
|
|
729
|
+
}
|
|
730
|
+
interface QueryVectorPredicate {
|
|
731
|
+
readonly kind: 'vector';
|
|
732
|
+
readonly boolean?: 'and' | 'or';
|
|
733
|
+
readonly column: string;
|
|
734
|
+
readonly vector: readonly number[];
|
|
735
|
+
readonly minSimilarity: number;
|
|
736
|
+
}
|
|
737
|
+
interface QueryGroupPredicate {
|
|
738
|
+
readonly kind: 'group';
|
|
739
|
+
readonly boolean?: 'and' | 'or';
|
|
740
|
+
readonly negated?: boolean;
|
|
741
|
+
readonly predicates: readonly QueryPredicateNode[];
|
|
742
|
+
}
|
|
743
|
+
interface QueryExistsPredicate {
|
|
744
|
+
readonly kind: 'exists';
|
|
745
|
+
readonly boolean?: 'and' | 'or';
|
|
746
|
+
readonly negated?: boolean;
|
|
747
|
+
readonly subquery: SelectQueryPlan;
|
|
748
|
+
}
|
|
749
|
+
interface QuerySubqueryPredicate {
|
|
750
|
+
readonly kind: 'subquery';
|
|
751
|
+
readonly boolean?: 'and' | 'or';
|
|
752
|
+
readonly column: string;
|
|
753
|
+
readonly operator: Exclude<QueryOperator, 'between' | 'not between'>;
|
|
754
|
+
readonly subquery: SelectQueryPlan;
|
|
755
|
+
}
|
|
756
|
+
interface QueryRawPredicate {
|
|
757
|
+
readonly kind: 'raw';
|
|
758
|
+
readonly boolean?: 'and' | 'or';
|
|
759
|
+
readonly sql: string;
|
|
760
|
+
readonly bindings: readonly unknown[];
|
|
761
|
+
}
|
|
762
|
+
type QueryPredicateNode = QueryPredicate | QueryColumnPredicate | QueryNullPredicate | QueryDatePredicate | QueryJsonPredicate | QueryFullTextPredicate | QueryVectorPredicate | QueryGroupPredicate | QueryExistsPredicate | QuerySubqueryPredicate | QueryRawPredicate;
|
|
763
|
+
type QueryOrderBy = {
|
|
764
|
+
readonly kind: 'column';
|
|
765
|
+
readonly column: string;
|
|
766
|
+
readonly direction: QueryDirection;
|
|
767
|
+
} | {
|
|
768
|
+
readonly kind: 'vector';
|
|
769
|
+
readonly column: string;
|
|
770
|
+
readonly vector: readonly number[];
|
|
771
|
+
} | {
|
|
772
|
+
readonly kind: 'random';
|
|
773
|
+
} | {
|
|
774
|
+
readonly kind: 'raw';
|
|
775
|
+
readonly sql: string;
|
|
776
|
+
readonly bindings: readonly unknown[];
|
|
777
|
+
};
|
|
778
|
+
interface SelectQueryPlan {
|
|
779
|
+
readonly kind: 'select';
|
|
780
|
+
readonly source: QuerySource;
|
|
781
|
+
readonly distinct: boolean;
|
|
782
|
+
readonly selections: readonly QuerySelection[];
|
|
783
|
+
readonly joins: readonly QueryJoinClause[];
|
|
784
|
+
readonly unions: readonly QueryUnionClause[];
|
|
785
|
+
readonly predicates: readonly QueryPredicateNode[];
|
|
786
|
+
readonly groupBy: readonly string[];
|
|
787
|
+
readonly having: readonly QueryHavingClause[];
|
|
788
|
+
readonly orderBy: readonly QueryOrderBy[];
|
|
789
|
+
readonly lockMode?: QueryLockMode;
|
|
790
|
+
readonly limit?: number;
|
|
791
|
+
readonly offset?: number;
|
|
792
|
+
}
|
|
793
|
+
interface InsertQueryPlan {
|
|
794
|
+
readonly kind: 'insert';
|
|
795
|
+
readonly source: QuerySource;
|
|
796
|
+
readonly ignoreConflicts: boolean;
|
|
797
|
+
readonly values: readonly Record<string, unknown>[];
|
|
798
|
+
}
|
|
799
|
+
interface UpsertQueryPlan {
|
|
800
|
+
readonly kind: 'upsert';
|
|
801
|
+
readonly source: QuerySource;
|
|
802
|
+
readonly values: readonly Record<string, unknown>[];
|
|
803
|
+
readonly uniqueBy: readonly string[];
|
|
804
|
+
readonly updateColumns: readonly string[];
|
|
805
|
+
}
|
|
806
|
+
interface UpdateQueryPlan {
|
|
807
|
+
readonly kind: 'update';
|
|
808
|
+
readonly source: QuerySource;
|
|
809
|
+
readonly predicates: readonly QueryPredicateNode[];
|
|
810
|
+
readonly values: Readonly<Record<string, QueryUpdateValue>>;
|
|
811
|
+
}
|
|
812
|
+
interface DeleteQueryPlan {
|
|
813
|
+
readonly kind: 'delete';
|
|
814
|
+
readonly source: QuerySource;
|
|
815
|
+
readonly predicates: readonly QueryPredicateNode[];
|
|
816
|
+
}
|
|
817
|
+
type QueryPlan = SelectQueryPlan | InsertQueryPlan | UpsertQueryPlan | UpdateQueryPlan | DeleteQueryPlan;
|
|
818
|
+
interface QueryJsonUpdateOperation {
|
|
819
|
+
readonly kind: 'json-set';
|
|
820
|
+
readonly path: readonly string[];
|
|
821
|
+
readonly value: unknown;
|
|
822
|
+
}
|
|
823
|
+
type QueryUpdateValue = unknown | QueryJsonUpdateOperation | readonly QueryJsonUpdateOperation[];
|
|
824
|
+
declare function createTableSource(table: string | TableDefinition): QuerySource;
|
|
825
|
+
declare function createSelectQueryPlan(source: QuerySource): SelectQueryPlan;
|
|
826
|
+
declare function withSelections(plan: SelectQueryPlan, columns: readonly string[]): SelectQueryPlan;
|
|
827
|
+
declare function withPredicate(plan: SelectQueryPlan, predicate: QueryPredicateNode): SelectQueryPlan;
|
|
828
|
+
declare function withOrderBy(plan: SelectQueryPlan, orderBy: QueryOrderBy): SelectQueryPlan;
|
|
829
|
+
declare function withLimit(plan: SelectQueryPlan, limit?: number): SelectQueryPlan;
|
|
830
|
+
declare function withOffset(plan: SelectQueryPlan, offset?: number): SelectQueryPlan;
|
|
831
|
+
declare function createInsertQueryPlan(source: QuerySource, values: readonly Record<string, unknown>[], options?: {
|
|
832
|
+
ignoreConflicts?: boolean;
|
|
833
|
+
}): InsertQueryPlan;
|
|
834
|
+
declare function createUpdateQueryPlan(source: QuerySource, predicates: readonly QueryPredicateNode[], values: Readonly<Record<string, unknown>>): UpdateQueryPlan;
|
|
835
|
+
declare function createDeleteQueryPlan(source: QuerySource, predicates: readonly QueryPredicateNode[]): DeleteQueryPlan;
|
|
836
|
+
|
|
837
|
+
type SelectRow<TTableOrName extends string | TableDefinition> = TTableOrName extends TableDefinition ? InferSelect<TTableOrName> : Record<string, unknown>;
|
|
838
|
+
type TableReference = string | TableDefinition;
|
|
839
|
+
type BuilderCallback$2<TBuilder> = (query: TBuilder) => unknown;
|
|
840
|
+
type ValueBuilderCallback$2<TBuilder, TValue> = (query: TBuilder, value: TValue) => unknown;
|
|
841
|
+
type SelectedColumnNames<TRow extends Record<string, unknown>> = Extract<keyof TRow, string>;
|
|
842
|
+
type ExactDeclaredColumnName<TTableOrName extends TableReference> = TTableOrName extends TableDefinition ? Extract<keyof SelectRow<TTableOrName>, string> : string;
|
|
843
|
+
type DeclaredColumnName<TTableOrName extends TableReference> = TTableOrName extends TableDefinition ? ExactDeclaredColumnName<TTableOrName> | `${string}.${ExactDeclaredColumnName<TTableOrName>}` : string;
|
|
844
|
+
type AliasedColumnSelection<TTableOrName extends TableReference> = TTableOrName extends TableDefinition ? `${DeclaredColumnName<TTableOrName>} as ${string}` : string;
|
|
845
|
+
type ColumnReference$1<TTableOrName extends TableReference> = TTableOrName extends TableDefinition ? DeclaredColumnName<TTableOrName> | `${string}.${string}` : string;
|
|
846
|
+
type JsonColumnPath<TTableOrName extends TableReference> = TTableOrName extends TableDefinition ? DeclaredColumnName<TTableOrName> | `${DeclaredColumnName<TTableOrName>}->${string}` : string;
|
|
847
|
+
type SelectionResult<TTableOrName extends TableReference, TCurrentRow extends Record<string, unknown>, TColumns extends readonly SelectedColumnNames<SelectRow<TTableOrName>>[]> = TColumns extends readonly [] ? TCurrentRow : Pick<SelectRow<TTableOrName>, TColumns[number]>;
|
|
848
|
+
type MergeSelections<TTableOrName extends TableReference, TCurrentRow extends Record<string, unknown>, TColumns extends readonly SelectedColumnNames<SelectRow<TTableOrName>>[]> = TCurrentRow & Pick<SelectRow<TTableOrName>, TColumns[number]>;
|
|
849
|
+
type AggregateSelectionResult<TAlias extends string, TValue> = Record<TAlias, TValue>;
|
|
850
|
+
declare class TableQueryBuilder<TTableOrName extends TableReference = string, TSelectedRow extends Record<string, unknown> = SelectRow<TTableOrName>> {
|
|
851
|
+
private readonly connection;
|
|
852
|
+
private readonly source;
|
|
853
|
+
private readonly plan;
|
|
854
|
+
constructor(table: TTableOrName, connection: DatabaseContext, plan?: SelectQueryPlan);
|
|
855
|
+
getTableName(): string;
|
|
856
|
+
getConnectionName(): string;
|
|
857
|
+
getConnection(): DatabaseContext;
|
|
858
|
+
getPlan(): SelectQueryPlan;
|
|
859
|
+
from(table: string): TableQueryBuilder<string, TSelectedRow>;
|
|
860
|
+
select<const TColumns extends readonly SelectedColumnNames<SelectRow<TTableOrName>>[]>(...columns: TColumns): TableQueryBuilder<TTableOrName, SelectionResult<TTableOrName, TSelectedRow, TColumns>>;
|
|
861
|
+
select(...columns: readonly (DeclaredColumnName<TTableOrName> | AliasedColumnSelection<TTableOrName>)[]): TableQueryBuilder<TTableOrName, Record<string, unknown>>;
|
|
862
|
+
addSelect<const TColumns extends readonly SelectedColumnNames<SelectRow<TTableOrName>>[]>(...columns: TColumns): TableQueryBuilder<TTableOrName, MergeSelections<TTableOrName, TSelectedRow, TColumns>>;
|
|
863
|
+
addSelect(...columns: readonly (DeclaredColumnName<TTableOrName> | AliasedColumnSelection<TTableOrName>)[]): TableQueryBuilder<TTableOrName, Record<string, unknown>>;
|
|
864
|
+
selectCount<TAlias extends string = 'count'>(alias?: TAlias, column?: DeclaredColumnName<TTableOrName> | '*'): TableQueryBuilder<TTableOrName, AggregateSelectionResult<TAlias, number>>;
|
|
865
|
+
addSelectCount<TAlias extends string = 'count'>(alias?: TAlias, column?: DeclaredColumnName<TTableOrName> | '*'): TableQueryBuilder<TTableOrName, TSelectedRow & AggregateSelectionResult<TAlias, number>>;
|
|
866
|
+
selectSum<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, AggregateSelectionResult<TAlias, number | null>>;
|
|
867
|
+
addSelectSum<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow & AggregateSelectionResult<TAlias, number | null>>;
|
|
868
|
+
selectAvg<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, AggregateSelectionResult<TAlias, number | null>>;
|
|
869
|
+
addSelectAvg<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow & AggregateSelectionResult<TAlias, number | null>>;
|
|
870
|
+
selectMin<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, AggregateSelectionResult<TAlias, number | null>>;
|
|
871
|
+
addSelectMin<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow & AggregateSelectionResult<TAlias, number | null>>;
|
|
872
|
+
selectMax<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, AggregateSelectionResult<TAlias, number | null>>;
|
|
873
|
+
addSelectMax<TAlias extends string>(alias: TAlias, column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow & AggregateSelectionResult<TAlias, number | null>>;
|
|
874
|
+
unsafeSelect(sql: string, bindings: readonly unknown[]): TableQueryBuilder<TTableOrName, Record<string, unknown>>;
|
|
875
|
+
addUnsafeSelect(sql: string, bindings: readonly unknown[]): TableQueryBuilder<TTableOrName, Record<string, unknown>>;
|
|
876
|
+
selectSub(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>, alias: string): TableQueryBuilder<TTableOrName, Record<string, unknown>>;
|
|
877
|
+
addSelectSub(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>, alias: string): TableQueryBuilder<TTableOrName, Record<string, unknown>>;
|
|
878
|
+
distinct(): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
879
|
+
where(callback: BuilderCallback$2<TableQueryBuilder<TTableOrName, SelectRow<TTableOrName>>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
880
|
+
where(column: JsonColumnPath<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
881
|
+
orWhere(callback: BuilderCallback$2<TableQueryBuilder<TTableOrName, SelectRow<TTableOrName>>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
882
|
+
orWhere(column: JsonColumnPath<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
883
|
+
private whereGroupWithBoolean;
|
|
884
|
+
whereNot(callback: BuilderCallback$2<TableQueryBuilder<TTableOrName, SelectRow<TTableOrName>>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
885
|
+
orWhereNot(callback: BuilderCallback$2<TableQueryBuilder<TTableOrName, SelectRow<TTableOrName>>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
886
|
+
whereExists(subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
887
|
+
orWhereExists(subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
888
|
+
whereNotExists(subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
889
|
+
orWhereNotExists(subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
890
|
+
whereSub(column: DeclaredColumnName<TTableOrName>, operator: QueryOperator, subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
891
|
+
orWhereSub(column: DeclaredColumnName<TTableOrName>, operator: QueryOperator, subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
892
|
+
whereInSub(column: DeclaredColumnName<TTableOrName>, subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
893
|
+
whereNotInSub(column: DeclaredColumnName<TTableOrName>, subquery: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
894
|
+
private whereWithBoolean;
|
|
895
|
+
private whereExistsWithBoolean;
|
|
896
|
+
private whereSubWithBoolean;
|
|
897
|
+
private whereDatePart;
|
|
898
|
+
private isScalarJsonValue;
|
|
899
|
+
private createAggregateSelection;
|
|
900
|
+
private getColumnDefinition;
|
|
901
|
+
private assertJsonRootColumn;
|
|
902
|
+
private parseJsonPath;
|
|
903
|
+
private whereJsonValueWithBoolean;
|
|
904
|
+
private whereJsonContainsWithBoolean;
|
|
905
|
+
private whereJsonLengthWithBoolean;
|
|
906
|
+
whereNull(column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
907
|
+
orWhereNull(column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
908
|
+
private whereNullWithBoolean;
|
|
909
|
+
whereNotNull(column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
910
|
+
orWhereNotNull(column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
911
|
+
private whereNotNullWithBoolean;
|
|
912
|
+
whereColumn(column: ColumnReference$1<TTableOrName>, operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>, compareTo: ColumnReference$1<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
913
|
+
whereIn(column: DeclaredColumnName<TTableOrName>, values: readonly unknown[]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
914
|
+
whereNotIn(column: DeclaredColumnName<TTableOrName>, values: readonly unknown[]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
915
|
+
whereBetween(column: DeclaredColumnName<TTableOrName>, range: readonly [unknown, unknown]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
916
|
+
whereNotBetween(column: DeclaredColumnName<TTableOrName>, range: readonly [unknown, unknown]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
917
|
+
whereLike(column: DeclaredColumnName<TTableOrName>, pattern: string): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
918
|
+
orWhereLike(column: DeclaredColumnName<TTableOrName>, pattern: string): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
919
|
+
whereAny(columns: readonly DeclaredColumnName<TTableOrName>[], operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
920
|
+
whereAll(columns: readonly DeclaredColumnName<TTableOrName>[], operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
921
|
+
whereNone(columns: readonly DeclaredColumnName<TTableOrName>[], operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
922
|
+
whereDate(column: DeclaredColumnName<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
923
|
+
whereMonth(column: DeclaredColumnName<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
924
|
+
whereDay(column: DeclaredColumnName<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
925
|
+
whereYear(column: DeclaredColumnName<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
926
|
+
whereTime(column: DeclaredColumnName<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
927
|
+
whereJson(columnPath: JsonColumnPath<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
928
|
+
orWhereJson(columnPath: JsonColumnPath<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
929
|
+
whereJsonContains(columnPath: JsonColumnPath<TTableOrName>, value: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
930
|
+
orWhereJsonContains(columnPath: JsonColumnPath<TTableOrName>, value: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
931
|
+
whereJsonLength(columnPath: JsonColumnPath<TTableOrName>, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
932
|
+
groupBy(...columns: readonly DeclaredColumnName<TTableOrName>[]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
933
|
+
join(table: string, leftColumn: ColumnReference$1<TTableOrName>, operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>, rightColumn: ColumnReference$1<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
934
|
+
leftJoin(table: string, leftColumn: ColumnReference$1<TTableOrName>, operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>, rightColumn: ColumnReference$1<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
935
|
+
rightJoin(table: string, leftColumn: ColumnReference$1<TTableOrName>, operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>, rightColumn: ColumnReference$1<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
936
|
+
joinSub(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>, alias: string, leftColumn: ColumnReference$1<TTableOrName>, operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>, rightColumn: ColumnReference$1<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
937
|
+
leftJoinSub(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>, alias: string, leftColumn: ColumnReference$1<TTableOrName>, operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>, rightColumn: ColumnReference$1<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
938
|
+
rightJoinSub(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>, alias: string, leftColumn: ColumnReference$1<TTableOrName>, operator: Exclude<QueryOperator, 'in' | 'not in' | 'between' | 'not between'>, rightColumn: ColumnReference$1<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
939
|
+
joinLateral(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>, alias: string): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
940
|
+
leftJoinLateral(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>, alias: string): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
941
|
+
crossJoin(table: string): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
942
|
+
union(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
943
|
+
unionAll(query: TableQueryBuilder<TableDefinition, Record<string, unknown>>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
944
|
+
having(expression: string, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
945
|
+
havingBetween(expression: string, range: readonly [unknown, unknown]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
946
|
+
orWhereJsonLength(columnPath: string, operator: QueryOperator | unknown, value?: unknown): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
947
|
+
unsafeWhere(sql: string, bindings: readonly unknown[]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
948
|
+
orUnsafeWhere(sql: string, bindings: readonly unknown[]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
949
|
+
whereFullText(columns: DeclaredColumnName<TTableOrName> | readonly DeclaredColumnName<TTableOrName>[], value: string, options?: {
|
|
950
|
+
mode?: 'natural' | 'boolean';
|
|
951
|
+
}): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
952
|
+
orWhereFullText(columns: DeclaredColumnName<TTableOrName> | readonly DeclaredColumnName<TTableOrName>[], value: string, options?: {
|
|
953
|
+
mode?: 'natural' | 'boolean';
|
|
954
|
+
}): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
955
|
+
whereVectorSimilarTo(column: DeclaredColumnName<TTableOrName>, vector: readonly number[], minSimilarity?: number): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
956
|
+
orWhereVectorSimilarTo(column: DeclaredColumnName<TTableOrName>, vector: readonly number[], minSimilarity?: number): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
957
|
+
when<TValue>(value: TValue, callback: ValueBuilderCallback$2<TableQueryBuilder<TTableOrName, TSelectedRow>, TValue>, defaultCallback?: ValueBuilderCallback$2<TableQueryBuilder<TTableOrName, TSelectedRow>, TValue>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
958
|
+
unless<TValue>(value: TValue, callback: ValueBuilderCallback$2<TableQueryBuilder<TTableOrName, TSelectedRow>, TValue>, defaultCallback?: ValueBuilderCallback$2<TableQueryBuilder<TTableOrName, TSelectedRow>, TValue>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
959
|
+
withoutWhereNull(column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
960
|
+
withoutWhereNotNull(column: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
961
|
+
orderBy(column: DeclaredColumnName<TTableOrName>, direction?: QueryDirection): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
962
|
+
unsafeOrderBy(sql: string, bindings: readonly unknown[]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
963
|
+
inRandomOrder(): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
964
|
+
latest(column?: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
965
|
+
oldest(column?: DeclaredColumnName<TTableOrName>): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
966
|
+
reorder(column?: DeclaredColumnName<TTableOrName>, direction?: QueryDirection): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
967
|
+
orderByVectorSimilarity(column: DeclaredColumnName<TTableOrName>, vector: readonly number[]): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
968
|
+
lock(mode: 'update' | 'share'): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
969
|
+
lockForUpdate(): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
970
|
+
sharedLock(): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
971
|
+
limit(value?: number): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
972
|
+
offset(value?: number): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
973
|
+
skip(value: number): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
974
|
+
take(value: number): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
975
|
+
forPage(page: number, perPage?: number): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
976
|
+
toSQL(): CompiledStatement;
|
|
977
|
+
debug(): {
|
|
978
|
+
bindings: unknown[];
|
|
979
|
+
connectionName: string;
|
|
980
|
+
scope: TransactionScopeKind;
|
|
981
|
+
schedulingMode: "concurrent" | "serialized" | "worker";
|
|
982
|
+
metadata: {
|
|
983
|
+
debug: {
|
|
984
|
+
connectionName: string;
|
|
985
|
+
scope: TransactionScopeKind;
|
|
986
|
+
schedulingMode: "concurrent" | "serialized" | "worker";
|
|
987
|
+
tableName: string;
|
|
988
|
+
hasJoins: boolean;
|
|
989
|
+
hasUnions: boolean;
|
|
990
|
+
hasGrouping: boolean;
|
|
991
|
+
hasHaving: boolean;
|
|
992
|
+
complexity: number;
|
|
993
|
+
lockMode?: string;
|
|
994
|
+
intent: CompiledQueryIntent;
|
|
995
|
+
transactionAffinity: CompiledQueryTransactionAffinity;
|
|
996
|
+
streaming: CompiledQueryStreamingMode;
|
|
997
|
+
};
|
|
998
|
+
kind: CompiledQueryKind;
|
|
999
|
+
resultMode: CompiledQueryResultMode;
|
|
1000
|
+
selectedShape: {
|
|
1001
|
+
mode: "all" | "projection" | "write";
|
|
1002
|
+
columns: readonly string[];
|
|
1003
|
+
aggregates: readonly string[];
|
|
1004
|
+
hasRawSelections: boolean;
|
|
1005
|
+
hasSubqueries: boolean;
|
|
1006
|
+
};
|
|
1007
|
+
safety: {
|
|
1008
|
+
unsafe: boolean;
|
|
1009
|
+
containsRawSql: boolean;
|
|
1010
|
+
};
|
|
1011
|
+
} | undefined;
|
|
1012
|
+
unsafe?: true;
|
|
1013
|
+
sql: string;
|
|
1014
|
+
source?: string;
|
|
1015
|
+
};
|
|
1016
|
+
dump(): TableQueryBuilder<TTableOrName, TSelectedRow>;
|
|
1017
|
+
get<TRow extends Record<string, unknown> = TSelectedRow>(): Promise<TRow[]>;
|
|
1018
|
+
first<TRow extends Record<string, unknown> = TSelectedRow>(): Promise<TRow | undefined>;
|
|
1019
|
+
sole<TRow extends Record<string, unknown> = TSelectedRow>(): Promise<TRow>;
|
|
1020
|
+
paginate<TRow extends Record<string, unknown> = TSelectedRow>(perPage?: number, page?: number, options?: PaginationOptions): Promise<PaginatedResult<TRow>>;
|
|
1021
|
+
simplePaginate<TRow extends Record<string, unknown> = TSelectedRow>(perPage?: number, page?: number, options?: PaginationOptions): Promise<SimplePaginatedResult<TRow>>;
|
|
1022
|
+
cursorPaginate<TRow extends Record<string, unknown> = TSelectedRow>(perPage?: number, cursor?: string | null, options?: CursorPaginationOptions): Promise<CursorPaginatedResult<TRow>>;
|
|
1023
|
+
chunk<TRow extends Record<string, unknown> = TSelectedRow>(size: number, callback: (rows: readonly TRow[], page: number) => unknown | Promise<unknown>): Promise<void>;
|
|
1024
|
+
chunkById<TRow extends Record<string, unknown> = TSelectedRow>(size: number, callback: (rows: readonly TRow[], page: number) => unknown | Promise<unknown>, column?: string): Promise<void>;
|
|
1025
|
+
chunkByIdDesc<TRow extends Record<string, unknown> = TSelectedRow>(size: number, callback: (rows: readonly TRow[], page: number) => unknown | Promise<unknown>, column?: string): Promise<void>;
|
|
1026
|
+
lazy<TRow extends Record<string, unknown> = TSelectedRow>(size?: number): AsyncGenerator<TRow, void, unknown>;
|
|
1027
|
+
cursor<TRow extends Record<string, unknown> = TSelectedRow>(): AsyncGenerator<TRow, void, unknown>;
|
|
1028
|
+
count(): Promise<number>;
|
|
1029
|
+
exists(): Promise<boolean>;
|
|
1030
|
+
doesntExist(): Promise<boolean>;
|
|
1031
|
+
pluck<TKey extends SelectedColumnNames<TSelectedRow>>(column: TKey): Promise<Array<TSelectedRow[TKey]>>;
|
|
1032
|
+
value<TKey extends SelectedColumnNames<TSelectedRow>>(column: TKey): Promise<TSelectedRow[TKey] | undefined>;
|
|
1033
|
+
valueOrFail<TKey extends SelectedColumnNames<TSelectedRow>>(column: TKey): Promise<TSelectedRow[TKey]>;
|
|
1034
|
+
soleValue<TKey extends SelectedColumnNames<TSelectedRow>>(column: TKey): Promise<TSelectedRow[TKey]>;
|
|
1035
|
+
sum(column: string): Promise<number>;
|
|
1036
|
+
avg(column: string): Promise<number | null>;
|
|
1037
|
+
min(column: string): Promise<number | null>;
|
|
1038
|
+
max(column: string): Promise<number | null>;
|
|
1039
|
+
find<TRow extends Record<string, unknown> = TSelectedRow>(value: unknown, column?: string): Promise<TRow | undefined>;
|
|
1040
|
+
insert(values: Readonly<Record<string, unknown>> | readonly Readonly<Record<string, unknown>>[]): Promise<DriverExecutionResult>;
|
|
1041
|
+
insertOrIgnore(values: Readonly<Record<string, unknown>> | readonly Readonly<Record<string, unknown>>[]): Promise<DriverExecutionResult>;
|
|
1042
|
+
insertGetId(values: Readonly<Record<string, unknown>>): Promise<number | string | undefined>;
|
|
1043
|
+
upsert(values: Readonly<Record<string, unknown>> | readonly Readonly<Record<string, unknown>>[], uniqueBy: readonly string[], updateColumns?: readonly string[]): Promise<DriverExecutionResult>;
|
|
1044
|
+
increment(column: string, amount?: number, extraValues?: Readonly<Record<string, unknown>>): Promise<DriverExecutionResult>;
|
|
1045
|
+
decrement(column: string, amount?: number, extraValues?: Readonly<Record<string, unknown>>): Promise<DriverExecutionResult>;
|
|
1046
|
+
update(values: Readonly<Record<string, unknown>>): Promise<DriverExecutionResult>;
|
|
1047
|
+
updateJson(columnPath: string, value: unknown): Promise<DriverExecutionResult>;
|
|
1048
|
+
delete(): Promise<DriverExecutionResult>;
|
|
1049
|
+
unsafeQuery<TRow extends Record<string, unknown> = Record<string, unknown>>(statement: Omit<UnsafeStatement, 'source'>): Promise<DriverQueryResult<TRow>>;
|
|
1050
|
+
unsafeExecute(statement: Omit<UnsafeStatement, 'source'>): Promise<DriverExecutionResult>;
|
|
1051
|
+
private clone;
|
|
1052
|
+
private getCompiler;
|
|
1053
|
+
private getUnpaginatedRows;
|
|
1054
|
+
private resolvePrimaryKeyColumn;
|
|
1055
|
+
private normalizeOperatorValue;
|
|
1056
|
+
private adjustNumericColumn;
|
|
1057
|
+
private whereMultiColumns;
|
|
1058
|
+
private whereFullTextWithBoolean;
|
|
1059
|
+
private whereVectorSimilarToWithBoolean;
|
|
1060
|
+
private assertPositiveInteger;
|
|
1061
|
+
private normalizePaginationParameterName;
|
|
1062
|
+
private prepareCursorPaginationQuery;
|
|
1063
|
+
private encodeCursor;
|
|
1064
|
+
private decodeCursor;
|
|
1065
|
+
private aggregateNumeric;
|
|
1066
|
+
private extractNumericValues;
|
|
1067
|
+
private normalizeUpdateValues;
|
|
1068
|
+
private normalizeWriteRecord;
|
|
1069
|
+
private normalizeWriteValueForColumn;
|
|
1070
|
+
private normalizePredicateValueForColumn;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
type CollectionLoadedItem<TItem, TTable extends TableDefinition, TRelations extends RelationMap, TPaths extends readonly ModelRelationPath<TRelations>[]> = TItem & ResolveEagerLoads<TRelations, TPaths> & (TItem extends {
|
|
1074
|
+
toJSON(): infer TSerialized;
|
|
1075
|
+
} ? {
|
|
1076
|
+
toJSON(): TSerialized & SerializeLoaded<ResolveEagerLoads<TRelations, TPaths>>;
|
|
1077
|
+
} : {
|
|
1078
|
+
toJSON(): ModelRecord<TTable> & SerializeLoaded<ResolveEagerLoads<TRelations, TPaths>>;
|
|
1079
|
+
});
|
|
1080
|
+
type CollectionItem<TCollection, TTable extends TableDefinition, TRelations extends RelationMap> = TCollection extends readonly (infer TItem)[] ? TItem : Entity<TTable, TRelations>;
|
|
1081
|
+
interface ModelCollectionMethods<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap> {
|
|
1082
|
+
modelKeys(): unknown[];
|
|
1083
|
+
toQuery(): ModelQueryBuilder<TTable, TRelations>;
|
|
1084
|
+
load<TPaths extends readonly ModelRelationPath<TRelations>[]>(...relations: TPaths): Promise<this & Array<CollectionLoadedItem<CollectionItem<this, TTable, TRelations>, TTable, TRelations, TPaths>>>;
|
|
1085
|
+
loadMissing<TPaths extends readonly ModelRelationPath<TRelations>[]>(...relations: TPaths): Promise<this & Array<CollectionLoadedItem<CollectionItem<this, TTable, TRelations>, TTable, TRelations, TPaths>>>;
|
|
1086
|
+
loadMorph(relation: ModelRelationName<TRelations>, mapping: ModelMorphLoadMap): Promise<ModelCollection<TTable, TRelations>>;
|
|
1087
|
+
loadCount(...relations: readonly ModelRelationName<TRelations>[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
1088
|
+
loadExists(...relations: readonly ModelRelationName<TRelations>[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
1089
|
+
loadSum<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<ModelCollection<TTable, TRelations>>;
|
|
1090
|
+
loadAvg<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<ModelCollection<TTable, TRelations>>;
|
|
1091
|
+
loadMin<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<ModelCollection<TTable, TRelations>>;
|
|
1092
|
+
loadMax<TRelationName extends ModelRelationName<TRelations>>(relation: TRelationName, column: RelatedColumnNameOfRelation<TRelations[TRelationName]>): Promise<ModelCollection<TTable, TRelations>>;
|
|
1093
|
+
fresh(): Promise<ModelCollection<TTable, TRelations>>;
|
|
1094
|
+
append(...keys: readonly string[]): ModelCollection<TTable, TRelations>;
|
|
1095
|
+
withoutAppends(): ModelCollection<TTable, TRelations>;
|
|
1096
|
+
makeVisible(...keys: readonly string[]): ModelCollection<TTable, TRelations>;
|
|
1097
|
+
makeHidden(...keys: readonly string[]): ModelCollection<TTable, TRelations>;
|
|
1098
|
+
setVisible(keys: readonly string[]): ModelCollection<TTable, TRelations>;
|
|
1099
|
+
setHidden(keys: readonly string[]): ModelCollection<TTable, TRelations>;
|
|
1100
|
+
}
|
|
1101
|
+
type ModelCollection<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap> = Array<Entity<TTable, TRelations>> & ModelCollectionMethods<TTable, TRelations>;
|
|
1102
|
+
declare function createModelCollection<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap>(items: readonly Entity<TTable, TRelations>[]): ModelCollection<TTable, TRelations>;
|
|
1103
|
+
|
|
1104
|
+
type WriteMode = 'create' | 'update';
|
|
1105
|
+
type PivotAttributes = Record<string, unknown>;
|
|
1106
|
+
type PivotSyncResult = {
|
|
1107
|
+
attached: unknown[];
|
|
1108
|
+
detached: unknown[];
|
|
1109
|
+
updated: unknown[];
|
|
1110
|
+
};
|
|
1111
|
+
type PivotToggleResult = {
|
|
1112
|
+
attached: unknown[];
|
|
1113
|
+
detached: unknown[];
|
|
1114
|
+
};
|
|
1115
|
+
type RelationConstraint$1 = (query: ModelQueryBuilder<TableDefinition>) => unknown;
|
|
1116
|
+
type RelationFilter$1 = {
|
|
1117
|
+
relation: string;
|
|
1118
|
+
negate: boolean;
|
|
1119
|
+
constraint?: RelationConstraint$1;
|
|
1120
|
+
boolean?: 'and' | 'or';
|
|
1121
|
+
morphTypes?: readonly string[];
|
|
1122
|
+
};
|
|
1123
|
+
type EagerLoad$1 = {
|
|
1124
|
+
relation: string;
|
|
1125
|
+
constraint?: RelationConstraint$1;
|
|
1126
|
+
};
|
|
1127
|
+
type AggregateLoad$1 = {
|
|
1128
|
+
relation: string;
|
|
1129
|
+
kind: RelationAggregateKind;
|
|
1130
|
+
constraint?: RelationConstraint$1;
|
|
1131
|
+
column?: string;
|
|
1132
|
+
alias?: string;
|
|
1133
|
+
};
|
|
1134
|
+
declare function getModelDefinition<TTable extends TableDefinition>(reference: ModelDefinitionLike | ModelDefinition<TTable> | ModelReference<TTable>): ModelDefinition<TTable>;
|
|
1135
|
+
declare class ModelRepository<TTable extends TableDefinition = TableDefinition> {
|
|
1136
|
+
private readonly connection;
|
|
1137
|
+
readonly definition: ModelDefinition<TTable>;
|
|
1138
|
+
constructor(definition: ModelDefinition<TTable>, connection: DatabaseContext);
|
|
1139
|
+
static from<TTable extends TableDefinition>(reference: ModelDefinitionLike | ModelDefinition<TTable> | ModelReference<TTable>, connection?: DatabaseContext): ModelRepository<TTable>;
|
|
1140
|
+
getConnection(): DatabaseContext;
|
|
1141
|
+
getConnectionName(): string;
|
|
1142
|
+
getDeletedAtColumn(): string | undefined;
|
|
1143
|
+
getRelationNames(): readonly string[];
|
|
1144
|
+
getRelationDefinition(name: string): RelationDefinition;
|
|
1145
|
+
createCollection(items: readonly Entity<TTable>[]): ModelCollection<TTable>;
|
|
1146
|
+
query(): ModelQueryBuilder<TTable>;
|
|
1147
|
+
newQuery(): ModelQueryBuilder<TTable>;
|
|
1148
|
+
newModelQuery(): ModelQueryBuilder<TTable>;
|
|
1149
|
+
newQueryWithoutScopes(): ModelQueryBuilder<TTable>;
|
|
1150
|
+
queryWithoutGlobalScope(name: string): ModelQueryBuilder<TTable>;
|
|
1151
|
+
queryWithoutGlobalScopes(names?: readonly string[]): ModelQueryBuilder<TTable>;
|
|
1152
|
+
newQueryWithoutRelationships(): ModelQueryBuilder<TTable>;
|
|
1153
|
+
find(value: unknown): Promise<Entity<TTable> | undefined>;
|
|
1154
|
+
findOrFail(value: unknown): Promise<Entity<TTable>>;
|
|
1155
|
+
first(): Promise<Entity<TTable> | undefined>;
|
|
1156
|
+
firstOrFail(): Promise<Entity<TTable>>;
|
|
1157
|
+
get(): Promise<ModelCollection<TTable>>;
|
|
1158
|
+
sole(): Promise<Entity<TTable>>;
|
|
1159
|
+
all(): Promise<ModelCollection<TTable>>;
|
|
1160
|
+
findMany(values: readonly unknown[]): Promise<ModelCollection<TTable>>;
|
|
1161
|
+
firstWhere(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): Promise<Entity<TTable> | undefined>;
|
|
1162
|
+
firstOrNew(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1163
|
+
firstOrCreate(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1164
|
+
make(values?: Partial<ModelRecord<TTable>>): Entity<TTable>;
|
|
1165
|
+
hydrate(values: Partial<ModelRecord<TTable>>): Entity<TTable>;
|
|
1166
|
+
retrieve(values: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1167
|
+
retrieveWithCasts(values: Partial<ModelRecord<TTable>>, casts: Record<string, ModelCastDefinition>): Promise<Entity<TTable>>;
|
|
1168
|
+
freshEntity(entity: Entity<TTable>): Promise<Entity<TTable> | undefined>;
|
|
1169
|
+
refreshEntity(entity: Entity<TTable>): Promise<Entity<TTable>>;
|
|
1170
|
+
loadRelations(entities: readonly Entity<TTable>[], relations: readonly (string | EagerLoad$1)[], missingOnly?: boolean): Promise<void>;
|
|
1171
|
+
filterByRelations(entities: readonly Entity<TTable>[], filters: readonly RelationFilter$1[]): Promise<Array<Entity<TTable>>>;
|
|
1172
|
+
applyRelationExistenceFilter(query: TableQueryBuilder<TTable, Record<string, unknown>>, filter: RelationFilter$1): TableQueryBuilder<TTable, Record<string, unknown>>;
|
|
1173
|
+
loadMorphRelations(entities: readonly Entity<TTable>[], relationName: string, mapping: Readonly<Record<string, string | readonly string[] | Readonly<Record<string, RelationConstraint$1>>>>): Promise<void>;
|
|
1174
|
+
loadRelationAggregates(entities: readonly Entity<TTable>[], aggregates: readonly AggregateLoad$1[]): Promise<void>;
|
|
1175
|
+
create(values: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1176
|
+
createQuietly(values: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1177
|
+
createMany(values: readonly Partial<ModelRecord<TTable>>[]): Promise<ModelCollection<TTable>>;
|
|
1178
|
+
createManyQuietly(values: readonly Partial<ModelRecord<TTable>>[]): Promise<ModelCollection<TTable>>;
|
|
1179
|
+
saveMany(entities: readonly Entity<TTable>[]): Promise<ModelCollection<TTable>>;
|
|
1180
|
+
saveManyQuietly(entities: readonly Entity<TTable>[]): Promise<ModelCollection<TTable>>;
|
|
1181
|
+
update(id: unknown, values: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1182
|
+
delete(id: unknown): Promise<void>;
|
|
1183
|
+
destroy(ids: readonly unknown[]): Promise<number>;
|
|
1184
|
+
prune(): Promise<number>;
|
|
1185
|
+
associateRelation(entity: Entity<TTable>, relationName: string, relatedEntity: Entity | null): Entity<TTable>;
|
|
1186
|
+
dissociateRelation(entity: Entity<TTable>, relationName: string): Entity<TTable>;
|
|
1187
|
+
saveRelatedEntity(entity: Entity<TTable>, relationName: string, relatedEntity: Entity): Promise<Entity>;
|
|
1188
|
+
saveRelatedEntityQuietly(entity: Entity<TTable>, relationName: string, relatedEntity: Entity): Promise<Entity>;
|
|
1189
|
+
saveManyRelatedEntities(entity: Entity<TTable>, relationName: string, relatedEntities: readonly Entity[]): Promise<Entity[]>;
|
|
1190
|
+
saveManyRelatedEntitiesQuietly(entity: Entity<TTable>, relationName: string, relatedEntities: readonly Entity[]): Promise<Entity[]>;
|
|
1191
|
+
createRelatedEntity(entity: Entity<TTable>, relationName: string, values: Record<string, unknown>): Promise<Entity>;
|
|
1192
|
+
createRelatedEntityQuietly(entity: Entity<TTable>, relationName: string, values: Record<string, unknown>): Promise<Entity>;
|
|
1193
|
+
createManyRelatedEntities(entity: Entity<TTable>, relationName: string, values: readonly Record<string, unknown>[]): Promise<ModelCollection>;
|
|
1194
|
+
createManyRelatedEntitiesQuietly(entity: Entity<TTable>, relationName: string, values: readonly Record<string, unknown>[]): Promise<ModelCollection>;
|
|
1195
|
+
private createRecord;
|
|
1196
|
+
restore(id: unknown): Promise<Entity<TTable>>;
|
|
1197
|
+
forceDelete(id: unknown): Promise<void>;
|
|
1198
|
+
upsert(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1199
|
+
updateOrCreate(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable>>;
|
|
1200
|
+
sanitizeWritePayload(values: Partial<ModelRecord<TTable>> | Record<string, unknown>, mode: WriteMode, internalColumns?: ReadonlySet<string>): Partial<ModelUpdatePayload<TTable>>;
|
|
1201
|
+
saveEntity(entity: Entity<TTable>, internalColumns?: ReadonlySet<string>): Promise<Entity<TTable>>;
|
|
1202
|
+
saveEntityQuietly(entity: Entity<TTable>, internalColumns?: ReadonlySet<string>): Promise<Entity<TTable>>;
|
|
1203
|
+
deleteEntity(entity: Entity<TTable>): Promise<void>;
|
|
1204
|
+
deleteEntityQuietly(entity: Entity<TTable>): Promise<void>;
|
|
1205
|
+
shouldKeepEntityPersistedOnDelete(): boolean;
|
|
1206
|
+
restoreEntity(entity: Entity<TTable>): Promise<Entity<TTable>>;
|
|
1207
|
+
restoreEntityQuietly(entity: Entity<TTable>): Promise<Entity<TTable>>;
|
|
1208
|
+
forceDeleteEntity(entity: Entity<TTable>): Promise<void>;
|
|
1209
|
+
private runWriteUnit;
|
|
1210
|
+
forceDeleteEntityQuietly(entity: Entity<TTable>): Promise<void>;
|
|
1211
|
+
replicateEntity(entity: Entity<TTable>, except?: readonly string[]): Entity<TTable>;
|
|
1212
|
+
attachRelation(entity: Entity<TTable>, relationName: string, ids: unknown, attributes?: PivotAttributes): Promise<void>;
|
|
1213
|
+
detachRelation(entity: Entity<TTable>, relationName: string, ids?: unknown): Promise<number>;
|
|
1214
|
+
syncRelation(entity: Entity<TTable>, relationName: string, ids: unknown, detachMissing: boolean): Promise<PivotSyncResult>;
|
|
1215
|
+
updateExistingPivot(entity: Entity<TTable>, relationName: string, id: unknown, attributes: PivotAttributes): Promise<number>;
|
|
1216
|
+
toggleRelation(entity: Entity<TTable>, relationName: string, ids: unknown): Promise<PivotToggleResult>;
|
|
1217
|
+
private loadRelation;
|
|
1218
|
+
private createQuery;
|
|
1219
|
+
private collectLoadedRelationEntities;
|
|
1220
|
+
private loadBelongsToRelation;
|
|
1221
|
+
private loadHasManyRelation;
|
|
1222
|
+
private loadHasOneRelation;
|
|
1223
|
+
private loadHasOneOfManyRelation;
|
|
1224
|
+
private loadMorphManyRelation;
|
|
1225
|
+
private loadMorphOneRelation;
|
|
1226
|
+
private loadMorphOneOfManyRelation;
|
|
1227
|
+
private loadMorphToRelation;
|
|
1228
|
+
private loadHasManyThroughRelation;
|
|
1229
|
+
private loadHasOneThroughRelation;
|
|
1230
|
+
private loadBelongsToManyRelation;
|
|
1231
|
+
private loadMorphToManyRelation;
|
|
1232
|
+
private loadMorphedByManyRelation;
|
|
1233
|
+
private resolveRelatedRepository;
|
|
1234
|
+
private resolveThroughRepository;
|
|
1235
|
+
private getMorphTypeValue;
|
|
1236
|
+
private resolveMorphRepository;
|
|
1237
|
+
private normalizeEagerLoads;
|
|
1238
|
+
private getMatchingParentKeys;
|
|
1239
|
+
private getRelationMatchCounts;
|
|
1240
|
+
private applyRelationConstraint;
|
|
1241
|
+
private buildRelationExistenceSubqueries;
|
|
1242
|
+
private resolveMorphExistenceReferences;
|
|
1243
|
+
private assertRelationExistenceSupported;
|
|
1244
|
+
private applyExistsBoolean;
|
|
1245
|
+
private applyExistsBooleanGroup;
|
|
1246
|
+
private qualifyParentColumn;
|
|
1247
|
+
private getRelationParentValue;
|
|
1248
|
+
private getAggregateAttributeKey;
|
|
1249
|
+
private getRelationAggregateValues;
|
|
1250
|
+
private computeAggregateValue;
|
|
1251
|
+
private assertNumericAggregateValue;
|
|
1252
|
+
private getRelatedEntitiesByParentKey;
|
|
1253
|
+
attachCollection(entities: readonly Entity<TTable>[]): readonly Entity<TTable>[];
|
|
1254
|
+
resolveRelationProperty(entity: Entity<TTable>, relationName: string): unknown;
|
|
1255
|
+
private getMatchingBelongsToParentKeys;
|
|
1256
|
+
private getBelongsToMatchCounts;
|
|
1257
|
+
private getBelongsToEntitiesByParentKey;
|
|
1258
|
+
private getMatchingHasManyParentKeys;
|
|
1259
|
+
private getMatchingMorphManyParentKeys;
|
|
1260
|
+
private getHasManyMatchCounts;
|
|
1261
|
+
private getMorphManyMatchCounts;
|
|
1262
|
+
private getMatchingMorphToParentKeys;
|
|
1263
|
+
private getMorphToMatchCounts;
|
|
1264
|
+
private getMatchingThroughParentKeys;
|
|
1265
|
+
private getThroughMatchCounts;
|
|
1266
|
+
private getHasManyEntitiesByParentKey;
|
|
1267
|
+
private getMorphManyEntitiesByParentKey;
|
|
1268
|
+
private getMorphToEntitiesByParentKey;
|
|
1269
|
+
private matchesMorphType;
|
|
1270
|
+
private resolveMorphLoadTargets;
|
|
1271
|
+
private normalizeMorphLoadTargets;
|
|
1272
|
+
private serializeMorphLoadTargets;
|
|
1273
|
+
private selectOneOfManyEntity;
|
|
1274
|
+
private selectMorphOneOfManyEntity;
|
|
1275
|
+
private getThroughEntitiesByParentKey;
|
|
1276
|
+
private getMatchingBelongsToManyParentKeys;
|
|
1277
|
+
private getMatchingMorphToManyParentKeys;
|
|
1278
|
+
private getMatchingMorphedByManyParentKeys;
|
|
1279
|
+
private getBelongsToManyMatchCounts;
|
|
1280
|
+
private getMorphToManyMatchCounts;
|
|
1281
|
+
private getMorphedByManyMatchCounts;
|
|
1282
|
+
private getBelongsToManyEntitiesByParentKey;
|
|
1283
|
+
private getMorphToManyEntitiesByParentKey;
|
|
1284
|
+
private getMorphedByManyEntitiesByParentKey;
|
|
1285
|
+
private createBelongsToManyPivotQuery;
|
|
1286
|
+
private createMorphToManyPivotQuery;
|
|
1287
|
+
private createMorphedByManyPivotQuery;
|
|
1288
|
+
private applyPivotQueryConfig;
|
|
1289
|
+
private attachPivotAttributes;
|
|
1290
|
+
private extractPivotAttributes;
|
|
1291
|
+
private getDefaultPivotColumns;
|
|
1292
|
+
private getPivotMutationContext;
|
|
1293
|
+
private normalizePivotInput;
|
|
1294
|
+
private assertValidPivotEntries;
|
|
1295
|
+
private assertValidPivotAttributes;
|
|
1296
|
+
private getPivotRows;
|
|
1297
|
+
private indexPivotRows;
|
|
1298
|
+
private pivotAttributesChanged;
|
|
1299
|
+
private insertPivotRow;
|
|
1300
|
+
private updatePivotRow;
|
|
1301
|
+
private deletePivotRows;
|
|
1302
|
+
private isWritableColumn;
|
|
1303
|
+
private assertPersistedParentForRelation;
|
|
1304
|
+
private assertRelationSupportsManyWrites;
|
|
1305
|
+
private touchOwners;
|
|
1306
|
+
private resolveCompatibleRelatedRepository;
|
|
1307
|
+
private syncRelationAfterPersistence;
|
|
1308
|
+
private createPivotMutationQuery;
|
|
1309
|
+
private getPivotRelatedIdColumn;
|
|
1310
|
+
private getReservedPivotColumns;
|
|
1311
|
+
private buildPivotInsertPayload;
|
|
1312
|
+
private applyGeneratedUniqueIds;
|
|
1313
|
+
private applyPendingAttributes;
|
|
1314
|
+
private getObserverInstances;
|
|
1315
|
+
private dispatchCancelableEvent;
|
|
1316
|
+
private dispatchEvent;
|
|
1317
|
+
private dispatchSyncEvent;
|
|
1318
|
+
resolveAttribute(key: string, entity: Entity<TTable>, value: unknown): unknown;
|
|
1319
|
+
shouldPreventAccessingMissingAttributes(key: string): boolean;
|
|
1320
|
+
serializeEntity(entity: Entity<TTable>): Record<string, unknown>;
|
|
1321
|
+
private serializeRelationValue;
|
|
1322
|
+
private serializeOutputValue;
|
|
1323
|
+
serializeAttributeValue(key: string, value: unknown): unknown;
|
|
1324
|
+
private normalizeFromStorage;
|
|
1325
|
+
private applyTimestampDefaults;
|
|
1326
|
+
private normalizeForStorage;
|
|
1327
|
+
private applySchemaReadNormalization;
|
|
1328
|
+
private applySchemaWriteNormalization;
|
|
1329
|
+
private getSchemaDialectName;
|
|
1330
|
+
private applyCastGet;
|
|
1331
|
+
private applyCastSet;
|
|
1332
|
+
private resolveCastDefinition;
|
|
1333
|
+
private parseBuiltInCast;
|
|
1334
|
+
private parseVectorValue;
|
|
1335
|
+
private serializeVectorValue;
|
|
1336
|
+
private parseVectorString;
|
|
1337
|
+
private parseVectorDimensions;
|
|
1338
|
+
private formatDateCast;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
type BuilderCallback$1<TBuilder> = (query: TBuilder) => unknown;
|
|
1342
|
+
type ValueBuilderCallback$1<TBuilder, TValue> = (query: TBuilder, value: TValue) => unknown;
|
|
1343
|
+
type RelationConstraint = (query: ModelQueryBuilder<TableDefinition>) => unknown;
|
|
1344
|
+
type SubqueryBuilder$1<TSubTable extends TableDefinition = TableDefinition> = TableQueryBuilder<TSubTable, Record<string, unknown>> | ModelQueryBuilder<TSubTable>;
|
|
1345
|
+
type RelationFilter = {
|
|
1346
|
+
relation: string;
|
|
1347
|
+
negate: boolean;
|
|
1348
|
+
constraint?: RelationConstraint;
|
|
1349
|
+
boolean?: 'and' | 'or';
|
|
1350
|
+
morphTypes?: readonly string[];
|
|
1351
|
+
};
|
|
1352
|
+
type MorphEntityTarget$1 = {
|
|
1353
|
+
exists(): boolean;
|
|
1354
|
+
getRepository(): {
|
|
1355
|
+
definition: {
|
|
1356
|
+
morphClass: string;
|
|
1357
|
+
primaryKey: string;
|
|
1358
|
+
};
|
|
1359
|
+
};
|
|
1360
|
+
get(key: string): unknown;
|
|
1361
|
+
};
|
|
1362
|
+
type MorphModelTarget$1 = {
|
|
1363
|
+
definition?: {
|
|
1364
|
+
morphClass?: string;
|
|
1365
|
+
};
|
|
1366
|
+
};
|
|
1367
|
+
type MorphTypeSelector$1 = string | MorphModelTarget$1 | MorphEntityTarget$1 | null;
|
|
1368
|
+
type EagerLoad = {
|
|
1369
|
+
relation: string;
|
|
1370
|
+
constraint?: RelationConstraint;
|
|
1371
|
+
};
|
|
1372
|
+
type AggregateLoad = {
|
|
1373
|
+
relation: string;
|
|
1374
|
+
kind: 'count' | 'exists' | 'sum' | 'avg' | 'min' | 'max';
|
|
1375
|
+
constraint?: RelationConstraint;
|
|
1376
|
+
column?: string;
|
|
1377
|
+
alias?: string;
|
|
1378
|
+
};
|
|
1379
|
+
declare class ModelQueryBuilder<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap, TLoaded = unknown> {
|
|
1380
|
+
private readonly repository;
|
|
1381
|
+
private readonly tableQuery;
|
|
1382
|
+
private readonly eagerLoads;
|
|
1383
|
+
private readonly relationFilters;
|
|
1384
|
+
private readonly aggregateLoads;
|
|
1385
|
+
private readonly queryCasts;
|
|
1386
|
+
constructor(repository: ModelRepository<TTable>, tableQuery: TableQueryBuilder<TTable, Record<string, unknown>>, eagerLoads?: readonly EagerLoad[], relationFilters?: readonly RelationFilter[], aggregateLoads?: readonly AggregateLoad[], queryCasts?: Readonly<Record<string, ModelCastDefinition>>);
|
|
1387
|
+
getConnection(): DatabaseContext;
|
|
1388
|
+
getConnectionName(): string;
|
|
1389
|
+
getTableQueryBuilder(): TableQueryBuilder<TTable, Record<string, unknown>>;
|
|
1390
|
+
from(table: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1391
|
+
where(callback: BuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1392
|
+
where(column: ModelColumnName<TTable> | ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1393
|
+
orWhere(callback: BuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1394
|
+
orWhere(column: ModelColumnName<TTable> | ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1395
|
+
whereNot(callback: BuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1396
|
+
orWhereNot(callback: BuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1397
|
+
whereExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1398
|
+
orWhereExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1399
|
+
whereNotExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1400
|
+
orWhereNotExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1401
|
+
whereSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'in' | 'not in' | 'like', subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1402
|
+
orWhereSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'in' | 'not in' | 'like', subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1403
|
+
whereInSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1404
|
+
whereNotInSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, subquery: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1405
|
+
whereNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1406
|
+
orWhereNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1407
|
+
whereNotNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1408
|
+
orWhereNotNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1409
|
+
when<TValue>(value: TValue, callback: ValueBuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>, TValue>, defaultCallback?: ValueBuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>, TValue>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1410
|
+
unless<TValue>(value: TValue, callback: ValueBuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>, TValue>, defaultCallback?: ValueBuilderCallback$1<ModelQueryBuilder<TTable, TRelations, TLoaded>, TValue>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1411
|
+
orderBy(column: ModelColumnName<TTable>, direction?: 'asc' | 'desc'): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1412
|
+
latest(column?: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1413
|
+
oldest(column?: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1414
|
+
inRandomOrder(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1415
|
+
reorder(column?: ModelColumnName<TTable>, direction?: 'asc' | 'desc'): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1416
|
+
lock(mode: 'update' | 'share'): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1417
|
+
lockForUpdate(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1418
|
+
sharedLock(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1419
|
+
withoutGlobalScope(name: string): ModelQueryBuilder<TTable, TRelations>;
|
|
1420
|
+
withoutGlobalScopes(names?: readonly string[]): ModelQueryBuilder<TTable, TRelations>;
|
|
1421
|
+
limit(value?: number): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1422
|
+
offset(value?: number): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1423
|
+
skip(value: number): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1424
|
+
take(value: number): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1425
|
+
forPage(page: number, perPage?: number): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1426
|
+
select(...columns: readonly ModelSelectableColumn<TTable>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1427
|
+
addSelect(...columns: readonly ModelSelectableColumn<TTable>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1428
|
+
selectSub<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1429
|
+
addSelectSub<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1430
|
+
distinct(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1431
|
+
withCasts(casts: Record<string, ModelCastDefinition>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1432
|
+
whereColumn(column: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', compareTo: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1433
|
+
whereIn(column: ModelColumnName<TTable>, values: readonly unknown[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1434
|
+
whereNotIn(column: ModelColumnName<TTable>, values: readonly unknown[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1435
|
+
whereBetween(column: ModelColumnName<TTable>, range: readonly [unknown, unknown]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1436
|
+
whereNotBetween(column: ModelColumnName<TTable>, range: readonly [unknown, unknown]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1437
|
+
whereLike(column: ModelColumnName<TTable>, pattern: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1438
|
+
orWhereLike(column: ModelColumnName<TTable>, pattern: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1439
|
+
whereAny(columns: readonly ModelColumnName<TTable>[], operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1440
|
+
whereAll(columns: readonly ModelColumnName<TTable>[], operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1441
|
+
whereNone(columns: readonly ModelColumnName<TTable>[], operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1442
|
+
join(table: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1443
|
+
leftJoin(table: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1444
|
+
rightJoin(table: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1445
|
+
crossJoin(table: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1446
|
+
joinSub<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>, alias: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1447
|
+
leftJoinSub<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>, alias: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1448
|
+
rightJoinSub<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>, alias: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1449
|
+
joinLateral<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1450
|
+
leftJoinLateral<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1451
|
+
union<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1452
|
+
unionAll<TSubTable extends TableDefinition>(query: SubqueryBuilder$1<TSubTable>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1453
|
+
groupBy(...columns: readonly ModelColumnName<TTable>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1454
|
+
having(expression: string, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1455
|
+
havingBetween(expression: string, range: readonly [unknown, unknown]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1456
|
+
unsafeWhere(sql: string, bindings: readonly unknown[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1457
|
+
orUnsafeWhere(sql: string, bindings: readonly unknown[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1458
|
+
whereDate(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1459
|
+
whereMonth(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1460
|
+
whereDay(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1461
|
+
whereYear(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1462
|
+
whereTime(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1463
|
+
whereJson(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1464
|
+
orWhereJson(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1465
|
+
whereJsonContains(columnPath: ModelJsonColumnPath<TTable>, value: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1466
|
+
orWhereJsonContains(columnPath: ModelJsonColumnPath<TTable>, value: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1467
|
+
whereJsonLength(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1468
|
+
orWhereJsonLength(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1469
|
+
whereFullText(columns: ModelColumnName<TTable> | readonly ModelColumnName<TTable>[], value: string, options?: {
|
|
1470
|
+
mode?: 'natural' | 'boolean';
|
|
1471
|
+
}): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1472
|
+
orWhereFullText(columns: ModelColumnName<TTable> | readonly ModelColumnName<TTable>[], value: string, options?: {
|
|
1473
|
+
mode?: 'natural' | 'boolean';
|
|
1474
|
+
}): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1475
|
+
whereVectorSimilarTo(column: ModelColumnName<TTable>, vector: readonly number[], minSimilarity?: number): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1476
|
+
orWhereVectorSimilarTo(column: ModelColumnName<TTable>, vector: readonly number[], minSimilarity?: number): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1477
|
+
unsafeOrderBy(sql: string, bindings: readonly unknown[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1478
|
+
with<TPaths extends readonly ModelRelationPath<TRelations>[]>(...relations: TPaths): ModelQueryBuilder<TTable, TRelations, TLoaded & ResolveEagerLoads<TRelations, TPaths>>;
|
|
1479
|
+
with<TPath extends ModelRelationPath<TRelations>>(relation: TPath, constraint: RelationConstraint): ModelQueryBuilder<TTable, TRelations, TLoaded & ResolveEagerLoads<TRelations, readonly [TPath]>>;
|
|
1480
|
+
with(relations: Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraint>>>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1481
|
+
has(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1482
|
+
orHas(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1483
|
+
whereHas(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraint): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1484
|
+
orWhereHas(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraint): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1485
|
+
doesntHave(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1486
|
+
orDoesntHave(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1487
|
+
whereDoesntHave(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraint): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1488
|
+
orWhereDoesntHave(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraint): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1489
|
+
whereRelation<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1490
|
+
orWhereRelation<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1491
|
+
whereMorphRelation<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath, types: string | {
|
|
1492
|
+
definition?: {
|
|
1493
|
+
morphClass?: string;
|
|
1494
|
+
};
|
|
1495
|
+
} | readonly (string | {
|
|
1496
|
+
definition?: {
|
|
1497
|
+
morphClass?: string;
|
|
1498
|
+
};
|
|
1499
|
+
})[], column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1500
|
+
orWhereMorphRelation<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath, types: string | {
|
|
1501
|
+
definition?: {
|
|
1502
|
+
morphClass?: string;
|
|
1503
|
+
};
|
|
1504
|
+
} | readonly (string | {
|
|
1505
|
+
definition?: {
|
|
1506
|
+
morphClass?: string;
|
|
1507
|
+
};
|
|
1508
|
+
})[], column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1509
|
+
whereBelongsTo<TRelated extends TableDefinition>(relatedEntity: Entity<TRelated>, relationName?: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1510
|
+
orWhereBelongsTo<TRelated extends TableDefinition>(relatedEntity: Entity<TRelated>, relationName?: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1511
|
+
whereMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector$1): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1512
|
+
orWhereMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector$1): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1513
|
+
whereNotMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector$1): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1514
|
+
orWhereNotMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector$1): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1515
|
+
withWhereHas<TPath extends ModelRelationPath<TRelations>>(relation: TPath, constraint?: RelationConstraint): ModelQueryBuilder<TTable, TRelations, TLoaded & ResolveEagerLoads<TRelations, readonly [TPath]>>;
|
|
1516
|
+
withCount(...relations: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1517
|
+
withCount(relations: Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraint>>>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1518
|
+
withExists(...relations: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1519
|
+
withExists(relations: Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraint>>>): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1520
|
+
withSum<TRelationPath extends ModelRelationPath<TRelations>>(first: TRelationPath | Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraint>>>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1521
|
+
withAvg<TRelationPath extends ModelRelationPath<TRelations>>(first: TRelationPath | Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraint>>>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1522
|
+
withMin<TRelationPath extends ModelRelationPath<TRelations>>(first: TRelationPath | Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraint>>>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1523
|
+
withMax<TRelationPath extends ModelRelationPath<TRelations>>(first: TRelationPath | Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraint>>>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1524
|
+
toSQL(): CompiledStatement;
|
|
1525
|
+
debug(): {
|
|
1526
|
+
bindings: unknown[];
|
|
1527
|
+
connectionName: string;
|
|
1528
|
+
scope: TransactionScopeKind;
|
|
1529
|
+
schedulingMode: "concurrent" | "serialized" | "worker";
|
|
1530
|
+
metadata: {
|
|
1531
|
+
debug: {
|
|
1532
|
+
connectionName: string;
|
|
1533
|
+
scope: TransactionScopeKind;
|
|
1534
|
+
schedulingMode: "concurrent" | "serialized" | "worker";
|
|
1535
|
+
tableName: string;
|
|
1536
|
+
hasJoins: boolean;
|
|
1537
|
+
hasUnions: boolean;
|
|
1538
|
+
hasGrouping: boolean;
|
|
1539
|
+
hasHaving: boolean;
|
|
1540
|
+
complexity: number;
|
|
1541
|
+
lockMode?: string;
|
|
1542
|
+
intent: CompiledQueryIntent;
|
|
1543
|
+
transactionAffinity: CompiledQueryTransactionAffinity;
|
|
1544
|
+
streaming: CompiledQueryStreamingMode;
|
|
1545
|
+
};
|
|
1546
|
+
kind: CompiledQueryKind;
|
|
1547
|
+
resultMode: CompiledQueryResultMode;
|
|
1548
|
+
selectedShape: {
|
|
1549
|
+
mode: "all" | "projection" | "write";
|
|
1550
|
+
columns: readonly string[];
|
|
1551
|
+
aggregates: readonly string[];
|
|
1552
|
+
hasRawSelections: boolean;
|
|
1553
|
+
hasSubqueries: boolean;
|
|
1554
|
+
};
|
|
1555
|
+
safety: {
|
|
1556
|
+
unsafe: boolean;
|
|
1557
|
+
containsRawSql: boolean;
|
|
1558
|
+
};
|
|
1559
|
+
} | undefined;
|
|
1560
|
+
unsafe?: true;
|
|
1561
|
+
sql: string;
|
|
1562
|
+
source?: string;
|
|
1563
|
+
};
|
|
1564
|
+
dump(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1565
|
+
get(): Promise<ModelCollection<TTable, TRelations> & Array<EntityWithLoaded<TTable, TRelations, TLoaded>>>;
|
|
1566
|
+
first(): Promise<EntityWithLoaded<TTable, TRelations, TLoaded> | undefined>;
|
|
1567
|
+
sole(): Promise<EntityWithLoaded<TTable, TRelations, TLoaded>>;
|
|
1568
|
+
paginate(perPage?: number, page?: number, options?: PaginationOptions): Promise<PaginatedResult<EntityWithLoaded<TTable, TRelations, TLoaded>>>;
|
|
1569
|
+
simplePaginate(perPage?: number, page?: number, options?: PaginationOptions): Promise<SimplePaginatedResult<EntityWithLoaded<TTable, TRelations, TLoaded>>>;
|
|
1570
|
+
cursorPaginate(perPage?: number, cursor?: string | null, options?: CursorPaginationOptions): Promise<CursorPaginatedResult<EntityWithLoaded<TTable, TRelations, TLoaded>>>;
|
|
1571
|
+
chunk(size: number, callback: (rows: readonly EntityWithLoaded<TTable, TRelations, TLoaded>[], page: number) => unknown | Promise<unknown>): Promise<void>;
|
|
1572
|
+
chunkById(size: number, callback: (rows: readonly EntityWithLoaded<TTable, TRelations, TLoaded>[], page: number) => unknown | Promise<unknown>, column?: ModelAttributeKey<TTable>): Promise<void>;
|
|
1573
|
+
chunkByIdDesc(size: number, callback: (rows: readonly EntityWithLoaded<TTable, TRelations, TLoaded>[], page: number) => unknown | Promise<unknown>, column?: ModelAttributeKey<TTable>): Promise<void>;
|
|
1574
|
+
lazy(size?: number): AsyncGenerator<EntityWithLoaded<TTable, TRelations, TLoaded>, void, unknown>;
|
|
1575
|
+
cursor(): AsyncGenerator<EntityWithLoaded<TTable, TRelations, TLoaded>, void, unknown>;
|
|
1576
|
+
count(): Promise<number>;
|
|
1577
|
+
exists(): Promise<boolean>;
|
|
1578
|
+
doesntExist(): Promise<boolean>;
|
|
1579
|
+
pluck<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<Array<ModelRecord<TTable>[TColumn]>>;
|
|
1580
|
+
value<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<ModelRecord<TTable>[TColumn] | undefined>;
|
|
1581
|
+
valueOrFail<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<ModelRecord<TTable>[TColumn]>;
|
|
1582
|
+
soleValue<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<ModelRecord<TTable>[TColumn]>;
|
|
1583
|
+
sum(column: ModelColumnName<TTable>): Promise<number>;
|
|
1584
|
+
avg(column: ModelColumnName<TTable>): Promise<number | null>;
|
|
1585
|
+
min(column: ModelColumnName<TTable>): Promise<number | null>;
|
|
1586
|
+
max(column: ModelColumnName<TTable>): Promise<number | null>;
|
|
1587
|
+
firstOrFail(): Promise<EntityWithLoaded<TTable, TRelations, TLoaded>>;
|
|
1588
|
+
find(value: unknown, column?: string): Promise<EntityWithLoaded<TTable, TRelations, TLoaded> | undefined>;
|
|
1589
|
+
findOrFail(value: unknown, column?: string): Promise<EntityWithLoaded<TTable, TRelations, TLoaded>>;
|
|
1590
|
+
update(values: Partial<ModelRecord<TTable>>): Promise<DriverExecutionResult>;
|
|
1591
|
+
updateJson(columnPath: ModelJsonColumnPath<TTable>, value: unknown): Promise<DriverExecutionResult>;
|
|
1592
|
+
increment(column: ModelColumnName<TTable>, amount?: number, extraValues?: Partial<ModelRecord<TTable>>): Promise<DriverExecutionResult>;
|
|
1593
|
+
decrement(column: ModelColumnName<TTable>, amount?: number, extraValues?: Partial<ModelRecord<TTable>>): Promise<DriverExecutionResult>;
|
|
1594
|
+
upsert(values: Partial<ModelRecord<TTable>> | readonly Partial<ModelRecord<TTable>>[], uniqueBy: readonly ModelColumnName<TTable>[], updateColumns?: readonly ModelColumnName<TTable>[]): Promise<DriverExecutionResult>;
|
|
1595
|
+
delete(): Promise<DriverExecutionResult>;
|
|
1596
|
+
withTrashed(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1597
|
+
onlyTrashed(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1598
|
+
withoutTrashed(): ModelQueryBuilder<TTable, TRelations, TLoaded>;
|
|
1599
|
+
restore(): Promise<number>;
|
|
1600
|
+
forceDelete(): Promise<number>;
|
|
1601
|
+
private clone;
|
|
1602
|
+
private normalizeExistsSubquery;
|
|
1603
|
+
private withRelationFilter;
|
|
1604
|
+
private withAggregateLoads;
|
|
1605
|
+
private normalizeEagerLoads;
|
|
1606
|
+
private mergeEagerLoads;
|
|
1607
|
+
private normalizeAggregateLoads;
|
|
1608
|
+
private normalizeMorphTypes;
|
|
1609
|
+
private applyMorphedToFilter;
|
|
1610
|
+
private normalizeMorphedToTarget;
|
|
1611
|
+
private isMorphEntityTarget;
|
|
1612
|
+
private getMorphTargetLabels;
|
|
1613
|
+
private assertMorphToRelation;
|
|
1614
|
+
private normalizeColumnAggregateLoads;
|
|
1615
|
+
private parseAggregateRelation;
|
|
1616
|
+
private resolveBelongsToRelation;
|
|
1617
|
+
private resolveBelongsToRelationName;
|
|
1618
|
+
private extractNumericValues;
|
|
1619
|
+
private getUnpaginatedEntities;
|
|
1620
|
+
private encodeCursor;
|
|
1621
|
+
private decodeCursor;
|
|
1622
|
+
private assertPositiveInteger;
|
|
1623
|
+
private normalizePaginationParameterName;
|
|
1624
|
+
private prepareCursorPaginationQuery;
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
type ModelInsertPayload<TTable extends TableDefinition> = Partial<InferInsert<TTable>>;
|
|
1628
|
+
type ModelUpdatePayload<TTable extends TableDefinition> = Partial<InferUpdate<TTable>>;
|
|
1629
|
+
type ModelRecord<TTable extends TableDefinition> = InferSelect<TTable>;
|
|
1630
|
+
|
|
1631
|
+
type ModelAttributeKey<TTable extends TableDefinition> = Extract<keyof InferSelect<TTable>, string>;
|
|
1632
|
+
type ModelColumnName<TTable extends TableDefinition> = ModelAttributeKey<TTable> | `${string}.${ModelAttributeKey<TTable>}`;
|
|
1633
|
+
type ModelColumnReference<TTable extends TableDefinition> = ModelColumnName<TTable> | `${string}.${string}`;
|
|
1634
|
+
type ModelJsonColumnPath<TTable extends TableDefinition> = ModelColumnName<TTable> | `${ModelColumnName<TTable>}->${string}`;
|
|
1635
|
+
type ModelSelectableColumn<TTable extends TableDefinition> = ModelColumnName<TTable> | `${ModelColumnName<TTable>} as ${string}`;
|
|
1636
|
+
interface AnyModelDefinition {
|
|
1637
|
+
readonly kind: 'model';
|
|
1638
|
+
readonly table: TableDefinition;
|
|
1639
|
+
readonly name: string;
|
|
1640
|
+
readonly primaryKey: string;
|
|
1641
|
+
readonly connectionName?: string;
|
|
1642
|
+
readonly morphClass: string;
|
|
1643
|
+
readonly with: readonly string[];
|
|
1644
|
+
readonly pendingAttributes: Partial<Record<string, unknown>>;
|
|
1645
|
+
readonly preventLazyLoading: boolean;
|
|
1646
|
+
readonly preventAccessingMissingAttributes: boolean;
|
|
1647
|
+
readonly automaticEagerLoading: boolean;
|
|
1648
|
+
readonly timestamps: boolean;
|
|
1649
|
+
readonly createdAtColumn?: string;
|
|
1650
|
+
readonly updatedAtColumn?: string;
|
|
1651
|
+
readonly fillable: readonly string[];
|
|
1652
|
+
readonly hasExplicitFillable?: boolean;
|
|
1653
|
+
readonly guarded: readonly string[];
|
|
1654
|
+
readonly relations: RelationMap;
|
|
1655
|
+
readonly casts: Record<string, ModelCastDefinition>;
|
|
1656
|
+
readonly accessors: Record<string, ModelAccessor>;
|
|
1657
|
+
readonly mutators: Record<string, ModelMutator>;
|
|
1658
|
+
readonly hidden: readonly string[];
|
|
1659
|
+
readonly visible: readonly string[];
|
|
1660
|
+
readonly appended: readonly string[];
|
|
1661
|
+
readonly serializeDate?: ModelDateSerializer;
|
|
1662
|
+
readonly massPrunable: boolean;
|
|
1663
|
+
readonly touches: readonly string[];
|
|
1664
|
+
readonly replicationExcludes: readonly string[];
|
|
1665
|
+
readonly softDeletes: boolean;
|
|
1666
|
+
readonly deletedAtColumn?: string;
|
|
1667
|
+
readonly events: Partial<Record<ModelLifecycleEventName, readonly ModelLifecycleEventHandler[]>>;
|
|
1668
|
+
readonly observers: readonly unknown[];
|
|
1669
|
+
}
|
|
1670
|
+
interface AnyEntity {
|
|
1671
|
+
getRepository(): {
|
|
1672
|
+
definition: AnyModelDefinition;
|
|
1673
|
+
};
|
|
1674
|
+
toAttributes(): Record<string, unknown>;
|
|
1675
|
+
getChanges(): Record<string, unknown>;
|
|
1676
|
+
}
|
|
1677
|
+
type ModelDefinitionLike<TTable extends TableDefinition = TableDefinition> = (AnyModelDefinition & {
|
|
1678
|
+
readonly table: TTable;
|
|
1679
|
+
}) | {
|
|
1680
|
+
readonly definition: AnyModelDefinition & {
|
|
1681
|
+
readonly table: TTable;
|
|
1682
|
+
};
|
|
1683
|
+
};
|
|
1684
|
+
interface ModelScopeMap<TTable extends TableDefinition = TableDefinition> {
|
|
1685
|
+
readonly [key: string]: (query: ModelQueryBuilder<TTable>, ...args: readonly unknown[]) => ModelQueryBuilder<TTable>;
|
|
1686
|
+
}
|
|
1687
|
+
type RelationConstraintDefinition = (query: ModelQueryBuilder<TableDefinition>) => unknown;
|
|
1688
|
+
interface ScopedRelationDefinition {
|
|
1689
|
+
readonly constraint?: RelationConstraintDefinition;
|
|
1690
|
+
}
|
|
1691
|
+
type ModelDefinitionTable<TReference extends ModelDefinitionLike> = TReference extends {
|
|
1692
|
+
readonly definition: {
|
|
1693
|
+
readonly table: infer TTable extends TableDefinition;
|
|
1694
|
+
};
|
|
1695
|
+
} ? TTable : TReference extends {
|
|
1696
|
+
readonly table: infer TTable extends TableDefinition;
|
|
1697
|
+
} ? TTable : TableDefinition;
|
|
1698
|
+
type PivotTableColumnName<TPivotTable extends string | TableDefinition> = TPivotTable extends TableDefinition ? Extract<keyof InferSelect<TPivotTable>, string> : string;
|
|
1699
|
+
interface BelongsToRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1700
|
+
readonly kind: 'belongsTo';
|
|
1701
|
+
readonly related: () => TRelated;
|
|
1702
|
+
readonly foreignKey: string;
|
|
1703
|
+
readonly ownerKey: string;
|
|
1704
|
+
}
|
|
1705
|
+
interface HasManyRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1706
|
+
readonly kind: 'hasMany';
|
|
1707
|
+
readonly related: () => TRelated;
|
|
1708
|
+
readonly foreignKey: string;
|
|
1709
|
+
readonly localKey: string;
|
|
1710
|
+
}
|
|
1711
|
+
interface HasOneRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1712
|
+
readonly kind: 'hasOne';
|
|
1713
|
+
readonly related: () => TRelated;
|
|
1714
|
+
readonly foreignKey: string;
|
|
1715
|
+
readonly localKey: string;
|
|
1716
|
+
}
|
|
1717
|
+
interface HasOneOfManyRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1718
|
+
readonly kind: 'hasOneOfMany';
|
|
1719
|
+
readonly related: () => TRelated;
|
|
1720
|
+
readonly foreignKey: string;
|
|
1721
|
+
readonly localKey: string;
|
|
1722
|
+
readonly aggregateColumn: string;
|
|
1723
|
+
readonly aggregate: 'min' | 'max';
|
|
1724
|
+
}
|
|
1725
|
+
interface MorphOneRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1726
|
+
readonly kind: 'morphOne';
|
|
1727
|
+
readonly related: () => TRelated;
|
|
1728
|
+
readonly morphName: string;
|
|
1729
|
+
readonly morphTypeColumn: string;
|
|
1730
|
+
readonly morphIdColumn: string;
|
|
1731
|
+
readonly localKey: string;
|
|
1732
|
+
}
|
|
1733
|
+
interface MorphManyRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1734
|
+
readonly kind: 'morphMany';
|
|
1735
|
+
readonly related: () => TRelated;
|
|
1736
|
+
readonly morphName: string;
|
|
1737
|
+
readonly morphTypeColumn: string;
|
|
1738
|
+
readonly morphIdColumn: string;
|
|
1739
|
+
readonly localKey: string;
|
|
1740
|
+
}
|
|
1741
|
+
interface MorphOneOfManyRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1742
|
+
readonly kind: 'morphOneOfMany';
|
|
1743
|
+
readonly related: () => TRelated;
|
|
1744
|
+
readonly morphName: string;
|
|
1745
|
+
readonly morphTypeColumn: string;
|
|
1746
|
+
readonly morphIdColumn: string;
|
|
1747
|
+
readonly localKey: string;
|
|
1748
|
+
readonly aggregateColumn: string;
|
|
1749
|
+
readonly aggregate: 'min' | 'max';
|
|
1750
|
+
}
|
|
1751
|
+
interface MorphToRelationDefinition<TTable extends TableDefinition = TableDefinition> extends ScopedRelationDefinition {
|
|
1752
|
+
readonly kind: 'morphTo';
|
|
1753
|
+
readonly morphName: string;
|
|
1754
|
+
readonly morphTypeColumn: string;
|
|
1755
|
+
readonly morphIdColumn: string;
|
|
1756
|
+
}
|
|
1757
|
+
interface BelongsToManyRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike, TPivotTable extends string | TableDefinition = string | TableDefinition> extends ScopedRelationDefinition {
|
|
1758
|
+
readonly kind: 'belongsToMany';
|
|
1759
|
+
readonly related: () => TRelated;
|
|
1760
|
+
readonly pivotTable: TPivotTable;
|
|
1761
|
+
readonly foreignPivotKey: string;
|
|
1762
|
+
readonly relatedPivotKey: string;
|
|
1763
|
+
readonly parentKey: string;
|
|
1764
|
+
readonly relatedKey: string;
|
|
1765
|
+
readonly pivotColumns: readonly PivotTableColumnName<TPivotTable>[];
|
|
1766
|
+
readonly pivotWheres: readonly PivotWhereDefinition[];
|
|
1767
|
+
readonly pivotOrderBy: readonly PivotOrderDefinition[];
|
|
1768
|
+
readonly pivotAccessor: string;
|
|
1769
|
+
readonly pivotModel?: () => ModelDefinitionLike;
|
|
1770
|
+
withPivot(...columns: readonly PivotTableColumnName<TPivotTable>[]): BelongsToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1771
|
+
wherePivot(column: PivotTableColumnName<TPivotTable>, operator: unknown, value?: unknown): BelongsToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1772
|
+
orderByPivot(column: PivotTableColumnName<TPivotTable>, direction?: 'asc' | 'desc'): BelongsToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1773
|
+
as(accessor: string): BelongsToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1774
|
+
using(model: () => ModelDefinitionLike): BelongsToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1775
|
+
}
|
|
1776
|
+
interface MorphToManyRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike, TPivotTable extends string | TableDefinition = string | TableDefinition> extends ScopedRelationDefinition {
|
|
1777
|
+
readonly kind: 'morphToMany';
|
|
1778
|
+
readonly related: () => TRelated;
|
|
1779
|
+
readonly pivotTable: TPivotTable;
|
|
1780
|
+
readonly morphName: string;
|
|
1781
|
+
readonly morphTypeColumn: string;
|
|
1782
|
+
readonly morphIdColumn: string;
|
|
1783
|
+
readonly foreignPivotKey: string;
|
|
1784
|
+
readonly parentKey: string;
|
|
1785
|
+
readonly relatedKey: string;
|
|
1786
|
+
readonly pivotColumns: readonly PivotTableColumnName<TPivotTable>[];
|
|
1787
|
+
readonly pivotWheres: readonly PivotWhereDefinition[];
|
|
1788
|
+
readonly pivotOrderBy: readonly PivotOrderDefinition[];
|
|
1789
|
+
readonly pivotAccessor: string;
|
|
1790
|
+
readonly pivotModel?: () => ModelDefinitionLike;
|
|
1791
|
+
withPivot(...columns: readonly PivotTableColumnName<TPivotTable>[]): MorphToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1792
|
+
wherePivot(column: PivotTableColumnName<TPivotTable>, operator: unknown, value?: unknown): MorphToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1793
|
+
orderByPivot(column: PivotTableColumnName<TPivotTable>, direction?: 'asc' | 'desc'): MorphToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1794
|
+
as(accessor: string): MorphToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1795
|
+
using(model: () => ModelDefinitionLike): MorphToManyRelationDefinition<TRelated, TPivotTable>;
|
|
1796
|
+
}
|
|
1797
|
+
interface MorphedByManyRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike, TPivotTable extends string | TableDefinition = string | TableDefinition> extends ScopedRelationDefinition {
|
|
1798
|
+
readonly kind: 'morphedByMany';
|
|
1799
|
+
readonly related: () => TRelated;
|
|
1800
|
+
readonly pivotTable: TPivotTable;
|
|
1801
|
+
readonly morphName: string;
|
|
1802
|
+
readonly morphTypeColumn: string;
|
|
1803
|
+
readonly morphIdColumn: string;
|
|
1804
|
+
readonly foreignPivotKey: string;
|
|
1805
|
+
readonly parentKey: string;
|
|
1806
|
+
readonly relatedKey: string;
|
|
1807
|
+
readonly pivotColumns: readonly PivotTableColumnName<TPivotTable>[];
|
|
1808
|
+
readonly pivotWheres: readonly PivotWhereDefinition[];
|
|
1809
|
+
readonly pivotOrderBy: readonly PivotOrderDefinition[];
|
|
1810
|
+
readonly pivotAccessor: string;
|
|
1811
|
+
readonly pivotModel?: () => ModelDefinitionLike;
|
|
1812
|
+
withPivot(...columns: readonly PivotTableColumnName<TPivotTable>[]): MorphedByManyRelationDefinition<TRelated, TPivotTable>;
|
|
1813
|
+
wherePivot(column: PivotTableColumnName<TPivotTable>, operator: unknown, value?: unknown): MorphedByManyRelationDefinition<TRelated, TPivotTable>;
|
|
1814
|
+
orderByPivot(column: PivotTableColumnName<TPivotTable>, direction?: 'asc' | 'desc'): MorphedByManyRelationDefinition<TRelated, TPivotTable>;
|
|
1815
|
+
as(accessor: string): MorphedByManyRelationDefinition<TRelated, TPivotTable>;
|
|
1816
|
+
using(model: () => ModelDefinitionLike): MorphedByManyRelationDefinition<TRelated, TPivotTable>;
|
|
1817
|
+
}
|
|
1818
|
+
interface PivotWhereDefinition {
|
|
1819
|
+
readonly column: string;
|
|
1820
|
+
readonly operator: string;
|
|
1821
|
+
readonly value: unknown;
|
|
1822
|
+
}
|
|
1823
|
+
interface PivotOrderDefinition {
|
|
1824
|
+
readonly column: string;
|
|
1825
|
+
readonly direction: 'asc' | 'desc';
|
|
1826
|
+
}
|
|
1827
|
+
interface PivotRelationMethods<TRelation, TPivotTable extends string | TableDefinition = string | TableDefinition> {
|
|
1828
|
+
withPivot(...columns: readonly PivotTableColumnName<TPivotTable>[]): TRelation;
|
|
1829
|
+
wherePivot(column: PivotTableColumnName<TPivotTable>, operator: unknown, value?: unknown): TRelation;
|
|
1830
|
+
orderByPivot(column: PivotTableColumnName<TPivotTable>, direction?: 'asc' | 'desc'): TRelation;
|
|
1831
|
+
as(accessor: string): TRelation;
|
|
1832
|
+
using(model: () => ModelDefinitionLike): TRelation;
|
|
1833
|
+
}
|
|
1834
|
+
interface HasOneThroughRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike, TThrough extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1835
|
+
readonly kind: 'hasOneThrough';
|
|
1836
|
+
readonly related: () => TRelated;
|
|
1837
|
+
readonly through: () => TThrough;
|
|
1838
|
+
readonly firstKey: string;
|
|
1839
|
+
readonly secondKey: string;
|
|
1840
|
+
readonly localKey: string;
|
|
1841
|
+
readonly secondLocalKey: string;
|
|
1842
|
+
}
|
|
1843
|
+
interface HasManyThroughRelationDefinition<TRelated extends ModelDefinitionLike = ModelDefinitionLike, TThrough extends ModelDefinitionLike = ModelDefinitionLike> extends ScopedRelationDefinition {
|
|
1844
|
+
readonly kind: 'hasManyThrough';
|
|
1845
|
+
readonly related: () => TRelated;
|
|
1846
|
+
readonly through: () => TThrough;
|
|
1847
|
+
readonly firstKey: string;
|
|
1848
|
+
readonly secondKey: string;
|
|
1849
|
+
readonly localKey: string;
|
|
1850
|
+
readonly secondLocalKey: string;
|
|
1851
|
+
}
|
|
1852
|
+
type RelationDefinition = BelongsToRelationDefinition | HasManyRelationDefinition | HasOneRelationDefinition | HasOneOfManyRelationDefinition | MorphOneRelationDefinition | MorphManyRelationDefinition | MorphOneOfManyRelationDefinition | MorphToRelationDefinition | BelongsToManyRelationDefinition | MorphToManyRelationDefinition | MorphedByManyRelationDefinition | HasOneThroughRelationDefinition | HasManyThroughRelationDefinition;
|
|
1853
|
+
interface RelationMap {
|
|
1854
|
+
readonly [key: string]: RelationDefinition;
|
|
1855
|
+
}
|
|
1856
|
+
type ModelRelationName<TRelations extends RelationMap = RelationMap> = Extract<keyof TRelations, string>;
|
|
1857
|
+
type ModelRelationPath<TRelations extends RelationMap = RelationMap> = InternalRelationPath<TRelations, 15>;
|
|
1858
|
+
type InternalRelationPath<TRelations extends RelationMap, TDepth extends number> = ModelRelationName<TRelations> | NestedRelationPath<TRelations, TDepth>;
|
|
1859
|
+
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
|
1860
|
+
type NestedRelationPath<TRelations extends RelationMap, TDepth extends number> = TDepth extends 0 ? never : string extends ModelRelationName<TRelations> ? `${string}.${string}` : {
|
|
1861
|
+
[K in ModelRelationName<TRelations>]: TRelations[K] extends {
|
|
1862
|
+
readonly kind: 'morphTo';
|
|
1863
|
+
} ? `${K}.${string}` : TRelations[K] extends {
|
|
1864
|
+
readonly related: () => infer TRef;
|
|
1865
|
+
} ? `${K}.${InternalRelationPath<RelatedRelationsOfDefinition<TRef>, Prev[TDepth]>}` : never;
|
|
1866
|
+
}[ModelRelationName<TRelations>];
|
|
1867
|
+
type RelationRootName<TRelations extends RelationMap, TRelationPath extends ModelRelationPath<TRelations>> = TRelationPath extends `${infer TRoot}.${string}` ? TRoot extends ModelRelationName<TRelations> ? TRoot : never : TRelationPath extends ModelRelationName<TRelations> ? TRelationPath : never;
|
|
1868
|
+
type RelatedTableOfRelation<TRelation extends RelationDefinition> = TRelation extends {
|
|
1869
|
+
readonly related: () => infer TReference extends ModelDefinitionLike;
|
|
1870
|
+
} ? ModelDefinitionTable<TReference> : TableDefinition;
|
|
1871
|
+
type RelatedColumnNameOfRelation<TRelation extends RelationDefinition> = ModelAttributeKey<RelatedTableOfRelation<TRelation>>;
|
|
1872
|
+
type RelatedColumnNameForRelationPath<TRelations extends RelationMap, TRelationPath extends ModelRelationPath<TRelations>> = RelatedColumnNameOfRelation<TRelations[RelationRootName<TRelations, TRelationPath>]>;
|
|
1873
|
+
/**
|
|
1874
|
+
* Extracts the RelationMap from a related model definition referenced by a
|
|
1875
|
+
* relation. This enables recursive type resolution for nested eager loads
|
|
1876
|
+
* like `'posts.comments'`.
|
|
1877
|
+
*/
|
|
1878
|
+
type RelatedRelationsOfDefinition<TRef> = TRef extends {
|
|
1879
|
+
readonly relations: infer R extends RelationMap;
|
|
1880
|
+
} ? R : TRef extends {
|
|
1881
|
+
readonly definition: {
|
|
1882
|
+
readonly relations: infer R extends RelationMap;
|
|
1883
|
+
};
|
|
1884
|
+
} ? R : RelationMap;
|
|
1885
|
+
type RelatedRelationsOfRelation<TRelation extends RelationDefinition> = TRelation extends {
|
|
1886
|
+
readonly related: () => infer TRef;
|
|
1887
|
+
} ? RelatedRelationsOfDefinition<TRef> : RelationMap;
|
|
1888
|
+
/** True for relation kinds that resolve to an array of entities. */
|
|
1889
|
+
type IsToManyRelation<TRelation extends RelationDefinition> = TRelation extends {
|
|
1890
|
+
readonly kind: 'hasMany' | 'belongsToMany' | 'morphMany' | 'morphToMany' | 'morphedByMany' | 'hasManyThrough';
|
|
1891
|
+
} ? true : false;
|
|
1892
|
+
/** Resolves a single (non-nested) relation to its typed entity shape. */
|
|
1893
|
+
type ResolveRelationEntity<TRelation extends RelationDefinition> = Entity<RelatedTableOfRelation<TRelation>, RelatedRelationsOfRelation<TRelation>>;
|
|
1894
|
+
/**
|
|
1895
|
+
* Wraps a base entity type in the correct cardinality for a relation:
|
|
1896
|
+
* - to-many → `TEntity[]`
|
|
1897
|
+
* - to-one → `TEntity | null`
|
|
1898
|
+
*/
|
|
1899
|
+
type WrapRelationCardinality<TRelation extends RelationDefinition, TEntity> = IsToManyRelation<TRelation> extends true ? TEntity[] : TEntity | null;
|
|
1900
|
+
/**
|
|
1901
|
+
* Recursively resolves a dot-separated eager-load path against a RelationMap.
|
|
1902
|
+
*
|
|
1903
|
+
* - `'posts'` → `{ posts: Entity<PostsTable>[] }`
|
|
1904
|
+
* - `'posts.comments'` → `{ posts: (Entity<PostsTable> & { comments: Entity<CommentsTable>[] })[] }`
|
|
1905
|
+
* - `'profile'` → `{ profile: Entity<ProfileTable> | null }`
|
|
1906
|
+
*
|
|
1907
|
+
* Depth is bounded by TS's recursion limit (~25), but real-world nesting
|
|
1908
|
+
* rarely exceeds 3-4 levels.
|
|
1909
|
+
*/
|
|
1910
|
+
type ResolveEagerLoadPath<TRelations extends RelationMap, TPath extends string> = string extends TPath ? unknown : TPath extends `${infer TRoot}.${infer TRest}` ? TRoot extends keyof TRelations & string ? TRelations[TRoot] extends {
|
|
1911
|
+
readonly kind: 'morphTo';
|
|
1912
|
+
} ? {
|
|
1913
|
+
readonly [K in TRoot]: WrapRelationCardinality<TRelations[TRoot], ResolveRelationEntity<TRelations[TRoot]>>;
|
|
1914
|
+
} : {
|
|
1915
|
+
readonly [K in TRoot]: WrapRelationCardinality<TRelations[TRoot], ResolveRelationEntity<TRelations[TRoot]> & ResolveEagerLoadPath<RelatedRelationsOfRelation<TRelations[TRoot]>, TRest>>;
|
|
1916
|
+
} : never : TPath extends keyof TRelations & string ? {
|
|
1917
|
+
readonly [K in TPath]: WrapRelationCardinality<TRelations[TPath], ResolveRelationEntity<TRelations[TPath]>>;
|
|
1918
|
+
} : never;
|
|
1919
|
+
/**
|
|
1920
|
+
* Merges multiple eager-load paths into a single intersection type.
|
|
1921
|
+
* Used by `with()` and `load()` to accumulate loaded relation shapes.
|
|
1922
|
+
*/
|
|
1923
|
+
type ResolveEagerLoads<TRelations extends RelationMap, TPaths extends readonly string[]> = TPaths extends readonly [] ? unknown : TPaths extends readonly [infer TFirst extends string, ...infer TRest extends readonly string[]] ? ResolveEagerLoadPath<TRelations, TFirst> & ResolveEagerLoads<TRelations, TRest> : ResolveEagerLoadUnion<TRelations, TPaths[number]>;
|
|
1924
|
+
/**
|
|
1925
|
+
* Converts a union to an intersection via distributive conditional types.
|
|
1926
|
+
* `A | B` → `A & B`
|
|
1927
|
+
*/
|
|
1928
|
+
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (x: TUnion) => void : never) extends (x: infer TIntersection) => void ? TIntersection : never;
|
|
1929
|
+
/**
|
|
1930
|
+
* Resolves a union of eager-load paths into an intersection of their
|
|
1931
|
+
* resolved shapes. Used by the object-form `with()` overload where
|
|
1932
|
+
* the paths come from `keyof TMap` (a union, not a tuple).
|
|
1933
|
+
*/
|
|
1934
|
+
type ResolveEagerLoadUnion<TRelations extends RelationMap, TPaths extends string> = UnionToIntersection<TPaths extends unknown ? ResolveEagerLoadPath<TRelations, TPaths> : never>;
|
|
1935
|
+
/**
|
|
1936
|
+
* Recursively converts an eager-loaded shape from entity types to their
|
|
1937
|
+
* serialized (JSON) form. Replaces `Entity<T>` with `ModelRecord<T>` and
|
|
1938
|
+
* recurses into nested loaded relations.
|
|
1939
|
+
*
|
|
1940
|
+
* - `Entity<T>[]` → `ModelRecord<T>[]`
|
|
1941
|
+
* - `Entity<T> | null` → `ModelRecord<T> | null`
|
|
1942
|
+
* - `Entity<T> & { r: Entity<U>[] }` → `ModelRecord<T> & { r: ModelRecord<U>[] }`
|
|
1943
|
+
*/
|
|
1944
|
+
type SerializeLoadedValue<TValue> = TValue extends readonly (infer TItem)[] ? SerializeLoadedValue<TItem>[] : TValue extends null ? null : TValue extends Entity<infer TTable, infer _TRelations> ? ModelRecord<TTable> & SerializeLoaded<Omit<TValue, keyof Entity<TTable, _TRelations>>> : TValue;
|
|
1945
|
+
type SerializeLoaded<TLoaded> = unknown extends TLoaded ? unknown : {
|
|
1946
|
+
readonly [K in keyof TLoaded]: SerializeLoadedValue<TLoaded[K]>;
|
|
1947
|
+
};
|
|
1948
|
+
/**
|
|
1949
|
+
* The serialized (JSON) form of an entity with eager-loaded relations.
|
|
1950
|
+
* This is the return type of `toJSON()` when called on an entity that
|
|
1951
|
+
* has loaded relations via `with()` or `load()`.
|
|
1952
|
+
*/
|
|
1953
|
+
type SerializedEntityWithLoaded<TTable extends TableDefinition, TLoaded> = ModelRecord<TTable> & SerializeLoaded<TLoaded>;
|
|
1954
|
+
/**
|
|
1955
|
+
* The entity type returned by terminal query methods when eager loads
|
|
1956
|
+
* have been accumulated via `with()`.
|
|
1957
|
+
*/
|
|
1958
|
+
type EntityWithLoaded<TTable extends TableDefinition, TRelations extends RelationMap, TLoaded> = Entity<TTable, TRelations> & TLoaded & {
|
|
1959
|
+
toJSON(): SerializedEntityWithLoaded<TTable, TLoaded>;
|
|
1960
|
+
};
|
|
1961
|
+
type EmptyScopeMap = Record<never, never>;
|
|
1962
|
+
type ModelScopesDefinition = Readonly<Record<string, unknown>>;
|
|
1963
|
+
type ModelLifecycleEventName = 'retrieved' | 'creating' | 'created' | 'updating' | 'updated' | 'saving' | 'saved' | 'deleting' | 'trashed' | 'forceDeleting' | 'forceDeleted' | 'restoring' | 'restored' | 'deleted' | 'replicating';
|
|
1964
|
+
type ModelLifecycleEventHandler = (...args: readonly unknown[]) => unknown | Promise<unknown>;
|
|
1965
|
+
type BuiltInCastName = 'boolean' | 'number' | 'string' | 'json' | 'date' | 'datetime' | 'timestamp' | 'vector';
|
|
1966
|
+
type BuiltInCastString = BuiltInCastName | `${BuiltInCastName}:${string}`;
|
|
1967
|
+
type UniqueIdTraitKind = 'uuid' | 'ulid' | 'snowflake' | 'custom';
|
|
1968
|
+
type RelationAggregateKind = 'count' | 'exists' | 'sum' | 'avg' | 'min' | 'max';
|
|
1969
|
+
interface EnumCastDefinition {
|
|
1970
|
+
readonly kind: 'enum';
|
|
1971
|
+
readonly enumObject: Readonly<Record<string, string | number>>;
|
|
1972
|
+
readonly values: readonly (string | number)[];
|
|
1973
|
+
}
|
|
1974
|
+
interface CastableDefinition {
|
|
1975
|
+
castUsing(): ModelCastDefinition;
|
|
1976
|
+
}
|
|
1977
|
+
type ModelCastDefinition = BuiltInCastString | EnumCastDefinition | CastableDefinition | {
|
|
1978
|
+
get?: (value: unknown) => unknown;
|
|
1979
|
+
set?: (value: unknown) => unknown;
|
|
1980
|
+
};
|
|
1981
|
+
type ModelAccessor = (value: unknown, entity: AnyEntity) => unknown;
|
|
1982
|
+
type ModelMutator = (value: unknown, entity?: AnyEntity) => unknown;
|
|
1983
|
+
type ModelDateSerializer = (value: Date) => unknown;
|
|
1984
|
+
type ModelCollectionFactory<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap> = (items: readonly Entity<TTable, TRelations>[]) => ModelCollection<TTable, TRelations>;
|
|
1985
|
+
type ModelPrunableDefinition<TTable extends TableDefinition = TableDefinition, TRelations extends RelationMap = RelationMap> = (query: ModelQueryBuilder<TTable, TRelations>) => unknown;
|
|
1986
|
+
interface UniqueIdTrait<TTable extends TableDefinition = TableDefinition> {
|
|
1987
|
+
readonly kind: 'uniqueIds';
|
|
1988
|
+
readonly name: string;
|
|
1989
|
+
readonly type: UniqueIdTraitKind;
|
|
1990
|
+
readonly columns?: readonly ModelAttributeKey<TTable>[];
|
|
1991
|
+
readonly generator?: () => string;
|
|
1992
|
+
}
|
|
1993
|
+
type ModelTrait<TTable extends TableDefinition = TableDefinition> = UniqueIdTrait<TTable>;
|
|
1994
|
+
interface UniqueIdRuntimeConfig<TTable extends TableDefinition = TableDefinition> {
|
|
1995
|
+
readonly usesUniqueIds: boolean;
|
|
1996
|
+
readonly columns: readonly ModelAttributeKey<TTable>[];
|
|
1997
|
+
readonly generator: () => string;
|
|
1998
|
+
readonly traitName: string;
|
|
1999
|
+
readonly traitType: UniqueIdTraitKind;
|
|
2000
|
+
}
|
|
2001
|
+
interface DefineModelOptions<TTable extends TableDefinition = TableDefinition, TScopes extends ModelScopesDefinition = EmptyScopeMap, TRelations extends RelationMap = RelationMap> {
|
|
2002
|
+
name?: string;
|
|
2003
|
+
primaryKey?: ModelAttributeKey<TTable>;
|
|
2004
|
+
connectionName?: string;
|
|
2005
|
+
morphClass?: string;
|
|
2006
|
+
with?: readonly string[];
|
|
2007
|
+
pendingAttributes?: Partial<InferInsert<TTable>>;
|
|
2008
|
+
preventLazyLoading?: boolean;
|
|
2009
|
+
preventAccessingMissingAttributes?: boolean;
|
|
2010
|
+
automaticEagerLoading?: boolean;
|
|
2011
|
+
timestamps?: boolean;
|
|
2012
|
+
createdAtColumn?: ModelAttributeKey<TTable>;
|
|
2013
|
+
updatedAtColumn?: ModelAttributeKey<TTable>;
|
|
2014
|
+
fillable?: readonly (ModelAttributeKey<TTable> | '*')[];
|
|
2015
|
+
guarded?: readonly (ModelAttributeKey<TTable> | '*')[];
|
|
2016
|
+
scopes?: TScopes;
|
|
2017
|
+
globalScopes?: ModelScopeMap<TTable>;
|
|
2018
|
+
relations?: TRelations;
|
|
2019
|
+
casts?: Record<string, ModelCastDefinition>;
|
|
2020
|
+
accessors?: Record<string, ModelAccessor>;
|
|
2021
|
+
mutators?: Record<string, ModelMutator>;
|
|
2022
|
+
hidden?: readonly string[];
|
|
2023
|
+
visible?: readonly string[];
|
|
2024
|
+
appended?: readonly string[];
|
|
2025
|
+
serializeDate?: ModelDateSerializer;
|
|
2026
|
+
collection?: ModelCollectionFactory<TTable>;
|
|
2027
|
+
prunable?: ModelPrunableDefinition<TTable>;
|
|
2028
|
+
massPrunable?: boolean;
|
|
2029
|
+
touches?: readonly string[];
|
|
2030
|
+
traits?: readonly ModelTrait<TTable>[];
|
|
2031
|
+
uniqueIds?: readonly ModelAttributeKey<TTable>[];
|
|
2032
|
+
newUniqueId?: () => string;
|
|
2033
|
+
replicationExcludes?: readonly string[];
|
|
2034
|
+
softDeletes?: boolean;
|
|
2035
|
+
deletedAtColumn?: ModelAttributeKey<TTable>;
|
|
2036
|
+
events?: Partial<Record<ModelLifecycleEventName, ModelLifecycleEventHandler | readonly ModelLifecycleEventHandler[]>>;
|
|
2037
|
+
observers?: readonly unknown[];
|
|
2038
|
+
}
|
|
2039
|
+
interface ModelDefinition<TTable extends TableDefinition = TableDefinition, TScopes extends ModelScopesDefinition = EmptyScopeMap, TRelations extends RelationMap = RelationMap> {
|
|
2040
|
+
readonly kind: 'model';
|
|
2041
|
+
readonly table: TTable;
|
|
2042
|
+
readonly name: string;
|
|
2043
|
+
readonly primaryKey: ModelAttributeKey<TTable>;
|
|
2044
|
+
readonly connectionName?: string;
|
|
2045
|
+
readonly morphClass: string;
|
|
2046
|
+
readonly with: readonly string[];
|
|
2047
|
+
readonly pendingAttributes: Partial<InferInsert<TTable>>;
|
|
2048
|
+
readonly preventLazyLoading: boolean;
|
|
2049
|
+
readonly preventAccessingMissingAttributes: boolean;
|
|
2050
|
+
readonly automaticEagerLoading: boolean;
|
|
2051
|
+
readonly timestamps: boolean;
|
|
2052
|
+
readonly createdAtColumn?: ModelAttributeKey<TTable>;
|
|
2053
|
+
readonly updatedAtColumn?: ModelAttributeKey<TTable>;
|
|
2054
|
+
readonly fillable: readonly string[];
|
|
2055
|
+
readonly hasExplicitFillable?: boolean;
|
|
2056
|
+
readonly guarded: readonly string[];
|
|
2057
|
+
readonly scopes: TScopes;
|
|
2058
|
+
readonly globalScopes: ModelScopeMap<TTable>;
|
|
2059
|
+
readonly relations: TRelations;
|
|
2060
|
+
readonly casts: Record<string, ModelCastDefinition>;
|
|
2061
|
+
readonly accessors: Record<string, ModelAccessor>;
|
|
2062
|
+
readonly mutators: Record<string, ModelMutator>;
|
|
2063
|
+
readonly hidden: readonly string[];
|
|
2064
|
+
readonly visible: readonly string[];
|
|
2065
|
+
readonly appended: readonly string[];
|
|
2066
|
+
readonly serializeDate?: ModelDateSerializer;
|
|
2067
|
+
readonly collection?: ModelCollectionFactory<TTable>;
|
|
2068
|
+
readonly prunable?: ModelPrunableDefinition<TTable>;
|
|
2069
|
+
readonly massPrunable: boolean;
|
|
2070
|
+
readonly touches: readonly string[];
|
|
2071
|
+
readonly traits: readonly ModelTrait<TTable>[];
|
|
2072
|
+
readonly uniqueIdConfig: UniqueIdRuntimeConfig<TTable> | null;
|
|
2073
|
+
readonly replicationExcludes: readonly string[];
|
|
2074
|
+
readonly softDeletes: boolean;
|
|
2075
|
+
readonly deletedAtColumn?: ModelAttributeKey<TTable>;
|
|
2076
|
+
readonly events: Partial<Record<ModelLifecycleEventName, readonly ModelLifecycleEventHandler[]>>;
|
|
2077
|
+
readonly observers: readonly unknown[];
|
|
2078
|
+
}
|
|
2079
|
+
interface ModelReference<TTable extends TableDefinition = TableDefinition, TScopes extends ModelScopesDefinition = EmptyScopeMap, TRelations extends RelationMap = RelationMap> {
|
|
2080
|
+
readonly definition: ModelDefinition<TTable, TScopes, TRelations>;
|
|
2081
|
+
}
|
|
2082
|
+
type DynamicRelationResolver = () => RelationDefinition;
|
|
2083
|
+
type ModelMorphLoadMap = Readonly<Record<string, string | readonly string[] | Readonly<Record<string, RelationConstraintDefinition>>>>;
|
|
2084
|
+
type ModelScopeArgs<TScope> = TScope extends (query: unknown, ...args: infer TArgs) => unknown ? TArgs : never;
|
|
2085
|
+
type ModelScopeMethods<TTable extends TableDefinition, TScopes extends ModelScopesDefinition, TRelations extends RelationMap = RelationMap> = {
|
|
2086
|
+
[K in keyof TScopes]: TScopes[K] extends (query: ModelQueryBuilder<TTable, TRelations>, ...args: infer TArgs) => ModelQueryBuilder<TTable, TRelations> ? (...args: TArgs) => ModelQueryBuilder<TTable, TRelations> : never;
|
|
2087
|
+
};
|
|
2088
|
+
interface ModelRepositoryLike<TTable extends TableDefinition = TableDefinition, TScopes extends ModelScopesDefinition = EmptyScopeMap, TRelations extends RelationMap = RelationMap> {
|
|
2089
|
+
readonly definition: ModelDefinition<TTable, TScopes, TRelations>;
|
|
2090
|
+
getConnection(): DatabaseContext;
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
interface FactoryEntityReference<TTable extends TableDefinition = TableDefinition> {
|
|
2094
|
+
attach(relation: string, ids: unknown, attributes?: Record<string, unknown>): Promise<void>;
|
|
2095
|
+
exists(): boolean;
|
|
2096
|
+
get(key: Extract<keyof ModelRecord<TTable>, string>): ModelRecord<TTable>[Extract<keyof ModelRecord<TTable>, string>];
|
|
2097
|
+
set(key: Extract<keyof ModelRecord<TTable>, string>, value: ModelRecord<TTable>[Extract<keyof ModelRecord<TTable>, string>]): FactoryEntityReference<TTable>;
|
|
2098
|
+
getRelation(name: string): unknown;
|
|
2099
|
+
hasRelation(name: string): boolean;
|
|
2100
|
+
setRelation(name: string, value: unknown): FactoryEntityReference<TTable>;
|
|
2101
|
+
toAttributes(): Record<string, unknown>;
|
|
2102
|
+
getRepository(): unknown;
|
|
2103
|
+
}
|
|
2104
|
+
interface FactoryModelReference<TTable extends TableDefinition = TableDefinition> {
|
|
2105
|
+
readonly definition: {
|
|
2106
|
+
table: TTable;
|
|
2107
|
+
morphClass?: string;
|
|
2108
|
+
};
|
|
2109
|
+
getRepository(): unknown;
|
|
2110
|
+
make(values?: Partial<ModelRecord<TTable>>): FactoryEntityReference<TTable>;
|
|
2111
|
+
create(values?: Partial<ModelRecord<TTable>>): Promise<FactoryEntityReference<TTable>>;
|
|
2112
|
+
getConnectionName?(): string | undefined;
|
|
2113
|
+
}
|
|
2114
|
+
interface FactoryContext<TModel extends FactoryModelReference = FactoryModelReference> {
|
|
2115
|
+
readonly sequence: number;
|
|
2116
|
+
readonly model: TModel;
|
|
2117
|
+
}
|
|
2118
|
+
type FactoryAttributes<TModel extends FactoryModelReference> = Partial<ModelRecord<TModel['definition']['table']>>;
|
|
2119
|
+
type FactoryDefinition<TModel extends FactoryModelReference> = (context: FactoryContext<TModel>) => FactoryAttributes<TModel> | Promise<FactoryAttributes<TModel>>;
|
|
2120
|
+
type FactoryStateDefinition<TModel extends FactoryModelReference> = FactoryAttributes<TModel> | ((attributes: FactoryAttributes<TModel>, context: FactoryContext<TModel>) => FactoryAttributes<TModel> | Promise<FactoryAttributes<TModel>>);
|
|
2121
|
+
type FactoryHook<TModel extends FactoryModelReference> = (entity: FactoryEntityReference<TModel['definition']['table']>, context: FactoryContext<TModel>) => void | Promise<void>;
|
|
2122
|
+
|
|
2123
|
+
type RelatedEntity = FactoryEntityReference<TableDefinition>;
|
|
2124
|
+
type FactorySource = {
|
|
2125
|
+
readonly model: Pick<FactoryModelReference, 'definition' | 'getConnectionName' | 'getRepository'>;
|
|
2126
|
+
getAmount(): number;
|
|
2127
|
+
createOne(sequence?: number, overrides?: Record<string, unknown>): Promise<RelatedEntity>;
|
|
2128
|
+
makeOne(sequence?: number, overrides?: Record<string, unknown>): Promise<RelatedEntity>;
|
|
2129
|
+
createMany(amount?: number, overrides?: Record<string, unknown>): Promise<RelatedEntity[]>;
|
|
2130
|
+
makeMany(amount?: number, overrides?: Record<string, unknown>): Promise<RelatedEntity[]>;
|
|
2131
|
+
};
|
|
2132
|
+
type ParentRelationSource = FactorySource | RelatedEntity;
|
|
2133
|
+
type AttachedRelationSource = FactorySource | RelatedEntity | readonly RelatedEntity[];
|
|
2134
|
+
declare class Factory<TModel extends FactoryModelReference = FactoryModelReference> {
|
|
2135
|
+
readonly model: TModel;
|
|
2136
|
+
private readonly definition;
|
|
2137
|
+
private readonly states;
|
|
2138
|
+
private readonly afterMakingHooks;
|
|
2139
|
+
private readonly afterCreatingHooks;
|
|
2140
|
+
private readonly recycledEntities;
|
|
2141
|
+
private readonly parentRelations;
|
|
2142
|
+
private readonly childRelations;
|
|
2143
|
+
private readonly attachedRelations;
|
|
2144
|
+
private readonly amount;
|
|
2145
|
+
constructor(model: TModel, definition: FactoryDefinition<TModel>, options?: {
|
|
2146
|
+
states?: readonly FactoryStateDefinition<TModel>[];
|
|
2147
|
+
afterMakingHooks?: readonly FactoryHook<TModel>[];
|
|
2148
|
+
afterCreatingHooks?: readonly FactoryHook<TModel>[];
|
|
2149
|
+
recycledEntities?: readonly RelatedEntity[];
|
|
2150
|
+
parentRelations?: ReadonlyArray<{
|
|
2151
|
+
relation: string;
|
|
2152
|
+
source: ParentRelationSource;
|
|
2153
|
+
}>;
|
|
2154
|
+
childRelations?: ReadonlyArray<{
|
|
2155
|
+
relation: string;
|
|
2156
|
+
factory: FactorySource;
|
|
2157
|
+
}>;
|
|
2158
|
+
attachedRelations?: ReadonlyArray<{
|
|
2159
|
+
relation: string;
|
|
2160
|
+
source: AttachedRelationSource;
|
|
2161
|
+
pivotAttributes: Record<string, unknown>;
|
|
2162
|
+
}>;
|
|
2163
|
+
amount?: number;
|
|
2164
|
+
});
|
|
2165
|
+
count(amount: number): Factory<TModel>;
|
|
2166
|
+
getAmount(): number;
|
|
2167
|
+
state(definition: FactoryStateDefinition<TModel>): Factory<TModel>;
|
|
2168
|
+
sequence(...definitions: readonly FactoryStateDefinition<TModel>[]): Factory<TModel>;
|
|
2169
|
+
afterMaking(hook: FactoryHook<TModel>): Factory<TModel>;
|
|
2170
|
+
afterCreating(hook: FactoryHook<TModel>): Factory<TModel>;
|
|
2171
|
+
recycle(source: RelatedEntity | readonly RelatedEntity[]): Factory<TModel>;
|
|
2172
|
+
for(source: ParentRelationSource, relation: string): Factory<TModel>;
|
|
2173
|
+
has(factory: FactorySource, relation: string): Factory<TModel>;
|
|
2174
|
+
hasAttached(source: AttachedRelationSource, relation: string, pivotAttributes?: Record<string, unknown>): Factory<TModel>;
|
|
2175
|
+
raw(overrides?: FactoryAttributes<TModel>): Promise<FactoryAttributes<TModel> | FactoryAttributes<TModel>[]>;
|
|
2176
|
+
make(overrides?: FactoryAttributes<TModel>): Promise<Entity<TModel['definition']['table']> | Array<Entity<TModel['definition']['table']>>>;
|
|
2177
|
+
create(overrides?: FactoryAttributes<TModel>): Promise<Entity<TModel['definition']['table']> | Array<Entity<TModel['definition']['table']>>>;
|
|
2178
|
+
makeOne(sequence?: number, overrides?: FactoryAttributes<TModel>): Promise<Entity<TModel['definition']['table']>>;
|
|
2179
|
+
createOne(sequence?: number, overrides?: FactoryAttributes<TModel>): Promise<Entity<TModel['definition']['table']>>;
|
|
2180
|
+
makeMany(amount?: number, overrides?: FactoryAttributes<TModel>): Promise<Array<Entity<TModel['definition']['table']>>>;
|
|
2181
|
+
createMany(amount?: number, overrides?: FactoryAttributes<TModel>): Promise<Array<Entity<TModel['definition']['table']>>>;
|
|
2182
|
+
private clone;
|
|
2183
|
+
private resolveAttributes;
|
|
2184
|
+
private runHooks;
|
|
2185
|
+
private makeContext;
|
|
2186
|
+
private getRepository;
|
|
2187
|
+
private getRelationDefinition;
|
|
2188
|
+
private getPreparedRelationNames;
|
|
2189
|
+
private resolveSingleSource;
|
|
2190
|
+
private resolveManySource;
|
|
2191
|
+
private takeRecycledEntities;
|
|
2192
|
+
private applyParentRelations;
|
|
2193
|
+
private applyChildRelations;
|
|
2194
|
+
private applyAttachedRelations;
|
|
2195
|
+
private makeChildOverrides;
|
|
2196
|
+
private makeMorphChildOverrides;
|
|
2197
|
+
private attachPivotAccessor;
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
declare class FactoryService {
|
|
2201
|
+
private readonly factories;
|
|
2202
|
+
register<TModel extends FactoryModelReference>(name: string, factory: Factory<TModel>): this;
|
|
2203
|
+
get(name: string): Factory<FactoryModelReference> | undefined;
|
|
2204
|
+
has(name: string): boolean;
|
|
2205
|
+
list(): readonly Factory<FactoryModelReference>[];
|
|
2206
|
+
clear(): void;
|
|
2207
|
+
}
|
|
2208
|
+
declare function createFactoryService(): FactoryService;
|
|
2209
|
+
|
|
2210
|
+
type ColumnShapeInput$1 = Record<string, ColumnInput>;
|
|
2211
|
+
type WithColumn<TColumns extends ColumnShapeInput$1, TColumnName extends string, TColumn extends ColumnInput> = TColumns & {
|
|
2212
|
+
[K in TColumnName]: TColumn;
|
|
2213
|
+
};
|
|
2214
|
+
type TimestampColumn = ReturnType<typeof column.timestamp>;
|
|
2215
|
+
type NullableTimestampColumn = ReturnType<ReturnType<typeof column.timestamp>['nullable']>;
|
|
2216
|
+
type StringColumn = ReturnType<typeof column.string>;
|
|
2217
|
+
type NullableStringColumn = ReturnType<ReturnType<typeof column.string>['nullable']>;
|
|
2218
|
+
type WithTimestamps<TColumns extends ColumnShapeInput$1> = TColumns & {
|
|
2219
|
+
created_at: TimestampColumn;
|
|
2220
|
+
updated_at: TimestampColumn;
|
|
2221
|
+
};
|
|
2222
|
+
type WithSoftDeletes<TColumns extends ColumnShapeInput$1, TColumnName extends string> = TColumns & {
|
|
2223
|
+
[K in TColumnName]: NullableTimestampColumn;
|
|
2224
|
+
};
|
|
2225
|
+
type WithMorphColumns<TColumns extends ColumnShapeInput$1, TMorphName extends string, TIdColumn extends AnyColumnBuilder> = TColumns & {
|
|
2226
|
+
[K in `${TMorphName}_type`]: StringColumn;
|
|
2227
|
+
} & {
|
|
2228
|
+
[K in `${TMorphName}_id`]: TIdColumn;
|
|
2229
|
+
};
|
|
2230
|
+
type WithNullableMorphColumns<TColumns extends ColumnShapeInput$1, TMorphName extends string, TIdColumn extends AnyColumnBuilder> = TColumns & {
|
|
2231
|
+
[K in `${TMorphName}_type`]: NullableStringColumn;
|
|
2232
|
+
} & {
|
|
2233
|
+
[K in `${TMorphName}_id`]: ReturnType<TIdColumn['nullable']>;
|
|
2234
|
+
};
|
|
2235
|
+
type ColumnReference = {
|
|
2236
|
+
builder: AnyColumnBuilder;
|
|
2237
|
+
};
|
|
2238
|
+
declare class TableCreateColumnBuilder<TName extends string, TColumns extends ColumnShapeInput$1> {
|
|
2239
|
+
protected readonly root: TableDefinitionBuilder<TName, TColumns>;
|
|
2240
|
+
protected readonly builderRef: ColumnReference;
|
|
2241
|
+
constructor(root: TableDefinitionBuilder<TName, TColumns>, builderRef: ColumnReference);
|
|
2242
|
+
build(): BoundTableDefinition<TName, TColumns>;
|
|
2243
|
+
notNull(): this;
|
|
2244
|
+
nullable(): this;
|
|
2245
|
+
default(value: unknown): this;
|
|
2246
|
+
defaultNow(): this;
|
|
2247
|
+
generated(): this;
|
|
2248
|
+
primaryKey(): this;
|
|
2249
|
+
unique(): this;
|
|
2250
|
+
unique(columns: readonly string[], name?: string): TableDefinitionBuilder<TName, TColumns>;
|
|
2251
|
+
foreign(columnName: string): TableCreateForeignKeyBuilder<TName, TColumns>;
|
|
2252
|
+
foreignId<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.bigInteger>>>;
|
|
2253
|
+
foreignUuid<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.uuid>>>;
|
|
2254
|
+
foreignUlid<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.ulid>>>;
|
|
2255
|
+
foreignSnowflake<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.snowflake>>>;
|
|
2256
|
+
id<TColumnName extends string = 'id'>(columnName?: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.id>>>;
|
|
2257
|
+
autoIncrementId<TColumnName extends string = 'id'>(columnName?: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.autoIncrementId>>>;
|
|
2258
|
+
integer<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.integer>>>;
|
|
2259
|
+
bigInteger<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.bigInteger>>>;
|
|
2260
|
+
string<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.string>>>;
|
|
2261
|
+
text<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.text>>>;
|
|
2262
|
+
boolean<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.boolean>>>;
|
|
2263
|
+
real<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.real>>>;
|
|
2264
|
+
decimal<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.decimal>>>;
|
|
2265
|
+
date<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.date>>>;
|
|
2266
|
+
datetime<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.datetime>>>;
|
|
2267
|
+
timestamp<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.timestamp>>>;
|
|
2268
|
+
json<TColumnName extends string, TValue = unknown>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.json<TValue>>>>;
|
|
2269
|
+
blob<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.blob>>>;
|
|
2270
|
+
uuid<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.uuid>>>;
|
|
2271
|
+
ulid<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.ulid>>>;
|
|
2272
|
+
snowflake<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.snowflake>>>;
|
|
2273
|
+
vector<TColumnName extends string>(columnName: TColumnName, options: {
|
|
2274
|
+
dimensions: number;
|
|
2275
|
+
}): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.vector>>>;
|
|
2276
|
+
enum<const TValues extends readonly string[], TColumnName extends string>(columnName: TColumnName, values: TValues): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.enum<TValues>>>>;
|
|
2277
|
+
index(columns: readonly string[], name?: string): TableDefinitionBuilder<TName, TColumns>;
|
|
2278
|
+
timestamps(): TableDefinitionBuilder<TName, WithTimestamps<TColumns>>;
|
|
2279
|
+
softDeletes<TColumnName extends string = 'deleted_at'>(columnName?: TColumnName): TableDefinitionBuilder<TName, WithSoftDeletes<TColumns, TColumnName>>;
|
|
2280
|
+
morphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.bigInteger>>>;
|
|
2281
|
+
nullableMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.bigInteger>>>;
|
|
2282
|
+
uuidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.uuid>>>;
|
|
2283
|
+
nullableUuidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.uuid>>>;
|
|
2284
|
+
ulidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.ulid>>>;
|
|
2285
|
+
nullableUlidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.ulid>>>;
|
|
2286
|
+
snowflakeMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.snowflake>>>;
|
|
2287
|
+
nullableSnowflakeMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.snowflake>>>;
|
|
2288
|
+
}
|
|
2289
|
+
declare class TableCreateForeignIdBuilder<TName extends string, TColumns extends ColumnShapeInput$1> extends TableCreateColumnBuilder<TName, TColumns> {
|
|
2290
|
+
private readonly columnName;
|
|
2291
|
+
private referenceTable?;
|
|
2292
|
+
private referenceColumn;
|
|
2293
|
+
private onDeleteAction?;
|
|
2294
|
+
private onUpdateAction?;
|
|
2295
|
+
constructor(root: TableDefinitionBuilder<TName, TColumns>, builderRef: ColumnReference, columnName: string);
|
|
2296
|
+
references(columnName: string): this;
|
|
2297
|
+
on(table: string): this;
|
|
2298
|
+
constrained(table?: string, columnName?: string): this;
|
|
2299
|
+
onDelete(action: NonNullable<ForeignKeyReference['onDelete']>): this;
|
|
2300
|
+
onUpdate(action: NonNullable<ForeignKeyReference['onUpdate']>): this;
|
|
2301
|
+
cascadeOnDelete(): this;
|
|
2302
|
+
restrictOnDelete(): this;
|
|
2303
|
+
nullOnDelete(): this;
|
|
2304
|
+
noActionOnDelete(): this;
|
|
2305
|
+
cascadeOnUpdate(): this;
|
|
2306
|
+
restrictOnUpdate(): this;
|
|
2307
|
+
nullOnUpdate(): this;
|
|
2308
|
+
noActionOnUpdate(): this;
|
|
2309
|
+
private applyReference;
|
|
2310
|
+
}
|
|
2311
|
+
declare class TableCreateForeignKeyBuilder<TName extends string, TColumns extends ColumnShapeInput$1> {
|
|
2312
|
+
private readonly root;
|
|
2313
|
+
private readonly builderRef;
|
|
2314
|
+
private readonly columnName;
|
|
2315
|
+
private referenceTable?;
|
|
2316
|
+
private referenceColumn;
|
|
2317
|
+
private onDeleteAction?;
|
|
2318
|
+
private onUpdateAction?;
|
|
2319
|
+
constructor(root: TableDefinitionBuilder<TName, TColumns>, builderRef: ColumnReference, columnName: string);
|
|
2320
|
+
references(columnName: string): this;
|
|
2321
|
+
on(table: string): this;
|
|
2322
|
+
constrained(table?: string, columnName?: string): this;
|
|
2323
|
+
onDelete(action: NonNullable<ForeignKeyReference['onDelete']>): this;
|
|
2324
|
+
onUpdate(action: NonNullable<ForeignKeyReference['onUpdate']>): this;
|
|
2325
|
+
cascadeOnDelete(): this;
|
|
2326
|
+
restrictOnDelete(): this;
|
|
2327
|
+
nullOnDelete(): this;
|
|
2328
|
+
noActionOnDelete(): this;
|
|
2329
|
+
cascadeOnUpdate(): this;
|
|
2330
|
+
restrictOnUpdate(): this;
|
|
2331
|
+
nullOnUpdate(): this;
|
|
2332
|
+
noActionOnUpdate(): this;
|
|
2333
|
+
build(): BoundTableDefinition<TName, TColumns>;
|
|
2334
|
+
private applyReference;
|
|
2335
|
+
}
|
|
2336
|
+
declare class TableDefinitionBuilder<TName extends string, TColumns extends ColumnShapeInput$1 = Record<never, never>> {
|
|
2337
|
+
readonly tableName: TName;
|
|
2338
|
+
private readonly columns;
|
|
2339
|
+
private readonly columnRefs;
|
|
2340
|
+
private readonly indexes;
|
|
2341
|
+
constructor(tableName: TName);
|
|
2342
|
+
build(): BoundTableDefinition<TName, TColumns>;
|
|
2343
|
+
id<TColumnName extends string = 'id'>(columnName?: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.id>>>;
|
|
2344
|
+
autoIncrementId<TColumnName extends string = 'id'>(columnName?: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.autoIncrementId>>>;
|
|
2345
|
+
integer<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.integer>>>;
|
|
2346
|
+
bigInteger<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.bigInteger>>>;
|
|
2347
|
+
foreignId<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.bigInteger>>>;
|
|
2348
|
+
foreignUuid<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.uuid>>>;
|
|
2349
|
+
foreignUlid<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.ulid>>>;
|
|
2350
|
+
foreignSnowflake<TColumnName extends string>(columnName: TColumnName): TableCreateForeignIdBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.snowflake>>>;
|
|
2351
|
+
string<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.string>>>;
|
|
2352
|
+
text<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.text>>>;
|
|
2353
|
+
boolean<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.boolean>>>;
|
|
2354
|
+
real<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.real>>>;
|
|
2355
|
+
decimal<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.decimal>>>;
|
|
2356
|
+
date<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.date>>>;
|
|
2357
|
+
datetime<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.datetime>>>;
|
|
2358
|
+
timestamp<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.timestamp>>>;
|
|
2359
|
+
json<TColumnName extends string, TValue = unknown>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.json<TValue>>>>;
|
|
2360
|
+
blob<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.blob>>>;
|
|
2361
|
+
uuid<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.uuid>>>;
|
|
2362
|
+
ulid<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.ulid>>>;
|
|
2363
|
+
snowflake<TColumnName extends string>(columnName: TColumnName): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.snowflake>>>;
|
|
2364
|
+
vector<TColumnName extends string>(columnName: TColumnName, options: {
|
|
2365
|
+
dimensions: number;
|
|
2366
|
+
}): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.vector>>>;
|
|
2367
|
+
enum<const TValues extends readonly string[], TColumnName extends string>(columnName: TColumnName, values: TValues): TableCreateColumnBuilder<TName, WithColumn<TColumns, TColumnName, ReturnType<typeof column.enum<TValues>>>>;
|
|
2368
|
+
index(columns: readonly string[], name?: string): this;
|
|
2369
|
+
unique(columns: readonly string[], name?: string): this;
|
|
2370
|
+
foreign(columnName: string): TableCreateForeignKeyBuilder<TName, TColumns>;
|
|
2371
|
+
timestamps(): TableDefinitionBuilder<TName, WithTimestamps<TColumns>>;
|
|
2372
|
+
softDeletes<TColumnName extends string = 'deleted_at'>(columnName?: TColumnName): TableDefinitionBuilder<TName, WithSoftDeletes<TColumns, TColumnName>>;
|
|
2373
|
+
morphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.bigInteger>>>;
|
|
2374
|
+
nullableMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.bigInteger>>>;
|
|
2375
|
+
uuidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.uuid>>>;
|
|
2376
|
+
nullableUuidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.uuid>>>;
|
|
2377
|
+
ulidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.ulid>>>;
|
|
2378
|
+
nullableUlidMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.ulid>>>;
|
|
2379
|
+
snowflakeMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithMorphColumns<TColumns, TMorphName, ReturnType<typeof column.snowflake>>>;
|
|
2380
|
+
nullableSnowflakeMorphs<TMorphName extends string>(name: TMorphName, indexName?: string): TableDefinitionBuilder<TName, WithNullableMorphColumns<TColumns, TMorphName, ReturnType<typeof column.snowflake>>>;
|
|
2381
|
+
private column;
|
|
2382
|
+
private foreignColumn;
|
|
2383
|
+
private applyMorphColumns;
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
interface AddColumnMutationOperation {
|
|
2387
|
+
kind: 'addColumn';
|
|
2388
|
+
columnName: string;
|
|
2389
|
+
column: AnyColumnBuilder;
|
|
2390
|
+
}
|
|
2391
|
+
interface AlterColumnMutationOperation {
|
|
2392
|
+
kind: 'alterColumn';
|
|
2393
|
+
columnName: string;
|
|
2394
|
+
column: AnyColumnBuilder;
|
|
2395
|
+
}
|
|
2396
|
+
interface DropColumnMutationOperation {
|
|
2397
|
+
kind: 'dropColumn';
|
|
2398
|
+
columnName: string;
|
|
2399
|
+
}
|
|
2400
|
+
interface RenameColumnMutationOperation {
|
|
2401
|
+
kind: 'renameColumn';
|
|
2402
|
+
fromColumnName: string;
|
|
2403
|
+
toColumnName: string;
|
|
2404
|
+
}
|
|
2405
|
+
interface CreateIndexMutationOperation {
|
|
2406
|
+
kind: 'createIndex';
|
|
2407
|
+
index: TableIndexDefinition;
|
|
2408
|
+
}
|
|
2409
|
+
interface DropIndexMutationOperation {
|
|
2410
|
+
kind: 'dropIndex';
|
|
2411
|
+
indexName: string;
|
|
2412
|
+
}
|
|
2413
|
+
interface RenameIndexMutationOperation {
|
|
2414
|
+
kind: 'renameIndex';
|
|
2415
|
+
fromIndexName: string;
|
|
2416
|
+
toIndexName: string;
|
|
2417
|
+
}
|
|
2418
|
+
interface CreateForeignKeyMutationOperation {
|
|
2419
|
+
kind: 'createForeignKey';
|
|
2420
|
+
columnName: string;
|
|
2421
|
+
reference: ForeignKeyReference;
|
|
2422
|
+
constraintName?: string;
|
|
2423
|
+
}
|
|
2424
|
+
interface DropForeignKeyMutationOperation {
|
|
2425
|
+
kind: 'dropForeignKey';
|
|
2426
|
+
constraintName: string;
|
|
2427
|
+
}
|
|
2428
|
+
interface MutableColumnMutationOperation {
|
|
2429
|
+
kind: ColumnMutationMode;
|
|
2430
|
+
columnName: string;
|
|
2431
|
+
column: AnyColumnBuilder;
|
|
2432
|
+
}
|
|
2433
|
+
type TableMutationOperation = AddColumnMutationOperation | AlterColumnMutationOperation | DropColumnMutationOperation | RenameColumnMutationOperation | CreateIndexMutationOperation | DropIndexMutationOperation | RenameIndexMutationOperation | CreateForeignKeyMutationOperation | DropForeignKeyMutationOperation;
|
|
2434
|
+
type ColumnMutationMode = 'addColumn' | 'alterColumn';
|
|
2435
|
+
declare class TableForeignKeyBuilder {
|
|
2436
|
+
private readonly operation;
|
|
2437
|
+
constructor(operation: CreateForeignKeyMutationOperation);
|
|
2438
|
+
references(columnName: string): this;
|
|
2439
|
+
on(table: string): this;
|
|
2440
|
+
constrained(table?: string, columnName?: string): this;
|
|
2441
|
+
onDelete(action: NonNullable<ForeignKeyReference['onDelete']>): this;
|
|
2442
|
+
onUpdate(action: NonNullable<ForeignKeyReference['onUpdate']>): this;
|
|
2443
|
+
cascadeOnDelete(): this;
|
|
2444
|
+
restrictOnDelete(): this;
|
|
2445
|
+
nullOnDelete(): this;
|
|
2446
|
+
noActionOnDelete(): this;
|
|
2447
|
+
cascadeOnUpdate(): this;
|
|
2448
|
+
restrictOnUpdate(): this;
|
|
2449
|
+
nullOnUpdate(): this;
|
|
2450
|
+
noActionOnUpdate(): this;
|
|
2451
|
+
}
|
|
2452
|
+
declare class TableColumnMutationBuilder {
|
|
2453
|
+
protected readonly root: TableMutationBuilder;
|
|
2454
|
+
protected readonly operation: MutableColumnMutationOperation;
|
|
2455
|
+
constructor(root: TableMutationBuilder, operation: MutableColumnMutationOperation);
|
|
2456
|
+
notNull(): this;
|
|
2457
|
+
nullable(): this;
|
|
2458
|
+
default(value: unknown): this;
|
|
2459
|
+
defaultNow(): this;
|
|
2460
|
+
generated(): this;
|
|
2461
|
+
primaryKey(): this;
|
|
2462
|
+
unique(): this;
|
|
2463
|
+
foreignId(columnName: string): TableForeignIdMutationBuilder;
|
|
2464
|
+
foreignUuid(columnName: string): TableForeignIdMutationBuilder;
|
|
2465
|
+
foreignUlid(columnName: string): TableForeignIdMutationBuilder;
|
|
2466
|
+
foreignSnowflake(columnName: string): TableForeignIdMutationBuilder;
|
|
2467
|
+
change(): this;
|
|
2468
|
+
morphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2469
|
+
nullableMorphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2470
|
+
uuidMorphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2471
|
+
nullableUuidMorphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2472
|
+
ulidMorphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2473
|
+
nullableUlidMorphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2474
|
+
snowflakeMorphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2475
|
+
nullableSnowflakeMorphs(name: string, indexName?: string): TableMutationBuilder;
|
|
2476
|
+
}
|
|
2477
|
+
declare class TableForeignIdMutationBuilder extends TableColumnMutationBuilder {
|
|
2478
|
+
private readonly operations;
|
|
2479
|
+
private readonly columnName;
|
|
2480
|
+
private foreignOperation?;
|
|
2481
|
+
private referenceTable?;
|
|
2482
|
+
private referenceColumn;
|
|
2483
|
+
private onDeleteAction?;
|
|
2484
|
+
private onUpdateAction?;
|
|
2485
|
+
constructor(root: TableMutationBuilder, operation: MutableColumnMutationOperation, operations: TableMutationOperation[], columnName: string);
|
|
2486
|
+
references(columnName: string): this;
|
|
2487
|
+
on(table: string): this;
|
|
2488
|
+
constrained(table?: string, columnName?: string): this;
|
|
2489
|
+
onDelete(action: NonNullable<ForeignKeyReference['onDelete']>): this;
|
|
2490
|
+
onUpdate(action: NonNullable<ForeignKeyReference['onUpdate']>): this;
|
|
2491
|
+
cascadeOnDelete(): this;
|
|
2492
|
+
restrictOnDelete(): this;
|
|
2493
|
+
nullOnDelete(): this;
|
|
2494
|
+
noActionOnDelete(): this;
|
|
2495
|
+
cascadeOnUpdate(): this;
|
|
2496
|
+
restrictOnUpdate(): this;
|
|
2497
|
+
nullOnUpdate(): this;
|
|
2498
|
+
noActionOnUpdate(): this;
|
|
2499
|
+
private applyForeignKey;
|
|
2500
|
+
private ensureForeignOperation;
|
|
2501
|
+
}
|
|
2502
|
+
declare class TableMutationBuilder {
|
|
2503
|
+
readonly table: string;
|
|
2504
|
+
private readonly operations;
|
|
2505
|
+
constructor(table: string);
|
|
2506
|
+
getOperations(): readonly TableMutationOperation[];
|
|
2507
|
+
id(columnName: string): TableColumnMutationBuilder;
|
|
2508
|
+
autoIncrementId(columnName: string): TableColumnMutationBuilder;
|
|
2509
|
+
integer(columnName: string): TableColumnMutationBuilder;
|
|
2510
|
+
bigInteger(columnName: string): TableColumnMutationBuilder;
|
|
2511
|
+
foreignId(columnName: string): TableForeignIdMutationBuilder;
|
|
2512
|
+
foreignUuid(columnName: string): TableForeignIdMutationBuilder;
|
|
2513
|
+
foreignUlid(columnName: string): TableForeignIdMutationBuilder;
|
|
2514
|
+
foreignSnowflake(columnName: string): TableForeignIdMutationBuilder;
|
|
2515
|
+
string(columnName: string): TableColumnMutationBuilder;
|
|
2516
|
+
text(columnName: string): TableColumnMutationBuilder;
|
|
2517
|
+
boolean(columnName: string): TableColumnMutationBuilder;
|
|
2518
|
+
real(columnName: string): TableColumnMutationBuilder;
|
|
2519
|
+
decimal(columnName: string): TableColumnMutationBuilder;
|
|
2520
|
+
date(columnName: string): TableColumnMutationBuilder;
|
|
2521
|
+
datetime(columnName: string): TableColumnMutationBuilder;
|
|
2522
|
+
timestamp(columnName: string): TableColumnMutationBuilder;
|
|
2523
|
+
json<TValue = unknown>(columnName: string): TableColumnMutationBuilder;
|
|
2524
|
+
blob(columnName: string): TableColumnMutationBuilder;
|
|
2525
|
+
uuid(columnName: string): TableColumnMutationBuilder;
|
|
2526
|
+
ulid(columnName: string): TableColumnMutationBuilder;
|
|
2527
|
+
snowflake(columnName: string): TableColumnMutationBuilder;
|
|
2528
|
+
vector(columnName: string, options: {
|
|
2529
|
+
dimensions: number;
|
|
2530
|
+
}): TableColumnMutationBuilder;
|
|
2531
|
+
enum<const TValues extends readonly string[]>(columnName: string, values: TValues): TableColumnMutationBuilder;
|
|
2532
|
+
dropColumn(columnName: string): void;
|
|
2533
|
+
renameColumn(fromColumnName: string, toColumnName: string): void;
|
|
2534
|
+
index(columns: readonly string[], name?: string): void;
|
|
2535
|
+
unique(columns: readonly string[], name?: string): void;
|
|
2536
|
+
dropIndex(indexName: string): void;
|
|
2537
|
+
renameIndex(fromIndexName: string, toIndexName: string): void;
|
|
2538
|
+
foreign(columnName: string, constraintName?: string): TableForeignKeyBuilder;
|
|
2539
|
+
dropForeign(indexName: string): void;
|
|
2540
|
+
morphs(name: string, indexName?: string): this;
|
|
2541
|
+
nullableMorphs(name: string, indexName?: string): this;
|
|
2542
|
+
uuidMorphs(name: string, indexName?: string): this;
|
|
2543
|
+
nullableUuidMorphs(name: string, indexName?: string): this;
|
|
2544
|
+
ulidMorphs(name: string, indexName?: string): this;
|
|
2545
|
+
nullableUlidMorphs(name: string, indexName?: string): this;
|
|
2546
|
+
snowflakeMorphs(name: string, indexName?: string): this;
|
|
2547
|
+
nullableSnowflakeMorphs(name: string, indexName?: string): this;
|
|
2548
|
+
private columnMutation;
|
|
2549
|
+
private foreignColumn;
|
|
2550
|
+
private applyMorphColumns;
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
interface IntrospectedColumn {
|
|
2554
|
+
name: string;
|
|
2555
|
+
type: string;
|
|
2556
|
+
logicalType: LogicalColumnKind | null;
|
|
2557
|
+
notNull: boolean;
|
|
2558
|
+
defaultValue: string | null;
|
|
2559
|
+
primaryKey: boolean;
|
|
2560
|
+
}
|
|
2561
|
+
interface IntrospectedIndex {
|
|
2562
|
+
name: string;
|
|
2563
|
+
unique: boolean;
|
|
2564
|
+
columns: string[];
|
|
2565
|
+
}
|
|
2566
|
+
interface IntrospectedForeignKey {
|
|
2567
|
+
table: string;
|
|
2568
|
+
from: string;
|
|
2569
|
+
to: string;
|
|
2570
|
+
onUpdate: string;
|
|
2571
|
+
onDelete: string;
|
|
2572
|
+
}
|
|
2573
|
+
interface SchemaSyncPlan {
|
|
2574
|
+
readonly mode: 'create_missing_only';
|
|
2575
|
+
readonly tablesToCreate: readonly string[];
|
|
2576
|
+
readonly existingTables: readonly string[];
|
|
2577
|
+
readonly destructiveChanges: false;
|
|
2578
|
+
}
|
|
2579
|
+
declare class SchemaService {
|
|
2580
|
+
private readonly connection;
|
|
2581
|
+
constructor(connection: DatabaseContext);
|
|
2582
|
+
getDialectName(): string;
|
|
2583
|
+
register<TTable extends TableDefinition>(table: TTable): TTable;
|
|
2584
|
+
createTable<TName extends string>(tableName: TName, callback: (table: TableDefinitionBuilder<TName>) => void | Promise<void>): Promise<void>;
|
|
2585
|
+
dropTable(tableName: string): Promise<void>;
|
|
2586
|
+
renameTable(fromTableName: string, toTableName: string): Promise<void>;
|
|
2587
|
+
table(tableName: string, callback: (table: TableMutationBuilder) => void | Promise<void>): Promise<void>;
|
|
2588
|
+
enableForeignKeyConstraints(): Promise<void>;
|
|
2589
|
+
disableForeignKeyConstraints(): Promise<void>;
|
|
2590
|
+
withoutForeignKeyConstraints<TResult>(callback: () => TResult | Promise<TResult>): Promise<TResult>;
|
|
2591
|
+
sync(tables?: readonly TableDefinition[]): Promise<void>;
|
|
2592
|
+
previewSync(tables?: readonly TableDefinition[]): Promise<SchemaSyncPlan>;
|
|
2593
|
+
hasTable(name: string): Promise<boolean>;
|
|
2594
|
+
getTables(): Promise<string[]>;
|
|
2595
|
+
getColumns(tableName: string): Promise<IntrospectedColumn[]>;
|
|
2596
|
+
getIndexes(tableName: string): Promise<IntrospectedIndex[]>;
|
|
2597
|
+
getForeignKeys(tableName: string): Promise<IntrospectedForeignKey[]>;
|
|
2598
|
+
private createCompiler;
|
|
2599
|
+
private execute;
|
|
2600
|
+
private isSqlite;
|
|
2601
|
+
private isPostgres;
|
|
2602
|
+
private isMySQL;
|
|
2603
|
+
private parsePostgresIndex;
|
|
2604
|
+
private unsupportedIntrospectionError;
|
|
2605
|
+
private assertAlterCapability;
|
|
2606
|
+
private assertForeignKeyCapability;
|
|
2607
|
+
private resolveColumnDefinition;
|
|
2608
|
+
private createDefinedTable;
|
|
2609
|
+
private executeTableMutation;
|
|
2610
|
+
private buildTableDefinition;
|
|
2611
|
+
private updateRegisteredTable;
|
|
2612
|
+
private renameRegisteredTable;
|
|
2613
|
+
private withColumn;
|
|
2614
|
+
private withAlteredColumn;
|
|
2615
|
+
private withoutColumn;
|
|
2616
|
+
private renameRegisteredColumn;
|
|
2617
|
+
private withIndex;
|
|
2618
|
+
private withoutIndex;
|
|
2619
|
+
private renameRegisteredIndex;
|
|
2620
|
+
private withForeignKey;
|
|
2621
|
+
private withoutForeignKey;
|
|
2622
|
+
private resolveIndexName;
|
|
2623
|
+
private resolveForeignKeyName;
|
|
2624
|
+
private createForeignKeyConstraintStatement;
|
|
2625
|
+
private inferLogicalColumnType;
|
|
2626
|
+
}
|
|
2627
|
+
declare function createSchemaService(connection: DatabaseContext): SchemaService;
|
|
2628
|
+
|
|
2629
|
+
interface MigrationContext {
|
|
2630
|
+
readonly db: DatabaseContext;
|
|
2631
|
+
readonly schema: SchemaService;
|
|
2632
|
+
}
|
|
2633
|
+
interface MigrationDefinition {
|
|
2634
|
+
readonly name?: string;
|
|
2635
|
+
up(context: MigrationContext): unknown | Promise<unknown>;
|
|
2636
|
+
down?(context: MigrationContext): unknown | Promise<unknown>;
|
|
2637
|
+
}
|
|
2638
|
+
interface MigrationStatus {
|
|
2639
|
+
readonly name: string;
|
|
2640
|
+
readonly status: 'pending' | 'ran';
|
|
2641
|
+
readonly batch?: number;
|
|
2642
|
+
readonly migratedAt?: Date;
|
|
2643
|
+
}
|
|
2644
|
+
interface MigrationSquashPlan {
|
|
2645
|
+
readonly archiveName: string;
|
|
2646
|
+
readonly includedMigrations: readonly string[];
|
|
2647
|
+
readonly fromBatch?: number;
|
|
2648
|
+
readonly toBatch?: number;
|
|
2649
|
+
readonly ranCount: number;
|
|
2650
|
+
}
|
|
2651
|
+
interface MigrateOptions {
|
|
2652
|
+
step?: number;
|
|
2653
|
+
}
|
|
2654
|
+
interface RollbackOptions {
|
|
2655
|
+
step?: number;
|
|
2656
|
+
batch?: number;
|
|
2657
|
+
}
|
|
2658
|
+
interface MigrationExecutionPolicy {
|
|
2659
|
+
readonly mode: 'exclusive';
|
|
2660
|
+
readonly scope: 'adapter';
|
|
2661
|
+
readonly allowsConcurrentMigrations: false;
|
|
2662
|
+
}
|
|
2663
|
+
type MigrationTemplateKind = 'blank' | 'create_table' | 'alter_table' | 'drop_table';
|
|
2664
|
+
interface MigrationTemplateOptions {
|
|
2665
|
+
date?: Date;
|
|
2666
|
+
kind?: MigrationTemplateKind;
|
|
2667
|
+
tableName?: string;
|
|
2668
|
+
}
|
|
2669
|
+
interface GeneratedMigrationTemplate {
|
|
2670
|
+
readonly fileName: string;
|
|
2671
|
+
readonly migrationName: string;
|
|
2672
|
+
readonly kind: MigrationTemplateKind;
|
|
2673
|
+
readonly tableName?: string;
|
|
2674
|
+
readonly contents: string;
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
type RegisteredMigrationDefinition = MigrationDefinition & {
|
|
2678
|
+
readonly name: string;
|
|
2679
|
+
};
|
|
2680
|
+
declare class MigrationService {
|
|
2681
|
+
private readonly connection;
|
|
2682
|
+
private readonly migrations;
|
|
2683
|
+
constructor(connection: DatabaseContext, migrations?: readonly MigrationDefinition[]);
|
|
2684
|
+
register(migration: MigrationDefinition): this;
|
|
2685
|
+
getMigrations(): readonly RegisteredMigrationDefinition[];
|
|
2686
|
+
getMigration(name: string): RegisteredMigrationDefinition | undefined;
|
|
2687
|
+
hasRan(name: string): Promise<boolean>;
|
|
2688
|
+
status(): Promise<MigrationStatus[]>;
|
|
2689
|
+
planSquash(archiveName?: string): Promise<MigrationSquashPlan>;
|
|
2690
|
+
migrate(options?: MigrateOptions): Promise<RegisteredMigrationDefinition[]>;
|
|
2691
|
+
rollback(options?: RollbackOptions): Promise<RegisteredMigrationDefinition[]>;
|
|
2692
|
+
getExecutionPolicy(): MigrationExecutionPolicy;
|
|
2693
|
+
private ensureTrackingTable;
|
|
2694
|
+
private getRanRecords;
|
|
2695
|
+
private createContext;
|
|
2696
|
+
private normalizeMigratedAt;
|
|
2697
|
+
private createMigrationLog;
|
|
2698
|
+
private runExclusively;
|
|
2699
|
+
}
|
|
2700
|
+
declare function createMigrationService(connection: DatabaseContext, migrations?: readonly MigrationDefinition[]): MigrationService;
|
|
2701
|
+
|
|
2702
|
+
declare class ModelEventService {
|
|
2703
|
+
areEventsMuted(): boolean;
|
|
2704
|
+
withoutEvents<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
2705
|
+
areGuardsDisabled(): boolean;
|
|
2706
|
+
withoutGuards<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
2707
|
+
}
|
|
2708
|
+
declare function createModelEventService(): ModelEventService;
|
|
2709
|
+
|
|
2710
|
+
type RuntimeState = {
|
|
2711
|
+
savepointCounter: number;
|
|
2712
|
+
scheduler: QueryScheduler;
|
|
2713
|
+
};
|
|
2714
|
+
type ScopeState = {
|
|
2715
|
+
kind: TransactionScopeKind;
|
|
2716
|
+
depth: number;
|
|
2717
|
+
savepointName?: string;
|
|
2718
|
+
};
|
|
2719
|
+
type TransactionCallbackState = {
|
|
2720
|
+
afterCommit: TransactionCallback[];
|
|
2721
|
+
afterRollback: TransactionCallback[];
|
|
2722
|
+
};
|
|
2723
|
+
type ContextInternals = {
|
|
2724
|
+
connectionName: string;
|
|
2725
|
+
schemaName?: string;
|
|
2726
|
+
adapter: DriverAdapter;
|
|
2727
|
+
dialect: Dialect;
|
|
2728
|
+
driver: DatabaseDriverName;
|
|
2729
|
+
logger?: DatabaseLogger;
|
|
2730
|
+
security: SecurityPolicy;
|
|
2731
|
+
concurrency: ConcurrencyOptions;
|
|
2732
|
+
schemaRegistry: SchemaRegistry;
|
|
2733
|
+
modelRegistry: ModelRegistry;
|
|
2734
|
+
runtime: RuntimeState;
|
|
2735
|
+
scope: ScopeState;
|
|
2736
|
+
transactionCallbacks?: TransactionCallbackState;
|
|
2737
|
+
};
|
|
2738
|
+
declare class DatabaseContext {
|
|
2739
|
+
private readonly _connectionName;
|
|
2740
|
+
private readonly _schemaName?;
|
|
2741
|
+
private readonly _adapter;
|
|
2742
|
+
private readonly _dialect;
|
|
2743
|
+
private readonly _driver;
|
|
2744
|
+
private readonly _logger?;
|
|
2745
|
+
private readonly _security;
|
|
2746
|
+
private readonly _concurrency;
|
|
2747
|
+
private readonly _schemaRegistry;
|
|
2748
|
+
private readonly _modelRegistry;
|
|
2749
|
+
private readonly _runtime;
|
|
2750
|
+
private readonly _scope;
|
|
2751
|
+
private readonly _transactionCallbacks?;
|
|
2752
|
+
private _migrationService?;
|
|
2753
|
+
private _factoryService?;
|
|
2754
|
+
private _eventService?;
|
|
2755
|
+
constructor(options: DatabaseContextOptions | ContextInternals);
|
|
2756
|
+
initialize(): Promise<void>;
|
|
2757
|
+
disconnect(): Promise<void>;
|
|
2758
|
+
isConnected(): boolean;
|
|
2759
|
+
getDriver(): DatabaseDriverName;
|
|
2760
|
+
getConnectionName(): string;
|
|
2761
|
+
getSchemaName(): string | undefined;
|
|
2762
|
+
getAdapter(): DriverAdapter;
|
|
2763
|
+
getDialect(): Dialect;
|
|
2764
|
+
getCapabilities(): DatabaseCapabilities;
|
|
2765
|
+
getSecurityPolicy(): SecurityPolicy;
|
|
2766
|
+
getConcurrencyOptions(): ConcurrencyOptions;
|
|
2767
|
+
getSchemaRegistry(): SchemaRegistry;
|
|
2768
|
+
getModelRegistry(): ModelRegistry;
|
|
2769
|
+
getMigrationService(): MigrationService;
|
|
2770
|
+
getFactoryService(): FactoryService;
|
|
2771
|
+
getEventService(): ModelEventService;
|
|
2772
|
+
registerModel(reference: ModelDefinitionLike): AnyModelDefinition;
|
|
2773
|
+
model(reference: ModelDefinitionLike): ModelRepository;
|
|
2774
|
+
getLogger(): DatabaseLogger | undefined;
|
|
2775
|
+
getScope(): Readonly<ScopeState>;
|
|
2776
|
+
afterCommit(callback: TransactionCallback): void;
|
|
2777
|
+
afterRollback(callback: TransactionCallback): void;
|
|
2778
|
+
getSchedulingModeHint(): 'concurrent' | 'serialized' | 'worker';
|
|
2779
|
+
unsafeQuery<TRow extends Record<string, unknown> = Record<string, unknown>>(statement: UnsafeStatement, options?: DatabaseOperationOptions): Promise<DriverQueryResult<TRow>>;
|
|
2780
|
+
unsafeExecute(statement: UnsafeStatement, options?: DatabaseOperationOptions): Promise<DriverExecutionResult>;
|
|
2781
|
+
queryCompiled<TRow extends Record<string, unknown> = Record<string, unknown>>(statement: CompiledStatement, options?: DatabaseOperationOptions): Promise<DriverQueryResult<TRow>>;
|
|
2782
|
+
introspectCompiled<TRow extends Record<string, unknown> = Record<string, unknown>>(statement: CompiledStatement, options?: DatabaseOperationOptions): Promise<DriverQueryResult<TRow>>;
|
|
2783
|
+
executeCompiled(statement: CompiledStatement, options?: DatabaseOperationOptions): Promise<DriverExecutionResult>;
|
|
2784
|
+
transaction<T>(callback: (tx: DatabaseContext) => Promise<T>, options?: DatabaseOperationOptions): Promise<T>;
|
|
2785
|
+
private _runRootTransaction;
|
|
2786
|
+
private _runNestedTransaction;
|
|
2787
|
+
private _createChildContext;
|
|
2788
|
+
private _runTransactionCallback;
|
|
2789
|
+
private _createTransactionCallbackState;
|
|
2790
|
+
private _registerTransactionCallback;
|
|
2791
|
+
private _mergeCommittedTransactionCallbacks;
|
|
2792
|
+
private _flushTransactionCallbacks;
|
|
2793
|
+
private _assertUnsafeRawAllowed;
|
|
2794
|
+
private _assertUnsafeStatement;
|
|
2795
|
+
private _assertCompiledStatementAllowed;
|
|
2796
|
+
private _runLogged;
|
|
2797
|
+
private _wrapDriverError;
|
|
2798
|
+
private _callTransactionHook;
|
|
2799
|
+
private _guardOperation;
|
|
2800
|
+
private _assertValidOperationOptions;
|
|
2801
|
+
private _throwIfAborted;
|
|
2802
|
+
private _createGuardError;
|
|
2803
|
+
}
|
|
2804
|
+
declare function createDatabase(options: DatabaseContextOptions): DatabaseContext;
|
|
2805
|
+
|
|
2806
|
+
declare function unsafeSql(sql: string, bindings?: readonly unknown[], source?: string): UnsafeStatement;
|
|
2807
|
+
|
|
2808
|
+
declare class DatabaseError extends Error {
|
|
2809
|
+
readonly name: string;
|
|
2810
|
+
readonly code: string;
|
|
2811
|
+
readonly cause?: unknown;
|
|
2812
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
2813
|
+
}
|
|
2814
|
+
declare class ConfigurationError extends DatabaseError {
|
|
2815
|
+
constructor(message: string, cause?: unknown);
|
|
2816
|
+
}
|
|
2817
|
+
declare class CompilerError extends DatabaseError {
|
|
2818
|
+
constructor(message: string, cause?: unknown);
|
|
2819
|
+
}
|
|
2820
|
+
declare class CapabilityError extends DatabaseError {
|
|
2821
|
+
constructor(message: string, cause?: unknown);
|
|
2822
|
+
}
|
|
2823
|
+
declare class SecurityError extends DatabaseError {
|
|
2824
|
+
constructor(message: string, cause?: unknown);
|
|
2825
|
+
}
|
|
2826
|
+
declare class SchemaError extends DatabaseError {
|
|
2827
|
+
constructor(message: string, cause?: unknown);
|
|
2828
|
+
}
|
|
2829
|
+
declare class RelationError extends DatabaseError {
|
|
2830
|
+
constructor(message: string, cause?: unknown);
|
|
2831
|
+
}
|
|
2832
|
+
declare class TransactionError extends DatabaseError {
|
|
2833
|
+
constructor(message: string, cause?: unknown);
|
|
2834
|
+
}
|
|
2835
|
+
declare class HydrationError extends DatabaseError {
|
|
2836
|
+
constructor(message: string, cause?: unknown);
|
|
2837
|
+
}
|
|
2838
|
+
declare class ModelNotFoundException extends DatabaseError {
|
|
2839
|
+
readonly statusCode = 404;
|
|
2840
|
+
readonly model: string;
|
|
2841
|
+
constructor(model: string, message?: string, cause?: unknown);
|
|
2842
|
+
}
|
|
2843
|
+
declare class SerializationError extends DatabaseError {
|
|
2844
|
+
constructor(message: string, cause?: unknown);
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
interface ConnectionManagerOptions {
|
|
2848
|
+
defaultConnection: string;
|
|
2849
|
+
connections: Record<string, DatabaseContext | DatabaseContextOptions>;
|
|
2850
|
+
}
|
|
2851
|
+
declare class ConnectionManager {
|
|
2852
|
+
private readonly defaultConnection;
|
|
2853
|
+
private readonly definitions;
|
|
2854
|
+
private readonly resolved;
|
|
2855
|
+
constructor(options: ConnectionManagerOptions);
|
|
2856
|
+
getDefaultConnectionName(): string;
|
|
2857
|
+
getConnectionNames(): string[];
|
|
2858
|
+
hasConnection(name: string): boolean;
|
|
2859
|
+
connection(name?: string): DatabaseContext;
|
|
2860
|
+
initializeAll(): Promise<void>;
|
|
2861
|
+
disconnectAll(): Promise<void>;
|
|
2862
|
+
transaction<T>(callback: (connection: DatabaseContext) => Promise<T>, connectionName?: string): Promise<T>;
|
|
2863
|
+
}
|
|
2864
|
+
declare function createConnectionManager(options: ConnectionManagerOptions): ConnectionManager;
|
|
2865
|
+
|
|
2866
|
+
declare class DatabaseFacade {
|
|
2867
|
+
private manager?;
|
|
2868
|
+
configure(manager: ConnectionManager): void;
|
|
2869
|
+
reset(): void;
|
|
2870
|
+
getManager(): ConnectionManager;
|
|
2871
|
+
connection(name?: string): DatabaseContext;
|
|
2872
|
+
table<TTable extends TableDefinition>(table: TTable, connectionName?: string): TableQueryBuilder<TTable>;
|
|
2873
|
+
table(name: string, connectionName?: string): TableQueryBuilder<string>;
|
|
2874
|
+
raw(sql: string, bindings?: readonly unknown[], source?: string): UnsafeStatement;
|
|
2875
|
+
transaction<T>(callback: (connection: DatabaseContext) => Promise<T>, connectionName?: string, options?: DatabaseOperationOptions): Promise<T>;
|
|
2876
|
+
afterCommit(callback: () => void | Promise<void>, connectionName?: string): void;
|
|
2877
|
+
afterRollback(callback: () => void | Promise<void>, connectionName?: string): void;
|
|
2878
|
+
unsafeQuery<TRow extends Record<string, unknown> = Record<string, unknown>>(statement: UnsafeStatement, connectionName?: string, options?: DatabaseOperationOptions): Promise<DriverQueryResult<TRow>>;
|
|
2879
|
+
unsafeExecute(statement: UnsafeStatement, connectionName?: string, options?: DatabaseOperationOptions): Promise<DriverExecutionResult>;
|
|
2880
|
+
}
|
|
2881
|
+
declare const DB: DatabaseFacade;
|
|
2882
|
+
declare function configureDB(manager: ConnectionManager): void;
|
|
2883
|
+
declare function resetDB(): void;
|
|
2884
|
+
|
|
2885
|
+
interface ActiveConnectionScope {
|
|
2886
|
+
connectionName: string;
|
|
2887
|
+
connection: DatabaseContext;
|
|
2888
|
+
}
|
|
2889
|
+
declare class AsyncConnectionContext {
|
|
2890
|
+
private readonly storage;
|
|
2891
|
+
run<T>(scope: ActiveConnectionScope, callback: () => T): T;
|
|
2892
|
+
getActive(): ActiveConnectionScope | undefined;
|
|
2893
|
+
}
|
|
2894
|
+
declare const connectionAsyncContext: AsyncConnectionContext;
|
|
2895
|
+
|
|
2896
|
+
interface SQLiteStatementLike {
|
|
2897
|
+
all(...params: readonly unknown[]): Record<string, unknown>[];
|
|
2898
|
+
run(...params: readonly unknown[]): {
|
|
2899
|
+
changes?: number;
|
|
2900
|
+
lastInsertRowid?: unknown;
|
|
2901
|
+
};
|
|
2902
|
+
}
|
|
2903
|
+
interface SQLiteDatabaseLike {
|
|
2904
|
+
prepare(sql: string): SQLiteStatementLike;
|
|
2905
|
+
exec(sql: string): unknown;
|
|
2906
|
+
close(): unknown;
|
|
2907
|
+
}
|
|
2908
|
+
interface SQLiteAdapterOptions {
|
|
2909
|
+
filename?: string;
|
|
2910
|
+
database?: SQLiteDatabaseLike;
|
|
2911
|
+
createDatabase?: (filename: string) => SQLiteDatabaseLike;
|
|
2912
|
+
}
|
|
2913
|
+
declare class SQLiteAdapter implements DriverAdapter {
|
|
2914
|
+
private database?;
|
|
2915
|
+
private connected;
|
|
2916
|
+
private readonly filename;
|
|
2917
|
+
private readonly createDatabaseInstance;
|
|
2918
|
+
constructor(options?: SQLiteAdapterOptions);
|
|
2919
|
+
initialize(): Promise<void>;
|
|
2920
|
+
disconnect(): Promise<void>;
|
|
2921
|
+
isConnected(): boolean;
|
|
2922
|
+
query<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[]): Promise<DriverQueryResult<TRow>>;
|
|
2923
|
+
introspect<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[]): Promise<DriverQueryResult<TRow>>;
|
|
2924
|
+
execute(sql: string, bindings?: readonly unknown[]): Promise<DriverExecutionResult>;
|
|
2925
|
+
beginTransaction(): Promise<void>;
|
|
2926
|
+
commit(): Promise<void>;
|
|
2927
|
+
rollback(): Promise<void>;
|
|
2928
|
+
createSavepoint(name: string): Promise<void>;
|
|
2929
|
+
rollbackToSavepoint(name: string): Promise<void>;
|
|
2930
|
+
releaseSavepoint(name: string): Promise<void>;
|
|
2931
|
+
private getDatabase;
|
|
2932
|
+
private normalizeSavepointName;
|
|
2933
|
+
private invokeStatement;
|
|
2934
|
+
private isBindingArityError;
|
|
2935
|
+
}
|
|
2936
|
+
declare function createSQLiteAdapter(options?: SQLiteAdapterOptions): SQLiteAdapter;
|
|
2937
|
+
|
|
2938
|
+
interface PostgresQueryableLike {
|
|
2939
|
+
query(sql: string, bindings?: readonly unknown[]): Promise<QueryResult<Record<string, unknown>> | {
|
|
2940
|
+
rows: Record<string, unknown>[];
|
|
2941
|
+
rowCount?: number | null;
|
|
2942
|
+
}>;
|
|
2943
|
+
}
|
|
2944
|
+
interface PostgresClientLike extends PostgresQueryableLike {
|
|
2945
|
+
release?(): void;
|
|
2946
|
+
end?(): Promise<void>;
|
|
2947
|
+
}
|
|
2948
|
+
interface PostgresPoolLike extends PostgresQueryableLike {
|
|
2949
|
+
connect(): Promise<PostgresClientLike>;
|
|
2950
|
+
end(): Promise<void>;
|
|
2951
|
+
}
|
|
2952
|
+
interface PostgresAdapterOptions {
|
|
2953
|
+
connectionString?: string;
|
|
2954
|
+
config?: PoolConfig;
|
|
2955
|
+
client?: PostgresClientLike;
|
|
2956
|
+
pool?: PostgresPoolLike;
|
|
2957
|
+
createPool?: (config?: PoolConfig) => PostgresPoolLike;
|
|
2958
|
+
}
|
|
2959
|
+
declare class PostgresAdapter implements DriverAdapter {
|
|
2960
|
+
private pool?;
|
|
2961
|
+
private readonly directClient?;
|
|
2962
|
+
private readonly createPoolInstance?;
|
|
2963
|
+
private readonly config?;
|
|
2964
|
+
private connected;
|
|
2965
|
+
private transactionClient?;
|
|
2966
|
+
private leasedTransactionClient;
|
|
2967
|
+
private readonly transactionScope;
|
|
2968
|
+
constructor(options?: PostgresAdapterOptions);
|
|
2969
|
+
initialize(): Promise<void>;
|
|
2970
|
+
disconnect(): Promise<void>;
|
|
2971
|
+
isConnected(): boolean;
|
|
2972
|
+
runWithTransactionScope<T>(callback: () => Promise<T>): Promise<T>;
|
|
2973
|
+
query<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[]): Promise<DriverQueryResult<TRow>>;
|
|
2974
|
+
introspect<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[]): Promise<DriverQueryResult<TRow>>;
|
|
2975
|
+
execute(sql: string, bindings?: readonly unknown[]): Promise<DriverExecutionResult>;
|
|
2976
|
+
beginTransaction(): Promise<void>;
|
|
2977
|
+
commit(): Promise<void>;
|
|
2978
|
+
rollback(): Promise<void>;
|
|
2979
|
+
createSavepoint(name: string): Promise<void>;
|
|
2980
|
+
rollbackToSavepoint(name: string): Promise<void>;
|
|
2981
|
+
releaseSavepoint(name: string): Promise<void>;
|
|
2982
|
+
private getQueryable;
|
|
2983
|
+
private leaseTransactionClient;
|
|
2984
|
+
private requireTransactionClient;
|
|
2985
|
+
private releaseTransactionClient;
|
|
2986
|
+
private releaseScopedTransaction;
|
|
2987
|
+
private normalizeSavepointName;
|
|
2988
|
+
}
|
|
2989
|
+
declare function createPostgresAdapter(options?: PostgresAdapterOptions): PostgresAdapter;
|
|
2990
|
+
|
|
2991
|
+
interface MySQLQueryableLike {
|
|
2992
|
+
query(sql: string, bindings?: readonly unknown[]): Promise<readonly [unknown, unknown]>;
|
|
2993
|
+
}
|
|
2994
|
+
interface MySQLClientLike extends MySQLQueryableLike {
|
|
2995
|
+
release?(): void;
|
|
2996
|
+
end?(): Promise<void>;
|
|
2997
|
+
}
|
|
2998
|
+
interface MySQLPoolLike extends MySQLQueryableLike {
|
|
2999
|
+
getConnection(): Promise<MySQLClientLike>;
|
|
3000
|
+
end(): Promise<void>;
|
|
3001
|
+
}
|
|
3002
|
+
interface MySQLAdapterOptions {
|
|
3003
|
+
uri?: string;
|
|
3004
|
+
config?: PoolOptions;
|
|
3005
|
+
client?: MySQLClientLike;
|
|
3006
|
+
pool?: MySQLPoolLike;
|
|
3007
|
+
createPool?: (config: PoolOptions) => MySQLPoolLike;
|
|
3008
|
+
}
|
|
3009
|
+
declare class MySQLAdapter implements DriverAdapter {
|
|
3010
|
+
private pool?;
|
|
3011
|
+
private readonly directClient?;
|
|
3012
|
+
private readonly createPoolInstance?;
|
|
3013
|
+
private readonly config;
|
|
3014
|
+
private connected;
|
|
3015
|
+
private transactionClient?;
|
|
3016
|
+
private leasedTransactionClient;
|
|
3017
|
+
private readonly transactionScope;
|
|
3018
|
+
constructor(options?: MySQLAdapterOptions);
|
|
3019
|
+
initialize(): Promise<void>;
|
|
3020
|
+
disconnect(): Promise<void>;
|
|
3021
|
+
isConnected(): boolean;
|
|
3022
|
+
runWithTransactionScope<T>(callback: () => Promise<T>): Promise<T>;
|
|
3023
|
+
query<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[]): Promise<DriverQueryResult<TRow>>;
|
|
3024
|
+
introspect<TRow extends Record<string, unknown> = Record<string, unknown>>(sql: string, bindings?: readonly unknown[]): Promise<DriverQueryResult<TRow>>;
|
|
3025
|
+
execute(sql: string, bindings?: readonly unknown[]): Promise<DriverExecutionResult>;
|
|
3026
|
+
beginTransaction(): Promise<void>;
|
|
3027
|
+
commit(): Promise<void>;
|
|
3028
|
+
rollback(): Promise<void>;
|
|
3029
|
+
createSavepoint(name: string): Promise<void>;
|
|
3030
|
+
rollbackToSavepoint(name: string): Promise<void>;
|
|
3031
|
+
releaseSavepoint(name: string): Promise<void>;
|
|
3032
|
+
private getQueryable;
|
|
3033
|
+
private leaseTransactionClient;
|
|
3034
|
+
private requireTransactionClient;
|
|
3035
|
+
private releaseTransactionClient;
|
|
3036
|
+
private releaseScopedTransaction;
|
|
3037
|
+
private normalizeSavepointName;
|
|
3038
|
+
}
|
|
3039
|
+
declare function createMySQLAdapter(options?: MySQLAdapterOptions): MySQLAdapter;
|
|
3040
|
+
|
|
3041
|
+
type SupportedDatabaseDriver = 'sqlite' | 'postgres' | 'mysql';
|
|
3042
|
+
interface RuntimeConnectionConfig {
|
|
3043
|
+
driver?: SupportedDatabaseDriver | string;
|
|
3044
|
+
url?: string;
|
|
3045
|
+
host?: string;
|
|
3046
|
+
port?: number | string;
|
|
3047
|
+
username?: string;
|
|
3048
|
+
password?: string;
|
|
3049
|
+
database?: string;
|
|
3050
|
+
filename?: string;
|
|
3051
|
+
schema?: string;
|
|
3052
|
+
ssl?: boolean | Record<string, unknown>;
|
|
3053
|
+
logging?: boolean;
|
|
3054
|
+
}
|
|
3055
|
+
interface RuntimeDatabaseConfig {
|
|
3056
|
+
defaultConnection?: string;
|
|
3057
|
+
connections?: Record<string, RuntimeConnectionConfig | string>;
|
|
3058
|
+
}
|
|
3059
|
+
interface RuntimeHoloConfig {
|
|
3060
|
+
appEnv?: 'production' | 'development' | 'test';
|
|
3061
|
+
appDebug?: boolean;
|
|
3062
|
+
appUrl?: string;
|
|
3063
|
+
}
|
|
3064
|
+
interface RuntimeConfigInput {
|
|
3065
|
+
holo?: RuntimeHoloConfig;
|
|
3066
|
+
db?: RuntimeDatabaseConfig;
|
|
3067
|
+
}
|
|
3068
|
+
type RuntimeAdapterConnectionConfig = {
|
|
3069
|
+
url?: string;
|
|
3070
|
+
host?: string;
|
|
3071
|
+
port?: number;
|
|
3072
|
+
username?: string;
|
|
3073
|
+
password?: string;
|
|
3074
|
+
database?: string;
|
|
3075
|
+
ssl?: boolean | Record<string, unknown>;
|
|
3076
|
+
};
|
|
3077
|
+
declare function isSupportedDatabaseDriver(value: string): value is SupportedDatabaseDriver;
|
|
3078
|
+
declare function parseDatabaseDriver(value: string | undefined, fallback: SupportedDatabaseDriver): SupportedDatabaseDriver;
|
|
3079
|
+
declare function createDialect(driver: SupportedDatabaseDriver): Dialect;
|
|
3080
|
+
declare function createAdapter(driver: SupportedDatabaseDriver, connection: string | RuntimeAdapterConnectionConfig): SQLiteAdapter | PostgresAdapter | MySQLAdapter;
|
|
3081
|
+
declare function createRuntimeLogger(enabled: boolean): DatabaseLogger | undefined;
|
|
3082
|
+
declare function createRuntimeConnectionOptions(driver: SupportedDatabaseDriver, connection: string | RuntimeAdapterConnectionConfig, dbLogging: boolean, schemaName?: string, connectionName?: string): DatabaseContextOptions;
|
|
3083
|
+
declare function resolveRuntimeConnectionManagerOptions(config: RuntimeConfigInput): ConnectionManager;
|
|
3084
|
+
|
|
3085
|
+
declare function validateQueryPlan(plan: QueryPlan): void;
|
|
3086
|
+
|
|
3087
|
+
type IdentifierQuoter$1 = (identifier: string) => string;
|
|
3088
|
+
type PlaceholderFactory = (index: number) => string;
|
|
3089
|
+
declare class SQLQueryCompiler {
|
|
3090
|
+
protected readonly quoteIdentifier: IdentifierQuoter$1;
|
|
3091
|
+
protected readonly createPlaceholder: PlaceholderFactory;
|
|
3092
|
+
constructor(quoteIdentifier: IdentifierQuoter$1, createPlaceholder: PlaceholderFactory);
|
|
3093
|
+
compile(plan: QueryPlan): CompiledStatement;
|
|
3094
|
+
protected compileSelect(plan: SelectQueryPlan): CompiledStatement;
|
|
3095
|
+
protected compileSelectSql(plan: SelectQueryPlan, bindings: unknown[]): string;
|
|
3096
|
+
protected compileInsert(plan: InsertQueryPlan): CompiledStatement;
|
|
3097
|
+
protected compileUpsert(plan: UpsertQueryPlan): CompiledStatement;
|
|
3098
|
+
protected compileUpdate(plan: UpdateQueryPlan): CompiledStatement;
|
|
3099
|
+
protected compileDelete(plan: DeleteQueryPlan): CompiledStatement;
|
|
3100
|
+
protected withMetadata(statement: CompiledStatement, metadata: CompiledStatementMetadata): CompiledStatement;
|
|
3101
|
+
protected createSelectMetadata(plan: SelectQueryPlan): CompiledStatementMetadata;
|
|
3102
|
+
protected createWriteMetadata(kind: 'insert' | 'update' | 'upsert' | 'delete', tableName: string, complexity: number): CompiledStatementMetadata;
|
|
3103
|
+
protected calculatePlanComplexity(plan: QueryPlan): number;
|
|
3104
|
+
private selectionComplexity;
|
|
3105
|
+
private predicateComplexity;
|
|
3106
|
+
protected planContainsRawSql(plan: SelectQueryPlan): boolean;
|
|
3107
|
+
protected predicateContainsRawSql(predicate: QueryPredicateNode): boolean;
|
|
3108
|
+
protected compilePredicates(predicates: readonly QueryPredicateNode[], bindings: unknown[]): string;
|
|
3109
|
+
protected compileJoins(joins: readonly QueryJoinClause[], bindings: unknown[]): string;
|
|
3110
|
+
protected compileUnions(unions: SelectQueryPlan['unions'], bindings: unknown[]): string;
|
|
3111
|
+
protected compileHaving(clauses: readonly QueryHavingClause[], bindings: unknown[]): string;
|
|
3112
|
+
protected compilePredicate(predicate: QueryPredicateNode, bindings: unknown[]): string;
|
|
3113
|
+
protected compileDatePredicate(predicate: QueryDatePredicate, placeholder: string): string;
|
|
3114
|
+
protected compileJsonPredicate(predicate: QueryJsonPredicate, _bindings: unknown[]): string;
|
|
3115
|
+
protected compileFullTextPredicate(predicate: QueryFullTextPredicate, _bindings: unknown[]): string;
|
|
3116
|
+
protected compileVectorPredicate(predicate: QueryVectorPredicate, bindings: unknown[]): string;
|
|
3117
|
+
protected compileOrderBy(orderBy: SelectQueryPlan['orderBy'][number], bindings: unknown[]): string;
|
|
3118
|
+
protected compileRandomOrder(): string;
|
|
3119
|
+
protected compileInsertPrefix(_plan: InsertQueryPlan): string;
|
|
3120
|
+
protected compileInsertSuffix(_plan: InsertQueryPlan): string;
|
|
3121
|
+
protected compileUpsertSuffix(plan: UpsertQueryPlan, _insertColumns: readonly string[]): string;
|
|
3122
|
+
protected compileHavingExpression(expression: string): string;
|
|
3123
|
+
protected compileColumnReference(reference: string): string;
|
|
3124
|
+
protected compileTableReference(reference: string): string;
|
|
3125
|
+
protected compileSource(source: SelectQueryPlan['source']): string;
|
|
3126
|
+
protected compileJoinSource(join: QueryJoinClause, bindings: unknown[]): string;
|
|
3127
|
+
protected compileLateralJoinSource(_subquery: string, _alias: string): string;
|
|
3128
|
+
protected compileUpdateValue(column: string, value: QueryUpdateValue, bindings: unknown[]): string;
|
|
3129
|
+
protected compileJsonUpdateOperations(column: string, _operations: readonly QueryJsonUpdateOperation[], _bindings: unknown[]): string;
|
|
3130
|
+
protected compileVectorDistanceExpression(_column: string, _vector: readonly number[], _bindings: unknown[]): string;
|
|
3131
|
+
protected compileLockClause(_lockMode: QueryLockMode): string;
|
|
3132
|
+
protected escapeSqlString(value: string): string;
|
|
3133
|
+
protected createSqlStringLiteral(value: string): string;
|
|
3134
|
+
protected createJsonPathLiteral(path: readonly string[]): string;
|
|
3135
|
+
protected createPostgresPathLiteral(path: readonly string[]): string;
|
|
3136
|
+
protected isJsonUpdateOperation(value: QueryUpdateValue): value is QueryJsonUpdateOperation;
|
|
3137
|
+
protected isUnsafeSelectPlan(plan: SelectQueryPlan): boolean;
|
|
3138
|
+
protected isUnsafePredicate(predicate: QueryPredicateNode): boolean;
|
|
3139
|
+
private compilePredicateSequence;
|
|
3140
|
+
protected prefixPredicate(predicate: QueryPredicateNode, compiled: string, index: number): string;
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3143
|
+
declare class SQLiteQueryCompiler extends SQLQueryCompiler {
|
|
3144
|
+
protected compileJsonPredicate(predicate: QueryJsonPredicate, bindings: unknown[]): string;
|
|
3145
|
+
protected compileJsonUpdateOperations(column: string, operations: readonly QueryJsonUpdateOperation[], bindings: unknown[]): string;
|
|
3146
|
+
protected compileDatePredicate(predicate: QueryDatePredicate, placeholder: string): string;
|
|
3147
|
+
protected compileInsertPrefix(plan: InsertQueryPlan): string;
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
declare class PostgresQueryCompiler extends SQLQueryCompiler {
|
|
3151
|
+
protected compileLateralJoinSource(subquery: string, alias: string): string;
|
|
3152
|
+
protected compileLockClause(lockMode: QueryLockMode): string;
|
|
3153
|
+
protected compileInsertSuffix(plan: InsertQueryPlan): string;
|
|
3154
|
+
protected compileUpsertSuffix(plan: UpsertQueryPlan, insertColumns: readonly string[]): string;
|
|
3155
|
+
protected compileJsonPredicate(predicate: QueryJsonPredicate, bindings: unknown[]): string;
|
|
3156
|
+
protected compileJsonUpdateOperations(column: string, operations: readonly QueryJsonUpdateOperation[], bindings: unknown[]): string;
|
|
3157
|
+
protected compileFullTextPredicate(predicate: QueryFullTextPredicate, bindings: unknown[]): string;
|
|
3158
|
+
protected compileVectorDistanceExpression(column: string, vector: readonly number[], bindings: unknown[]): string;
|
|
3159
|
+
protected compileDatePredicate(predicate: QueryDatePredicate, placeholder: string): string;
|
|
3160
|
+
}
|
|
3161
|
+
|
|
3162
|
+
declare class MySQLQueryCompiler extends SQLQueryCompiler {
|
|
3163
|
+
protected compileLateralJoinSource(subquery: string, alias: string): string;
|
|
3164
|
+
protected compileLockClause(lockMode: QueryLockMode): string;
|
|
3165
|
+
protected compileInsertPrefix(plan: InsertQueryPlan): string;
|
|
3166
|
+
protected compileUpsertSuffix(plan: UpsertQueryPlan, insertColumns: readonly string[]): string;
|
|
3167
|
+
protected compileRandomOrder(): string;
|
|
3168
|
+
protected compileJsonPredicate(predicate: QueryJsonPredicate, bindings: unknown[]): string;
|
|
3169
|
+
protected compileJsonUpdateOperations(column: string, operations: readonly QueryJsonUpdateOperation[], bindings: unknown[]): string;
|
|
3170
|
+
protected compileFullTextPredicate(predicate: QueryFullTextPredicate, bindings: unknown[]): string;
|
|
3171
|
+
protected compileDatePredicate(predicate: QueryDatePredicate, placeholder: string): string;
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
declare function createPaginator<T>(data: readonly T[], meta: Omit<PaginationMeta, 'pageName'> & {
|
|
3175
|
+
pageName?: string;
|
|
3176
|
+
}): PaginatedResult<T>;
|
|
3177
|
+
declare function createSimplePaginator<T>(data: readonly T[], meta: Omit<SimplePaginationMeta, 'pageName'> & {
|
|
3178
|
+
pageName?: string;
|
|
3179
|
+
}): SimplePaginatedResult<T>;
|
|
3180
|
+
declare function createCursorPaginator<T>(data: readonly T[], meta: {
|
|
3181
|
+
perPage: number;
|
|
3182
|
+
nextCursor: string | null;
|
|
3183
|
+
prevCursor: string | null;
|
|
3184
|
+
cursorName?: string;
|
|
3185
|
+
}): CursorPaginatedResult<T>;
|
|
3186
|
+
|
|
3187
|
+
interface SchemaColumnMismatch {
|
|
3188
|
+
readonly column: string;
|
|
3189
|
+
readonly expected: {
|
|
3190
|
+
readonly type: string;
|
|
3191
|
+
readonly notNull: boolean;
|
|
3192
|
+
readonly primaryKey: boolean;
|
|
3193
|
+
};
|
|
3194
|
+
readonly actual: {
|
|
3195
|
+
readonly type: string;
|
|
3196
|
+
readonly notNull: boolean;
|
|
3197
|
+
readonly primaryKey: boolean;
|
|
3198
|
+
};
|
|
3199
|
+
}
|
|
3200
|
+
interface SchemaIndexMismatch {
|
|
3201
|
+
readonly index: string;
|
|
3202
|
+
readonly expected: {
|
|
3203
|
+
readonly unique: boolean;
|
|
3204
|
+
readonly columns: readonly string[];
|
|
3205
|
+
};
|
|
3206
|
+
readonly actual: {
|
|
3207
|
+
readonly unique: boolean;
|
|
3208
|
+
readonly columns: readonly string[];
|
|
3209
|
+
};
|
|
3210
|
+
}
|
|
3211
|
+
interface SchemaForeignKeyMismatch {
|
|
3212
|
+
readonly foreignKey: string;
|
|
3213
|
+
readonly expected: {
|
|
3214
|
+
readonly table: string;
|
|
3215
|
+
readonly from: string;
|
|
3216
|
+
readonly to: string;
|
|
3217
|
+
readonly onUpdate: string;
|
|
3218
|
+
readonly onDelete: string;
|
|
3219
|
+
};
|
|
3220
|
+
readonly actual: {
|
|
3221
|
+
readonly table: string;
|
|
3222
|
+
readonly from: string;
|
|
3223
|
+
readonly to: string;
|
|
3224
|
+
readonly onUpdate: string;
|
|
3225
|
+
readonly onDelete: string;
|
|
3226
|
+
};
|
|
3227
|
+
}
|
|
3228
|
+
interface TableSchemaDiff {
|
|
3229
|
+
readonly table: string;
|
|
3230
|
+
readonly missingColumns: readonly string[];
|
|
3231
|
+
readonly extraColumns: readonly string[];
|
|
3232
|
+
readonly mismatchedColumns: readonly SchemaColumnMismatch[];
|
|
3233
|
+
readonly missingIndexes: readonly string[];
|
|
3234
|
+
readonly extraIndexes: readonly string[];
|
|
3235
|
+
readonly mismatchedIndexes: readonly SchemaIndexMismatch[];
|
|
3236
|
+
readonly missingForeignKeys: readonly string[];
|
|
3237
|
+
readonly extraForeignKeys: readonly string[];
|
|
3238
|
+
readonly mismatchedForeignKeys: readonly SchemaForeignKeyMismatch[];
|
|
3239
|
+
readonly hasChanges: boolean;
|
|
3240
|
+
}
|
|
3241
|
+
interface SchemaDiff {
|
|
3242
|
+
readonly missingTables: readonly string[];
|
|
3243
|
+
readonly extraTables: readonly string[];
|
|
3244
|
+
readonly tables: readonly TableSchemaDiff[];
|
|
3245
|
+
readonly hasChanges: boolean;
|
|
3246
|
+
}
|
|
3247
|
+
declare function diffSchema(schema: SchemaService, tables: readonly TableDefinition[]): Promise<SchemaDiff>;
|
|
3248
|
+
|
|
3249
|
+
interface CreateTableOperation {
|
|
3250
|
+
readonly kind: 'createTable';
|
|
3251
|
+
readonly table: TableDefinition;
|
|
3252
|
+
}
|
|
3253
|
+
interface DropTableOperation {
|
|
3254
|
+
readonly kind: 'dropTable';
|
|
3255
|
+
readonly tableName: string;
|
|
3256
|
+
}
|
|
3257
|
+
interface RenameTableOperation {
|
|
3258
|
+
readonly kind: 'renameTable';
|
|
3259
|
+
readonly fromTableName: string;
|
|
3260
|
+
readonly toTableName: string;
|
|
3261
|
+
}
|
|
3262
|
+
interface CreateIndexOperation {
|
|
3263
|
+
readonly kind: 'createIndex';
|
|
3264
|
+
readonly tableName: string;
|
|
3265
|
+
readonly index: {
|
|
3266
|
+
readonly name?: string;
|
|
3267
|
+
readonly columns: readonly string[];
|
|
3268
|
+
readonly unique: boolean;
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
interface DropIndexOperation {
|
|
3272
|
+
readonly kind: 'dropIndex';
|
|
3273
|
+
readonly tableName: string;
|
|
3274
|
+
readonly indexName: string;
|
|
3275
|
+
}
|
|
3276
|
+
interface RenameIndexOperation {
|
|
3277
|
+
readonly kind: 'renameIndex';
|
|
3278
|
+
readonly tableName: string;
|
|
3279
|
+
readonly fromIndexName: string;
|
|
3280
|
+
readonly toIndexName: string;
|
|
3281
|
+
}
|
|
3282
|
+
interface AddColumnOperation {
|
|
3283
|
+
readonly kind: 'addColumn';
|
|
3284
|
+
readonly tableName: string;
|
|
3285
|
+
readonly column: AnyColumnDefinition;
|
|
3286
|
+
}
|
|
3287
|
+
interface DropColumnOperation {
|
|
3288
|
+
readonly kind: 'dropColumn';
|
|
3289
|
+
readonly tableName: string;
|
|
3290
|
+
readonly columnName: string;
|
|
3291
|
+
}
|
|
3292
|
+
interface RenameColumnOperation {
|
|
3293
|
+
readonly kind: 'renameColumn';
|
|
3294
|
+
readonly tableName: string;
|
|
3295
|
+
readonly fromColumnName: string;
|
|
3296
|
+
readonly toColumnName: string;
|
|
3297
|
+
}
|
|
3298
|
+
interface AlterColumnOperation {
|
|
3299
|
+
readonly kind: 'alterColumn';
|
|
3300
|
+
readonly tableName: string;
|
|
3301
|
+
readonly column: AnyColumnDefinition;
|
|
3302
|
+
}
|
|
3303
|
+
interface CreateForeignKeyOperation {
|
|
3304
|
+
readonly kind: 'createForeignKey';
|
|
3305
|
+
readonly tableName: string;
|
|
3306
|
+
readonly columnName: string;
|
|
3307
|
+
readonly reference: ForeignKeyReference;
|
|
3308
|
+
readonly constraintName?: string;
|
|
3309
|
+
}
|
|
3310
|
+
interface DropForeignKeyOperation {
|
|
3311
|
+
readonly kind: 'dropForeignKey';
|
|
3312
|
+
readonly tableName: string;
|
|
3313
|
+
readonly constraintName: string;
|
|
3314
|
+
}
|
|
3315
|
+
type DDLOperation = CreateTableOperation | DropTableOperation | RenameTableOperation | CreateIndexOperation | DropIndexOperation | RenameIndexOperation | AddColumnOperation | DropColumnOperation | RenameColumnOperation | AlterColumnOperation | CreateForeignKeyOperation | DropForeignKeyOperation;
|
|
3316
|
+
interface DDLStatement {
|
|
3317
|
+
readonly sql: string;
|
|
3318
|
+
readonly bindings?: readonly unknown[];
|
|
3319
|
+
readonly source: string;
|
|
3320
|
+
}
|
|
3321
|
+
declare function createTableOperation(table: TableDefinition): CreateTableOperation;
|
|
3322
|
+
declare function dropTableOperation(tableName: string): DropTableOperation;
|
|
3323
|
+
declare function renameTableOperation(fromTableName: string, toTableName: string): RenameTableOperation;
|
|
3324
|
+
declare function createIndexOperation(tableName: string, index: CreateIndexOperation['index']): CreateIndexOperation;
|
|
3325
|
+
declare function dropIndexOperation(tableName: string, indexName: string): DropIndexOperation;
|
|
3326
|
+
declare function renameIndexOperation(tableName: string, fromIndexName: string, toIndexName: string): RenameIndexOperation;
|
|
3327
|
+
declare function addColumnOperation(tableName: string, column: AnyColumnDefinition): AddColumnOperation;
|
|
3328
|
+
declare function dropColumnOperation(tableName: string, columnName: string): DropColumnOperation;
|
|
3329
|
+
declare function renameColumnOperation(tableName: string, fromColumnName: string, toColumnName: string): RenameColumnOperation;
|
|
3330
|
+
declare function alterColumnOperation(tableName: string, column: AnyColumnDefinition): AlterColumnOperation;
|
|
3331
|
+
declare function createForeignKeyOperation(tableName: string, columnName: string, reference: ForeignKeyReference, constraintName?: string): CreateForeignKeyOperation;
|
|
3332
|
+
declare function dropForeignKeyOperation(tableName: string, constraintName: string): DropForeignKeyOperation;
|
|
3333
|
+
|
|
3334
|
+
type IdentifierQuoter = (identifier: string) => string;
|
|
3335
|
+
declare abstract class SQLSchemaCompiler {
|
|
3336
|
+
protected readonly quoteIdentifier: IdentifierQuoter;
|
|
3337
|
+
constructor(quoteIdentifier: IdentifierQuoter);
|
|
3338
|
+
compile(operation: DDLOperation): DDLStatement[];
|
|
3339
|
+
compileCreateTable(table: TableDefinition): DDLStatement[];
|
|
3340
|
+
compileAddColumn(tableName: string, column: AnyColumnDefinition): DDLStatement;
|
|
3341
|
+
compileDropColumn(tableName: string, columnName: string): DDLStatement;
|
|
3342
|
+
compileRenameColumn(tableName: string, fromColumnName: string, toColumnName: string): DDLStatement;
|
|
3343
|
+
compileAlterColumn(tableName: string, column: AnyColumnDefinition): DDLStatement[];
|
|
3344
|
+
compileCreateForeignKey(tableName: string, columnName: string, reference: NonNullable<AnyColumnDefinition['references']>, constraintName?: string): DDLStatement;
|
|
3345
|
+
compileDropForeignKey(tableName: string, constraintName: string): DDLStatement;
|
|
3346
|
+
compileCreateIndex(tableName: string, index: TableIndexDefinition): DDLStatement;
|
|
3347
|
+
compileDropIndex(tableName: string, indexName: string): DDLStatement;
|
|
3348
|
+
compileRenameTable(fromTableName: string, toTableName: string): DDLStatement;
|
|
3349
|
+
compileRenameIndex(tableName: string, fromIndexName: string, toIndexName: string): DDLStatement;
|
|
3350
|
+
protected compileColumn(column: AnyColumnDefinition): string;
|
|
3351
|
+
protected appendPrimaryKeyExtras(_parts: string[], _column: AnyColumnDefinition): void;
|
|
3352
|
+
protected compileCurrentTimestamp(): string;
|
|
3353
|
+
protected compileIdentifierPath(identifier: string): string;
|
|
3354
|
+
protected assertSupportedDefaultValue(value: unknown, column: AnyColumnDefinition): void;
|
|
3355
|
+
protected isSupportedDefaultValue(value: unknown): boolean;
|
|
3356
|
+
protected resolveIndexName(tableName: string, index: TableIndexDefinition): string;
|
|
3357
|
+
protected resolveForeignKeyName(tableName: string, columnName: string, constraintName?: string): string;
|
|
3358
|
+
protected assertSupportedAlterColumnDefinition(column: AnyColumnDefinition): void;
|
|
3359
|
+
protected abstract getDialectLabel(): string;
|
|
3360
|
+
protected abstract compileColumnType(column: AnyColumnDefinition): string;
|
|
3361
|
+
protected abstract compileDefaultValue(value: unknown): string;
|
|
3362
|
+
}
|
|
3363
|
+
|
|
3364
|
+
declare class SQLiteSchemaCompiler extends SQLSchemaCompiler {
|
|
3365
|
+
protected getDialectLabel(): string;
|
|
3366
|
+
protected appendPrimaryKeyExtras(parts: string[], column: ColumnDefinition): void;
|
|
3367
|
+
protected compileColumnType(column: ColumnDefinition): string;
|
|
3368
|
+
protected compileDefaultValue(value: unknown): string;
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
declare class PostgresSchemaCompiler extends SQLSchemaCompiler {
|
|
3372
|
+
protected getDialectLabel(): string;
|
|
3373
|
+
protected compileColumnType(column: ColumnDefinition): string;
|
|
3374
|
+
protected compileDefaultValue(value: unknown): string;
|
|
3375
|
+
compileAlterColumn(tableName: string, column: ColumnDefinition): Array<{
|
|
3376
|
+
sql: string;
|
|
3377
|
+
source: string;
|
|
3378
|
+
}>;
|
|
3379
|
+
}
|
|
3380
|
+
|
|
3381
|
+
declare class MySQLSchemaCompiler extends SQLSchemaCompiler {
|
|
3382
|
+
protected getDialectLabel(): string;
|
|
3383
|
+
protected compileColumnType(column: ColumnDefinition): string;
|
|
3384
|
+
protected compileDefaultValue(value: unknown): string;
|
|
3385
|
+
compileRenameTable(fromTableName: string, toTableName: string): {
|
|
3386
|
+
sql: string;
|
|
3387
|
+
source: string;
|
|
3388
|
+
};
|
|
3389
|
+
compileRenameIndex(tableName: string, fromIndexName: string, toIndexName: string): {
|
|
3390
|
+
sql: string;
|
|
3391
|
+
source: string;
|
|
3392
|
+
};
|
|
3393
|
+
compileCreateIndex(tableName: string, index: TableIndexDefinition): {
|
|
3394
|
+
sql: string;
|
|
3395
|
+
source: string;
|
|
3396
|
+
};
|
|
3397
|
+
compileDropIndex(tableName: string, indexName: string): {
|
|
3398
|
+
sql: string;
|
|
3399
|
+
source: string;
|
|
3400
|
+
};
|
|
3401
|
+
compileDropForeignKey(tableName: string, constraintName: string): {
|
|
3402
|
+
sql: string;
|
|
3403
|
+
source: string;
|
|
3404
|
+
};
|
|
3405
|
+
}
|
|
3406
|
+
|
|
3407
|
+
type SchemaDefaultDialectName = 'sqlite' | 'postgres' | 'mysql';
|
|
3408
|
+
declare function compileDialectDefaultLiteral(dialect: SchemaDefaultDialectName, value: unknown): string;
|
|
3409
|
+
|
|
3410
|
+
type SchemaDialectName = 'sqlite' | 'postgres' | 'mysql';
|
|
3411
|
+
type ColumnTypeResolver = (column: AnyColumnDefinition) => string;
|
|
3412
|
+
type DialectTypeEntry = string | ColumnTypeResolver;
|
|
3413
|
+
type DialectTypeMapping = Readonly<Record<LogicalColumnKind, DialectTypeEntry>>;
|
|
3414
|
+
type DialectIdStrategyMap = Readonly<Record<IdGenerationStrategy, string>>;
|
|
3415
|
+
declare const DIALECT_ID_STRATEGY_MAP: Readonly<Record<SchemaDialectName, DialectIdStrategyMap>>;
|
|
3416
|
+
declare function resolveDialectIdStrategyType(dialect: SchemaDialectName, strategy: IdGenerationStrategy): string;
|
|
3417
|
+
declare const DIALECT_LOGICAL_TYPE_MAP: Readonly<Record<SchemaDialectName, DialectTypeMapping>>;
|
|
3418
|
+
declare function resolveDialectColumnType(dialect: SchemaDialectName, column: AnyColumnDefinition): string;
|
|
3419
|
+
|
|
3420
|
+
declare const DIALECT_VECTOR_SUPPORT: Readonly<Record<SchemaDialectName, boolean>>;
|
|
3421
|
+
declare function normalizeDialectReadValue(dialect: SchemaDialectName, column: AnyColumnDefinition, value: unknown): unknown;
|
|
3422
|
+
declare function normalizeDialectWriteValue(dialect: SchemaDialectName, column: AnyColumnDefinition, value: unknown): unknown;
|
|
3423
|
+
|
|
3424
|
+
declare function defineMigration<TDefinition extends MigrationDefinition>(definition: TDefinition): TDefinition;
|
|
3425
|
+
|
|
3426
|
+
declare function normalizeMigrationSlug(name: string): string;
|
|
3427
|
+
declare function createMigrationTimestamp(date?: Date): string;
|
|
3428
|
+
declare function createMigrationFileName(name: string, date?: Date): string;
|
|
3429
|
+
declare function inferMigrationTemplateKind(slug: string): MigrationTemplateKind;
|
|
3430
|
+
declare function inferMigrationTableName(slug: string, kind: MigrationTemplateKind): string | undefined;
|
|
3431
|
+
declare function generateMigrationTemplate(name: string, options?: MigrationTemplateOptions): GeneratedMigrationTemplate;
|
|
3432
|
+
|
|
3433
|
+
interface SeederContext {
|
|
3434
|
+
readonly db: DatabaseContext;
|
|
3435
|
+
readonly schema: SchemaService;
|
|
3436
|
+
call(...names: readonly string[]): Promise<readonly SeederDefinition[]>;
|
|
3437
|
+
}
|
|
3438
|
+
interface SeederDefinition {
|
|
3439
|
+
readonly name: string;
|
|
3440
|
+
run(context: SeederContext): unknown | Promise<unknown>;
|
|
3441
|
+
}
|
|
3442
|
+
interface SeedOptions {
|
|
3443
|
+
only?: readonly string[];
|
|
3444
|
+
quietly?: boolean;
|
|
3445
|
+
force?: boolean;
|
|
3446
|
+
environment?: string;
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
declare class SeederService {
|
|
3450
|
+
private readonly connection;
|
|
3451
|
+
private readonly seeders;
|
|
3452
|
+
constructor(connection: DatabaseContext, seeders?: readonly SeederDefinition[]);
|
|
3453
|
+
register(seeder: SeederDefinition): this;
|
|
3454
|
+
getSeeders(): readonly SeederDefinition[];
|
|
3455
|
+
getSeeder(name: string): SeederDefinition | undefined;
|
|
3456
|
+
seed(options?: SeedOptions): Promise<SeederDefinition[]>;
|
|
3457
|
+
private selectSeeders;
|
|
3458
|
+
private runSeeders;
|
|
3459
|
+
private createContext;
|
|
3460
|
+
private assertCanSeed;
|
|
3461
|
+
private createSeederLog;
|
|
3462
|
+
}
|
|
3463
|
+
declare function createSeederService(connection: DatabaseContext, seeders?: readonly SeederDefinition[]): SeederService;
|
|
3464
|
+
|
|
3465
|
+
declare function defineSeeder<TSeeder extends SeederDefinition>(seeder: TSeeder): TSeeder;
|
|
3466
|
+
|
|
3467
|
+
declare function defineFactory<TModel extends FactoryModelReference>(model: TModel, definition: FactoryDefinition<TModel>): Factory<TModel>;
|
|
3468
|
+
|
|
3469
|
+
declare function enumCast<TEnum extends Record<string, string | number>>(enumObject: TEnum): EnumCastDefinition;
|
|
3470
|
+
declare function binaryCast(): Readonly<{
|
|
3471
|
+
get(value: unknown): Uint8Array | null | undefined;
|
|
3472
|
+
set(value: unknown): Uint8Array | null | undefined;
|
|
3473
|
+
}>;
|
|
3474
|
+
declare function encryptedCast(secret: string): Readonly<{
|
|
3475
|
+
get(value: unknown): unknown;
|
|
3476
|
+
set(value: unknown): string | null | undefined;
|
|
3477
|
+
}>;
|
|
3478
|
+
|
|
3479
|
+
type BuilderCallback<TBuilder> = (query: TBuilder) => unknown;
|
|
3480
|
+
type ValueBuilderCallback<TBuilder, TValue> = (query: TBuilder, value: TValue) => unknown;
|
|
3481
|
+
type RelationConstraintCallback = (query: ModelQueryBuilder<TableDefinition>) => unknown;
|
|
3482
|
+
type RelationConstraintMap<TRelations extends RelationMap> = Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraintCallback>>>;
|
|
3483
|
+
type MorphEntityTarget = {
|
|
3484
|
+
exists(): boolean;
|
|
3485
|
+
getRepository(): {
|
|
3486
|
+
definition: {
|
|
3487
|
+
morphClass: string;
|
|
3488
|
+
primaryKey: string;
|
|
3489
|
+
};
|
|
3490
|
+
};
|
|
3491
|
+
get(key: string): unknown;
|
|
3492
|
+
};
|
|
3493
|
+
type MorphModelTarget = {
|
|
3494
|
+
definition?: {
|
|
3495
|
+
morphClass?: string;
|
|
3496
|
+
};
|
|
3497
|
+
};
|
|
3498
|
+
type MorphTypeSelector = string | MorphModelTarget | MorphEntityTarget | null;
|
|
3499
|
+
type SubqueryBuilder<TSubTable extends TableDefinition = TableDefinition> = ModelQueryBuilder<TSubTable> | TableQueryBuilder<TSubTable, Record<string, unknown>>;
|
|
3500
|
+
type ColumnShapeInput = Record<string, ColumnInput>;
|
|
3501
|
+
type EmptyColumnShape = Record<never, never>;
|
|
3502
|
+
type ModelTableBuilderResult<TName extends string, TColumns extends ColumnShapeInput> = {
|
|
3503
|
+
build(): BoundTableDefinition<TName, TColumns>;
|
|
3504
|
+
};
|
|
3505
|
+
type StaticModelApi<TTable extends TableDefinition, TScopes extends ModelScopesDefinition, TRelations extends RelationMap = RelationMap> = ModelReference<TTable, TScopes, TRelations> & ModelScopeMethods<TTable, TScopes, TRelations> & {
|
|
3506
|
+
query(): ModelQueryBuilder<TTable, TRelations>;
|
|
3507
|
+
newQuery(): ModelQueryBuilder<TTable, TRelations>;
|
|
3508
|
+
newModelQuery(): ModelQueryBuilder<TTable, TRelations>;
|
|
3509
|
+
newQueryWithoutScopes(): ModelQueryBuilder<TTable, TRelations>;
|
|
3510
|
+
newQueryWithoutRelationships(): ModelQueryBuilder<TTable, TRelations>;
|
|
3511
|
+
from(table: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3512
|
+
debug(): ReturnType<ModelQueryBuilder<TTable, TRelations>['debug']>;
|
|
3513
|
+
dump(): ModelQueryBuilder<TTable, TRelations>;
|
|
3514
|
+
preventLazyLoading(value?: boolean): StaticModelApi<TTable, TScopes, TRelations>;
|
|
3515
|
+
preventAccessingMissingAttributes(value?: boolean): StaticModelApi<TTable, TScopes, TRelations>;
|
|
3516
|
+
automaticallyEagerLoadRelationships(value?: boolean): StaticModelApi<TTable, TScopes, TRelations>;
|
|
3517
|
+
withoutEvents<TResult>(callback: () => TResult | Promise<TResult>): Promise<TResult>;
|
|
3518
|
+
unguarded<TResult>(callback: () => TResult | Promise<TResult>): Promise<TResult>;
|
|
3519
|
+
where(callback: BuilderCallback<ModelQueryBuilder<TTable, TRelations>>): ModelQueryBuilder<TTable, TRelations>;
|
|
3520
|
+
where(column: ModelColumnName<TTable> | ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3521
|
+
orWhere(callback: BuilderCallback<ModelQueryBuilder<TTable, TRelations>>): ModelQueryBuilder<TTable, TRelations>;
|
|
3522
|
+
orWhere(column: ModelColumnName<TTable> | ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3523
|
+
whereNot(callback: BuilderCallback<ModelQueryBuilder<TTable, TRelations>>): ModelQueryBuilder<TTable, TRelations>;
|
|
3524
|
+
orWhereNot(callback: BuilderCallback<ModelQueryBuilder<TTable, TRelations>>): ModelQueryBuilder<TTable, TRelations>;
|
|
3525
|
+
whereExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3526
|
+
orWhereExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3527
|
+
whereNotExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3528
|
+
orWhereNotExists<TSubTable extends TableDefinition>(subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3529
|
+
whereSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'in' | 'not in' | 'like', subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3530
|
+
orWhereSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'in' | 'not in' | 'like', subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3531
|
+
whereInSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3532
|
+
whereNotInSub<TSubTable extends TableDefinition>(column: ModelColumnName<TTable>, subquery: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3533
|
+
select(...columns: readonly ModelSelectableColumn<TTable>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3534
|
+
addSelect(...columns: readonly ModelSelectableColumn<TTable>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3535
|
+
withCasts(casts: Record<string, ModelCastDefinition>): ModelQueryBuilder<TTable, TRelations>;
|
|
3536
|
+
selectSub<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3537
|
+
addSelectSub<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3538
|
+
whereNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3539
|
+
orWhereNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3540
|
+
whereNotNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3541
|
+
orWhereNotNull(column: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3542
|
+
when<TValue>(value: TValue, callback: ValueBuilderCallback<ModelQueryBuilder<TTable, TRelations>, TValue>, defaultCallback?: ValueBuilderCallback<ModelQueryBuilder<TTable, TRelations>, TValue>): ModelQueryBuilder<TTable, TRelations>;
|
|
3543
|
+
unless<TValue>(value: TValue, callback: ValueBuilderCallback<ModelQueryBuilder<TTable, TRelations>, TValue>, defaultCallback?: ValueBuilderCallback<ModelQueryBuilder<TTable, TRelations>, TValue>): ModelQueryBuilder<TTable, TRelations>;
|
|
3544
|
+
distinct(): ModelQueryBuilder<TTable, TRelations>;
|
|
3545
|
+
whereColumn(column: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', compareTo: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3546
|
+
whereIn(column: ModelColumnName<TTable>, values: readonly unknown[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3547
|
+
whereNotIn(column: ModelColumnName<TTable>, values: readonly unknown[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3548
|
+
whereBetween(column: ModelColumnName<TTable>, range: readonly [unknown, unknown]): ModelQueryBuilder<TTable, TRelations>;
|
|
3549
|
+
whereNotBetween(column: ModelColumnName<TTable>, range: readonly [unknown, unknown]): ModelQueryBuilder<TTable, TRelations>;
|
|
3550
|
+
whereLike(column: ModelColumnName<TTable>, pattern: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3551
|
+
orWhereLike(column: ModelColumnName<TTable>, pattern: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3552
|
+
whereAny(columns: readonly ModelColumnName<TTable>[], operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3553
|
+
whereAll(columns: readonly ModelColumnName<TTable>[], operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3554
|
+
whereNone(columns: readonly ModelColumnName<TTable>[], operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3555
|
+
join(table: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3556
|
+
leftJoin(table: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3557
|
+
rightJoin(table: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3558
|
+
crossJoin(table: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3559
|
+
joinSub<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>, alias: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3560
|
+
leftJoinSub<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>, alias: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3561
|
+
rightJoinSub<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>, alias: string, leftColumn: ModelColumnReference<TTable>, operator: '!=' | '=' | '>' | '>=' | '<' | '<=' | 'like', rightColumn: ModelColumnReference<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3562
|
+
joinLateral<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3563
|
+
leftJoinLateral<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>, alias: string): ModelQueryBuilder<TTable, TRelations>;
|
|
3564
|
+
union<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3565
|
+
unionAll<TSubTable extends TableDefinition>(query: SubqueryBuilder<TSubTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3566
|
+
groupBy(...columns: readonly ModelColumnName<TTable>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3567
|
+
having(expression: string, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3568
|
+
havingBetween(expression: string, range: readonly [unknown, unknown]): ModelQueryBuilder<TTable, TRelations>;
|
|
3569
|
+
unsafeWhere(sql: string, bindings: readonly unknown[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3570
|
+
orUnsafeWhere(sql: string, bindings: readonly unknown[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3571
|
+
whereDate(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3572
|
+
whereMonth(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3573
|
+
whereDay(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3574
|
+
whereYear(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3575
|
+
whereTime(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3576
|
+
whereJson(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3577
|
+
orWhereJson(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3578
|
+
whereJsonContains(columnPath: ModelJsonColumnPath<TTable>, value: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3579
|
+
orWhereJsonContains(columnPath: ModelJsonColumnPath<TTable>, value: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3580
|
+
whereJsonLength(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3581
|
+
orWhereJsonLength(columnPath: ModelJsonColumnPath<TTable>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3582
|
+
whereFullText(columns: ModelColumnName<TTable> | readonly ModelColumnName<TTable>[], value: string, options?: {
|
|
3583
|
+
mode?: 'natural' | 'boolean';
|
|
3584
|
+
}): ModelQueryBuilder<TTable, TRelations>;
|
|
3585
|
+
orWhereFullText(columns: ModelColumnName<TTable> | readonly ModelColumnName<TTable>[], value: string, options?: {
|
|
3586
|
+
mode?: 'natural' | 'boolean';
|
|
3587
|
+
}): ModelQueryBuilder<TTable, TRelations>;
|
|
3588
|
+
whereVectorSimilarTo(column: ModelColumnName<TTable>, vector: readonly number[], minSimilarity?: number): ModelQueryBuilder<TTable, TRelations>;
|
|
3589
|
+
orWhereVectorSimilarTo(column: ModelColumnName<TTable>, vector: readonly number[], minSimilarity?: number): ModelQueryBuilder<TTable, TRelations>;
|
|
3590
|
+
latest(column?: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3591
|
+
oldest(column?: ModelColumnName<TTable>): ModelQueryBuilder<TTable, TRelations>;
|
|
3592
|
+
inRandomOrder(): ModelQueryBuilder<TTable, TRelations>;
|
|
3593
|
+
reorder(column?: ModelColumnName<TTable>, direction?: 'asc' | 'desc'): ModelQueryBuilder<TTable, TRelations>;
|
|
3594
|
+
unsafeOrderBy(sql: string, bindings: readonly unknown[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3595
|
+
lock(mode: 'update' | 'share'): ModelQueryBuilder<TTable, TRelations>;
|
|
3596
|
+
lockForUpdate(): ModelQueryBuilder<TTable, TRelations>;
|
|
3597
|
+
sharedLock(): ModelQueryBuilder<TTable, TRelations>;
|
|
3598
|
+
with<TPaths extends readonly ModelRelationPath<TRelations>[]>(...relations: TPaths): ModelQueryBuilder<TTable, TRelations, ResolveEagerLoads<TRelations, TPaths>>;
|
|
3599
|
+
with<TPath extends ModelRelationPath<TRelations>>(relation: TPath, constraint: RelationConstraintCallback): ModelQueryBuilder<TTable, TRelations, ResolveEagerLoads<TRelations, readonly [TPath]>>;
|
|
3600
|
+
with<TMap extends Readonly<Partial<Record<ModelRelationPath<TRelations>, RelationConstraintCallback>>>>(relations: TMap): ModelQueryBuilder<TTable, TRelations>;
|
|
3601
|
+
withCount(...relations: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3602
|
+
withCount(relations: RelationConstraintMap<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3603
|
+
withExists(...relations: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3604
|
+
withExists(relations: RelationConstraintMap<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3605
|
+
withSum<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath | RelationConstraintMap<TRelations>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3606
|
+
withAvg<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath | RelationConstraintMap<TRelations>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3607
|
+
withMin<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath | RelationConstraintMap<TRelations>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3608
|
+
withMax<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath | RelationConstraintMap<TRelations>, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, ...rest: readonly ModelRelationPath<TRelations>[]): ModelQueryBuilder<TTable, TRelations>;
|
|
3609
|
+
has(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3610
|
+
orHas(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3611
|
+
whereHas(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraintCallback): ModelQueryBuilder<TTable, TRelations>;
|
|
3612
|
+
orWhereHas(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraintCallback): ModelQueryBuilder<TTable, TRelations>;
|
|
3613
|
+
doesntHave(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3614
|
+
orDoesntHave(relation: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3615
|
+
whereDoesntHave(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraintCallback): ModelQueryBuilder<TTable, TRelations>;
|
|
3616
|
+
orWhereDoesntHave(relation: ModelRelationPath<TRelations>, constraint?: RelationConstraintCallback): ModelQueryBuilder<TTable, TRelations>;
|
|
3617
|
+
whereRelation<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3618
|
+
orWhereRelation<TRelationPath extends ModelRelationPath<TRelations>>(relation: TRelationPath, column: RelatedColumnNameForRelationPath<TRelations, TRelationPath>, operator: unknown, value?: unknown): ModelQueryBuilder<TTable, TRelations>;
|
|
3619
|
+
whereBelongsTo<TRelated extends TableDefinition>(entity: Entity<TRelated>, relationName?: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3620
|
+
orWhereBelongsTo<TRelated extends TableDefinition>(entity: Entity<TRelated>, relationName?: ModelRelationPath<TRelations>): ModelQueryBuilder<TTable, TRelations>;
|
|
3621
|
+
whereMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector): ModelQueryBuilder<TTable, TRelations>;
|
|
3622
|
+
orWhereMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector): ModelQueryBuilder<TTable, TRelations>;
|
|
3623
|
+
whereNotMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector): ModelQueryBuilder<TTable, TRelations>;
|
|
3624
|
+
orWhereNotMorphedTo(relation: ModelRelationPath<TRelations>, target: MorphTypeSelector): ModelQueryBuilder<TTable, TRelations>;
|
|
3625
|
+
withWhereHas<TPath extends ModelRelationPath<TRelations>>(relation: TPath, constraint?: RelationConstraintCallback): ModelQueryBuilder<TTable, TRelations, ResolveEagerLoads<TRelations, readonly [TPath]>>;
|
|
3626
|
+
find(value: unknown): Promise<Entity<TTable, TRelations> | undefined>;
|
|
3627
|
+
findMany(values: readonly unknown[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
3628
|
+
findOrFail(value: unknown): Promise<Entity<TTable, TRelations>>;
|
|
3629
|
+
first(): Promise<Entity<TTable, TRelations> | undefined>;
|
|
3630
|
+
firstOrFail(): Promise<Entity<TTable, TRelations>>;
|
|
3631
|
+
sole(): Promise<Entity<TTable, TRelations>>;
|
|
3632
|
+
firstWhere(column: ModelColumnName<TTable>, operator: unknown, value?: unknown): Promise<Entity<TTable, TRelations> | undefined>;
|
|
3633
|
+
get(): Promise<ModelCollection<TTable, TRelations>>;
|
|
3634
|
+
all(): Promise<ModelCollection<TTable, TRelations>>;
|
|
3635
|
+
paginate(perPage?: number, page?: number, options?: PaginationOptions): Promise<PaginatedResult<Entity<TTable, TRelations>> & {
|
|
3636
|
+
data: ModelCollection<TTable, TRelations>;
|
|
3637
|
+
}>;
|
|
3638
|
+
simplePaginate(perPage?: number, page?: number, options?: PaginationOptions): Promise<SimplePaginatedResult<Entity<TTable, TRelations>> & {
|
|
3639
|
+
data: ModelCollection<TTable, TRelations>;
|
|
3640
|
+
}>;
|
|
3641
|
+
cursorPaginate(perPage?: number, cursor?: string | null, options?: CursorPaginationOptions): Promise<CursorPaginatedResult<Entity<TTable, TRelations>> & {
|
|
3642
|
+
data: ModelCollection<TTable, TRelations>;
|
|
3643
|
+
}>;
|
|
3644
|
+
chunk(size: number, callback: (rows: readonly Entity<TTable, TRelations>[], page: number) => unknown | Promise<unknown>): Promise<void>;
|
|
3645
|
+
chunkById(size: number, callback: (rows: readonly Entity<TTable, TRelations>[], page: number) => unknown | Promise<unknown>, column?: ModelAttributeKey<TTable>): Promise<void>;
|
|
3646
|
+
chunkByIdDesc(size: number, callback: (rows: readonly Entity<TTable, TRelations>[], page: number) => unknown | Promise<unknown>, column?: ModelAttributeKey<TTable>): Promise<void>;
|
|
3647
|
+
lazy(size?: number): AsyncGenerator<Entity<TTable, TRelations>, void, unknown>;
|
|
3648
|
+
cursor(): AsyncGenerator<Entity<TTable, TRelations>, void, unknown>;
|
|
3649
|
+
count(): Promise<number>;
|
|
3650
|
+
exists(): Promise<boolean>;
|
|
3651
|
+
doesntExist(): Promise<boolean>;
|
|
3652
|
+
pluck<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<Array<ModelRecord<TTable>[TColumn]>>;
|
|
3653
|
+
value<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<ModelRecord<TTable>[TColumn] | undefined>;
|
|
3654
|
+
valueOrFail<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<ModelRecord<TTable>[TColumn]>;
|
|
3655
|
+
soleValue<TColumn extends ModelAttributeKey<TTable>>(column: TColumn): Promise<ModelRecord<TTable>[TColumn]>;
|
|
3656
|
+
sum(column: ModelColumnName<TTable>): Promise<number>;
|
|
3657
|
+
avg(column: ModelColumnName<TTable>): Promise<number | null>;
|
|
3658
|
+
min(column: ModelColumnName<TTable>): Promise<number | null>;
|
|
3659
|
+
max(column: ModelColumnName<TTable>): Promise<number | null>;
|
|
3660
|
+
create(values: Partial<ModelRecord<TTable>>): Promise<Entity<TTable, TRelations>>;
|
|
3661
|
+
create(values: InferInsert<TTable>): Promise<Entity<TTable, TRelations>>;
|
|
3662
|
+
createMany(values: readonly Partial<ModelRecord<TTable>>[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
3663
|
+
createMany(values: readonly InferInsert<TTable>[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
3664
|
+
createQuietly(values: Partial<ModelRecord<TTable>>): Promise<Entity<TTable, TRelations>>;
|
|
3665
|
+
createQuietly(values: InferInsert<TTable>): Promise<Entity<TTable, TRelations>>;
|
|
3666
|
+
createManyQuietly(values: readonly Partial<ModelRecord<TTable>>[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
3667
|
+
createManyQuietly(values: readonly InferInsert<TTable>[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
3668
|
+
update(id: unknown, values: ModelUpdatePayload<TTable>): Promise<Entity<TTable, TRelations>>;
|
|
3669
|
+
prune(): Promise<number>;
|
|
3670
|
+
increment(column: ModelColumnName<TTable>, amount?: number, extraValues?: Partial<ModelRecord<TTable>>): Promise<DriverExecutionResult>;
|
|
3671
|
+
decrement(column: ModelColumnName<TTable>, amount?: number, extraValues?: Partial<ModelRecord<TTable>>): Promise<DriverExecutionResult>;
|
|
3672
|
+
delete(id: unknown): Promise<void>;
|
|
3673
|
+
destroy(ids: readonly unknown[]): Promise<number>;
|
|
3674
|
+
restore(id: unknown): Promise<Entity<TTable, TRelations>>;
|
|
3675
|
+
forceDelete(id: unknown): Promise<void>;
|
|
3676
|
+
withTrashed(): ModelQueryBuilder<TTable, TRelations>;
|
|
3677
|
+
onlyTrashed(): ModelQueryBuilder<TTable, TRelations>;
|
|
3678
|
+
updateOrCreate(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable, TRelations>>;
|
|
3679
|
+
upsert(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable, TRelations>>;
|
|
3680
|
+
firstOrNew(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable, TRelations>>;
|
|
3681
|
+
firstOrCreate(match: Partial<ModelRecord<TTable>>, values?: Partial<ModelRecord<TTable>>): Promise<Entity<TTable, TRelations>>;
|
|
3682
|
+
saveMany(entities: readonly Entity<TTable, TRelations>[]): Promise<ModelCollection<TTable, TRelations>>;
|
|
3683
|
+
resolveRelationUsing(name: string, resolver: DynamicRelationResolver): StaticModelApi<TTable, TScopes, TRelations>;
|
|
3684
|
+
make(values?: Partial<ModelRecord<TTable>>): Entity<TTable, TRelations>;
|
|
3685
|
+
getRepository(): ModelRepository<TTable>;
|
|
3686
|
+
getConnectionName(): string | undefined;
|
|
3687
|
+
getTableName(): string;
|
|
3688
|
+
};
|
|
3689
|
+
declare function defineModel<TTable extends TableDefinition, TScopes extends ModelScopesDefinition = EmptyScopeMap, TRelations extends RelationMap = RelationMap>(table: TTable, options?: DefineModelOptions<TTable, TScopes, TRelations>): StaticModelApi<TTable, TScopes, TRelations>;
|
|
3690
|
+
declare function defineModel<TName extends string, TColumns extends ColumnShapeInput, TScopes extends ModelScopesDefinition = EmptyScopeMap, TRelations extends RelationMap = RelationMap>(tableName: TName, builder: (table: TableDefinitionBuilder<TName, EmptyColumnShape>) => ModelTableBuilderResult<TName, TColumns>, options?: DefineModelOptions<BoundTableDefinition<TName, TColumns>, TScopes, TRelations>): StaticModelApi<BoundTableDefinition<TName, TColumns>, TScopes, TRelations>;
|
|
3691
|
+
declare function defineModel<TName extends string, TScopes extends ModelScopesDefinition = EmptyScopeMap, TRelations extends RelationMap = RelationMap>(tableName: TName, options?: DefineModelOptions<GeneratedSchemaTable<TName>, TScopes, TRelations>): StaticModelApi<GeneratedSchemaTable<TName>, TScopes, TRelations>;
|
|
3692
|
+
|
|
3693
|
+
declare function resolveMorphModel(type: string): ModelDefinitionLike | undefined;
|
|
3694
|
+
declare function resetMorphRegistry(): void;
|
|
3695
|
+
|
|
3696
|
+
declare function belongsTo<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, foreignKeyOrOptions: string | {
|
|
3697
|
+
foreignKey: string;
|
|
3698
|
+
ownerKey?: string;
|
|
3699
|
+
}, ownerKey?: string): BelongsToRelationDefinition<TRelated>;
|
|
3700
|
+
declare function hasMany<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, foreignKeyOrOptions: string | {
|
|
3701
|
+
foreignKey: string;
|
|
3702
|
+
localKey?: string;
|
|
3703
|
+
}, localKey?: string): HasManyRelationDefinition<TRelated>;
|
|
3704
|
+
declare function hasOne<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, foreignKeyOrOptions: string | {
|
|
3705
|
+
foreignKey: string;
|
|
3706
|
+
localKey?: string;
|
|
3707
|
+
}, localKey?: string): HasOneRelationDefinition<TRelated>;
|
|
3708
|
+
declare function morphOne<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, name: string, type?: string, id?: string, localKey?: string): MorphOneRelationDefinition<TRelated>;
|
|
3709
|
+
declare function morphMany<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, name: string, type?: string, id?: string, localKey?: string): MorphManyRelationDefinition<TRelated>;
|
|
3710
|
+
declare function morphOfMany<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, name: string, aggregateColumn: string, aggregate?: 'min' | 'max', type?: string, id?: string, localKey?: string): MorphOneOfManyRelationDefinition<TRelated>;
|
|
3711
|
+
declare function latestMorphOne<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, name: string, column?: string, type?: string, id?: string, localKey?: string): MorphOneOfManyRelationDefinition<TRelated>;
|
|
3712
|
+
declare function oldestMorphOne<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, name: string, column?: string, type?: string, id?: string, localKey?: string): MorphOneOfManyRelationDefinition<TRelated>;
|
|
3713
|
+
declare function morphTo(name: string, type?: string, id?: string): MorphToRelationDefinition;
|
|
3714
|
+
declare function ofMany<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, foreignKey: string, aggregateColumn: string, aggregate?: 'min' | 'max', localKey?: string): HasOneOfManyRelationDefinition<TRelated>;
|
|
3715
|
+
declare function latestOfMany<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, foreignKey: string, localKey?: string, column?: string): HasOneOfManyRelationDefinition<TRelated>;
|
|
3716
|
+
declare function oldestOfMany<TRelated extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, foreignKey: string, localKey?: string, column?: string): HasOneOfManyRelationDefinition<TRelated>;
|
|
3717
|
+
declare function belongsToMany<TRelated extends ModelDefinitionLike<TableDefinition>, TPivotTable extends string | TableDefinition>(related: () => TRelated, pivotTableOrOptions: TPivotTable | {
|
|
3718
|
+
pivotTable: TPivotTable;
|
|
3719
|
+
foreignPivotKey: string;
|
|
3720
|
+
relatedPivotKey: string;
|
|
3721
|
+
parentKey?: string;
|
|
3722
|
+
relatedKey?: string;
|
|
3723
|
+
}, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): BelongsToManyRelationDefinition<TRelated, TPivotTable> & PivotRelationMethods<BelongsToManyRelationDefinition<TRelated, TPivotTable>, TPivotTable>;
|
|
3724
|
+
declare function morphToMany<TRelated extends ModelDefinitionLike<TableDefinition>, TPivotTable extends string | TableDefinition>(related: () => TRelated, name: string, pivotTable: TPivotTable, foreignPivotKey: string, parentKey?: string, relatedKey?: string, type?: string, id?: string): MorphToManyRelationDefinition<TRelated, TPivotTable> & PivotRelationMethods<MorphToManyRelationDefinition<TRelated, TPivotTable>, TPivotTable>;
|
|
3725
|
+
declare function morphedByMany<TRelated extends ModelDefinitionLike<TableDefinition>, TPivotTable extends string | TableDefinition>(related: () => TRelated, name: string, pivotTable: TPivotTable, foreignPivotKey: string, parentKey?: string, relatedKey?: string, type?: string, id?: string): MorphedByManyRelationDefinition<TRelated, TPivotTable> & PivotRelationMethods<MorphedByManyRelationDefinition<TRelated, TPivotTable>, TPivotTable>;
|
|
3726
|
+
declare function scopeRelation<TRelation extends RelationDefinition>(relation: TRelation, constraint: RelationConstraintDefinition): TRelation;
|
|
3727
|
+
declare function hasOneThrough<TRelated extends ModelDefinitionLike<TableDefinition>, TThrough extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, through: () => TThrough, firstKey: string, secondKey: string, localKey?: string, secondLocalKey?: string): HasOneThroughRelationDefinition<TRelated, TThrough>;
|
|
3728
|
+
declare function hasManyThrough<TRelated extends ModelDefinitionLike<TableDefinition>, TThrough extends ModelDefinitionLike<TableDefinition>>(related: () => TRelated, through: () => TThrough, firstKey: string, secondKey: string, localKey?: string, secondLocalKey?: string): HasManyThroughRelationDefinition<TRelated, TThrough>;
|
|
3729
|
+
|
|
3730
|
+
interface UniqueIdTraitOptions<TTable extends TableDefinition = TableDefinition> {
|
|
3731
|
+
columns?: readonly ModelAttributeKey<TTable>[];
|
|
3732
|
+
generator?: () => string;
|
|
3733
|
+
}
|
|
3734
|
+
declare function generateUuidV7(): string;
|
|
3735
|
+
declare function generateUlid(): string;
|
|
3736
|
+
declare function generateSnowflake(): string;
|
|
3737
|
+
declare function HasUniqueIds<TTable extends TableDefinition = TableDefinition>(options?: UniqueIdTraitOptions<TTable>): UniqueIdTrait<TTable>;
|
|
3738
|
+
declare function HasUuids<TTable extends TableDefinition = TableDefinition>(options?: Omit<UniqueIdTraitOptions<TTable>, 'generator'>): UniqueIdTrait<TTable>;
|
|
3739
|
+
declare function HasUlids<TTable extends TableDefinition = TableDefinition>(options?: Omit<UniqueIdTraitOptions<TTable>, 'generator'>): UniqueIdTrait<TTable>;
|
|
3740
|
+
declare function HasSnowflakes<TTable extends TableDefinition = TableDefinition>(options?: Omit<UniqueIdTraitOptions<TTable>, 'generator'>): UniqueIdTrait<TTable>;
|
|
3741
|
+
|
|
3742
|
+
interface HoloProjectPaths {
|
|
3743
|
+
models: string;
|
|
3744
|
+
migrations: string;
|
|
3745
|
+
generatedSchema: string;
|
|
3746
|
+
seeders: string;
|
|
3747
|
+
observers: string;
|
|
3748
|
+
factories: string;
|
|
3749
|
+
commands: string;
|
|
3750
|
+
jobs: string;
|
|
3751
|
+
events: string;
|
|
3752
|
+
listeners: string;
|
|
3753
|
+
}
|
|
3754
|
+
interface HoloProjectConnectionConfig {
|
|
3755
|
+
driver?: SupportedDatabaseDriver;
|
|
3756
|
+
url?: string;
|
|
3757
|
+
host?: string;
|
|
3758
|
+
port?: number | string;
|
|
3759
|
+
username?: string;
|
|
3760
|
+
password?: string;
|
|
3761
|
+
database?: string;
|
|
3762
|
+
filename?: string;
|
|
3763
|
+
schema?: string;
|
|
3764
|
+
ssl?: boolean | Record<string, unknown>;
|
|
3765
|
+
logging?: boolean;
|
|
3766
|
+
}
|
|
3767
|
+
interface HoloProjectDatabaseConfig {
|
|
3768
|
+
defaultConnection?: string;
|
|
3769
|
+
connections?: Record<string, HoloProjectConnectionConfig | string>;
|
|
3770
|
+
}
|
|
3771
|
+
interface HoloProjectConfig {
|
|
3772
|
+
paths?: Partial<HoloProjectPaths>;
|
|
3773
|
+
database?: HoloProjectDatabaseConfig;
|
|
3774
|
+
models?: readonly string[];
|
|
3775
|
+
migrations?: readonly string[];
|
|
3776
|
+
seeders?: readonly string[];
|
|
3777
|
+
}
|
|
3778
|
+
declare const DEFAULT_HOLO_PROJECT_PATHS: Readonly<HoloProjectPaths>;
|
|
3779
|
+
interface NormalizedHoloProjectConfig {
|
|
3780
|
+
readonly paths: Readonly<HoloProjectPaths>;
|
|
3781
|
+
readonly database?: HoloProjectDatabaseConfig;
|
|
3782
|
+
readonly models: readonly string[];
|
|
3783
|
+
readonly migrations: readonly string[];
|
|
3784
|
+
readonly seeders: readonly string[];
|
|
3785
|
+
}
|
|
3786
|
+
declare function normalizeHoloProjectConfig(config?: HoloProjectConfig): NormalizedHoloProjectConfig;
|
|
3787
|
+
declare function defineHoloProject<TConfig extends HoloProjectConfig>(config: TConfig): NormalizedHoloProjectConfig & TConfig;
|
|
3788
|
+
|
|
3789
|
+
export { type AddColumnOperation, type AlterColumnOperation, type AnyColumnDefinition, AsyncConnectionContext, CapabilityError, ColumnBuilder, type ColumnDefinition, type CompiledStatement, CompilerError, type ConcurrencyOptions, ConfigurationError, ConnectionManager, type ConnectionManagerOptions, type CreateForeignKeyOperation, type CreateIndexOperation, type CreateTableOperation, type CursorPaginatedResult, DB, type DDLOperation, type DDLStatement, DEFAULT_CAPABILITIES, DEFAULT_HOLO_PROJECT_PATHS, DEFAULT_SECURITY_POLICY, DIALECT_ID_STRATEGY_MAP, DIALECT_LOGICAL_TYPE_MAP, DIALECT_VECTOR_SUPPORT, type DatabaseCapabilities, DatabaseContext, type DatabaseContextOptions, type DatabaseDriverName, DatabaseError, type DatabaseLogger, type DatabaseOperationOptions, type DefineModelOptions, type DeleteQueryPlan, type Dialect, type DriverAdapter, type DriverExecutionResult, type DriverQueryResult, type DropColumnOperation, type DropForeignKeyOperation, type DropIndexOperation, type DropTableOperation, type DynamicRelationResolver, Entity, type EntityWithLoaded, Factory, type FactoryAttributes, type FactoryContext, type FactoryDefinition, type FactoryHook, type FactoryModelReference, FactoryService, type FactoryStateDefinition, type ForeignKeyReference, type GeneratedMigrationTemplate, type GeneratedSchemaTable, type GeneratedSchemaTableName, type GeneratedSchemaTables, HasSnowflakes, HasUlids, HasUniqueIds, HasUuids, type HoloProjectConfig, type HoloProjectConnectionConfig, type HoloProjectDatabaseConfig, type HoloProjectPaths, HydrationError, type IdGenerationStrategy, type InferInsert, type InferSelect, type InferUpdate, type InsertQueryPlan, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedIndex, type LogicalColumnKind, type MigrateOptions, type MigrationContext, type MigrationDefinition, type MigrationErrorLog, type MigrationExecutionPolicy, MigrationService, type MigrationSquashPlan, type MigrationStartLog, type MigrationStatus, type MigrationSuccessLog, type MigrationTemplateKind, type MigrationTemplateOptions, type ModelAttributeKey, type ModelCollection, type ModelDefinition, ModelEventService, type ModelInsertPayload, ModelNotFoundException, ModelQueryBuilder, type ModelRecord, type ModelReference, ModelRegistry, ModelRepository, type ModelScopeArgs, type ModelScopeMap, type ModelTrait, type ModelUpdatePayload, MySQLAdapter, type MySQLAdapterOptions, type MySQLClientLike, type MySQLPoolLike, MySQLQueryCompiler, type MySQLQueryableLike, MySQLSchemaCompiler, type NormalizedHoloProjectConfig, type PaginatedResult, type PaginationMeta, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientLike, type PostgresPoolLike, PostgresQueryCompiler, type PostgresQueryableLike, PostgresSchemaCompiler, type QueryDirection, type QueryOperator, type QueryOrderBy, type QueryPlan, type QueryPredicate, QueryScheduler, type QuerySelection, type QuerySource, type RelationDefinition, RelationError, type RelationMap, type RenameColumnOperation, type RenameIndexOperation, type RenameTableOperation, type ResolveEagerLoadPath, type ResolveEagerLoadUnion, type ResolveEagerLoads, type RollbackOptions, type RuntimeConfigInput, type RuntimeConnectionConfig, type RuntimeDatabaseConfig, type RuntimeHoloConfig, SQLQueryCompiler, SQLSchemaCompiler, SQLiteAdapter, type SQLiteAdapterOptions, type SQLiteDatabaseLike, SQLiteQueryCompiler, SQLiteSchemaCompiler, type SQLiteStatementLike, type SchemaColumnMismatch, type SchemaDefaultDialectName, type SchemaDialectName, type SchemaDiff, SchemaError, type SchemaForeignKeyMismatch, type SchemaIndexMismatch, SchemaRegistry, SchemaService, type SchemaSyncPlan, SecurityError, type SecurityPolicy, type SeedOptions, type SeederContext, type SeederDefinition, type SeederErrorLog, SeederService, type SeederStartLog, type SeederSuccessLog, type SelectQueryPlan, SerializationError, type SerializedEntityWithLoaded, type SimplePaginatedResult, type SimplePaginationMeta, type SupportedDatabaseDriver, type TableColumnsShape, type TableDefinition, TableDefinitionBuilder, type TableIndexDefinition, TableMutationBuilder, TableQueryBuilder, type TableSchemaDiff, type TransactionCallback, TransactionError, type UniqueIdRuntimeConfig, type UniqueIdTrait, type UniqueIdTraitKind, type UnsafeStatement, type UpdateQueryPlan, type VectorValue, addColumnOperation, alterColumnOperation, belongsTo, belongsToMany, binaryCast, clearGeneratedTables, column, compileDialectDefaultLiteral, configureDB, connectionAsyncContext, createAdapter, createCapabilities, createConnectionManager, createCursorPaginator, createDatabase, createDeleteQueryPlan, createDialect, createFactoryService, createForeignKeyOperation, createIndexOperation, createInsertQueryPlan, createMigrationFileName, createMigrationService, createMigrationTimestamp, createModelCollection, createModelEventService, createModelRegistry, createMySQLAdapter, createPaginator, createPostgresAdapter, createQueryScheduler, createRuntimeConnectionOptions, createRuntimeLogger, createSQLiteAdapter, diffSchema as createSchemaDiff, createSchemaRegistry, createSchemaService, createSecurityPolicy, createSeederService, createSelectQueryPlan, createSimplePaginator, createTableOperation, createTableSource, createUpdateQueryPlan, defineFactory, defineGeneratedTable, defineHoloProject, defineMigration, defineModel, defineSeeder, diffSchema, dropColumnOperation, dropForeignKeyOperation, dropIndexOperation, dropTableOperation, encryptedCast, enumCast, generateMigrationTemplate, generateSnowflake, generateUlid, generateUuidV7, getGeneratedTableDefinition, getModelDefinition, hasMany, hasManyThrough, hasOne, hasOneThrough, inferMigrationTableName, inferMigrationTemplateKind, isSupportedDatabaseDriver, latestMorphOne, latestOfMany, listGeneratedTableDefinitions, morphMany, morphOfMany, morphOne, morphTo, morphToMany, morphedByMany, normalizeDialectReadValue, normalizeDialectWriteValue, normalizeHoloProjectConfig, normalizeMigrationSlug, ofMany, oldestMorphOne, oldestOfMany, parseDatabaseDriver, redactBindings, redactSql, registerGeneratedTables, renameColumnOperation, renameIndexOperation, renameTableOperation, renderGeneratedSchemaModule, renderGeneratedSchemaPlaceholder, resetDB, resetMorphRegistry, resolveDialectColumnType, resolveDialectIdStrategyType, resolveGeneratedTableDefinition, resolveMorphModel, resolveRuntimeConnectionManagerOptions, scopeRelation, unsafeSql, validateQueryPlan, withLimit, withOffset, withOrderBy, withPredicate, withSelections };
|