hysteria-orm 10.5.4 → 10.5.6
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/lib/cli.js +32 -32
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +22 -22
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1257 -1358
- package/lib/index.d.ts +1257 -1358
- package/lib/index.js +22 -22
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -2152,71 +2152,38 @@ declare class InterpreterUtils {
|
|
|
2152
2152
|
getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
|
|
2153
2153
|
}
|
|
2154
2154
|
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
};
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
declare class OnDuplicateNode extends QueryNode {
|
|
2188
|
-
table: string;
|
|
2189
|
-
conflictColumns: string[];
|
|
2190
|
-
columnsToUpdate: string[];
|
|
2191
|
-
returning?: string[];
|
|
2192
|
-
mode: "update" | "ignore";
|
|
2193
|
-
chainsWith: string;
|
|
2194
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
2195
|
-
folder: string;
|
|
2196
|
-
file: string;
|
|
2197
|
-
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
2201
|
-
|
|
2202
|
-
declare class TruncateNode extends QueryNode {
|
|
2203
|
-
fromNode: FromNode | string;
|
|
2204
|
-
chainsWith: string;
|
|
2205
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
2206
|
-
folder: string;
|
|
2207
|
-
file: string;
|
|
2208
|
-
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
declare class UpdateNode extends QueryNode {
|
|
2212
|
-
fromNode: FromNode;
|
|
2213
|
-
columns: string[];
|
|
2214
|
-
values: (any | RawNode)[];
|
|
2215
|
-
chainsWith: string;
|
|
2216
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
2217
|
-
folder: string;
|
|
2218
|
-
file: string;
|
|
2219
|
-
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
2155
|
+
/**
|
|
2156
|
+
* A PromiseLike wrapper for write operations that allows SQL inspection without execution.
|
|
2157
|
+
* The operation is only executed when awaited (via `then()`).
|
|
2158
|
+
*
|
|
2159
|
+
* @example
|
|
2160
|
+
* ```ts
|
|
2161
|
+
* // Get SQL without executing
|
|
2162
|
+
* const sql = sql.query("users").insert({ name: "John" }).toQuery();
|
|
2163
|
+
*
|
|
2164
|
+
* // Execute the operation
|
|
2165
|
+
* const result = await sql.query("users").insert({ name: "John" });
|
|
2166
|
+
* ```
|
|
2167
|
+
*/
|
|
2168
|
+
declare class WriteOperation<T> implements PromiseLike<T> {
|
|
2169
|
+
private unWrapFn;
|
|
2170
|
+
private toQueryFn;
|
|
2171
|
+
private executor;
|
|
2172
|
+
readonly [Symbol.toStringTag] = "WriteOperation";
|
|
2173
|
+
constructor(unWrapFn: () => ReturnType<typeof AstParser.prototype.parse>, toQueryFn: () => string, executor: () => Promise<T>);
|
|
2174
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
|
2175
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
|
|
2176
|
+
finally(onfinally?: (() => void) | null | undefined): Promise<T>;
|
|
2177
|
+
/**
|
|
2178
|
+
* @description Returns the query with the parameters bound to the query
|
|
2179
|
+
* @warning Does not apply any hook from the model
|
|
2180
|
+
*/
|
|
2181
|
+
toQuery(): string;
|
|
2182
|
+
/**
|
|
2183
|
+
* @description Returns the query with database driver placeholders and the params
|
|
2184
|
+
* @warning Does not apply any hook from the model
|
|
2185
|
+
*/
|
|
2186
|
+
unWrap(): ReturnType<typeof AstParser.prototype.parse>;
|
|
2220
2187
|
}
|
|
2221
2188
|
|
|
2222
2189
|
type BaseValues$1 = string | number | boolean | null;
|
|
@@ -2268,1717 +2235,1729 @@ declare class WhereGroupNode extends QueryNode {
|
|
|
2268
2235
|
constructor(nodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[], chainsWith?: "and" | "or");
|
|
2269
2236
|
}
|
|
2270
2237
|
|
|
2271
|
-
|
|
2272
|
-
chainsWith: string;
|
|
2273
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
2274
|
-
folder: string;
|
|
2275
|
-
file: string;
|
|
2276
|
-
constructor();
|
|
2277
|
-
}
|
|
2238
|
+
type JsonPathInput = string | (string | number)[];
|
|
2278
2239
|
|
|
2279
|
-
declare class
|
|
2280
|
-
|
|
2240
|
+
declare class DeleteNode extends QueryNode {
|
|
2241
|
+
fromNode: FromNode;
|
|
2281
2242
|
chainsWith: string;
|
|
2282
2243
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
2283
2244
|
folder: string;
|
|
2284
2245
|
file: string;
|
|
2285
|
-
constructor(
|
|
2246
|
+
constructor(fromNode: FromNode, isRawValue?: boolean);
|
|
2286
2247
|
}
|
|
2287
2248
|
|
|
2288
|
-
declare class
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2249
|
+
declare class InsertNode extends QueryNode {
|
|
2250
|
+
fromNode: FromNode;
|
|
2251
|
+
records: Record<string, any>[];
|
|
2252
|
+
returning?: string[];
|
|
2253
|
+
disableReturning: boolean;
|
|
2292
2254
|
chainsWith: string;
|
|
2293
2255
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
2294
2256
|
folder: string;
|
|
2295
2257
|
file: string;
|
|
2296
|
-
constructor(
|
|
2258
|
+
constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
|
|
2297
2259
|
}
|
|
2298
2260
|
|
|
2299
|
-
declare class
|
|
2261
|
+
declare class OnDuplicateNode extends QueryNode {
|
|
2300
2262
|
table: string;
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
right?: string;
|
|
2306
|
-
operator: string;
|
|
2307
|
-
};
|
|
2308
|
-
chainsWith: string;
|
|
2309
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
2310
|
-
folder: string;
|
|
2311
|
-
file: string;
|
|
2312
|
-
type: "inner" | "left" | "right" | "full" | "cross" | "natural";
|
|
2313
|
-
additionalConditions?: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
|
|
2314
|
-
constructor(table: string, left: string, right: string, type: "inner" | "left" | "right" | "full" | "cross" | "natural" | undefined, on: {
|
|
2315
|
-
left?: string;
|
|
2316
|
-
right?: string;
|
|
2317
|
-
operator: string;
|
|
2318
|
-
}, isRawValue?: boolean, additionalConditions?: (WhereNode | WhereGroupNode | WhereSubqueryNode)[]);
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
declare class GroupByNode extends QueryNode {
|
|
2322
|
-
column: string;
|
|
2263
|
+
conflictColumns: string[];
|
|
2264
|
+
columnsToUpdate: string[];
|
|
2265
|
+
returning?: string[];
|
|
2266
|
+
mode: "update" | "ignore";
|
|
2323
2267
|
chainsWith: string;
|
|
2324
2268
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
2325
2269
|
folder: string;
|
|
2326
2270
|
file: string;
|
|
2327
|
-
constructor(
|
|
2271
|
+
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
2328
2272
|
}
|
|
2329
2273
|
|
|
2330
|
-
|
|
2331
|
-
limit: number;
|
|
2332
|
-
chainsWith: string;
|
|
2333
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
2334
|
-
folder: string;
|
|
2335
|
-
file: string;
|
|
2336
|
-
constructor(limit: number);
|
|
2337
|
-
}
|
|
2274
|
+
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
2338
2275
|
|
|
2339
|
-
declare class
|
|
2340
|
-
|
|
2276
|
+
declare class TruncateNode extends QueryNode {
|
|
2277
|
+
fromNode: FromNode | string;
|
|
2341
2278
|
chainsWith: string;
|
|
2342
2279
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
2343
2280
|
folder: string;
|
|
2344
2281
|
file: string;
|
|
2345
|
-
constructor(
|
|
2282
|
+
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
2346
2283
|
}
|
|
2347
2284
|
|
|
2348
|
-
declare class
|
|
2349
|
-
|
|
2350
|
-
|
|
2285
|
+
declare class UpdateNode extends QueryNode {
|
|
2286
|
+
fromNode: FromNode;
|
|
2287
|
+
columns: string[];
|
|
2288
|
+
values: (any | RawNode)[];
|
|
2351
2289
|
chainsWith: string;
|
|
2352
2290
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
2353
2291
|
folder: string;
|
|
2354
2292
|
file: string;
|
|
2355
|
-
constructor(
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
|
-
type DateFormat = "ISO" | "TIMESTAMP" | "DATE_ONLY" | "TIME_ONLY";
|
|
2359
|
-
type Timezone = "UTC" | "LOCAL";
|
|
2360
|
-
|
|
2361
|
-
/**
|
|
2362
|
-
* @description Options for the relation
|
|
2363
|
-
* @property {string} softDeleteColumn - The column name for the soft delete column, if set, the relation will only return rows that have not been soft deleted
|
|
2364
|
-
* @property {string} softDeleteType - The type of the soft delete column
|
|
2365
|
-
*/
|
|
2366
|
-
declare enum RelationEnum {
|
|
2367
|
-
hasOne = "hasOne",// One to One without foreign key
|
|
2368
|
-
belongsTo = "belongsTo",// One to One with foreign key
|
|
2369
|
-
hasMany = "hasMany",
|
|
2370
|
-
manyToMany = "manyToMany"
|
|
2371
|
-
}
|
|
2372
|
-
/**
|
|
2373
|
-
* Main Relation Class
|
|
2374
|
-
*/
|
|
2375
|
-
declare abstract class Relation {
|
|
2376
|
-
abstract type: RelationEnum;
|
|
2377
|
-
model: typeof Model;
|
|
2378
|
-
columnName: string;
|
|
2379
|
-
foreignKey?: string;
|
|
2380
|
-
relatedModel: string;
|
|
2381
|
-
protected constructor(model: typeof Model, columnName: string);
|
|
2293
|
+
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
2382
2294
|
}
|
|
2383
2295
|
|
|
2384
|
-
type
|
|
2385
|
-
|
|
2386
|
-
type?: "char" | "varchar" | "string" | "uuid" | "ulid" | "varbinary" | "integer" | "tinyint" | "smallint" | "mediumint" | "bigint" | "increment" | "bigIncrement";
|
|
2387
|
-
length?: number;
|
|
2388
|
-
};
|
|
2389
|
-
type ColumnDataTypeOptionWithEnum = {
|
|
2390
|
-
type?: readonly string[];
|
|
2391
|
-
};
|
|
2392
|
-
type ColumnDataTypeOptionWithPrecision = {
|
|
2393
|
-
type?: "float" | "double" | "real";
|
|
2394
|
-
precision?: number;
|
|
2395
|
-
};
|
|
2396
|
-
type ColumnDataTypeOptionWithScaleAndPrecision = {
|
|
2397
|
-
type?: "decimal" | "numeric";
|
|
2398
|
-
precision?: number;
|
|
2399
|
-
scale?: number;
|
|
2400
|
-
};
|
|
2401
|
-
type ColumnDataTypeOptionWithText = {
|
|
2402
|
-
type?: "text" | "longtext" | "mediumtext" | "tinytext";
|
|
2403
|
-
};
|
|
2404
|
-
type ColumnDataTypeOptionWithBinary = {
|
|
2405
|
-
type?: "binary" | "blob" | "tinyblob" | "mediumblob" | "longblob";
|
|
2406
|
-
};
|
|
2407
|
-
type ColumnDataTypeOptionWithDatePrecision = {
|
|
2408
|
-
type?: "date" | "time" | "datetime" | "timestamp";
|
|
2409
|
-
precision?: number;
|
|
2410
|
-
withTimezone?: boolean;
|
|
2296
|
+
type DeleteOptions = {
|
|
2297
|
+
ignoreBeforeDeleteHook?: boolean;
|
|
2411
2298
|
};
|
|
2412
|
-
type
|
|
2413
|
-
|
|
2299
|
+
type SoftDeleteOptions<T> = {
|
|
2300
|
+
column?: MongoCollectionKey<T>;
|
|
2301
|
+
value?: string | number | boolean;
|
|
2302
|
+
ignoreBeforeUpdateHook?: boolean;
|
|
2414
2303
|
};
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2304
|
+
|
|
2305
|
+
declare class QueryBuilder<T extends Model = any, S extends Record<string, any> = Record<string, any>> extends JsonQueryBuilder<T, S> {
|
|
2306
|
+
model: typeof Model;
|
|
2307
|
+
protected astParser: AstParser;
|
|
2308
|
+
protected unionNodes: UnionNode[];
|
|
2309
|
+
protected withNodes: WithNode[];
|
|
2310
|
+
protected lockQueryNodes: LockNode[];
|
|
2311
|
+
protected isNestedCondition: boolean;
|
|
2312
|
+
protected interpreterUtils: InterpreterUtils;
|
|
2313
|
+
protected insertNode: InsertNode | null;
|
|
2314
|
+
protected onDuplicateNode: OnDuplicateNode | null;
|
|
2315
|
+
protected updateNode: UpdateNode | null;
|
|
2316
|
+
protected deleteNode: DeleteNode | null;
|
|
2317
|
+
protected truncateNode: TruncateNode | null;
|
|
2318
|
+
protected replicationMode: ReplicationType | null;
|
|
2424
2319
|
/**
|
|
2425
|
-
* @description
|
|
2320
|
+
* @description Performance methods that return the time that took to execute the query with the result
|
|
2426
2321
|
*/
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2322
|
+
performance: {
|
|
2323
|
+
many: (returnType?: "millis" | "seconds") => Promise<{
|
|
2324
|
+
data: S[];
|
|
2325
|
+
time: number;
|
|
2326
|
+
}>;
|
|
2327
|
+
one: (returnType?: "millis" | "seconds") => Promise<{
|
|
2328
|
+
data: S | null;
|
|
2329
|
+
time: number;
|
|
2330
|
+
}>;
|
|
2331
|
+
oneOrFail: (returnType?: "millis" | "seconds") => Promise<{
|
|
2332
|
+
data: S;
|
|
2333
|
+
time: number;
|
|
2334
|
+
}>;
|
|
2335
|
+
paginate: (page: number, perPage: number, returnType?: "millis" | "seconds") => Promise<{
|
|
2336
|
+
data: RawPaginatedData<S>;
|
|
2337
|
+
time: number;
|
|
2338
|
+
}>;
|
|
2339
|
+
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
2340
|
+
data: [RawCursorPaginatedData<S>, Cursor<T, ModelKey<T>>];
|
|
2341
|
+
time: number;
|
|
2342
|
+
}>;
|
|
2343
|
+
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
2344
|
+
data: boolean;
|
|
2345
|
+
time: number;
|
|
2346
|
+
}>;
|
|
2347
|
+
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
2348
|
+
data: void;
|
|
2349
|
+
time: number;
|
|
2350
|
+
}>;
|
|
2351
|
+
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
2352
|
+
data: number;
|
|
2353
|
+
time: number;
|
|
2354
|
+
}>;
|
|
2355
|
+
insert: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
2356
|
+
data: T;
|
|
2357
|
+
time: number;
|
|
2358
|
+
}>;
|
|
2359
|
+
insertMany: (data: Record<string, any>[], returnType?: "millis" | "seconds") => Promise<{
|
|
2360
|
+
data: T[];
|
|
2361
|
+
time: number;
|
|
2362
|
+
}>;
|
|
2363
|
+
update: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
2364
|
+
data: number;
|
|
2365
|
+
time: number;
|
|
2366
|
+
}>;
|
|
2367
|
+
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
2368
|
+
data: number;
|
|
2369
|
+
time: number;
|
|
2370
|
+
}>;
|
|
2371
|
+
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
2372
|
+
data: PluckReturnType<T, ModelKey<T>>;
|
|
2373
|
+
time: number;
|
|
2374
|
+
}>;
|
|
2375
|
+
};
|
|
2376
|
+
constructor(model: typeof Model, sqlDataSource?: SqlDataSource);
|
|
2377
|
+
/**
|
|
2378
|
+
* @description Sets the replication mode for the query builder
|
|
2379
|
+
* @param replicationMode - The replication mode to use for the query builder
|
|
2380
|
+
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
2381
|
+
* @description If set to "master", all operations will use master
|
|
2382
|
+
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
2439
2383
|
*/
|
|
2440
|
-
|
|
2384
|
+
setReplicationMode(replicationMode: ReplicationType): this;
|
|
2441
2385
|
/**
|
|
2442
|
-
* @description
|
|
2443
|
-
* @
|
|
2386
|
+
* @description Adds a SELECT condition to the query with type safety.
|
|
2387
|
+
* @description Can be stacked multiple times
|
|
2388
|
+
* @description Supports: "column", "table.column", "*", "table.*", or [column, alias] tuples
|
|
2389
|
+
* @example
|
|
2390
|
+
* ```ts
|
|
2391
|
+
* const user = await sql.query("users").select("name", "age").one();
|
|
2392
|
+
* // user type: { name: any, age: any } | null
|
|
2393
|
+
*
|
|
2394
|
+
* const user = await sql.query("users").select(["name", "userName"]).one();
|
|
2395
|
+
* // user type: { userName: any } | null
|
|
2396
|
+
* ```
|
|
2444
2397
|
*/
|
|
2445
|
-
|
|
2398
|
+
select<const Columns extends readonly Selectable[]>(...columns: Columns): QueryBuilder<T, ComposeBuildRawSelect<S, Columns>>;
|
|
2399
|
+
select<ValueType = any, Alias extends string = string>(cbOrQueryBuilder: ((subQuery: QueryBuilder<T>) => void) | QueryBuilder<any>, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
2400
|
+
[K in Alias]: ValueType;
|
|
2401
|
+
}>>;
|
|
2446
2402
|
/**
|
|
2447
|
-
* @description
|
|
2448
|
-
* @
|
|
2403
|
+
* @description Adds a raw SELECT statement to the query with type safety.
|
|
2404
|
+
* @description Use the generic parameter to specify the type of the selected columns.
|
|
2405
|
+
* @example
|
|
2406
|
+
* ```ts
|
|
2407
|
+
* const result = await sql.query("users")
|
|
2408
|
+
* .selectRaw<{ total: number }>("count(*) as total")
|
|
2409
|
+
* .one();
|
|
2410
|
+
* // result type: { total: number } | null
|
|
2411
|
+
* ```
|
|
2449
2412
|
*/
|
|
2450
|
-
|
|
2413
|
+
selectRaw<Added extends Record<string, any> = Record<string, any>>(statement: string): QueryBuilder<T, ComposeRawSelect<S, Added>>;
|
|
2451
2414
|
/**
|
|
2452
|
-
* @description
|
|
2453
|
-
* @default false
|
|
2415
|
+
* @description Clears the SELECT clause and resets type to default
|
|
2454
2416
|
*/
|
|
2455
|
-
|
|
2456
|
-
} & ColumnOptions;
|
|
2457
|
-
type SymmetricEncryptionOptions = {
|
|
2417
|
+
clearSelect(): QueryBuilder<T, Record<string, any>>;
|
|
2458
2418
|
/**
|
|
2459
|
-
* @description
|
|
2419
|
+
* @description Selects a SQL function applied to a column with a typed alias.
|
|
2420
|
+
* @description Provides intellisense for common SQL functions while accepting any custom function.
|
|
2421
|
+
* @description Return type is auto-inferred based on function name (number for count/sum/avg, string for upper/lower/trim, etc.)
|
|
2422
|
+
* @param sqlFunc The SQL function name (count, sum, avg, min, max, upper, lower, etc.)
|
|
2423
|
+
* @param column The column to apply the function to (use "*" for count(*))
|
|
2424
|
+
* @param alias The alias for the result
|
|
2425
|
+
* @example
|
|
2426
|
+
* ```ts
|
|
2427
|
+
* const result = await sql.query("users")
|
|
2428
|
+
* .selectFunc("count", "*", "total")
|
|
2429
|
+
* .one();
|
|
2430
|
+
* // result type: { total: number } | null - auto-inferred!
|
|
2431
|
+
* ```
|
|
2460
2432
|
*/
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2433
|
+
selectFunc<F extends SqlFunction, Alias extends string>(sqlFunc: F, column: string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
2434
|
+
[K in Alias]: SqlFunctionReturnType<F>;
|
|
2435
|
+
}>>;
|
|
2436
|
+
selectJson<ValueType = any, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
2437
|
+
[K in Alias]: ValueType;
|
|
2438
|
+
}>>;
|
|
2439
|
+
selectJsonText<ValueType = string, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
2440
|
+
[K in Alias]: ValueType;
|
|
2441
|
+
}>>;
|
|
2442
|
+
selectJsonArrayLength<Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
2443
|
+
[K in Alias]: number;
|
|
2444
|
+
}>>;
|
|
2445
|
+
selectJsonKeys<Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
2446
|
+
[K in Alias]: string[];
|
|
2447
|
+
}>>;
|
|
2448
|
+
selectJsonRaw<ValueType = any, Alias extends string = string>(raw: string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
2449
|
+
[K in Alias]: ValueType;
|
|
2450
|
+
}>>;
|
|
2464
2451
|
/**
|
|
2465
|
-
* @description
|
|
2452
|
+
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
2466
2453
|
*/
|
|
2467
|
-
|
|
2454
|
+
exists(): Promise<boolean>;
|
|
2468
2455
|
/**
|
|
2469
|
-
* @description
|
|
2456
|
+
* @description Executes the query and retrieves multiple results.
|
|
2470
2457
|
*/
|
|
2471
|
-
|
|
2472
|
-
} & ColumnOptions;
|
|
2473
|
-
/**
|
|
2474
|
-
* columns
|
|
2475
|
-
* @description Options for the column decorator
|
|
2476
|
-
*/
|
|
2477
|
-
type ColumnOptions = {
|
|
2458
|
+
many(): Promise<S[]>;
|
|
2478
2459
|
/**
|
|
2479
|
-
* @description
|
|
2480
|
-
* @
|
|
2481
|
-
* @throws {HysteriaError} if more than one primary key is defined
|
|
2482
|
-
* @default false
|
|
2460
|
+
* @description Executes the query and retrieves a single column from the results.
|
|
2461
|
+
* @param key - The column to retrieve from the results, must be a Model Column
|
|
2483
2462
|
*/
|
|
2484
|
-
|
|
2463
|
+
pluck<K extends ModelKey<T>>(key: K): Promise<PluckReturnType<T, K>>;
|
|
2485
2464
|
/**
|
|
2486
|
-
* @description
|
|
2465
|
+
* @description Executes the query and retrieves a single result.
|
|
2487
2466
|
*/
|
|
2488
|
-
|
|
2467
|
+
one(): Promise<S | null>;
|
|
2489
2468
|
/**
|
|
2490
|
-
* @description
|
|
2469
|
+
* @description Executes the query and retrieves the first result. Fail if no result is found.
|
|
2491
2470
|
*/
|
|
2492
|
-
|
|
2471
|
+
oneOrFail(): Promise<S>;
|
|
2493
2472
|
/**
|
|
2494
|
-
* @description
|
|
2495
|
-
* @
|
|
2473
|
+
* @description Executes the query and returns a node readable stream.
|
|
2474
|
+
* @description If used by a model query builder, it will serialize the models and apply the hooks and relations.
|
|
2475
|
+
* @postgres needs the pg-query-stream package in order to work
|
|
2476
|
+
* @throws If using postgres and the `pg-query-stream` package is not installed
|
|
2496
2477
|
*/
|
|
2497
|
-
|
|
2478
|
+
stream<M = S>(options?: StreamOptions): Promise<PassThrough & AsyncGenerator<M>>;
|
|
2498
2479
|
/**
|
|
2499
|
-
* @description
|
|
2500
|
-
* @
|
|
2480
|
+
* @description Chunks the query into smaller queries, it returns a generator of the chunks
|
|
2481
|
+
* @description It will continue to yield chunks until the query returns no results
|
|
2482
|
+
* @description Useful for large queries that need to be processed in chunks
|
|
2483
|
+
* @warning overrides limit and offset set before in the query builder
|
|
2484
|
+
* @param chunkSize - The size of the chunk
|
|
2485
|
+
* @returns a generator of the chunks
|
|
2486
|
+
* @example
|
|
2487
|
+
* const chunks = await queryBuilder.chunk(100);
|
|
2488
|
+
* // first chunk
|
|
2489
|
+
* const firstChunk = await chunks.next();
|
|
2490
|
+
* console.log(firstChunk.value);
|
|
2491
|
+
* // second chunk
|
|
2492
|
+
* const secondChunk = await chunks.next();
|
|
2493
|
+
* console.log(secondChunk.value);
|
|
2494
|
+
* // third chunk
|
|
2495
|
+
* const thirdChunk = await chunks.next();
|
|
2496
|
+
* console.log(thirdChunk.value);
|
|
2497
|
+
*
|
|
2498
|
+
* @example
|
|
2499
|
+
* const chunkSize = 3;
|
|
2500
|
+
* const chunks = [];
|
|
2501
|
+
* const query = sql.query("users").orderBy("name", "asc");
|
|
2502
|
+
* for await (const chunk of sql.chunk(chunkSize)) {
|
|
2503
|
+
* chunks.push(chunk);
|
|
2504
|
+
* }
|
|
2505
|
+
*
|
|
2506
|
+
* console.log(chunks);
|
|
2501
2507
|
*/
|
|
2502
|
-
|
|
2508
|
+
chunk(chunkSize: number): AsyncGenerator<S[], void, unknown>;
|
|
2503
2509
|
/**
|
|
2504
|
-
* @description
|
|
2505
|
-
* @
|
|
2510
|
+
* @description Executes the query and retrieves multiple paginated results.
|
|
2511
|
+
* @description Overrides the limit and offset clauses in order to paginate the results.
|
|
2512
|
+
* @description Allows to avoid offset clause that can be inefficient for large datasets
|
|
2513
|
+
* @description If using a model query builder, primary key is used as discriminator by default
|
|
2514
|
+
* @param options - The options for the paginate with cursor
|
|
2515
|
+
* @param options.discriminator - The discriminator to use for the paginate with Cursor pagination
|
|
2516
|
+
* @param options.operator - The operator to use for the paginate with Cursor pagination
|
|
2517
|
+
* @param options.orderBy - The order by to use for the paginate with Cursor pagination
|
|
2518
|
+
* @param cursor - The cursor to use for the paginate with Cursor pagination
|
|
2519
|
+
* @warning If no order by clause is present in the query, the query will add an order by clause to the query `orderBy(discriminator, "asc")`
|
|
2520
|
+
* @returns the pagination metadata and the cursor for the next page
|
|
2506
2521
|
*/
|
|
2507
|
-
|
|
2522
|
+
paginateWithCursor<K extends ModelKey<T>>(limit: number, options: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[RawCursorPaginatedData<S>, Cursor<T, K>]>;
|
|
2508
2523
|
/**
|
|
2509
|
-
* @description
|
|
2510
|
-
* @
|
|
2524
|
+
* @description Locks the table for update
|
|
2525
|
+
* @param skipLocked - If true, the query will skip locked rows
|
|
2526
|
+
* @sqlite does not support skipping locked rows, it will be ignored
|
|
2511
2527
|
*/
|
|
2512
|
-
|
|
2528
|
+
lockForUpdate(options?: {
|
|
2529
|
+
skipLocked?: boolean;
|
|
2530
|
+
noWait?: boolean;
|
|
2531
|
+
}): this;
|
|
2513
2532
|
/**
|
|
2514
|
-
* @description
|
|
2533
|
+
* @description Locks the table for share
|
|
2534
|
+
* @param skipLocked - If true, the query will skip locked rows
|
|
2535
|
+
* @sqlite does not support skipping locked rows, it will be ignored
|
|
2515
2536
|
*/
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2537
|
+
forShare(options?: {
|
|
2538
|
+
skipLocked?: boolean;
|
|
2539
|
+
noWait?: boolean;
|
|
2540
|
+
}): this;
|
|
2519
2541
|
/**
|
|
2520
|
-
* @description
|
|
2521
|
-
* @migration Only affects auto-generated migrations
|
|
2542
|
+
* @description Adds a UNION to the query.
|
|
2522
2543
|
*/
|
|
2523
|
-
|
|
2544
|
+
union(query: string, bindings?: any[]): this;
|
|
2545
|
+
union(cb: UnionCallBack<T>): this;
|
|
2524
2546
|
/**
|
|
2525
|
-
* @description
|
|
2526
|
-
* @migration Only affects auto-generated migrations
|
|
2547
|
+
* @description Adds a UNION ALL to the query.
|
|
2527
2548
|
*/
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
* @description The data type of the column
|
|
2532
|
-
* @migration Only affects auto-generated migrations
|
|
2533
|
-
*/
|
|
2534
|
-
ColumnDataTypeOption;
|
|
2535
|
-
type ColumnType = {
|
|
2536
|
-
columnName: string;
|
|
2537
|
-
databaseName: string;
|
|
2538
|
-
serialize?: (value: any) => any | Promise<any>;
|
|
2539
|
-
prepare?: (value: any) => any | Promise<any>;
|
|
2540
|
-
hidden?: boolean;
|
|
2541
|
-
autoUpdate?: boolean;
|
|
2542
|
-
isPrimary: boolean;
|
|
2543
|
-
openApi?: OpenApiModelPropertyType & {
|
|
2544
|
-
required?: boolean;
|
|
2545
|
-
};
|
|
2546
|
-
/** Database specific data for migrations, must be provided or it'll be ignored for auto-generated migrations */
|
|
2547
|
-
primaryKeyConstraintName?: string;
|
|
2548
|
-
type?: ColumnDataType;
|
|
2549
|
-
length?: number;
|
|
2550
|
-
precision?: number;
|
|
2551
|
-
scale?: number;
|
|
2552
|
-
withTimezone?: boolean;
|
|
2553
|
-
constraints?: {
|
|
2554
|
-
nullable?: boolean;
|
|
2555
|
-
default?: string | number | null | boolean;
|
|
2556
|
-
};
|
|
2557
|
-
};
|
|
2558
|
-
type ThroughModelCallback<T extends typeof Model> = () => T;
|
|
2559
|
-
type ThroughModelString = string;
|
|
2560
|
-
type ThroughModel<T extends typeof Model> = ThroughModelCallback<T> | ThroughModelString;
|
|
2561
|
-
type ExtractModelFromTM<TM extends ThroughModel<any>> = TM extends ThroughModelCallback<infer T> ? T : never;
|
|
2562
|
-
type ManyToManyOptions<T extends typeof Model, TM extends ThroughModel<T>> = {
|
|
2563
|
-
/**
|
|
2564
|
-
* @description The foreign key of current model on the Pivot table
|
|
2565
|
-
* @example If the current model is User and the through model is UserAddress, the leftForeignKey will be "userId"
|
|
2566
|
-
*/
|
|
2567
|
-
leftForeignKey?: TM extends ThroughModelString ? string : ModelKey<InstanceType<ExtractModelFromTM<TM>>>;
|
|
2549
|
+
unionAll(query: string, bindings?: any[]): this;
|
|
2550
|
+
unionAll(cb: UnionCallBack<T>): this;
|
|
2551
|
+
unionAll(queryBuilder: QueryBuilder<any>): this;
|
|
2568
2552
|
/**
|
|
2569
|
-
* @description
|
|
2570
|
-
* @
|
|
2553
|
+
* @description Increments the value of a column by a given amount
|
|
2554
|
+
* @typeSafe - In typescript, only numeric columns of the model will be accepted if using a Model
|
|
2555
|
+
* @default value + 1
|
|
2556
|
+
* @returns WriteOperation that resolves to the number of affected rows
|
|
2571
2557
|
*/
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
type ManyToManyStringOptions = {
|
|
2575
|
-
leftForeignKey?: string;
|
|
2576
|
-
rightForeignKey?: string;
|
|
2577
|
-
};
|
|
2578
|
-
type IndexType = {
|
|
2579
|
-
columns: string[];
|
|
2580
|
-
name: string;
|
|
2581
|
-
};
|
|
2582
|
-
type UniqueType = {
|
|
2583
|
-
columns: string[];
|
|
2584
|
-
name: string;
|
|
2585
|
-
};
|
|
2586
|
-
|
|
2587
|
-
declare abstract class FooterQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> {
|
|
2588
|
-
protected sqlDataSource: SqlDataSource;
|
|
2589
|
-
protected model: typeof Model;
|
|
2590
|
-
protected groupByNodes: GroupByNode[];
|
|
2591
|
-
protected orderByNodes: OrderByNode[];
|
|
2592
|
-
protected limitNode: LimitNode | null;
|
|
2593
|
-
protected offsetNode: OffsetNode | null;
|
|
2594
|
-
protected modelColumns: ColumnType[];
|
|
2595
|
-
protected modelColumnsMap: Map<string, ColumnType>;
|
|
2596
|
-
protected logs: boolean;
|
|
2597
|
-
protected constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
2558
|
+
increment(column: string, value: number): WriteOperation<number>;
|
|
2559
|
+
increment(column: NumberModelKey<T>, value: number): WriteOperation<number>;
|
|
2598
2560
|
/**
|
|
2599
|
-
* @description
|
|
2561
|
+
* @description Decrements the value of a column by a given amount
|
|
2562
|
+
* @typeSafe - In typescript, only numeric columns of the model will be accepted if using a Model
|
|
2563
|
+
* @default value - 1
|
|
2564
|
+
* @returns WriteOperation that resolves to the number of affected rows
|
|
2600
2565
|
*/
|
|
2601
|
-
|
|
2566
|
+
decrement(column: string, value: number): WriteOperation<number>;
|
|
2567
|
+
decrement(column: NumberModelKey<T>, value: number): WriteOperation<number>;
|
|
2602
2568
|
/**
|
|
2603
|
-
* @description
|
|
2569
|
+
* @description Executes the query and retrieves the count of results, it ignores all select, group by, order by, limit and offset clauses if they are present.
|
|
2604
2570
|
*/
|
|
2605
|
-
|
|
2571
|
+
getCount(column?: string): Promise<number>;
|
|
2606
2572
|
/**
|
|
2607
|
-
* @description
|
|
2573
|
+
* @description Executes the query and retrieves the maximum value of a column, it ignores all select, group by, order by, limit and offset clauses if they are present.
|
|
2608
2574
|
*/
|
|
2609
|
-
|
|
2575
|
+
getMax(column: string): Promise<number>;
|
|
2610
2576
|
/**
|
|
2611
|
-
* @description
|
|
2577
|
+
* @description Executes the query and retrieves the minimum value of a column, it ignores all select, group by, order by, limit and offset clauses if they are present.
|
|
2612
2578
|
*/
|
|
2613
|
-
|
|
2579
|
+
getMin(column: string): Promise<number>;
|
|
2614
2580
|
/**
|
|
2615
|
-
* @description
|
|
2581
|
+
* @description Executes the query and retrieves the average value of a column, it ignores all select, group by, order by, limit and offset clauses if they are present.
|
|
2616
2582
|
*/
|
|
2617
|
-
|
|
2618
|
-
groupBy<S extends string>(...columns: SelectableColumn$1<S>[]): this;
|
|
2583
|
+
getAvg(column: string): Promise<number>;
|
|
2619
2584
|
/**
|
|
2620
|
-
* @description
|
|
2585
|
+
* @description Executes the query and retrieves the sum of a column, it ignores all select, group by, order by, limit and offset clauses if they are present.
|
|
2621
2586
|
*/
|
|
2622
|
-
|
|
2587
|
+
getSum(column: string): Promise<number>;
|
|
2623
2588
|
/**
|
|
2624
|
-
* @description
|
|
2589
|
+
* @description Executes the query and retrieves multiple paginated results.
|
|
2590
|
+
* @description Overrides the limit and offset clauses in order to paginate the results.
|
|
2625
2591
|
*/
|
|
2626
|
-
|
|
2627
|
-
orderBy<S extends string>(column: SelectableColumn$1<S>, order: OrderByChoices): this;
|
|
2592
|
+
paginate(page: number, perPage: number): Promise<RawPaginatedData<S>>;
|
|
2628
2593
|
/**
|
|
2629
|
-
* @description
|
|
2594
|
+
* @description Overrides the from clause in the query.
|
|
2630
2595
|
*/
|
|
2631
|
-
|
|
2596
|
+
from<S extends string>(table: TableFormat<S>, alias?: string): this;
|
|
2597
|
+
from(cb: (qb: QueryBuilder<T>) => void, alias: string): this;
|
|
2632
2598
|
/**
|
|
2633
|
-
* @description Adds a
|
|
2599
|
+
* @description Adds a CTE to the query using a callback to build the subquery.
|
|
2634
2600
|
*/
|
|
2635
|
-
|
|
2601
|
+
with(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
2636
2602
|
/**
|
|
2637
|
-
* @description Adds
|
|
2603
|
+
* @description Adds a recursive CTE to the query using a callback to build the subquery.
|
|
2604
|
+
* @mssql not supported
|
|
2638
2605
|
*/
|
|
2639
|
-
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
declare class JoinOnQueryBuilder {
|
|
2643
|
-
protected sqlDataSource: SqlDataSource;
|
|
2644
|
-
protected whereNodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
|
|
2645
|
-
protected isNestedCondition: boolean;
|
|
2646
|
-
constructor(sqlDataSource: SqlDataSource, isNestedCondition?: boolean);
|
|
2606
|
+
withRecursive(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
2647
2607
|
/**
|
|
2648
|
-
* @description
|
|
2608
|
+
* @description Adds a materialized CTE to the query using a callback to build the subquery.
|
|
2609
|
+
* @postgres only
|
|
2610
|
+
* @throws HysteriaError if the database type is not postgres
|
|
2649
2611
|
*/
|
|
2650
|
-
|
|
2612
|
+
withMaterialized(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
2651
2613
|
/**
|
|
2652
|
-
* @description
|
|
2614
|
+
* @description Insert record into a table, you can use raw statements in the data object for literal references to other columns
|
|
2615
|
+
* @param returning - The columns to return from the query, only supported by postgres and cockroachdb - default is "*"
|
|
2616
|
+
* @returns WriteOperation that executes when awaited
|
|
2653
2617
|
*/
|
|
2654
|
-
|
|
2655
|
-
where(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
2656
|
-
where(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2618
|
+
insert(data: Record<string, WriteQueryParam>, returning?: string[]): WriteOperation<T>;
|
|
2657
2619
|
/**
|
|
2658
|
-
* @description
|
|
2620
|
+
* @description Insert multiple records into a table
|
|
2621
|
+
* @param returning - The columns to return from the query, only supported by postgres and cockroachdb - default is "*"
|
|
2622
|
+
* @returns WriteOperation that executes when awaited
|
|
2623
|
+
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
2659
2624
|
*/
|
|
2660
|
-
|
|
2661
|
-
andWhere(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2662
|
-
andWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
2625
|
+
insertMany(data: Record<string, WriteQueryParam>[], returning?: string[]): WriteOperation<T[]>;
|
|
2663
2626
|
/**
|
|
2664
|
-
* @description
|
|
2627
|
+
* @description Updates or creates a new record using upsert functionality
|
|
2628
|
+
* @param data The data to insert or update
|
|
2629
|
+
* @param searchCriteria The criteria to search for existing records
|
|
2630
|
+
* @param options Upsert options including updateOnConflict and returning columns
|
|
2631
|
+
* @returns WriteOperation that executes when awaited
|
|
2665
2632
|
*/
|
|
2666
|
-
|
|
2667
|
-
orWhere(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2668
|
-
orWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
2633
|
+
upsert<O extends Record<string, any>>(data: O, searchCriteria: Partial<O>, options?: UpsertOptionsRawBuilder): WriteOperation<T[]>;
|
|
2669
2634
|
/**
|
|
2670
|
-
* @description
|
|
2635
|
+
* @description Updates or creates multiple records using upsert functionality
|
|
2636
|
+
* @param conflictColumns The columns to check for conflicts
|
|
2637
|
+
* @param columnsToUpdate The columns to update on conflict
|
|
2638
|
+
* @param data Array of data objects to insert or update
|
|
2639
|
+
* @param options Upsert options including updateOnConflict and returning columns
|
|
2640
|
+
* @returns WriteOperation that executes when awaited
|
|
2671
2641
|
*/
|
|
2672
|
-
|
|
2673
|
-
whereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2642
|
+
upsertMany<O extends Record<string, any>>(conflictColumns: string[], columnsToUpdate: string[], data: O[], options?: UpsertOptionsRawBuilder): WriteOperation<T[]>;
|
|
2674
2643
|
/**
|
|
2675
|
-
* @description
|
|
2644
|
+
* @description Executes a MERGE statement for MSSQL upsert operations (raw query builder)
|
|
2676
2645
|
*/
|
|
2677
|
-
|
|
2678
|
-
andWhereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2646
|
+
private executeMssqlMergeRaw;
|
|
2679
2647
|
/**
|
|
2680
|
-
* @description
|
|
2648
|
+
* @description Updates records from a table, you can use raw statements in the data object for literal references to other columns
|
|
2649
|
+
* @returns WriteOperation that resolves to the number of affected rows
|
|
2681
2650
|
*/
|
|
2682
|
-
|
|
2683
|
-
orWhereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2651
|
+
update(data: Record<string, WriteQueryParam>): WriteOperation<number>;
|
|
2684
2652
|
/**
|
|
2685
|
-
* @description
|
|
2653
|
+
* @description Deletes all records from a table
|
|
2654
|
+
* @warning This operation does not trigger any hook
|
|
2655
|
+
* @returns WriteOperation that executes when awaited
|
|
2686
2656
|
*/
|
|
2687
|
-
|
|
2657
|
+
truncate(): WriteOperation<void>;
|
|
2688
2658
|
/**
|
|
2689
|
-
* @description
|
|
2659
|
+
* @description Deletes records from a table
|
|
2660
|
+
* @returns WriteOperation that resolves to the number of affected rows
|
|
2690
2661
|
*/
|
|
2691
|
-
|
|
2662
|
+
delete(): WriteOperation<number>;
|
|
2692
2663
|
/**
|
|
2693
|
-
* @description
|
|
2664
|
+
* @description Soft deletes records from a table
|
|
2665
|
+
* @default column - 'deletedAt'
|
|
2666
|
+
* @default value - The current date and time in UTC timezone in the format "YYYY-MM-DD HH:mm:ss"
|
|
2667
|
+
* @returns WriteOperation that resolves to the number of affected rows
|
|
2694
2668
|
*/
|
|
2695
|
-
|
|
2669
|
+
softDelete(options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">): WriteOperation<number>;
|
|
2696
2670
|
/**
|
|
2697
|
-
* @description
|
|
2671
|
+
* @description Returns the query with the parameters bound to the query
|
|
2672
|
+
* @warning Does not apply any hook from the model
|
|
2698
2673
|
*/
|
|
2699
|
-
|
|
2674
|
+
toQuery(): string;
|
|
2700
2675
|
/**
|
|
2701
|
-
* @description
|
|
2676
|
+
* @description Returns the query with database driver placeholders and the params
|
|
2677
|
+
* @warning Does not apply any hook from the model
|
|
2702
2678
|
*/
|
|
2703
|
-
|
|
2679
|
+
unWrap(): ReturnType<typeof AstParser.prototype.parse>;
|
|
2704
2680
|
/**
|
|
2705
|
-
* @description
|
|
2681
|
+
* @description Returns a deep clone of the query builder instance.
|
|
2706
2682
|
*/
|
|
2707
|
-
|
|
2683
|
+
clone(): QueryBuilder<T, S>;
|
|
2708
2684
|
/**
|
|
2709
|
-
* @description
|
|
2685
|
+
* @description Gives a fresh instance of the query builder
|
|
2710
2686
|
*/
|
|
2711
|
-
|
|
2687
|
+
clear(): QueryBuilder<T, Record<string, any>>;
|
|
2712
2688
|
/**
|
|
2713
|
-
* @description
|
|
2689
|
+
* @description Removes the lock query
|
|
2714
2690
|
*/
|
|
2715
|
-
|
|
2691
|
+
clearLockQuery(): this;
|
|
2716
2692
|
/**
|
|
2717
|
-
* @description
|
|
2693
|
+
* @description Removes any union query
|
|
2718
2694
|
*/
|
|
2719
|
-
|
|
2695
|
+
clearUnionQuery(): this;
|
|
2720
2696
|
/**
|
|
2721
|
-
* @description
|
|
2697
|
+
* @description Removes any with query
|
|
2722
2698
|
*/
|
|
2723
|
-
|
|
2699
|
+
clearWithQuery(): this;
|
|
2700
|
+
extractQueryNodes(): QueryNode[];
|
|
2701
|
+
protected clearForFunctions(): this;
|
|
2724
2702
|
/**
|
|
2725
|
-
* @description
|
|
2703
|
+
* @description Makes a many query and returns the time that took to execute that query
|
|
2726
2704
|
*/
|
|
2727
|
-
|
|
2705
|
+
private manyWithPerformance;
|
|
2728
2706
|
/**
|
|
2729
|
-
* @description
|
|
2707
|
+
* @description Makes a one query and returns the time that took to execute that query
|
|
2730
2708
|
*/
|
|
2731
|
-
|
|
2709
|
+
private oneWithPerformance;
|
|
2732
2710
|
/**
|
|
2733
|
-
* @
|
|
2711
|
+
* @alias oneOrFailWithPerformance
|
|
2734
2712
|
*/
|
|
2735
|
-
|
|
2713
|
+
private firstOrFailWithPerformance;
|
|
2714
|
+
private paginateWithPerformance;
|
|
2715
|
+
private paginateWithCursorWithPerformance;
|
|
2736
2716
|
/**
|
|
2737
|
-
* @description
|
|
2717
|
+
* @description Makes a one or fail query and returns the time that took to execute that query
|
|
2738
2718
|
*/
|
|
2739
|
-
|
|
2719
|
+
private oneOrFailWithPerformance;
|
|
2740
2720
|
/**
|
|
2741
|
-
* @description
|
|
2721
|
+
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
2722
|
+
* @description Returns the time that took to execute the query
|
|
2742
2723
|
*/
|
|
2743
|
-
|
|
2724
|
+
private existsWithPerformance;
|
|
2725
|
+
private pluckWithPerformance;
|
|
2726
|
+
private updateWithPerformance;
|
|
2727
|
+
private insertWithPerformance;
|
|
2728
|
+
private insertManyWithPerformance;
|
|
2729
|
+
private softDeleteWithPerformance;
|
|
2730
|
+
private deleteWithPerformance;
|
|
2731
|
+
private truncateWithPerformance;
|
|
2744
2732
|
/**
|
|
2745
|
-
* @description
|
|
2733
|
+
* @description Checks if the current context is an MSSQL transaction
|
|
2734
|
+
* @description MSSQL transactions can only handle one request at a time
|
|
2746
2735
|
*/
|
|
2747
|
-
|
|
2736
|
+
protected isMssqlTransaction(): boolean;
|
|
2748
2737
|
/**
|
|
2749
|
-
* @description
|
|
2738
|
+
* @description Executes pagination queries, serializing them for MSSQL transactions
|
|
2750
2739
|
*/
|
|
2751
|
-
|
|
2740
|
+
protected executePaginateQueries<M, C>(modelsQuery: () => Promise<M>, countQuery: () => Promise<C>): Promise<[M, C]>;
|
|
2741
|
+
protected getSqlDataSource(mode: "read" | "write"): Promise<SqlDataSource>;
|
|
2752
2742
|
/**
|
|
2753
|
-
* @description
|
|
2743
|
+
* @description Executes SQL with slave failure handling
|
|
2744
|
+
* @param mode The operation mode (read or write)
|
|
2745
|
+
* @param operation The execSql operation to perform
|
|
2746
|
+
* @returns The result of the operation
|
|
2754
2747
|
*/
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
whereRaw(sql: string, bindings?: BaseValues[]): this;
|
|
2844
|
-
/**
|
|
2845
|
-
* @description Adds an AND raw WHERE condition to the query.
|
|
2846
|
-
*/
|
|
2847
|
-
andWhereRaw(sql: string, bindings?: BaseValues[]): this;
|
|
2848
|
-
/**
|
|
2849
|
-
* @description Adds an OR raw WHERE condition to the query.
|
|
2850
|
-
*/
|
|
2851
|
-
orWhereRaw(sql: string, bindings?: BaseValues[]): this;
|
|
2748
|
+
protected execSqlWithSlaveHandling<R>(mode: "read" | "write", operation: (dataSource: SqlDataSource) => Promise<R>): Promise<R>;
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
declare class DistinctNode extends QueryNode {
|
|
2752
|
+
chainsWith: string;
|
|
2753
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2754
|
+
folder: string;
|
|
2755
|
+
file: string;
|
|
2756
|
+
constructor();
|
|
2757
|
+
}
|
|
2758
|
+
|
|
2759
|
+
declare class DistinctOnNode extends QueryNode {
|
|
2760
|
+
columns: string[];
|
|
2761
|
+
chainsWith: string;
|
|
2762
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2763
|
+
folder: string;
|
|
2764
|
+
file: string;
|
|
2765
|
+
constructor(columns: string[]);
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
declare class SelectNode extends QueryNode {
|
|
2769
|
+
column: string | QueryNode | QueryNode[];
|
|
2770
|
+
alias?: string;
|
|
2771
|
+
sqlFunction?: string;
|
|
2772
|
+
chainsWith: string;
|
|
2773
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2774
|
+
folder: string;
|
|
2775
|
+
file: string;
|
|
2776
|
+
constructor(column: string | QueryNode | QueryNode[], alias?: string, sqlFunction?: string, isRaw?: boolean);
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
declare class JoinNode extends QueryNode {
|
|
2780
|
+
table: string;
|
|
2781
|
+
left: string;
|
|
2782
|
+
right: string;
|
|
2783
|
+
on?: {
|
|
2784
|
+
left?: string;
|
|
2785
|
+
right?: string;
|
|
2786
|
+
operator: string;
|
|
2787
|
+
};
|
|
2788
|
+
chainsWith: string;
|
|
2789
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2790
|
+
folder: string;
|
|
2791
|
+
file: string;
|
|
2792
|
+
type: "inner" | "left" | "right" | "full" | "cross" | "natural";
|
|
2793
|
+
additionalConditions?: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
|
|
2794
|
+
constructor(table: string, left: string, right: string, type: "inner" | "left" | "right" | "full" | "cross" | "natural" | undefined, on: {
|
|
2795
|
+
left?: string;
|
|
2796
|
+
right?: string;
|
|
2797
|
+
operator: string;
|
|
2798
|
+
}, isRawValue?: boolean, additionalConditions?: (WhereNode | WhereGroupNode | WhereSubqueryNode)[]);
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
declare class GroupByNode extends QueryNode {
|
|
2802
|
+
column: string;
|
|
2803
|
+
chainsWith: string;
|
|
2804
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2805
|
+
folder: string;
|
|
2806
|
+
file: string;
|
|
2807
|
+
constructor(column: string, isRawValue?: boolean);
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
declare class LimitNode extends QueryNode {
|
|
2811
|
+
limit: number;
|
|
2812
|
+
chainsWith: string;
|
|
2813
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2814
|
+
folder: string;
|
|
2815
|
+
file: string;
|
|
2816
|
+
constructor(limit: number);
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
declare class OffsetNode extends QueryNode {
|
|
2820
|
+
offset: number;
|
|
2821
|
+
chainsWith: string;
|
|
2822
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2823
|
+
folder: string;
|
|
2824
|
+
file: string;
|
|
2825
|
+
constructor(offset: number);
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
declare class OrderByNode extends QueryNode {
|
|
2829
|
+
column: string;
|
|
2830
|
+
direction: "asc" | "desc";
|
|
2831
|
+
chainsWith: string;
|
|
2832
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2833
|
+
folder: string;
|
|
2834
|
+
file: string;
|
|
2835
|
+
constructor(column: string, direction?: "asc" | "desc", isRawValue?: boolean);
|
|
2852
2836
|
}
|
|
2853
2837
|
|
|
2838
|
+
type DateFormat = "ISO" | "TIMESTAMP" | "DATE_ONLY" | "TIME_ONLY";
|
|
2839
|
+
type Timezone = "UTC" | "LOCAL";
|
|
2840
|
+
|
|
2854
2841
|
/**
|
|
2855
|
-
* @description
|
|
2842
|
+
* @description Options for the relation
|
|
2843
|
+
* @property {string} softDeleteColumn - The column name for the soft delete column, if set, the relation will only return rows that have not been soft deleted
|
|
2844
|
+
* @property {string} softDeleteType - The type of the soft delete column
|
|
2856
2845
|
*/
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2846
|
+
declare enum RelationEnum {
|
|
2847
|
+
hasOne = "hasOne",// One to One without foreign key
|
|
2848
|
+
belongsTo = "belongsTo",// One to One with foreign key
|
|
2849
|
+
hasMany = "hasMany",
|
|
2850
|
+
manyToMany = "manyToMany"
|
|
2851
|
+
}
|
|
2852
|
+
/**
|
|
2853
|
+
* Main Relation Class
|
|
2854
|
+
*/
|
|
2855
|
+
declare abstract class Relation {
|
|
2856
|
+
abstract type: RelationEnum;
|
|
2857
|
+
model: typeof Model;
|
|
2858
|
+
columnName: string;
|
|
2859
|
+
foreignKey?: string;
|
|
2860
|
+
relatedModel: string;
|
|
2861
|
+
protected constructor(model: typeof Model, columnName: string);
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
type ColumnDataType = Exclude<keyof CreateTableBuilder, "enum" | "rawColumn" | "custom"> | readonly string[];
|
|
2865
|
+
type ColumnDataTypeOptionWithLength = {
|
|
2866
|
+
type?: "char" | "varchar" | "string" | "uuid" | "ulid" | "varbinary" | "integer" | "tinyint" | "smallint" | "mediumint" | "bigint" | "increment" | "bigIncrement";
|
|
2867
|
+
length?: number;
|
|
2868
|
+
};
|
|
2869
|
+
type ColumnDataTypeOptionWithEnum = {
|
|
2870
|
+
type?: readonly string[];
|
|
2871
|
+
};
|
|
2872
|
+
type ColumnDataTypeOptionWithPrecision = {
|
|
2873
|
+
type?: "float" | "double" | "real";
|
|
2874
|
+
precision?: number;
|
|
2875
|
+
};
|
|
2876
|
+
type ColumnDataTypeOptionWithScaleAndPrecision = {
|
|
2877
|
+
type?: "decimal" | "numeric";
|
|
2878
|
+
precision?: number;
|
|
2879
|
+
scale?: number;
|
|
2880
|
+
};
|
|
2881
|
+
type ColumnDataTypeOptionWithText = {
|
|
2882
|
+
type?: "text" | "longtext" | "mediumtext" | "tinytext";
|
|
2883
|
+
};
|
|
2884
|
+
type ColumnDataTypeOptionWithBinary = {
|
|
2885
|
+
type?: "binary" | "blob" | "tinyblob" | "mediumblob" | "longblob";
|
|
2886
|
+
};
|
|
2887
|
+
type ColumnDataTypeOptionWithDatePrecision = {
|
|
2888
|
+
type?: "date" | "time" | "datetime" | "timestamp";
|
|
2889
|
+
precision?: number;
|
|
2890
|
+
withTimezone?: boolean;
|
|
2891
|
+
};
|
|
2892
|
+
type ColumnDataTypeOptionSimple = {
|
|
2893
|
+
type?: "year" | "boolean" | "json" | "jsonb";
|
|
2894
|
+
};
|
|
2895
|
+
type ColumnDataTypeOption = ColumnDataTypeOptionWithLength | ColumnDataTypeOptionWithPrecision | ColumnDataTypeOptionWithScaleAndPrecision | ColumnDataTypeOptionWithText | ColumnDataTypeOptionWithBinary | ColumnDataTypeOptionWithDatePrecision | ColumnDataTypeOptionWithEnum | ColumnDataTypeOptionSimple;
|
|
2896
|
+
type LazyRelationType = {
|
|
2897
|
+
type?: RelationEnum;
|
|
2898
|
+
columnName: string;
|
|
2899
|
+
model: () => typeof Model;
|
|
2900
|
+
foreignKey: string | (() => string);
|
|
2901
|
+
constraintName: string | (() => string);
|
|
2902
|
+
onDelete?: OnUpdateOrDelete;
|
|
2903
|
+
onUpdate?: OnUpdateOrDelete;
|
|
2861
2904
|
/**
|
|
2862
|
-
* @description
|
|
2905
|
+
* @description Only for many to many relations
|
|
2863
2906
|
*/
|
|
2864
|
-
|
|
2907
|
+
manyToManyOptions?: {
|
|
2908
|
+
primaryModel: string;
|
|
2909
|
+
throughModel: string | (() => string);
|
|
2910
|
+
leftForeignKey: string | (() => string);
|
|
2911
|
+
rightForeignKey: string | (() => string);
|
|
2912
|
+
wasModelProvided: boolean;
|
|
2913
|
+
};
|
|
2914
|
+
};
|
|
2915
|
+
type DateColumnOptions = {
|
|
2865
2916
|
/**
|
|
2866
|
-
* @description
|
|
2917
|
+
* @description The format to store dates in ('ISO' or 'TIMESTAMP')
|
|
2918
|
+
* @default "ISO"
|
|
2867
2919
|
*/
|
|
2868
|
-
|
|
2920
|
+
format?: DateFormat;
|
|
2869
2921
|
/**
|
|
2870
|
-
* @description
|
|
2922
|
+
* @description The timezone to use ('UTC' or 'LOCAL')
|
|
2923
|
+
* @default "UTC"
|
|
2871
2924
|
*/
|
|
2872
|
-
|
|
2925
|
+
timezone?: Timezone;
|
|
2873
2926
|
/**
|
|
2874
|
-
* @description
|
|
2927
|
+
* @description Whether to automatically update the timestamp on record updates, uses timezone and format from the dateColumn options
|
|
2928
|
+
* @default false
|
|
2875
2929
|
*/
|
|
2876
|
-
|
|
2930
|
+
autoUpdate?: boolean;
|
|
2877
2931
|
/**
|
|
2878
|
-
* @description
|
|
2932
|
+
* @description Whether to automatically set the timestamp on record creation, uses timezone and format from the dateColumn options
|
|
2933
|
+
* @default false
|
|
2879
2934
|
*/
|
|
2880
|
-
|
|
2935
|
+
autoCreate?: boolean;
|
|
2936
|
+
} & ColumnOptions;
|
|
2937
|
+
type SymmetricEncryptionOptions = {
|
|
2881
2938
|
/**
|
|
2882
|
-
* @description
|
|
2939
|
+
* @description The key to use for the symmetric encryption
|
|
2883
2940
|
*/
|
|
2884
|
-
|
|
2941
|
+
key: string;
|
|
2942
|
+
} & ColumnOptions;
|
|
2943
|
+
type AsymmetricEncryptionOptions = {
|
|
2885
2944
|
/**
|
|
2886
|
-
* @description
|
|
2945
|
+
* @description The public key to use for the asymmetric encryption
|
|
2887
2946
|
*/
|
|
2888
|
-
|
|
2947
|
+
publicKey: string;
|
|
2889
2948
|
/**
|
|
2890
|
-
* @
|
|
2891
|
-
* @param relationTable - The table to join
|
|
2892
|
-
* @param referencingColumn - The column to reference from the relation table, must be in the format of `table.column`
|
|
2893
|
-
* @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
|
|
2894
|
-
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
2949
|
+
* @description The private key to use for the asymmetric encryption
|
|
2895
2950
|
*/
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
|
|
2951
|
+
privateKey: string;
|
|
2952
|
+
} & ColumnOptions;
|
|
2953
|
+
/**
|
|
2954
|
+
* columns
|
|
2955
|
+
* @description Options for the column decorator
|
|
2956
|
+
*/
|
|
2957
|
+
type ColumnOptions = {
|
|
2904
2958
|
/**
|
|
2905
|
-
* @description
|
|
2906
|
-
* @
|
|
2907
|
-
* @
|
|
2908
|
-
* @
|
|
2909
|
-
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
2959
|
+
* @description Whether the column is the primary key, composite primary keys are not supported
|
|
2960
|
+
* @warning Only one primary key is allowed per model
|
|
2961
|
+
* @throws {HysteriaError} if more than one primary key is defined
|
|
2962
|
+
* @default false
|
|
2910
2963
|
*/
|
|
2911
|
-
|
|
2912
|
-
join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
2913
|
-
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
2914
|
-
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
2915
|
-
join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
2916
|
-
join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
2917
|
-
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
2918
|
-
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
|
|
2964
|
+
primaryKey?: boolean;
|
|
2919
2965
|
/**
|
|
2920
|
-
* @description
|
|
2921
|
-
* @param relationTable - The table to join
|
|
2922
|
-
* @param referencingColumn - The column to reference from the relation table, must be in the format of `table.column`
|
|
2923
|
-
* @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
|
|
2924
|
-
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
2966
|
+
* @description The name of the primary key constraint in the database for automatic migrations
|
|
2925
2967
|
*/
|
|
2926
|
-
|
|
2927
|
-
leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
2928
|
-
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
2929
|
-
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
2930
|
-
leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
2931
|
-
leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
2932
|
-
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
2933
|
-
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
|
|
2968
|
+
primaryKeyConstraintName?: string;
|
|
2934
2969
|
/**
|
|
2935
|
-
* @description
|
|
2936
|
-
* @param relationTable - The table to join
|
|
2937
|
-
* @param referencingColumn - The column to reference from the relation table
|
|
2938
|
-
* @param primaryColumn - The primary column of the current model, default is caller model primary key if using A Model, if using a Raw Query Builder you must provide the key for the primary table
|
|
2939
|
-
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
2970
|
+
* @description Called on the value returned from the database before it is returned from the model
|
|
2940
2971
|
*/
|
|
2941
|
-
|
|
2942
|
-
rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
2943
|
-
rightJoin<R extends typeof Model>(relationTable: string | R, referencingColumnOrPrimaryColumn: ModelKey<InstanceType<R>> | JoinableColumn | ModelKey<T>, primaryColumn?: JoinableColumn | ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
2944
|
-
rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
2945
|
-
rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
2972
|
+
serialize?: (value: any) => any;
|
|
2946
2973
|
/**
|
|
2947
|
-
* @description
|
|
2948
|
-
* @
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
2952
|
-
*/
|
|
2953
|
-
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
2954
|
-
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
2955
|
-
fullJoin<R extends typeof Model>(relationTable: string | R, referencingColumnOrPrimaryColumn: ModelKey<InstanceType<R>> | JoinableColumn | ModelKey<T>, primaryColumn?: JoinableColumn | ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
2956
|
-
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
2957
|
-
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
2958
|
-
}
|
|
2959
|
-
|
|
2960
|
-
declare class SelectQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends JoinQueryBuilder<T, S> {
|
|
2961
|
-
protected dbType: SqlDataSourceType;
|
|
2962
|
-
protected modelSelectedColumns: string[];
|
|
2963
|
-
protected withQuery?: string;
|
|
2964
|
-
protected fromNode: FromNode;
|
|
2965
|
-
protected distinctNode: DistinctNode | null;
|
|
2966
|
-
protected distinctOnNode: DistinctOnNode | null;
|
|
2967
|
-
protected selectNodes: SelectNode[];
|
|
2968
|
-
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
2974
|
+
* @description Called on the value before it is inserted or updated in the database
|
|
2975
|
+
* @warning This will not be called on massive update operations since it's not possible to know which values are being updated, so you must pass the value you want to update in the payload
|
|
2976
|
+
*/
|
|
2977
|
+
prepare?: (value: any) => any;
|
|
2969
2978
|
/**
|
|
2970
|
-
* @description
|
|
2971
|
-
* @
|
|
2972
|
-
* @description Supports: "column", "table.column", "*", "table.*", or [column, alias] tuples
|
|
2973
|
-
* @example
|
|
2974
|
-
* .select("id", "name") // Simple columns
|
|
2975
|
-
* .select(["id", "userId"], ["name", "userName"]) // Columns with aliases
|
|
2976
|
-
* .select("id", ["name", "userName"]) // Mixed
|
|
2979
|
+
* @description Whether the column is returned in the serialization output, this column will always be undefined
|
|
2980
|
+
* @default false
|
|
2977
2981
|
*/
|
|
2978
|
-
|
|
2979
|
-
select(...columns: (ModelKey<T> | "*" | Selectable)[]): this;
|
|
2982
|
+
hidden?: boolean;
|
|
2980
2983
|
/**
|
|
2981
|
-
* @description
|
|
2984
|
+
* @description If true, the prepare function will always be called on update regardless of whether the value has been provided in the update payload
|
|
2985
|
+
* @default false
|
|
2982
2986
|
*/
|
|
2983
|
-
|
|
2987
|
+
autoUpdate?: boolean;
|
|
2984
2988
|
/**
|
|
2985
|
-
* @description
|
|
2986
|
-
* @
|
|
2987
|
-
* @param func The SQL function name (count, sum, avg, min, max, upper, lower, etc.)
|
|
2988
|
-
* @param column The column to apply the function to (use "*" for count(*))
|
|
2989
|
-
* @param alias The alias for the result
|
|
2990
|
-
* @example
|
|
2991
|
-
* .selectFunc("count", "*", "total")
|
|
2992
|
-
* .selectFunc("upper", "name", "upperName")
|
|
2993
|
-
* .selectFunc("custom_fn", "column", "result")
|
|
2989
|
+
* @description The name of the column in the database, can be used to specify the column name in the database
|
|
2990
|
+
* @default The name of the property following the model case convention
|
|
2994
2991
|
*/
|
|
2995
|
-
|
|
2992
|
+
databaseName?: string;
|
|
2996
2993
|
/**
|
|
2997
|
-
* @description
|
|
2994
|
+
* @description Custom OpenAPI schema for the column, if omitted, the column type will be inferred from the other options in best effort
|
|
2998
2995
|
*/
|
|
2999
|
-
|
|
2996
|
+
openApi?: OpenApiModelPropertyType & {
|
|
2997
|
+
required?: boolean;
|
|
2998
|
+
};
|
|
3000
2999
|
/**
|
|
3001
|
-
* @description
|
|
3000
|
+
* @description Whether the column can be null in the database
|
|
3001
|
+
* @migration Only affects auto-generated migrations
|
|
3002
3002
|
*/
|
|
3003
|
-
|
|
3003
|
+
nullable?: boolean;
|
|
3004
3004
|
/**
|
|
3005
|
-
* @description
|
|
3005
|
+
* @description The default value for the column in the database
|
|
3006
|
+
* @migration Only affects auto-generated migrations
|
|
3006
3007
|
*/
|
|
3007
|
-
|
|
3008
|
+
default?: string | number | null | boolean;
|
|
3009
|
+
} &
|
|
3010
|
+
/**
|
|
3011
|
+
* @description The data type of the column
|
|
3012
|
+
* @migration Only affects auto-generated migrations
|
|
3013
|
+
*/
|
|
3014
|
+
ColumnDataTypeOption;
|
|
3015
|
+
type ColumnType = {
|
|
3016
|
+
columnName: string;
|
|
3017
|
+
databaseName: string;
|
|
3018
|
+
serialize?: (value: any) => any | Promise<any>;
|
|
3019
|
+
prepare?: (value: any) => any | Promise<any>;
|
|
3020
|
+
hidden?: boolean;
|
|
3021
|
+
autoUpdate?: boolean;
|
|
3022
|
+
isPrimary: boolean;
|
|
3023
|
+
openApi?: OpenApiModelPropertyType & {
|
|
3024
|
+
required?: boolean;
|
|
3025
|
+
};
|
|
3026
|
+
/** Database specific data for migrations, must be provided or it'll be ignored for auto-generated migrations */
|
|
3027
|
+
primaryKeyConstraintName?: string;
|
|
3028
|
+
type?: ColumnDataType;
|
|
3029
|
+
length?: number;
|
|
3030
|
+
precision?: number;
|
|
3031
|
+
scale?: number;
|
|
3032
|
+
withTimezone?: boolean;
|
|
3033
|
+
constraints?: {
|
|
3034
|
+
nullable?: boolean;
|
|
3035
|
+
default?: string | number | null | boolean;
|
|
3036
|
+
};
|
|
3037
|
+
};
|
|
3038
|
+
type ThroughModelCallback<T extends typeof Model> = () => T;
|
|
3039
|
+
type ThroughModelString = string;
|
|
3040
|
+
type ThroughModel<T extends typeof Model> = ThroughModelCallback<T> | ThroughModelString;
|
|
3041
|
+
type ExtractModelFromTM<TM extends ThroughModel<any>> = TM extends ThroughModelCallback<infer T> ? T : never;
|
|
3042
|
+
type ManyToManyOptions<T extends typeof Model, TM extends ThroughModel<T>> = {
|
|
3008
3043
|
/**
|
|
3009
|
-
* @description
|
|
3044
|
+
* @description The foreign key of current model on the Pivot table
|
|
3045
|
+
* @example If the current model is User and the through model is UserAddress, the leftForeignKey will be "userId"
|
|
3010
3046
|
*/
|
|
3011
|
-
|
|
3047
|
+
leftForeignKey?: TM extends ThroughModelString ? string : ModelKey<InstanceType<ExtractModelFromTM<TM>>>;
|
|
3012
3048
|
/**
|
|
3013
|
-
* @description
|
|
3049
|
+
* @description The foreign key of the related model on the Pivot table
|
|
3050
|
+
* @example If the current model is User and the through model is UserAddress, the rightForeignKey will be "addressId"
|
|
3014
3051
|
*/
|
|
3015
|
-
|
|
3052
|
+
rightForeignKey?: TM extends ThroughModelString ? string : ModelKey<InstanceType<ExtractModelFromTM<TM>>>;
|
|
3053
|
+
};
|
|
3054
|
+
type ManyToManyStringOptions = {
|
|
3055
|
+
leftForeignKey?: string;
|
|
3056
|
+
rightForeignKey?: string;
|
|
3057
|
+
};
|
|
3058
|
+
type IndexType = {
|
|
3059
|
+
columns: string[];
|
|
3060
|
+
name: string;
|
|
3061
|
+
};
|
|
3062
|
+
type UniqueType = {
|
|
3063
|
+
columns: string[];
|
|
3064
|
+
name: string;
|
|
3065
|
+
};
|
|
3066
|
+
|
|
3067
|
+
declare abstract class FooterQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> {
|
|
3068
|
+
protected sqlDataSource: SqlDataSource;
|
|
3069
|
+
protected model: typeof Model;
|
|
3070
|
+
protected groupByNodes: GroupByNode[];
|
|
3071
|
+
protected orderByNodes: OrderByNode[];
|
|
3072
|
+
protected limitNode: LimitNode | null;
|
|
3073
|
+
protected offsetNode: OffsetNode | null;
|
|
3074
|
+
protected modelColumns: ColumnType[];
|
|
3075
|
+
protected modelColumnsMap: Map<string, ColumnType>;
|
|
3076
|
+
protected logs: boolean;
|
|
3077
|
+
protected constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3016
3078
|
/**
|
|
3017
|
-
* @description
|
|
3018
|
-
* @alias from
|
|
3079
|
+
* @description Clears the group by query
|
|
3019
3080
|
*/
|
|
3020
|
-
|
|
3081
|
+
clearGroupBy(): this;
|
|
3021
3082
|
/**
|
|
3022
|
-
* @description
|
|
3083
|
+
* @description Clears the order by query
|
|
3023
3084
|
*/
|
|
3024
|
-
|
|
3085
|
+
clearOrderBy(): this;
|
|
3025
3086
|
/**
|
|
3026
|
-
* @description
|
|
3027
|
-
* @postgresql Only usable with PostgreSQL
|
|
3087
|
+
* @description Clears the limit query
|
|
3028
3088
|
*/
|
|
3029
|
-
|
|
3030
|
-
distinctOn<C extends string>(...columns: SelectableColumn$1<C>[]): this;
|
|
3089
|
+
clearLimit(): this;
|
|
3031
3090
|
/**
|
|
3032
|
-
* @description
|
|
3091
|
+
* @description Clears the offset query
|
|
3033
3092
|
*/
|
|
3034
|
-
|
|
3035
|
-
selectJson<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3093
|
+
clearOffset(): this;
|
|
3036
3094
|
/**
|
|
3037
|
-
* @description
|
|
3095
|
+
* @description Adds a group by query
|
|
3038
3096
|
*/
|
|
3039
|
-
|
|
3040
|
-
|
|
3097
|
+
groupBy(...columns: ModelKey<T>[]): this;
|
|
3098
|
+
groupBy<S extends string>(...columns: SelectableColumn$1<S>[]): this;
|
|
3041
3099
|
/**
|
|
3042
|
-
* @description
|
|
3100
|
+
* @description Adds a raw group by query, GROUP BY clause is not necessary and will be added automatically
|
|
3043
3101
|
*/
|
|
3044
|
-
|
|
3045
|
-
selectJsonArrayLength<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3102
|
+
groupByRaw(query: string): this;
|
|
3046
3103
|
/**
|
|
3047
|
-
* @description
|
|
3104
|
+
* @description Adds an order by query
|
|
3048
3105
|
*/
|
|
3049
|
-
|
|
3050
|
-
|
|
3106
|
+
orderBy(column: ModelKey<T>, order: OrderByChoices): this;
|
|
3107
|
+
orderBy<S extends string>(column: SelectableColumn$1<S>, order: OrderByChoices): this;
|
|
3051
3108
|
/**
|
|
3052
|
-
* @description Adds a raw
|
|
3109
|
+
* @description Adds a raw order by query, ORDER BY clause is not necessary and will be added automatically
|
|
3053
3110
|
*/
|
|
3054
|
-
|
|
3111
|
+
orderByRaw(query: string): this;
|
|
3112
|
+
/**
|
|
3113
|
+
* @description Adds a limit query
|
|
3114
|
+
*/
|
|
3115
|
+
limit(limit: number): this;
|
|
3116
|
+
/**
|
|
3117
|
+
* @description Adds an offset query
|
|
3118
|
+
*/
|
|
3119
|
+
offset(offset: number): this;
|
|
3055
3120
|
}
|
|
3056
3121
|
|
|
3057
|
-
declare
|
|
3122
|
+
declare class JoinOnQueryBuilder {
|
|
3123
|
+
protected sqlDataSource: SqlDataSource;
|
|
3058
3124
|
protected whereNodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
|
|
3059
|
-
protected havingNodes: HavingNode[];
|
|
3060
3125
|
protected isNestedCondition: boolean;
|
|
3061
|
-
constructor(
|
|
3062
|
-
clearWhere(): this;
|
|
3063
|
-
clearHaving(): this;
|
|
3064
|
-
/**
|
|
3065
|
-
* @description Accepts a value and executes a callback only of the value is not null or undefined.
|
|
3066
|
-
* @warning The value is not checked for truthiness but existence, it is only checked for undefined or null. So false, 0, "", etc. will be considered truthy.
|
|
3067
|
-
*/
|
|
3068
|
-
strictWhen(value: any, cb: (query: this) => void): this;
|
|
3126
|
+
constructor(sqlDataSource: SqlDataSource, isNestedCondition?: boolean);
|
|
3069
3127
|
/**
|
|
3070
|
-
* @description
|
|
3071
|
-
* @warning The value is checked for truthiness, so false, 0, "", etc. will be considered falsy. Use strictWhen for null or undefined only cases.
|
|
3128
|
+
* @description Get the where conditions for the join
|
|
3072
3129
|
*/
|
|
3073
|
-
|
|
3130
|
+
getConditions(): (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
|
|
3074
3131
|
/**
|
|
3075
3132
|
* @description Adds a WHERE condition to the query.
|
|
3076
3133
|
*/
|
|
3077
|
-
where(column:
|
|
3078
|
-
where
|
|
3079
|
-
where(
|
|
3080
|
-
where(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3081
|
-
where(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3082
|
-
where(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3134
|
+
where(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3135
|
+
where(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
3136
|
+
where(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
3083
3137
|
/**
|
|
3084
3138
|
* @description Adds an AND WHERE condition to the query.
|
|
3085
3139
|
*/
|
|
3086
|
-
andWhere(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3087
3140
|
andWhere(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3088
|
-
andWhere(column:
|
|
3089
|
-
andWhere(cb: (queryBuilder:
|
|
3090
|
-
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3091
|
-
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3141
|
+
andWhere(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
3142
|
+
andWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
3092
3143
|
/**
|
|
3093
3144
|
* @description Adds an OR WHERE condition to the query.
|
|
3094
3145
|
*/
|
|
3095
|
-
orWhere(column:
|
|
3096
|
-
orWhere
|
|
3097
|
-
orWhere
|
|
3098
|
-
orWhere(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
|
|
3099
|
-
orWhere(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3100
|
-
orWhere(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3146
|
+
orWhere(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3147
|
+
orWhere(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
3148
|
+
orWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
3101
3149
|
/**
|
|
3102
3150
|
* @description Adds a negated WHERE condition to the query.
|
|
3103
3151
|
*/
|
|
3104
|
-
whereNot(column:
|
|
3105
|
-
whereNot
|
|
3106
|
-
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3107
|
-
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3108
|
-
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3152
|
+
whereNot(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3153
|
+
whereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
3109
3154
|
/**
|
|
3110
3155
|
* @description Adds a negated AND WHERE condition to the query.
|
|
3111
3156
|
*/
|
|
3112
|
-
andWhereNot(column:
|
|
3113
|
-
andWhereNot
|
|
3114
|
-
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3115
|
-
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3116
|
-
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3157
|
+
andWhereNot(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3158
|
+
andWhereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
3117
3159
|
/**
|
|
3118
3160
|
* @description Adds a negated OR WHERE condition to the query.
|
|
3119
3161
|
*/
|
|
3120
|
-
orWhereNot(column:
|
|
3121
|
-
orWhereNot
|
|
3122
|
-
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3123
|
-
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3124
|
-
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3162
|
+
orWhereNot(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3163
|
+
orWhereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
3125
3164
|
/**
|
|
3126
3165
|
* @description Adds a WHERE BETWEEN condition to the query.
|
|
3127
3166
|
*/
|
|
3128
|
-
whereBetween(column:
|
|
3129
|
-
whereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3167
|
+
whereBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
3130
3168
|
/**
|
|
3131
3169
|
* @description Adds an AND WHERE BETWEEN condition to the query.
|
|
3132
3170
|
*/
|
|
3133
|
-
andWhereBetween(column:
|
|
3134
|
-
andWhereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3171
|
+
andWhereBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
3135
3172
|
/**
|
|
3136
3173
|
* @description Adds an OR WHERE BETWEEN condition to the query.
|
|
3137
3174
|
*/
|
|
3138
|
-
orWhereBetween(column:
|
|
3139
|
-
orWhereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3175
|
+
orWhereBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
3140
3176
|
/**
|
|
3141
3177
|
* @description Adds a WHERE NOT BETWEEN condition to the query.
|
|
3142
3178
|
*/
|
|
3143
|
-
whereNotBetween(column:
|
|
3144
|
-
whereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3179
|
+
whereNotBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
3145
3180
|
/**
|
|
3146
3181
|
* @description Adds an AND WHERE NOT BETWEEN condition to the query.
|
|
3147
3182
|
*/
|
|
3148
|
-
andWhereNotBetween(column:
|
|
3149
|
-
andWhereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3183
|
+
andWhereNotBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
3150
3184
|
/**
|
|
3151
3185
|
* @description Adds an OR WHERE NOT BETWEEN condition to the query.
|
|
3152
3186
|
*/
|
|
3153
|
-
orWhereNotBetween(column:
|
|
3154
|
-
orWhereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3187
|
+
orWhereNotBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
3155
3188
|
/**
|
|
3156
3189
|
* @description Adds a WHERE LIKE condition to the query.
|
|
3157
3190
|
*/
|
|
3158
|
-
whereLike(column:
|
|
3159
|
-
whereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3191
|
+
whereLike(column: SelectableColumn$1<string>, value: string): this;
|
|
3160
3192
|
/**
|
|
3161
3193
|
* @description Adds an AND WHERE LIKE condition to the query.
|
|
3162
3194
|
*/
|
|
3163
|
-
andWhereLike(column:
|
|
3164
|
-
andWhereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3195
|
+
andWhereLike(column: SelectableColumn$1<string>, value: string): this;
|
|
3165
3196
|
/**
|
|
3166
3197
|
* @description Adds an OR WHERE LIKE condition to the query.
|
|
3167
3198
|
*/
|
|
3168
|
-
orWhereLike(column:
|
|
3169
|
-
orWhereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3199
|
+
orWhereLike(column: SelectableColumn$1<string>, value: string): this;
|
|
3170
3200
|
/**
|
|
3171
3201
|
* @description Adds a WHERE ILIKE condition to the query.
|
|
3172
3202
|
*/
|
|
3173
|
-
whereILike(column:
|
|
3174
|
-
whereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3203
|
+
whereILike(column: SelectableColumn$1<string>, value: string): this;
|
|
3175
3204
|
/**
|
|
3176
3205
|
* @description Adds an AND WHERE ILIKE condition to the query.
|
|
3177
3206
|
*/
|
|
3178
|
-
andWhereILike(column:
|
|
3179
|
-
andWhereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3207
|
+
andWhereILike(column: SelectableColumn$1<string>, value: string): this;
|
|
3180
3208
|
/**
|
|
3181
3209
|
* @description Adds an OR WHERE ILIKE condition to the query.
|
|
3182
3210
|
*/
|
|
3183
|
-
orWhereILike(column:
|
|
3184
|
-
orWhereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3211
|
+
orWhereILike(column: SelectableColumn$1<string>, value: string): this;
|
|
3185
3212
|
/**
|
|
3186
3213
|
* @description Adds a WHERE NOT LIKE condition to the query.
|
|
3187
3214
|
*/
|
|
3188
|
-
whereNotLike(column:
|
|
3189
|
-
whereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3215
|
+
whereNotLike(column: SelectableColumn$1<string>, value: string): this;
|
|
3190
3216
|
/**
|
|
3191
3217
|
* @description Adds an AND WHERE NOT LIKE condition to the query.
|
|
3192
3218
|
*/
|
|
3193
|
-
andWhereNotLike(column:
|
|
3194
|
-
andWhereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3219
|
+
andWhereNotLike(column: SelectableColumn$1<string>, value: string): this;
|
|
3195
3220
|
/**
|
|
3196
3221
|
* @description Adds an OR WHERE NOT LIKE condition to the query.
|
|
3197
3222
|
*/
|
|
3198
|
-
orWhereNotLike(column:
|
|
3199
|
-
orWhereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3223
|
+
orWhereNotLike(column: SelectableColumn$1<string>, value: string): this;
|
|
3200
3224
|
/**
|
|
3201
3225
|
* @description Adds a WHERE NOT ILIKE condition to the query.
|
|
3202
3226
|
*/
|
|
3203
|
-
whereNotILike(column:
|
|
3204
|
-
whereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3227
|
+
whereNotILike(column: SelectableColumn$1<string>, value: string): this;
|
|
3205
3228
|
/**
|
|
3206
3229
|
* @description Adds an AND WHERE NOT ILIKE condition to the query.
|
|
3207
3230
|
*/
|
|
3208
|
-
andWhereNotILike(column:
|
|
3209
|
-
andWhereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3231
|
+
andWhereNotILike(column: SelectableColumn$1<string>, value: string): this;
|
|
3210
3232
|
/**
|
|
3211
3233
|
* @description Adds an OR WHERE NOT ILIKE condition to the query.
|
|
3212
3234
|
*/
|
|
3213
|
-
orWhereNotILike(column:
|
|
3214
|
-
orWhereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3235
|
+
orWhereNotILike(column: SelectableColumn$1<string>, value: string): this;
|
|
3215
3236
|
/**
|
|
3216
3237
|
* @description Adds a WHERE IN condition to the query.
|
|
3217
|
-
* @warning If the array is empty, it will add an impossible condition.
|
|
3218
3238
|
*/
|
|
3219
|
-
whereIn(column:
|
|
3220
|
-
whereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3239
|
+
whereIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
3221
3240
|
/**
|
|
3222
3241
|
* @description Adds an AND WHERE IN condition to the query.
|
|
3223
|
-
* @warning If the array is empty, it will add an impossible condition.
|
|
3224
3242
|
*/
|
|
3225
|
-
andWhereIn(column:
|
|
3226
|
-
andWhereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3243
|
+
andWhereIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
3227
3244
|
/**
|
|
3228
3245
|
* @description Adds an OR WHERE IN condition to the query.
|
|
3229
|
-
* @warning If the array is empty, it will add an impossible condition.
|
|
3230
3246
|
*/
|
|
3231
|
-
orWhereIn(column:
|
|
3232
|
-
orWhereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3247
|
+
orWhereIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
3233
3248
|
/**
|
|
3234
3249
|
* @description Adds a WHERE NOT IN condition to the query.
|
|
3235
|
-
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3236
3250
|
*/
|
|
3237
|
-
whereNotIn(column:
|
|
3238
|
-
whereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3251
|
+
whereNotIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
3239
3252
|
/**
|
|
3240
|
-
* @description Adds an
|
|
3241
|
-
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3253
|
+
* @description Adds an AND WHERE NOT IN condition to the query.
|
|
3242
3254
|
*/
|
|
3243
|
-
andWhereNotIn(column:
|
|
3244
|
-
andWhereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3255
|
+
andWhereNotIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
3245
3256
|
/**
|
|
3246
3257
|
* @description Adds an OR WHERE NOT IN condition to the query.
|
|
3247
|
-
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3248
3258
|
*/
|
|
3249
|
-
orWhereNotIn(column:
|
|
3250
|
-
orWhereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3259
|
+
orWhereNotIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
3251
3260
|
/**
|
|
3252
3261
|
* @description Adds a WHERE NULL condition to the query.
|
|
3253
3262
|
*/
|
|
3254
|
-
whereNull(column:
|
|
3255
|
-
whereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3263
|
+
whereNull(column: SelectableColumn$1<string>): this;
|
|
3256
3264
|
/**
|
|
3257
3265
|
* @description Adds an AND WHERE NULL condition to the query.
|
|
3258
3266
|
*/
|
|
3259
|
-
andWhereNull(column:
|
|
3260
|
-
andWhereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3267
|
+
andWhereNull(column: SelectableColumn$1<string>): this;
|
|
3261
3268
|
/**
|
|
3262
3269
|
* @description Adds an OR WHERE NULL condition to the query.
|
|
3263
3270
|
*/
|
|
3264
|
-
orWhereNull(column:
|
|
3265
|
-
orWhereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3271
|
+
orWhereNull(column: SelectableColumn$1<string>): this;
|
|
3266
3272
|
/**
|
|
3267
3273
|
* @description Adds a WHERE NOT NULL condition to the query.
|
|
3268
3274
|
*/
|
|
3269
|
-
whereNotNull(column:
|
|
3270
|
-
whereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3275
|
+
whereNotNull(column: SelectableColumn$1<string>): this;
|
|
3271
3276
|
/**
|
|
3272
3277
|
* @description Adds an AND WHERE NOT NULL condition to the query.
|
|
3273
3278
|
*/
|
|
3274
|
-
andWhereNotNull(column:
|
|
3275
|
-
andWhereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3279
|
+
andWhereNotNull(column: SelectableColumn$1<string>): this;
|
|
3276
3280
|
/**
|
|
3277
3281
|
* @description Adds an OR WHERE NOT NULL condition to the query.
|
|
3278
3282
|
*/
|
|
3279
|
-
orWhereNotNull(column:
|
|
3280
|
-
orWhereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3283
|
+
orWhereNotNull(column: SelectableColumn$1<string>): this;
|
|
3281
3284
|
/**
|
|
3282
3285
|
* @description Adds a WHERE REGEXP condition to the query.
|
|
3283
|
-
* @mssql doesn't support REGEXP syntax
|
|
3284
|
-
* @sqlite doesn't support REGEXP syntax
|
|
3285
3286
|
*/
|
|
3286
|
-
whereRegexp(column:
|
|
3287
|
-
whereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3287
|
+
whereRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
3288
3288
|
/**
|
|
3289
3289
|
* @description Adds an AND WHERE REGEXP condition to the query.
|
|
3290
|
-
* @mssql doesn't support REGEXP syntax
|
|
3291
|
-
* @sqlite doesn't support REGEXP syntax
|
|
3292
3290
|
*/
|
|
3293
|
-
andWhereRegexp(column:
|
|
3294
|
-
andWhereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3291
|
+
andWhereRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
3295
3292
|
/**
|
|
3296
3293
|
* @description Adds an OR WHERE REGEXP condition to the query.
|
|
3297
|
-
* @mssql doesn't support REGEXP syntax
|
|
3298
|
-
* @sqlite doesn't support REGEXP syntax
|
|
3299
3294
|
*/
|
|
3300
|
-
orWhereRegexp(column:
|
|
3301
|
-
orWhereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3295
|
+
orWhereRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
3302
3296
|
/**
|
|
3303
3297
|
* @description Adds a WHERE NOT REGEXP condition to the query.
|
|
3304
|
-
* @mssql doesn't support REGEXP syntax
|
|
3305
|
-
* @sqlite doesn't support REGEXP syntax
|
|
3306
3298
|
*/
|
|
3307
|
-
whereNotRegexp(column:
|
|
3308
|
-
whereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3299
|
+
whereNotRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
3309
3300
|
/**
|
|
3310
3301
|
* @description Adds an AND WHERE NOT REGEXP condition to the query.
|
|
3311
|
-
* @mssql doesn't support REGEXP syntax
|
|
3312
|
-
* @sqlite doesn't support REGEXP syntax
|
|
3313
3302
|
*/
|
|
3314
|
-
andWhereNotRegexp(column:
|
|
3315
|
-
andWhereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3303
|
+
andWhereNotRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
3316
3304
|
/**
|
|
3317
3305
|
* @description Adds an OR WHERE NOT REGEXP condition to the query.
|
|
3318
|
-
* @mssql doesn't support REGEXP syntax
|
|
3319
|
-
* @sqlite doesn't support REGEXP syntax
|
|
3320
3306
|
*/
|
|
3321
|
-
orWhereNotRegexp(column:
|
|
3322
|
-
orWhereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3307
|
+
orWhereNotRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
3323
3308
|
/**
|
|
3324
|
-
* @description Adds a
|
|
3309
|
+
* @description Adds a WHERE group condition with AND.
|
|
3325
3310
|
*/
|
|
3326
|
-
|
|
3311
|
+
whereGroup(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
3327
3312
|
/**
|
|
3328
|
-
* @description Adds a
|
|
3313
|
+
* @description Adds a WHERE group condition with AND.
|
|
3329
3314
|
*/
|
|
3330
|
-
|
|
3315
|
+
andWhereGroup(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
3331
3316
|
/**
|
|
3332
|
-
* @description Adds a
|
|
3317
|
+
* @description Adds a WHERE group condition with OR.
|
|
3333
3318
|
*/
|
|
3334
|
-
|
|
3319
|
+
orWhereGroup(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
3335
3320
|
/**
|
|
3336
|
-
* @description Adds a WHERE
|
|
3321
|
+
* @description Adds a raw WHERE condition to the query.
|
|
3337
3322
|
*/
|
|
3338
|
-
|
|
3323
|
+
whereRaw(sql: string, bindings?: BaseValues[]): this;
|
|
3339
3324
|
/**
|
|
3340
|
-
* @description Adds
|
|
3325
|
+
* @description Adds an AND raw WHERE condition to the query.
|
|
3341
3326
|
*/
|
|
3342
|
-
|
|
3327
|
+
andWhereRaw(sql: string, bindings?: BaseValues[]): this;
|
|
3343
3328
|
/**
|
|
3344
|
-
* @description Adds
|
|
3329
|
+
* @description Adds an OR raw WHERE condition to the query.
|
|
3345
3330
|
*/
|
|
3346
|
-
|
|
3331
|
+
orWhereRaw(sql: string, bindings?: BaseValues[]): this;
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
/**
|
|
3335
|
+
* @description Callback type for join conditions
|
|
3336
|
+
*/
|
|
3337
|
+
type JoinOnCallback = (query: JoinOnQueryBuilder) => void;
|
|
3338
|
+
declare abstract class JoinQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends FooterQueryBuilder<T, S> {
|
|
3339
|
+
protected joinNodes: JoinNode[];
|
|
3340
|
+
protected constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3347
3341
|
/**
|
|
3348
|
-
* @description
|
|
3342
|
+
* @description Clear the join query
|
|
3349
3343
|
*/
|
|
3350
|
-
|
|
3344
|
+
clearJoin(): this;
|
|
3345
|
+
/**
|
|
3346
|
+
* @description Join a table with the current model, join clause is not necessary and will be added automatically
|
|
3347
|
+
*/
|
|
3348
|
+
joinRaw(query: string): this;
|
|
3349
|
+
/**
|
|
3350
|
+
* @description Join a table with the current model, join clause is not necessary and will be added automatically
|
|
3351
|
+
*/
|
|
3352
|
+
leftJoinRaw(query: string): this;
|
|
3353
|
+
/**
|
|
3354
|
+
* @description Join a table with the current model, join clause is not necessary and will be added automatically
|
|
3355
|
+
*/
|
|
3356
|
+
rightJoinRaw(query: string): this;
|
|
3357
|
+
/**
|
|
3358
|
+
* @description Join a table with the current model, join clause is not necessary and will be added automatically
|
|
3359
|
+
*/
|
|
3360
|
+
fullJoinRaw(query: string): this;
|
|
3361
|
+
/**
|
|
3362
|
+
* @description Join a table with the current model, join clause is not necessary and will be added automatically
|
|
3363
|
+
*/
|
|
3364
|
+
crossJoinRaw(query: string): this;
|
|
3365
|
+
/**
|
|
3366
|
+
* @description Join a table with the current model, join clause is not necessary and will be added automatically
|
|
3367
|
+
*/
|
|
3368
|
+
naturalJoinRaw(query: string): this;
|
|
3369
|
+
/**
|
|
3370
|
+
* @alias join
|
|
3371
|
+
* @param relationTable - The table to join
|
|
3372
|
+
* @param referencingColumn - The column to reference from the relation table, must be in the format of `table.column`
|
|
3373
|
+
* @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
|
|
3374
|
+
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
3375
|
+
*/
|
|
3376
|
+
innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3377
|
+
innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3378
|
+
innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3379
|
+
innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3380
|
+
innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3381
|
+
innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
3382
|
+
innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3383
|
+
innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
|
|
3384
|
+
/**
|
|
3385
|
+
* @description Join a table with the current model
|
|
3386
|
+
* @param relationTable - The table to join
|
|
3387
|
+
* @param referencingColumn - The column to reference from the relation table, must be in the format of `table.column`
|
|
3388
|
+
* @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
|
|
3389
|
+
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
3390
|
+
*/
|
|
3391
|
+
join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3392
|
+
join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3393
|
+
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3394
|
+
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3395
|
+
join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3396
|
+
join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
3397
|
+
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3398
|
+
join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
|
|
3399
|
+
/**
|
|
3400
|
+
* @description Join a table with the current model
|
|
3401
|
+
* @param relationTable - The table to join
|
|
3402
|
+
* @param referencingColumn - The column to reference from the relation table, must be in the format of `table.column`
|
|
3403
|
+
* @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
|
|
3404
|
+
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
3405
|
+
*/
|
|
3406
|
+
leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3407
|
+
leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3408
|
+
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3409
|
+
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3410
|
+
leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3411
|
+
leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
3412
|
+
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3413
|
+
leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
|
|
3414
|
+
/**
|
|
3415
|
+
* @description Join a table with the current model
|
|
3416
|
+
* @param relationTable - The table to join
|
|
3417
|
+
* @param referencingColumn - The column to reference from the relation table
|
|
3418
|
+
* @param primaryColumn - The primary column of the current model, default is caller model primary key if using A Model, if using a Raw Query Builder you must provide the key for the primary table
|
|
3419
|
+
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
3420
|
+
*/
|
|
3421
|
+
rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3422
|
+
rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3423
|
+
rightJoin<R extends typeof Model>(relationTable: string | R, referencingColumnOrPrimaryColumn: ModelKey<InstanceType<R>> | JoinableColumn | ModelKey<T>, primaryColumn?: JoinableColumn | ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3424
|
+
rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3425
|
+
rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
3426
|
+
/**
|
|
3427
|
+
* @description Perform a FULL OUTER JOIN with another table
|
|
3428
|
+
* @param relationTable - The table to join
|
|
3429
|
+
* @param referencingColumn - The column to reference from the relation table
|
|
3430
|
+
* @param primaryColumn - The primary column of the current model
|
|
3431
|
+
* @param operator - The comparison operator to use in the ON clause (default: "=")
|
|
3432
|
+
*/
|
|
3433
|
+
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3434
|
+
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
|
|
3435
|
+
fullJoin<R extends typeof Model>(relationTable: string | R, referencingColumnOrPrimaryColumn: ModelKey<InstanceType<R>> | JoinableColumn | ModelKey<T>, primaryColumn?: JoinableColumn | ModelKey<T>, operator?: BinaryOperatorType): this;
|
|
3436
|
+
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
|
|
3437
|
+
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
declare class SelectQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends JoinQueryBuilder<T, S> {
|
|
3441
|
+
protected dbType: SqlDataSourceType;
|
|
3442
|
+
protected modelSelectedColumns: string[];
|
|
3443
|
+
protected withQuery?: string;
|
|
3444
|
+
protected fromNode: FromNode;
|
|
3445
|
+
protected distinctNode: DistinctNode | null;
|
|
3446
|
+
protected distinctOnNode: DistinctOnNode | null;
|
|
3447
|
+
protected selectNodes: SelectNode[];
|
|
3448
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3449
|
+
/**
|
|
3450
|
+
* @description Adds a SELECT condition to the query.
|
|
3451
|
+
* @description Can be stacked multiple times
|
|
3452
|
+
* @description Supports: "column", "table.column", "*", "table.*", or [column, alias] tuples
|
|
3453
|
+
* @example
|
|
3454
|
+
* .select("id", "name") // Simple columns
|
|
3455
|
+
* .select(["id", "userId"], ["name", "userName"]) // Columns with aliases
|
|
3456
|
+
* .select("id", ["name", "userName"]) // Mixed
|
|
3457
|
+
*/
|
|
3458
|
+
select<C extends string>(...columns: (SelectableColumn$1<C> | Selectable)[]): this;
|
|
3459
|
+
select(...columns: (ModelKey<T> | "*" | Selectable)[]): this;
|
|
3351
3460
|
/**
|
|
3352
|
-
* @description Adds a raw
|
|
3461
|
+
* @description Adds a raw SELECT statement to the query
|
|
3353
3462
|
*/
|
|
3354
|
-
|
|
3463
|
+
selectRaw(statement: string): this;
|
|
3355
3464
|
/**
|
|
3356
|
-
* @description
|
|
3465
|
+
* @description Selects a SQL function applied to a column with a typed alias.
|
|
3466
|
+
* @description Provides intellisense for common SQL functions while accepting any custom function.
|
|
3467
|
+
* @param func The SQL function name (count, sum, avg, min, max, upper, lower, etc.)
|
|
3468
|
+
* @param column The column to apply the function to (use "*" for count(*))
|
|
3469
|
+
* @param alias The alias for the result
|
|
3470
|
+
* @example
|
|
3471
|
+
* .selectFunc("count", "*", "total")
|
|
3472
|
+
* .selectFunc("upper", "name", "upperName")
|
|
3473
|
+
* .selectFunc("custom_fn", "column", "result")
|
|
3357
3474
|
*/
|
|
3358
|
-
|
|
3475
|
+
selectFunc<A extends string>(sqlFunc: SqlFunction, column: string, alias: A): this;
|
|
3359
3476
|
/**
|
|
3360
|
-
* @description
|
|
3477
|
+
* @description Clears the SELECT clause
|
|
3361
3478
|
*/
|
|
3362
|
-
|
|
3363
|
-
having(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3479
|
+
clearSelect(): this;
|
|
3364
3480
|
/**
|
|
3365
|
-
* @description
|
|
3481
|
+
* @description Clears the FROM clause
|
|
3366
3482
|
*/
|
|
3367
|
-
|
|
3368
|
-
andHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3483
|
+
clearFrom(): this;
|
|
3369
3484
|
/**
|
|
3370
|
-
* @description
|
|
3485
|
+
* @description Clears the DISTINCT clause
|
|
3371
3486
|
*/
|
|
3372
|
-
|
|
3373
|
-
orHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3487
|
+
clearDistinct(): this;
|
|
3374
3488
|
/**
|
|
3375
|
-
* @description
|
|
3489
|
+
* @description Clears the DISTINCT ON clause
|
|
3376
3490
|
*/
|
|
3377
|
-
|
|
3491
|
+
clearDistinctOn(): this;
|
|
3378
3492
|
/**
|
|
3379
|
-
* @description
|
|
3493
|
+
* @description Sets the table to select from, by default is the table defined in the Model
|
|
3380
3494
|
*/
|
|
3381
|
-
|
|
3495
|
+
from<F extends string>(table: TableFormat<F>): this;
|
|
3382
3496
|
/**
|
|
3383
|
-
* @description
|
|
3497
|
+
* @description Sets the table to select from, by default is the table defined in the Model
|
|
3498
|
+
* @alias from
|
|
3384
3499
|
*/
|
|
3385
|
-
|
|
3386
|
-
private buildSubQuery;
|
|
3387
|
-
private andWhereSubQuery;
|
|
3388
|
-
private orWhereSubQuery;
|
|
3389
|
-
private andWhereGroup;
|
|
3390
|
-
private orWhereGroup;
|
|
3391
|
-
}
|
|
3392
|
-
|
|
3393
|
-
type JsonParam = Record<string, unknown> | any[];
|
|
3394
|
-
declare class JsonQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends WhereQueryBuilder<T, S> {
|
|
3500
|
+
table(table: string): this;
|
|
3395
3501
|
/**
|
|
3396
|
-
* @description
|
|
3502
|
+
* @description Adds a DISTINCT clause to the query
|
|
3397
3503
|
*/
|
|
3398
|
-
|
|
3399
|
-
whereJson(column: string, value: JsonParam): this;
|
|
3504
|
+
distinct(): this;
|
|
3400
3505
|
/**
|
|
3401
|
-
* @description
|
|
3402
|
-
* @
|
|
3506
|
+
* @description Adds a DISTINCT ON clause to the query
|
|
3507
|
+
* @postgresql Only usable with PostgreSQL
|
|
3403
3508
|
*/
|
|
3404
|
-
|
|
3405
|
-
|
|
3509
|
+
distinctOn(...columns: ModelKey<T>[]): this;
|
|
3510
|
+
distinctOn<C extends string>(...columns: SelectableColumn$1<C>[]): this;
|
|
3406
3511
|
/**
|
|
3407
|
-
* @description
|
|
3408
|
-
* @mssql Partial JSON matching not supported - only exact matches work
|
|
3512
|
+
* @description Selects a JSON value at the specified path and returns it as JSON
|
|
3409
3513
|
*/
|
|
3410
|
-
|
|
3411
|
-
|
|
3514
|
+
selectJson<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3515
|
+
selectJson<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3412
3516
|
/**
|
|
3413
|
-
* @description
|
|
3414
|
-
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3415
|
-
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3517
|
+
* @description Selects a JSON value at the specified path and returns it as text
|
|
3416
3518
|
*/
|
|
3417
|
-
|
|
3418
|
-
|
|
3519
|
+
selectJsonText<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3520
|
+
selectJsonText<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3419
3521
|
/**
|
|
3420
|
-
* @description
|
|
3421
|
-
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3422
|
-
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3522
|
+
* @description Selects the length of a JSON array
|
|
3423
3523
|
*/
|
|
3424
|
-
|
|
3425
|
-
|
|
3524
|
+
selectJsonArrayLength<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3525
|
+
selectJsonArrayLength<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3426
3526
|
/**
|
|
3427
|
-
* @description
|
|
3428
|
-
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3429
|
-
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3527
|
+
* @description Selects the keys of a JSON object
|
|
3430
3528
|
*/
|
|
3431
|
-
|
|
3432
|
-
|
|
3529
|
+
selectJsonKeys<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3530
|
+
selectJsonKeys<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3433
3531
|
/**
|
|
3434
|
-
* @description
|
|
3435
|
-
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3436
|
-
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3532
|
+
* @description Adds a raw JSON select expression
|
|
3437
3533
|
*/
|
|
3438
|
-
|
|
3439
|
-
|
|
3534
|
+
selectJsonRaw<A extends string>(raw: string, alias: A): this;
|
|
3535
|
+
}
|
|
3536
|
+
|
|
3537
|
+
declare abstract class WhereQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends SelectQueryBuilder<T, S> {
|
|
3538
|
+
protected whereNodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
|
|
3539
|
+
protected havingNodes: HavingNode[];
|
|
3540
|
+
protected isNestedCondition: boolean;
|
|
3541
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource, isNestedCondition?: boolean);
|
|
3542
|
+
clearWhere(): this;
|
|
3543
|
+
clearHaving(): this;
|
|
3440
3544
|
/**
|
|
3441
|
-
* @description
|
|
3442
|
-
* @
|
|
3443
|
-
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3545
|
+
* @description Accepts a value and executes a callback only of the value is not null or undefined.
|
|
3546
|
+
* @warning The value is not checked for truthiness but existence, it is only checked for undefined or null. So false, 0, "", etc. will be considered truthy.
|
|
3444
3547
|
*/
|
|
3445
|
-
|
|
3446
|
-
andWhereJsonContains(column: string, value: JsonParam): this;
|
|
3548
|
+
strictWhen(value: any, cb: (query: this) => void): this;
|
|
3447
3549
|
/**
|
|
3448
|
-
* @description
|
|
3449
|
-
* @
|
|
3450
|
-
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3550
|
+
* @description Accepts a value and executes a callback only of the value is not falsy.
|
|
3551
|
+
* @warning The value is checked for truthiness, so false, 0, "", etc. will be considered falsy. Use strictWhen for null or undefined only cases.
|
|
3451
3552
|
*/
|
|
3452
|
-
|
|
3453
|
-
orWhereJsonContains(column: string, value: JsonParam): this;
|
|
3553
|
+
when(value: any, cb: (query: this) => void): this;
|
|
3454
3554
|
/**
|
|
3455
|
-
* @description
|
|
3555
|
+
* @description Adds a WHERE condition to the query.
|
|
3456
3556
|
*/
|
|
3457
|
-
|
|
3458
|
-
|
|
3557
|
+
where(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3558
|
+
where<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3559
|
+
where(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
|
|
3560
|
+
where(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3561
|
+
where(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3562
|
+
where(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3459
3563
|
/**
|
|
3460
|
-
* @description
|
|
3564
|
+
* @description Adds an AND WHERE condition to the query.
|
|
3461
3565
|
*/
|
|
3462
|
-
|
|
3463
|
-
|
|
3566
|
+
andWhere(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3567
|
+
andWhere(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3568
|
+
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3569
|
+
andWhere(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
|
|
3570
|
+
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3571
|
+
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3464
3572
|
/**
|
|
3465
|
-
* @description
|
|
3573
|
+
* @description Adds an OR WHERE condition to the query.
|
|
3466
3574
|
*/
|
|
3467
|
-
|
|
3468
|
-
|
|
3575
|
+
orWhere(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3576
|
+
orWhere<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3577
|
+
orWhere<S extends string>(column: ModelKey<T> | SelectableColumn$1<S>, value: BaseValues): this;
|
|
3578
|
+
orWhere(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
|
|
3579
|
+
orWhere(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3580
|
+
orWhere(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3469
3581
|
/**
|
|
3470
|
-
* @description
|
|
3582
|
+
* @description Adds a negated WHERE condition to the query.
|
|
3471
3583
|
*/
|
|
3472
|
-
|
|
3584
|
+
whereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3585
|
+
whereNot<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3586
|
+
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3587
|
+
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3588
|
+
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3473
3589
|
/**
|
|
3474
|
-
* @description
|
|
3590
|
+
* @description Adds a negated AND WHERE condition to the query.
|
|
3475
3591
|
*/
|
|
3476
|
-
|
|
3592
|
+
andWhereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3593
|
+
andWhereNot<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3594
|
+
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3595
|
+
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3596
|
+
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3477
3597
|
/**
|
|
3478
|
-
* @description
|
|
3598
|
+
* @description Adds a negated OR WHERE condition to the query.
|
|
3479
3599
|
*/
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
protected astParser: AstParser;
|
|
3486
|
-
protected unionNodes: UnionNode[];
|
|
3487
|
-
protected withNodes: WithNode[];
|
|
3488
|
-
protected lockQueryNodes: LockNode[];
|
|
3489
|
-
protected isNestedCondition: boolean;
|
|
3490
|
-
protected interpreterUtils: InterpreterUtils;
|
|
3491
|
-
protected insertNode: InsertNode | null;
|
|
3492
|
-
protected onDuplicateNode: OnDuplicateNode | null;
|
|
3493
|
-
protected updateNode: UpdateNode | null;
|
|
3494
|
-
protected deleteNode: DeleteNode | null;
|
|
3495
|
-
protected truncateNode: TruncateNode | null;
|
|
3496
|
-
protected replicationMode: ReplicationType | null;
|
|
3600
|
+
orWhereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3601
|
+
orWhereNot<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3602
|
+
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3603
|
+
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3604
|
+
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3497
3605
|
/**
|
|
3498
|
-
* @description
|
|
3606
|
+
* @description Adds a WHERE BETWEEN condition to the query.
|
|
3499
3607
|
*/
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
data: S[];
|
|
3503
|
-
time: number;
|
|
3504
|
-
}>;
|
|
3505
|
-
one: (returnType?: "millis" | "seconds") => Promise<{
|
|
3506
|
-
data: S | null;
|
|
3507
|
-
time: number;
|
|
3508
|
-
}>;
|
|
3509
|
-
oneOrFail: (returnType?: "millis" | "seconds") => Promise<{
|
|
3510
|
-
data: S;
|
|
3511
|
-
time: number;
|
|
3512
|
-
}>;
|
|
3513
|
-
paginate: (page: number, perPage: number, returnType?: "millis" | "seconds") => Promise<{
|
|
3514
|
-
data: RawPaginatedData<S>;
|
|
3515
|
-
time: number;
|
|
3516
|
-
}>;
|
|
3517
|
-
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
3518
|
-
data: [RawCursorPaginatedData<S>, Cursor<T, ModelKey<T>>];
|
|
3519
|
-
time: number;
|
|
3520
|
-
}>;
|
|
3521
|
-
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
3522
|
-
data: boolean;
|
|
3523
|
-
time: number;
|
|
3524
|
-
}>;
|
|
3525
|
-
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
3526
|
-
data: void;
|
|
3527
|
-
time: number;
|
|
3528
|
-
}>;
|
|
3529
|
-
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
3530
|
-
data: number;
|
|
3531
|
-
time: number;
|
|
3532
|
-
}>;
|
|
3533
|
-
insert: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
3534
|
-
data: T;
|
|
3535
|
-
time: number;
|
|
3536
|
-
}>;
|
|
3537
|
-
insertMany: (data: Record<string, any>[], returnType?: "millis" | "seconds") => Promise<{
|
|
3538
|
-
data: T[];
|
|
3539
|
-
time: number;
|
|
3540
|
-
}>;
|
|
3541
|
-
update: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
3542
|
-
data: number;
|
|
3543
|
-
time: number;
|
|
3544
|
-
}>;
|
|
3545
|
-
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
3546
|
-
data: number;
|
|
3547
|
-
time: number;
|
|
3548
|
-
}>;
|
|
3549
|
-
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
3550
|
-
data: PluckReturnType<T, ModelKey<T>>;
|
|
3551
|
-
time: number;
|
|
3552
|
-
}>;
|
|
3553
|
-
};
|
|
3554
|
-
constructor(model: typeof Model, sqlDataSource?: SqlDataSource);
|
|
3608
|
+
whereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3609
|
+
whereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3555
3610
|
/**
|
|
3556
|
-
* @description
|
|
3557
|
-
* @param replicationMode - The replication mode to use for the query builder
|
|
3558
|
-
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
3559
|
-
* @description If set to "master", all operations will use master
|
|
3560
|
-
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
3611
|
+
* @description Adds an AND WHERE BETWEEN condition to the query.
|
|
3561
3612
|
*/
|
|
3562
|
-
|
|
3613
|
+
andWhereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3614
|
+
andWhereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3563
3615
|
/**
|
|
3564
|
-
* @description Adds
|
|
3565
|
-
* @description Can be stacked multiple times
|
|
3566
|
-
* @description Supports: "column", "table.column", "*", "table.*", or [column, alias] tuples
|
|
3567
|
-
* @example
|
|
3568
|
-
* ```ts
|
|
3569
|
-
* const user = await sql.query("users").select("name", "age").one();
|
|
3570
|
-
* // user type: { name: any, age: any } | null
|
|
3571
|
-
*
|
|
3572
|
-
* const user = await sql.query("users").select(["name", "userName"]).one();
|
|
3573
|
-
* // user type: { userName: any } | null
|
|
3574
|
-
* ```
|
|
3616
|
+
* @description Adds an OR WHERE BETWEEN condition to the query.
|
|
3575
3617
|
*/
|
|
3576
|
-
|
|
3618
|
+
orWhereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3619
|
+
orWhereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3577
3620
|
/**
|
|
3578
|
-
* @description Adds a
|
|
3579
|
-
* @description Use the generic parameter to specify the type of the selected columns.
|
|
3580
|
-
* @example
|
|
3581
|
-
* ```ts
|
|
3582
|
-
* const result = await sql.query("users")
|
|
3583
|
-
* .selectRaw<{ total: number }>("count(*) as total")
|
|
3584
|
-
* .one();
|
|
3585
|
-
* // result type: { total: number } | null
|
|
3586
|
-
* ```
|
|
3621
|
+
* @description Adds a WHERE NOT BETWEEN condition to the query.
|
|
3587
3622
|
*/
|
|
3588
|
-
|
|
3623
|
+
whereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3624
|
+
whereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3589
3625
|
/**
|
|
3590
|
-
* @description
|
|
3626
|
+
* @description Adds an AND WHERE NOT BETWEEN condition to the query.
|
|
3591
3627
|
*/
|
|
3592
|
-
|
|
3628
|
+
andWhereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3629
|
+
andWhereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3593
3630
|
/**
|
|
3594
|
-
* @description
|
|
3595
|
-
* @description Provides intellisense for common SQL functions while accepting any custom function.
|
|
3596
|
-
* @description Return type is auto-inferred based on function name (number for count/sum/avg, string for upper/lower/trim, etc.)
|
|
3597
|
-
* @param sqlFunc The SQL function name (count, sum, avg, min, max, upper, lower, etc.)
|
|
3598
|
-
* @param column The column to apply the function to (use "*" for count(*))
|
|
3599
|
-
* @param alias The alias for the result
|
|
3600
|
-
* @example
|
|
3601
|
-
* ```ts
|
|
3602
|
-
* const result = await sql.query("users")
|
|
3603
|
-
* .selectFunc("count", "*", "total")
|
|
3604
|
-
* .one();
|
|
3605
|
-
* // result type: { total: number } | null - auto-inferred!
|
|
3606
|
-
* ```
|
|
3631
|
+
* @description Adds an OR WHERE NOT BETWEEN condition to the query.
|
|
3607
3632
|
*/
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
}>>;
|
|
3633
|
+
orWhereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3634
|
+
orWhereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3611
3635
|
/**
|
|
3612
|
-
* @description
|
|
3636
|
+
* @description Adds a WHERE LIKE condition to the query.
|
|
3613
3637
|
*/
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
}>>;
|
|
3617
|
-
selectJson<ValueType = any, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3618
|
-
[K in Alias]: ValueType;
|
|
3619
|
-
}>>;
|
|
3620
|
-
selectJsonText<ValueType = string, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3621
|
-
[K in Alias]: ValueType;
|
|
3622
|
-
}>>;
|
|
3623
|
-
selectJsonArrayLength<Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3624
|
-
[K in Alias]: number;
|
|
3625
|
-
}>>;
|
|
3626
|
-
selectJsonKeys<Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3627
|
-
[K in Alias]: string[];
|
|
3628
|
-
}>>;
|
|
3629
|
-
selectJsonRaw<ValueType = any, Alias extends string = string>(raw: string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3630
|
-
[K in Alias]: ValueType;
|
|
3631
|
-
}>>;
|
|
3638
|
+
whereLike(column: ModelKey<T>, value: string): this;
|
|
3639
|
+
whereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3632
3640
|
/**
|
|
3633
|
-
* @description
|
|
3641
|
+
* @description Adds an AND WHERE LIKE condition to the query.
|
|
3634
3642
|
*/
|
|
3635
|
-
|
|
3643
|
+
andWhereLike(column: ModelKey<T>, value: string): this;
|
|
3644
|
+
andWhereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3636
3645
|
/**
|
|
3637
|
-
* @description
|
|
3646
|
+
* @description Adds an OR WHERE LIKE condition to the query.
|
|
3638
3647
|
*/
|
|
3639
|
-
|
|
3648
|
+
orWhereLike(column: ModelKey<T>, value: string): this;
|
|
3649
|
+
orWhereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3640
3650
|
/**
|
|
3641
|
-
* @description
|
|
3642
|
-
* @param key - The column to retrieve from the results, must be a Model Column
|
|
3651
|
+
* @description Adds a WHERE ILIKE condition to the query.
|
|
3643
3652
|
*/
|
|
3644
|
-
|
|
3653
|
+
whereILike(column: ModelKey<T>, value: string): this;
|
|
3654
|
+
whereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3645
3655
|
/**
|
|
3646
|
-
* @description
|
|
3656
|
+
* @description Adds an AND WHERE ILIKE condition to the query.
|
|
3647
3657
|
*/
|
|
3648
|
-
|
|
3658
|
+
andWhereILike(column: ModelKey<T>, value: string): this;
|
|
3659
|
+
andWhereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3649
3660
|
/**
|
|
3650
|
-
* @description
|
|
3661
|
+
* @description Adds an OR WHERE ILIKE condition to the query.
|
|
3651
3662
|
*/
|
|
3652
|
-
|
|
3663
|
+
orWhereILike(column: ModelKey<T>, value: string): this;
|
|
3664
|
+
orWhereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3653
3665
|
/**
|
|
3654
|
-
* @description
|
|
3655
|
-
* @description If used by a model query builder, it will serialize the models and apply the hooks and relations.
|
|
3656
|
-
* @postgres needs the pg-query-stream package in order to work
|
|
3657
|
-
* @throws If using postgres and the `pg-query-stream` package is not installed
|
|
3666
|
+
* @description Adds a WHERE NOT LIKE condition to the query.
|
|
3658
3667
|
*/
|
|
3659
|
-
|
|
3668
|
+
whereNotLike(column: ModelKey<T>, value: string): this;
|
|
3669
|
+
whereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3660
3670
|
/**
|
|
3661
|
-
* @description
|
|
3662
|
-
* @description It will continue to yield chunks until the query returns no results
|
|
3663
|
-
* @description Useful for large queries that need to be processed in chunks
|
|
3664
|
-
* @warning overrides limit and offset set before in the query builder
|
|
3665
|
-
* @param chunkSize - The size of the chunk
|
|
3666
|
-
* @returns a generator of the chunks
|
|
3667
|
-
* @example
|
|
3668
|
-
* const chunks = await queryBuilder.chunk(100);
|
|
3669
|
-
* // first chunk
|
|
3670
|
-
* const firstChunk = await chunks.next();
|
|
3671
|
-
* console.log(firstChunk.value);
|
|
3672
|
-
* // second chunk
|
|
3673
|
-
* const secondChunk = await chunks.next();
|
|
3674
|
-
* console.log(secondChunk.value);
|
|
3675
|
-
* // third chunk
|
|
3676
|
-
* const thirdChunk = await chunks.next();
|
|
3677
|
-
* console.log(thirdChunk.value);
|
|
3678
|
-
*
|
|
3679
|
-
* @example
|
|
3680
|
-
* const chunkSize = 3;
|
|
3681
|
-
* const chunks = [];
|
|
3682
|
-
* const query = sql.query("users").orderBy("name", "asc");
|
|
3683
|
-
* for await (const chunk of sql.chunk(chunkSize)) {
|
|
3684
|
-
* chunks.push(chunk);
|
|
3685
|
-
* }
|
|
3686
|
-
*
|
|
3687
|
-
* console.log(chunks);
|
|
3671
|
+
* @description Adds an AND WHERE NOT LIKE condition to the query.
|
|
3688
3672
|
*/
|
|
3689
|
-
|
|
3673
|
+
andWhereNotLike(column: ModelKey<T>, value: string): this;
|
|
3674
|
+
andWhereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3690
3675
|
/**
|
|
3691
|
-
* @description
|
|
3692
|
-
* @description Overrides the limit and offset clauses in order to paginate the results.
|
|
3693
|
-
* @description Allows to avoid offset clause that can be inefficient for large datasets
|
|
3694
|
-
* @description If using a model query builder, primary key is used as discriminator by default
|
|
3695
|
-
* @param options - The options for the paginate with cursor
|
|
3696
|
-
* @param options.discriminator - The discriminator to use for the paginate with Cursor pagination
|
|
3697
|
-
* @param options.operator - The operator to use for the paginate with Cursor pagination
|
|
3698
|
-
* @param options.orderBy - The order by to use for the paginate with Cursor pagination
|
|
3699
|
-
* @param cursor - The cursor to use for the paginate with Cursor pagination
|
|
3700
|
-
* @warning If no order by clause is present in the query, the query will add an order by clause to the query `orderBy(discriminator, "asc")`
|
|
3701
|
-
* @returns the pagination metadata and the cursor for the next page
|
|
3676
|
+
* @description Adds an OR WHERE NOT LIKE condition to the query.
|
|
3702
3677
|
*/
|
|
3703
|
-
|
|
3678
|
+
orWhereNotLike(column: ModelKey<T>, value: string): this;
|
|
3679
|
+
orWhereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3704
3680
|
/**
|
|
3705
|
-
* @description
|
|
3706
|
-
* @param skipLocked - If true, the query will skip locked rows
|
|
3707
|
-
* @sqlite does not support skipping locked rows, it will be ignored
|
|
3681
|
+
* @description Adds a WHERE NOT ILIKE condition to the query.
|
|
3708
3682
|
*/
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
noWait?: boolean;
|
|
3712
|
-
}): this;
|
|
3683
|
+
whereNotILike(column: ModelKey<T>, value: string): this;
|
|
3684
|
+
whereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3713
3685
|
/**
|
|
3714
|
-
* @description
|
|
3715
|
-
* @param skipLocked - If true, the query will skip locked rows
|
|
3716
|
-
* @sqlite does not support skipping locked rows, it will be ignored
|
|
3686
|
+
* @description Adds an AND WHERE NOT ILIKE condition to the query.
|
|
3717
3687
|
*/
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
noWait?: boolean;
|
|
3721
|
-
}): this;
|
|
3688
|
+
andWhereNotILike(column: ModelKey<T>, value: string): this;
|
|
3689
|
+
andWhereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3722
3690
|
/**
|
|
3723
|
-
* @description Adds
|
|
3691
|
+
* @description Adds an OR WHERE NOT ILIKE condition to the query.
|
|
3724
3692
|
*/
|
|
3725
|
-
|
|
3726
|
-
|
|
3693
|
+
orWhereNotILike(column: ModelKey<T>, value: string): this;
|
|
3694
|
+
orWhereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3727
3695
|
/**
|
|
3728
|
-
* @description Adds a
|
|
3696
|
+
* @description Adds a WHERE IN condition to the query.
|
|
3697
|
+
* @warning If the array is empty, it will add an impossible condition.
|
|
3729
3698
|
*/
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
unionAll(queryBuilder: QueryBuilder<any>): this;
|
|
3699
|
+
whereIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3700
|
+
whereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3733
3701
|
/**
|
|
3734
|
-
* @description
|
|
3735
|
-
* @
|
|
3736
|
-
* @default value + 1
|
|
3737
|
-
* @returns the number of affected rows
|
|
3702
|
+
* @description Adds an AND WHERE IN condition to the query.
|
|
3703
|
+
* @warning If the array is empty, it will add an impossible condition.
|
|
3738
3704
|
*/
|
|
3739
|
-
|
|
3740
|
-
|
|
3705
|
+
andWhereIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3706
|
+
andWhereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3741
3707
|
/**
|
|
3742
|
-
* @description
|
|
3743
|
-
* @
|
|
3744
|
-
* @default value - 1
|
|
3745
|
-
* @returns the number of affected rows
|
|
3708
|
+
* @description Adds an OR WHERE IN condition to the query.
|
|
3709
|
+
* @warning If the array is empty, it will add an impossible condition.
|
|
3746
3710
|
*/
|
|
3747
|
-
|
|
3748
|
-
|
|
3711
|
+
orWhereIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3712
|
+
orWhereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3749
3713
|
/**
|
|
3750
|
-
* @description
|
|
3714
|
+
* @description Adds a WHERE NOT IN condition to the query.
|
|
3715
|
+
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3751
3716
|
*/
|
|
3752
|
-
|
|
3717
|
+
whereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3718
|
+
whereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3753
3719
|
/**
|
|
3754
|
-
* @description
|
|
3720
|
+
* @description Adds an OR WHERE NOT IN condition to the query.
|
|
3721
|
+
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3755
3722
|
*/
|
|
3756
|
-
|
|
3723
|
+
andWhereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3724
|
+
andWhereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3757
3725
|
/**
|
|
3758
|
-
* @description
|
|
3726
|
+
* @description Adds an OR WHERE NOT IN condition to the query.
|
|
3727
|
+
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3759
3728
|
*/
|
|
3760
|
-
|
|
3729
|
+
orWhereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3730
|
+
orWhereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3761
3731
|
/**
|
|
3762
|
-
* @description
|
|
3732
|
+
* @description Adds a WHERE NULL condition to the query.
|
|
3763
3733
|
*/
|
|
3764
|
-
|
|
3734
|
+
whereNull(column: ModelKey<T>): this;
|
|
3735
|
+
whereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3765
3736
|
/**
|
|
3766
|
-
* @description
|
|
3737
|
+
* @description Adds an AND WHERE NULL condition to the query.
|
|
3738
|
+
*/
|
|
3739
|
+
andWhereNull(column: ModelKey<T>): this;
|
|
3740
|
+
andWhereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3741
|
+
/**
|
|
3742
|
+
* @description Adds an OR WHERE NULL condition to the query.
|
|
3743
|
+
*/
|
|
3744
|
+
orWhereNull(column: ModelKey<T>): this;
|
|
3745
|
+
orWhereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3746
|
+
/**
|
|
3747
|
+
* @description Adds a WHERE NOT NULL condition to the query.
|
|
3748
|
+
*/
|
|
3749
|
+
whereNotNull(column: ModelKey<T>): this;
|
|
3750
|
+
whereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3751
|
+
/**
|
|
3752
|
+
* @description Adds an AND WHERE NOT NULL condition to the query.
|
|
3753
|
+
*/
|
|
3754
|
+
andWhereNotNull(column: ModelKey<T>): this;
|
|
3755
|
+
andWhereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3756
|
+
/**
|
|
3757
|
+
* @description Adds an OR WHERE NOT NULL condition to the query.
|
|
3767
3758
|
*/
|
|
3768
|
-
|
|
3759
|
+
orWhereNotNull(column: ModelKey<T>): this;
|
|
3760
|
+
orWhereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3769
3761
|
/**
|
|
3770
|
-
* @description
|
|
3771
|
-
* @
|
|
3762
|
+
* @description Adds a WHERE REGEXP condition to the query.
|
|
3763
|
+
* @mssql doesn't support REGEXP syntax
|
|
3764
|
+
* @sqlite doesn't support REGEXP syntax
|
|
3772
3765
|
*/
|
|
3773
|
-
|
|
3766
|
+
whereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3767
|
+
whereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3774
3768
|
/**
|
|
3775
|
-
* @description
|
|
3769
|
+
* @description Adds an AND WHERE REGEXP condition to the query.
|
|
3770
|
+
* @mssql doesn't support REGEXP syntax
|
|
3771
|
+
* @sqlite doesn't support REGEXP syntax
|
|
3776
3772
|
*/
|
|
3777
|
-
|
|
3778
|
-
|
|
3773
|
+
andWhereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3774
|
+
andWhereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3779
3775
|
/**
|
|
3780
|
-
* @description Adds
|
|
3776
|
+
* @description Adds an OR WHERE REGEXP condition to the query.
|
|
3777
|
+
* @mssql doesn't support REGEXP syntax
|
|
3778
|
+
* @sqlite doesn't support REGEXP syntax
|
|
3781
3779
|
*/
|
|
3782
|
-
|
|
3780
|
+
orWhereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3781
|
+
orWhereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3783
3782
|
/**
|
|
3784
|
-
* @description Adds a
|
|
3785
|
-
* @mssql
|
|
3783
|
+
* @description Adds a WHERE NOT REGEXP condition to the query.
|
|
3784
|
+
* @mssql doesn't support REGEXP syntax
|
|
3785
|
+
* @sqlite doesn't support REGEXP syntax
|
|
3786
3786
|
*/
|
|
3787
|
-
|
|
3787
|
+
whereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3788
|
+
whereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3788
3789
|
/**
|
|
3789
|
-
* @description Adds
|
|
3790
|
-
* @
|
|
3791
|
-
* @
|
|
3790
|
+
* @description Adds an AND WHERE NOT REGEXP condition to the query.
|
|
3791
|
+
* @mssql doesn't support REGEXP syntax
|
|
3792
|
+
* @sqlite doesn't support REGEXP syntax
|
|
3792
3793
|
*/
|
|
3793
|
-
|
|
3794
|
+
andWhereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3795
|
+
andWhereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3794
3796
|
/**
|
|
3795
|
-
* @description
|
|
3796
|
-
* @
|
|
3797
|
-
* @
|
|
3797
|
+
* @description Adds an OR WHERE NOT REGEXP condition to the query.
|
|
3798
|
+
* @mssql doesn't support REGEXP syntax
|
|
3799
|
+
* @sqlite doesn't support REGEXP syntax
|
|
3798
3800
|
*/
|
|
3799
|
-
|
|
3801
|
+
orWhereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3802
|
+
orWhereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3800
3803
|
/**
|
|
3801
|
-
* @description
|
|
3802
|
-
* @param returning - The columns to return from the query, only supported by postgres and cockroachdb - default is "*"
|
|
3803
|
-
* @returns raw driver response
|
|
3804
|
-
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
3804
|
+
* @description Adds a AND WHERE EXISTS condition to the query. By default uses the same table, you can use the `from` method to change the table.
|
|
3805
3805
|
*/
|
|
3806
|
-
|
|
3806
|
+
whereExists(cbOrQueryBuilder: (queryBuilder: QueryBuilder<T>) => void | QueryBuilder<T>): this;
|
|
3807
3807
|
/**
|
|
3808
|
-
* @description
|
|
3809
|
-
* @param data The data to insert or update
|
|
3810
|
-
* @param searchCriteria The criteria to search for existing records
|
|
3811
|
-
* @param options Upsert options including updateOnConflict and returning columns
|
|
3812
|
-
* @returns The upserted record
|
|
3808
|
+
* @description Adds a AND WHERE EXISTS condition to the query. By default uses the same table, you can use the `from` method to change the table.
|
|
3813
3809
|
*/
|
|
3814
|
-
|
|
3810
|
+
andWhereExists(cbOrQueryBuilder: (queryBuilder: QueryBuilder<T>) => void | QueryBuilder<T>): this;
|
|
3815
3811
|
/**
|
|
3816
|
-
* @description
|
|
3817
|
-
* @param conflictColumns The columns to check for conflicts
|
|
3818
|
-
* @param columnsToUpdate The columns to update on conflict
|
|
3819
|
-
* @param data Array of data objects to insert or update
|
|
3820
|
-
* @param options Upsert options including updateOnConflict and returning columns
|
|
3812
|
+
* @description Adds a OR WHERE EXISTS condition to the query. By default uses the same table, you can use the `from` method to change the table.
|
|
3821
3813
|
*/
|
|
3822
|
-
|
|
3814
|
+
orWhereExists(cbOrQueryBuilder: (queryBuilder: QueryBuilder<T>) => void | QueryBuilder<T>): this;
|
|
3823
3815
|
/**
|
|
3824
|
-
* @description
|
|
3816
|
+
* @description Adds a WHERE NOT EXISTS condition to the query. By default uses the same table, you can use the `from` method to change the table.
|
|
3825
3817
|
*/
|
|
3826
|
-
|
|
3818
|
+
whereNotExists(cbOrQueryBuilder: (queryBuilder: QueryBuilder<T>) => void | QueryBuilder<T>): this;
|
|
3827
3819
|
/**
|
|
3828
|
-
* @description
|
|
3829
|
-
* @returns the number of affected rows
|
|
3820
|
+
* @description Adds a WHERE NOT EXISTS condition to the query. By default uses the same table, you can use the `from` method to change the table.
|
|
3830
3821
|
*/
|
|
3831
|
-
|
|
3822
|
+
andWhereNotExists(cbOrQueryBuilder: (queryBuilder: QueryBuilder<T>) => void | QueryBuilder<T>): this;
|
|
3832
3823
|
/**
|
|
3833
|
-
* @description
|
|
3834
|
-
* @warning This operation does not trigger any hook
|
|
3824
|
+
* @description Adds a WHERE NOT EXISTS condition to the query. By default uses the same table, you can use the `from` method to change the table.
|
|
3835
3825
|
*/
|
|
3836
|
-
|
|
3826
|
+
orWhereNotExists(cbOrQueryBuilder: (queryBuilder: QueryBuilder<T>) => void | QueryBuilder<T>): this;
|
|
3837
3827
|
/**
|
|
3838
|
-
* @description
|
|
3839
|
-
* @returns the number of affected rows
|
|
3828
|
+
* @description Adds a raw WHERE condition to the query.
|
|
3840
3829
|
*/
|
|
3841
|
-
|
|
3830
|
+
whereRaw(query: string, queryParams?: any[]): this;
|
|
3842
3831
|
/**
|
|
3843
|
-
* @description
|
|
3844
|
-
* @default column - 'deletedAt'
|
|
3845
|
-
* @default value - The current date and time in UTC timezone in the format "YYYY-MM-DD HH:mm:ss"
|
|
3846
|
-
* @returns the number of affected rows
|
|
3832
|
+
* @description Adds a raw AND WHERE condition to the query.
|
|
3847
3833
|
*/
|
|
3848
|
-
|
|
3834
|
+
andWhereRaw(query: string, queryParams?: any[]): this;
|
|
3849
3835
|
/**
|
|
3850
|
-
* @description
|
|
3836
|
+
* @description Adds a raw OR WHERE condition to the query.
|
|
3851
3837
|
*/
|
|
3852
|
-
|
|
3838
|
+
orWhereRaw(query: string, queryParams?: any[]): this;
|
|
3853
3839
|
/**
|
|
3854
|
-
* @description
|
|
3840
|
+
* @description Adds a HAVING condition to the query.
|
|
3855
3841
|
*/
|
|
3856
|
-
|
|
3842
|
+
having<S extends string>(column: SelectableColumn$1<S>, value: any): this;
|
|
3843
|
+
having(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3857
3844
|
/**
|
|
3858
|
-
* @description
|
|
3845
|
+
* @description Adds an AND HAVING condition to the query.
|
|
3859
3846
|
*/
|
|
3860
|
-
|
|
3847
|
+
andHaving<S extends string>(column: SelectableColumn$1<S>, value: any): this;
|
|
3848
|
+
andHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3861
3849
|
/**
|
|
3862
|
-
* @description
|
|
3850
|
+
* @description Adds an OR HAVING condition to the query.
|
|
3863
3851
|
*/
|
|
3864
|
-
|
|
3852
|
+
orHaving<S extends string>(column: SelectableColumn$1<S>, value: any): this;
|
|
3853
|
+
orHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3865
3854
|
/**
|
|
3866
|
-
* @description
|
|
3855
|
+
* @description Adds a raw HAVING condition to the query.
|
|
3867
3856
|
*/
|
|
3868
|
-
|
|
3857
|
+
havingRaw(query: string): this;
|
|
3869
3858
|
/**
|
|
3870
|
-
* @description
|
|
3859
|
+
* @description Adds a raw OR HAVING condition to the query.
|
|
3871
3860
|
*/
|
|
3872
|
-
|
|
3861
|
+
andHavingRaw(query: string): this;
|
|
3873
3862
|
/**
|
|
3874
|
-
* @description
|
|
3863
|
+
* @description Adds a raw OR HAVING condition to the query.
|
|
3875
3864
|
*/
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3865
|
+
orHavingRaw(query: string): this;
|
|
3866
|
+
private buildSubQuery;
|
|
3867
|
+
private andWhereSubQuery;
|
|
3868
|
+
private orWhereSubQuery;
|
|
3869
|
+
private andWhereGroup;
|
|
3870
|
+
private orWhereGroup;
|
|
3871
|
+
}
|
|
3872
|
+
|
|
3873
|
+
type JsonParam = Record<string, unknown> | any[];
|
|
3874
|
+
declare class JsonQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends WhereQueryBuilder<T, S> {
|
|
3879
3875
|
/**
|
|
3880
|
-
* @description
|
|
3876
|
+
* @description Filters records matching exact JSON value.
|
|
3881
3877
|
*/
|
|
3882
|
-
|
|
3878
|
+
whereJson(column: ModelKey<T>, value: JsonParam): this;
|
|
3879
|
+
whereJson(column: string, value: JsonParam): this;
|
|
3883
3880
|
/**
|
|
3884
|
-
* @description
|
|
3881
|
+
* @description Filters records matching the given JSON value.
|
|
3882
|
+
* @mssql Partial JSON matching not supported - only exact matches work
|
|
3885
3883
|
*/
|
|
3886
|
-
|
|
3884
|
+
andWhereJson(column: ModelKey<T>, value: JsonParam): this;
|
|
3885
|
+
andWhereJson(column: string, value: JsonParam): this;
|
|
3887
3886
|
/**
|
|
3888
|
-
* @
|
|
3887
|
+
* @description Filters records matching the given JSON value.
|
|
3888
|
+
* @mssql Partial JSON matching not supported - only exact matches work
|
|
3889
3889
|
*/
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
private paginateWithCursorWithPerformance;
|
|
3890
|
+
orWhereJson(column: ModelKey<T>, value: JsonParam): this;
|
|
3891
|
+
orWhereJson(column: string, value: JsonParam): this;
|
|
3893
3892
|
/**
|
|
3894
|
-
* @description
|
|
3893
|
+
* @description Filters records where JSON column does NOT contain the given value.
|
|
3894
|
+
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3895
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3895
3896
|
*/
|
|
3896
|
-
|
|
3897
|
+
whereJsonNotContains(column: ModelKey<T>, value: JsonParam): this;
|
|
3898
|
+
whereJsonNotContains(column: string, value: JsonParam): this;
|
|
3897
3899
|
/**
|
|
3898
|
-
* @description
|
|
3899
|
-
* @
|
|
3900
|
+
* @description Filters records where JSON column does NOT contain the given value (AND).
|
|
3901
|
+
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3902
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3900
3903
|
*/
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
private updateWithPerformance;
|
|
3904
|
-
private insertWithPerformance;
|
|
3905
|
-
private insertManyWithPerformance;
|
|
3906
|
-
private softDeleteWithPerformance;
|
|
3907
|
-
private deleteWithPerformance;
|
|
3908
|
-
private truncateWithPerformance;
|
|
3904
|
+
andWhereJsonNotContains(column: ModelKey<T>, value: JsonParam): this;
|
|
3905
|
+
andWhereJsonNotContains(column: string, value: JsonParam): this;
|
|
3909
3906
|
/**
|
|
3910
|
-
* @description
|
|
3911
|
-
* @
|
|
3907
|
+
* @description Filters records where JSON column does NOT contain the given value (OR).
|
|
3908
|
+
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3909
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3912
3910
|
*/
|
|
3913
|
-
|
|
3911
|
+
orWhereJsonNotContains(column: ModelKey<T>, value: JsonParam): this;
|
|
3912
|
+
orWhereJsonNotContains(column: string, value: JsonParam): this;
|
|
3914
3913
|
/**
|
|
3915
|
-
* @description
|
|
3914
|
+
* @description Filters records where JSON column contains the given value.
|
|
3915
|
+
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3916
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3916
3917
|
*/
|
|
3917
|
-
|
|
3918
|
-
|
|
3918
|
+
whereJsonContains(column: ModelKey<T>, value: JsonParam): this;
|
|
3919
|
+
whereJsonContains(column: string, value: JsonParam): this;
|
|
3919
3920
|
/**
|
|
3920
|
-
* @description
|
|
3921
|
-
* @
|
|
3922
|
-
* @
|
|
3923
|
-
* @returns The result of the operation
|
|
3921
|
+
* @description Filters records where JSON column contains the given value (AND).
|
|
3922
|
+
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3923
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3924
3924
|
*/
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
/**
|
|
3929
|
-
* Allows to get queries without executing them
|
|
3930
|
-
*/
|
|
3931
|
-
declare class DryQueryBuilder<T extends Model = any, S extends Record<string, any> = Record<string, any>> extends QueryBuilder<T, S> {
|
|
3932
|
-
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3933
|
-
many(): this;
|
|
3925
|
+
andWhereJsonContains(column: ModelKey<T>, value: JsonParam): this;
|
|
3926
|
+
andWhereJsonContains(column: string, value: JsonParam): this;
|
|
3934
3927
|
/**
|
|
3935
|
-
* @description
|
|
3936
|
-
* @
|
|
3937
|
-
* @
|
|
3938
|
-
* @returns The query builder
|
|
3928
|
+
* @description Filters records where JSON column contains the given value (OR).
|
|
3929
|
+
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3930
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
3939
3931
|
*/
|
|
3940
|
-
|
|
3932
|
+
orWhereJsonContains(column: ModelKey<T>, value: JsonParam): this;
|
|
3933
|
+
orWhereJsonContains(column: string, value: JsonParam): this;
|
|
3941
3934
|
/**
|
|
3942
|
-
* @description
|
|
3943
|
-
* @param args The arguments to pass to the insert many method
|
|
3944
|
-
* @warning This method does not run model or column hooks
|
|
3945
|
-
* @returns The query builder
|
|
3935
|
+
* @description Filters records where JSON column does NOT match the given value.
|
|
3946
3936
|
*/
|
|
3947
|
-
|
|
3937
|
+
whereNotJson(column: ModelKey<T>, value: JsonParam): this;
|
|
3938
|
+
whereNotJson(column: string, value: JsonParam): this;
|
|
3948
3939
|
/**
|
|
3949
|
-
* @description
|
|
3950
|
-
* @param args The arguments to pass to the upsert method
|
|
3951
|
-
* @warning This method does not run model or column hooks
|
|
3952
|
-
* @returns The query builder
|
|
3940
|
+
* @description Filters records where JSON column does NOT match the given value (AND).
|
|
3953
3941
|
*/
|
|
3954
|
-
|
|
3955
|
-
|
|
3942
|
+
andWhereNotJson(column: ModelKey<T>, value: JsonParam): this;
|
|
3943
|
+
andWhereNotJson(column: string, value: JsonParam): this;
|
|
3956
3944
|
/**
|
|
3957
|
-
* @description
|
|
3958
|
-
* @param data The data to update
|
|
3959
|
-
* @warning This method does not run model or column hooks
|
|
3960
|
-
* @returns The query builder
|
|
3945
|
+
* @description Filters records where JSON column does NOT match the given value (OR).
|
|
3961
3946
|
*/
|
|
3962
|
-
|
|
3947
|
+
orWhereNotJson(column: ModelKey<T>, value: JsonParam): this;
|
|
3948
|
+
orWhereNotJson(column: string, value: JsonParam): this;
|
|
3963
3949
|
/**
|
|
3964
|
-
* @description
|
|
3965
|
-
* @warning This method does not run model or column hooks
|
|
3966
|
-
* @returns The query builder
|
|
3950
|
+
* @description Add a raw JSON filter expression.
|
|
3967
3951
|
*/
|
|
3968
|
-
|
|
3952
|
+
whereJsonRaw(raw: string, params?: any[]): this;
|
|
3969
3953
|
/**
|
|
3970
|
-
* @description
|
|
3971
|
-
* @warning This method does not run model or column hooks
|
|
3972
|
-
* @returns The query builder
|
|
3954
|
+
* @description Add a raw JSON filter expression (AND).
|
|
3973
3955
|
*/
|
|
3974
|
-
|
|
3956
|
+
andWhereJsonRaw(raw: string, params?: any[]): this;
|
|
3975
3957
|
/**
|
|
3976
|
-
* @description
|
|
3977
|
-
* @param options Soft delete options
|
|
3978
|
-
* @warning This method does not run model or column hooks
|
|
3979
|
-
* @returns The query builder
|
|
3958
|
+
* @description Add a raw JSON filter expression (OR).
|
|
3980
3959
|
*/
|
|
3981
|
-
|
|
3960
|
+
orWhereJsonRaw(raw: string, params?: any[]): this;
|
|
3982
3961
|
}
|
|
3983
3962
|
|
|
3984
3963
|
type PluckReturnType<T extends Model, K extends ModelKey<T>> = T[K] extends infer U ? U[] : never;
|
|
@@ -4168,9 +4147,7 @@ type UpsertOptionsRawBuilder = {
|
|
|
4168
4147
|
updateOnConflict?: boolean;
|
|
4169
4148
|
returning?: string[];
|
|
4170
4149
|
};
|
|
4171
|
-
type
|
|
4172
|
-
type DryModelQueryBuilderWithoutReadOperations<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<DryModelQueryBuilder<T, A, R>, "many" | "one" | "oneOrFail" | "paginate" | "paginateWithCursor" | "exists" | "pluck" | "upsert" | "upsertMany" | "increment" | "decrement" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "stream" | "chunk" | "paginate" | "paginateWithCursor" | "exists">;
|
|
4173
|
-
type WriteQueryParam$1 = string | number | boolean | Date | RawNode | object | null | undefined;
|
|
4150
|
+
type WriteQueryParam = string | number | boolean | Date | RawNode | object | null | undefined;
|
|
4174
4151
|
/**
|
|
4175
4152
|
* Simple paginated data type for raw query builders (without Model constraint)
|
|
4176
4153
|
*/
|
|
@@ -4323,14 +4300,14 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4323
4300
|
/**
|
|
4324
4301
|
* @description Inserts a new record into the database, it is not advised to use this method directly from the query builder if using a ModelQueryBuilder (`Model.query()`), use the `Model.insert` method instead.
|
|
4325
4302
|
*/
|
|
4326
|
-
insert(...args: Parameters<typeof this$1.model.insert<T>>): ReturnType<typeof this$1.model.insert
|
|
4303
|
+
insert(...args: Parameters<typeof this$1.model.insert<T>>): Promise<ReturnType<typeof this$1.model.insert>>;
|
|
4327
4304
|
/**
|
|
4328
4305
|
* @description Inserts multiple records into the database, it is not advised to use this method directly from the query builder if using a ModelQueryBuilder (`Model.query()`), use the `Model.insertMany` method instead.
|
|
4329
4306
|
*/
|
|
4330
|
-
insertMany(...args: Parameters<typeof this$1.model.insertMany<T>>): ReturnType<typeof this$1.model.insertMany
|
|
4331
|
-
update(data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions):
|
|
4332
|
-
softDelete(options?: SoftDeleteOptions<T>):
|
|
4333
|
-
delete(options?: DeleteOptions):
|
|
4307
|
+
insertMany(...args: Parameters<typeof this$1.model.insertMany<T>>): Promise<ReturnType<typeof this$1.model.insertMany>>;
|
|
4308
|
+
update(data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions): WriteOperation<number>;
|
|
4309
|
+
softDelete(options?: SoftDeleteOptions<T>): WriteOperation<number>;
|
|
4310
|
+
delete(options?: DeleteOptions): WriteOperation<number>;
|
|
4334
4311
|
getCount(column?: string, options?: {
|
|
4335
4312
|
ignoreHooks: boolean;
|
|
4336
4313
|
}): Promise<number>;
|
|
@@ -4367,6 +4344,9 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4367
4344
|
* ```
|
|
4368
4345
|
*/
|
|
4369
4346
|
select<const Columns extends readonly ModelSelectableInput<T>[]>(...columns: Columns): ModelQueryBuilder<T, ComposeBuildSelect<S, T, Columns extends readonly (string | readonly [string, string])[] ? Columns : readonly (string | readonly [string, string])[]>, R>;
|
|
4347
|
+
select<ValueType = any, Alias extends string = string>(cbOrQueryBuilder: ((subQuery: QueryBuilder<T>) => void) | QueryBuilder<any>, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4348
|
+
[K in Alias]: ValueType;
|
|
4349
|
+
}>, R>;
|
|
4370
4350
|
/**
|
|
4371
4351
|
* @description Adds a raw SELECT statement with type-safe return type.
|
|
4372
4352
|
* @description Use the generic parameter to specify the type of the selected columns.
|
|
@@ -4411,28 +4391,6 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4411
4391
|
selectFunc<F extends SqlFunction, Alias extends string>(sqlFunc: F, column: ModelKey<T> | "*" | (string & {}), alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4412
4392
|
[K in Alias]: SqlFunctionReturnType<F>;
|
|
4413
4393
|
}>, R>;
|
|
4414
|
-
/**
|
|
4415
|
-
* @description Selects a subquery with a typed alias
|
|
4416
|
-
* @param cbOrQueryBuilder A callback that receives a QueryBuilder or a QueryBuilder instance
|
|
4417
|
-
* @param alias The alias for the subquery result
|
|
4418
|
-
* @description Subquery must return a single column
|
|
4419
|
-
* @example
|
|
4420
|
-
* ```ts
|
|
4421
|
-
* const users = await User.query()
|
|
4422
|
-
* .select("id")
|
|
4423
|
-
* .selectSubQuery<number, "postCount">((subQuery) => {
|
|
4424
|
-
* subQuery
|
|
4425
|
-
* .select("COUNT(*)")
|
|
4426
|
-
* .from("posts")
|
|
4427
|
-
* .whereColumn("posts.user_id", "users.id");
|
|
4428
|
-
* }, "postCount")
|
|
4429
|
-
* .many();
|
|
4430
|
-
* // users[0].postCount is typed as number
|
|
4431
|
-
* ```
|
|
4432
|
-
*/
|
|
4433
|
-
selectSubQuery<ValueType = any, Alias extends string = string>(cbOrQueryBuilder: ((subQuery: QueryBuilder<T>) => void) | QueryBuilder<any>, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4434
|
-
[K in Alias]: ValueType;
|
|
4435
|
-
}>, R>;
|
|
4436
4394
|
/**
|
|
4437
4395
|
* @description Clears the SELECT clause and resets to default model type
|
|
4438
4396
|
* @example
|
|
@@ -4718,53 +4676,6 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4718
4676
|
private truncateWithPerformance;
|
|
4719
4677
|
}
|
|
4720
4678
|
|
|
4721
|
-
/**
|
|
4722
|
-
* Allows to get model queries without executing them
|
|
4723
|
-
*/
|
|
4724
|
-
declare class DryModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends ModelQueryBuilder<T, A, R> {
|
|
4725
|
-
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
4726
|
-
many(): this;
|
|
4727
|
-
/**
|
|
4728
|
-
* @description Builds the insert query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4729
|
-
* @param args The arguments to pass to the insert method
|
|
4730
|
-
* @warning This method does not run model or column hooks
|
|
4731
|
-
* @returns The query builder
|
|
4732
|
-
*/
|
|
4733
|
-
insert(...args: Parameters<typeof this$1.model.insert<T>>): this;
|
|
4734
|
-
/**
|
|
4735
|
-
* @description Builds the insert many query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4736
|
-
* @param args The arguments to pass to the insert many method
|
|
4737
|
-
* @warning This method does not run model or column hooks
|
|
4738
|
-
* @returns The query builder
|
|
4739
|
-
*/
|
|
4740
|
-
insertMany(...args: Parameters<typeof this$1.model.insertMany<T>>): this;
|
|
4741
|
-
/**
|
|
4742
|
-
* @description Builds the update query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4743
|
-
* @param data The data to update
|
|
4744
|
-
* @warning This method does not run model or column hooks
|
|
4745
|
-
* @returns The query builder
|
|
4746
|
-
*/
|
|
4747
|
-
update(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["update"]>): this;
|
|
4748
|
-
/**
|
|
4749
|
-
* @description Builds the delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4750
|
-
* @param options Delete options
|
|
4751
|
-
* @returns The query builder
|
|
4752
|
-
*/
|
|
4753
|
-
delete(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["delete"]>): this;
|
|
4754
|
-
/**
|
|
4755
|
-
* @description Builds the truncate query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4756
|
-
* @returns The query builder
|
|
4757
|
-
*/
|
|
4758
|
-
truncate(): this;
|
|
4759
|
-
/**
|
|
4760
|
-
* @description Builds the soft delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4761
|
-
* @param options Soft delete options
|
|
4762
|
-
* @warning This method does not run model or column hooks
|
|
4763
|
-
* @returns The query builder
|
|
4764
|
-
*/
|
|
4765
|
-
softDelete(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["softDelete"]>): this;
|
|
4766
|
-
}
|
|
4767
|
-
|
|
4768
4679
|
declare class ModelManager<T extends Model> {
|
|
4769
4680
|
protected sqlDataSource: SqlDataSource;
|
|
4770
4681
|
protected sqlType: SqlDataSourceType;
|
|
@@ -4802,13 +4713,15 @@ declare class ModelManager<T extends Model> {
|
|
|
4802
4713
|
findOneByPrimaryKey(value: string | number, returning?: ModelKey<T>[]): Promise<ModelWithoutRelations<T> | null>;
|
|
4803
4714
|
/**
|
|
4804
4715
|
* @description Creates a new record in the database
|
|
4716
|
+
* @returns WriteOperation that executes when awaited
|
|
4805
4717
|
*/
|
|
4806
|
-
insert(model: Partial<T>, options?: InsertOptions<T>):
|
|
4718
|
+
insert(model: Partial<T>, options?: InsertOptions<T>): WriteOperation<ModelWithoutRelations<T>>;
|
|
4807
4719
|
/**
|
|
4808
4720
|
* @description Creates multiple records in the database
|
|
4721
|
+
* @returns WriteOperation that executes when awaited
|
|
4809
4722
|
*/
|
|
4810
|
-
insertMany(models: Partial<T>[], options?: InsertOptions<T>):
|
|
4811
|
-
upsertMany(conflictColumns: string[], columnsToUpdate: string[], data: ModelWithoutRelations<T>[], options?: UpsertOptions<T>):
|
|
4723
|
+
insertMany(models: Partial<T>[], options?: InsertOptions<T>): WriteOperation<ModelWithoutRelations<T>[]>;
|
|
4724
|
+
upsertMany(conflictColumns: string[], columnsToUpdate: string[], data: ModelWithoutRelations<T>[], options?: UpsertOptions<T>): WriteOperation<ModelWithoutRelations<T>[]>;
|
|
4812
4725
|
/**
|
|
4813
4726
|
* @description Executes a MERGE statement for MSSQL upsert operations
|
|
4814
4727
|
*/
|
|
@@ -4830,11 +4743,6 @@ declare class ModelManager<T extends Model> {
|
|
|
4830
4743
|
* @description Returns a query builder instance
|
|
4831
4744
|
*/
|
|
4832
4745
|
query(): Omit<ModelQueryBuilder<T>, "insert" | "insertMany">;
|
|
4833
|
-
/**
|
|
4834
|
-
* @description Returns a dry query builder instance
|
|
4835
|
-
* @description The dry query builder instance will not execute the query, it will return the query statement
|
|
4836
|
-
*/
|
|
4837
|
-
dryQuery(): Omit<DryModelQueryBuilder<T>, "insert" | "insertMany">;
|
|
4838
4746
|
/**
|
|
4839
4747
|
* @description Mysql does not return the inserted model, so we need to get the inserted model from the database
|
|
4840
4748
|
*/
|
|
@@ -5214,10 +5122,6 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
5214
5122
|
* @param table The table name to query from
|
|
5215
5123
|
*/
|
|
5216
5124
|
query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
|
|
5217
|
-
/**
|
|
5218
|
-
* @description Returns a DryQueryBuilder instance that returns the query statement without executing
|
|
5219
|
-
*/
|
|
5220
|
-
dryQuery<S extends string>(table: TableFormat<S>, options?: RawModelOptions): DryQueryBuilderWithoutReadOperations;
|
|
5221
5125
|
/**
|
|
5222
5126
|
* @description Returns a SchemaBuilder instance for DDL operations
|
|
5223
5127
|
* @description The builder will execute queries when awaited or when .execute() is called
|
|
@@ -6001,11 +5905,6 @@ declare abstract class Model<T extends Model<T> = any> extends Entity {
|
|
|
6001
5905
|
* @description Gives a query sqlInstance for the given model
|
|
6002
5906
|
*/
|
|
6003
5907
|
static query<T extends Model>(this: new () => T | typeof Model, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): ModelQueryBuilder<T>;
|
|
6004
|
-
/**
|
|
6005
|
-
* @description Returns a dry query builder instance
|
|
6006
|
-
* @description The dry query builder instance will not execute the query
|
|
6007
|
-
*/
|
|
6008
|
-
static dryQuery<T extends Model>(this: new () => T | typeof Model, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): DryModelQueryBuilderWithoutReadOperations<T>;
|
|
6009
5908
|
/**
|
|
6010
5909
|
* @description Finds the first record in the database
|
|
6011
5910
|
* @deprecated Used only for debugging purposes, use `.findOne` or `.query` instead
|
|
@@ -6048,7 +5947,7 @@ declare abstract class Model<T extends Model<T> = any> extends Entity {
|
|
|
6048
5947
|
* @sqlite If no Primary Key is present in the model definition, the model will be returned
|
|
6049
5948
|
* @sqlite Returning Not supported and won't have effect
|
|
6050
5949
|
*/
|
|
6051
|
-
static insert<T extends Model>(this: new () => T | typeof Model, modelData: Partial<ModelWithoutRelations<T>>, options?: BaseModelMethodOptions & InsertOptions<T>):
|
|
5950
|
+
static insert<T extends Model>(this: new () => T | typeof Model, modelData: Partial<ModelWithoutRelations<T>>, options?: BaseModelMethodOptions & InsertOptions<T>): WriteOperation<ModelQueryResult<T>>;
|
|
6052
5951
|
/**
|
|
6053
5952
|
* @description Saves multiple records to the database
|
|
6054
5953
|
* @warning If not using postgres and the model has no primary key, the models will be saved, but it won't be possible to retrieve them so at that point they will be returned as an empty array
|
|
@@ -6057,7 +5956,7 @@ declare abstract class Model<T extends Model<T> = any> extends Entity {
|
|
|
6057
5956
|
* @sqlite Returning Not supported and won't have effect
|
|
6058
5957
|
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
6059
5958
|
*/
|
|
6060
|
-
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>):
|
|
5959
|
+
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>): WriteOperation<ModelQueryResult<T>[]>;
|
|
6061
5960
|
/**
|
|
6062
5961
|
* @description Syncs in the through table the given models for the given relation
|
|
6063
5962
|
* @param relation The many to many relation to sync, this is not type safe since many to many relations defined at a decorator level
|
|
@@ -6614,8 +6513,8 @@ declare function getUniques(target: typeof Model): UniqueType[];
|
|
|
6614
6513
|
type FactoryReturnType<T extends number, O extends Model> = T extends 1 ? O : O[];
|
|
6615
6514
|
|
|
6616
6515
|
declare class ModelFactory<M extends Model> {
|
|
6617
|
-
typeofModel
|
|
6618
|
-
modelData
|
|
6516
|
+
private typeofModel;
|
|
6517
|
+
private modelData;
|
|
6619
6518
|
/**
|
|
6620
6519
|
* @description Constructor for the model factory
|
|
6621
6520
|
*/
|
|
@@ -7751,4 +7650,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
7751
7650
|
$id?: string;
|
|
7752
7651
|
}>;
|
|
7753
7652
|
|
|
7754
|
-
export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyConstructor, type AsymmetricEncryptionOptions, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type BigIntFields, BigIntMixin, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type Constructor, type DataSourceInput, type DataSourceType, type DateColumnOptions,
|
|
7653
|
+
export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyConstructor, type AsymmetricEncryptionOptions, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type BigIntFields, BigIntMixin, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type Constructor, type DataSourceInput, type DataSourceType, type DateColumnOptions, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type GetColumnType, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IncrementFields, IncrementMixin, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, type MigrationConfig, type MigrationConfigBase, type MixinColumns, MixinFactory, Model, type ModelDataProperties, type ModelInstanceMethods, type ModelInstanceType, ModelQueryBuilder, type ModelQueryResult, type ModelSelectTuple, type ModelSelectableInput, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type ReplicationType, Schema, SchemaBuilder, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, type TimestampFields, TimestampMixin, Transaction, type TransactionExecutionOptions, type UlidFields, UlidMixin, type UniqueType, type UseCacheReturnType, type UseConnectionInput, type UuidFields, UuidMixin, WriteOperation, belongsTo, bigIntMixin, column, createMixin, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, incrementMixin, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, timestampMixin, ulidMixin, unique, uuidMixin, view, withPerformance };
|