hysteria-orm 10.5.3 → 10.5.5

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