hysteria-orm 10.4.9 → 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +20 -20
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +15 -15
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2007 -1643
- package/lib/index.d.ts +2007 -1643
- package/lib/index.js +15 -15
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ import { PoolConfig, PoolClient, QueryResult as QueryResult$1 } from 'pg';
|
|
|
10
10
|
import * as mysql2_promise from 'mysql2/promise';
|
|
11
11
|
import { PoolOptions, PoolConnection, QueryResult } from 'mysql2/promise';
|
|
12
12
|
import { RedisOptions, Redis } from 'ioredis';
|
|
13
|
-
import { PassThrough } from 'node:stream';
|
|
14
|
-
import { FormatOptionsWithLanguage } from 'sql-formatter';
|
|
15
13
|
import express from 'express';
|
|
14
|
+
import { FormatOptionsWithLanguage } from 'sql-formatter';
|
|
15
|
+
import { PassThrough } from 'node:stream';
|
|
16
16
|
|
|
17
17
|
type CaseConvention = "camel" | "snake" | "preserve" | RegExp | ((column: string) => string);
|
|
18
18
|
|
|
@@ -765,6 +765,22 @@ type ForeignKeyOptions = CommonConstraintOptions & {
|
|
|
765
765
|
type CreateTableContext = "alter_table" | "create_table";
|
|
766
766
|
type CommonPostgresExtensions = "postgis" | "uuid-ossp" | "hstore" | "pg_trgm" | "btree_gin" | "btree_gist" | "citext" | "pgcrypto" | "tablefunc" | "unaccent" | "pg_stat_statements" | "ltree" | "cube" | "earthdistance" | "fuzzystrmatch" | "intarray" | "isn" | "lo" | "pg_buffercache" | "pgrowlocks" | "pgstattuple" | "pg_freespacemap" | "postgres_fdw" | "seg" | "tsm_system_rows" | "tsm_system_time" | "plpgsql" | "plperl" | "plpython3u" | "pltcl" | "adminpack" | "amcheck" | "autoinc" | "bloom" | "dict_int" | "dict_xsyn" | "file_fdw" | "insert_username" | "intagg" | "moddatetime" | "old_snapshot" | "pageinspect" | "pg_prewarm" | "pg_surgery" | "pg_visibility" | "pgaudit" | "pglogical" | "pgrouting" | "postgis_topology" | "postgis_raster" | "postgis_sfcgal" | "postgis_tiger_geocoder" | "address_standardizer" | "address_standardizer_data_us" | "refint" | "sslinfo" | "tcn" | "timescaledb" | "vector" | "xml2";
|
|
767
767
|
|
|
768
|
+
type OpenApiModelType = {
|
|
769
|
+
type: "object";
|
|
770
|
+
properties: Record<string, OpenApiModelPropertyType>;
|
|
771
|
+
required?: string[];
|
|
772
|
+
};
|
|
773
|
+
type OpenApiModelPropertyType = {
|
|
774
|
+
type: string;
|
|
775
|
+
items?: OpenApiModelType;
|
|
776
|
+
enum?: string[];
|
|
777
|
+
format?: string;
|
|
778
|
+
description?: string;
|
|
779
|
+
example?: any;
|
|
780
|
+
default?: any;
|
|
781
|
+
nullable?: boolean;
|
|
782
|
+
};
|
|
783
|
+
|
|
768
784
|
/**
|
|
769
785
|
* @description AdminJS plugin types - All AdminJS imports are done at runtime via dynamic import()
|
|
770
786
|
* @description This ensures the plugin is completely optional
|
|
@@ -1110,6 +1126,80 @@ interface CacheAdapter {
|
|
|
1110
1126
|
type CacheKeys = Record<string, (...args: any[]) => Promise<any> | any>;
|
|
1111
1127
|
type UseCacheReturnType<C extends CacheKeys, K extends keyof C> = K extends never ? never : Awaited<ReturnType<C[K]>>;
|
|
1112
1128
|
|
|
1129
|
+
declare abstract class QueryNode {
|
|
1130
|
+
/**
|
|
1131
|
+
* Sql keyword to use for the query e.g. "select"
|
|
1132
|
+
*/
|
|
1133
|
+
keyword: string;
|
|
1134
|
+
/**
|
|
1135
|
+
* The current parameter index to use for the query
|
|
1136
|
+
*/
|
|
1137
|
+
currParamIndex: number;
|
|
1138
|
+
/**
|
|
1139
|
+
* Whether the query node is a raw value and should not be parsed by the interpreter
|
|
1140
|
+
*/
|
|
1141
|
+
isRawValue: boolean;
|
|
1142
|
+
/**
|
|
1143
|
+
* Whether the keyword can be seen multiple times in the query, e.g. "join" can be seen multiple times in a query
|
|
1144
|
+
*/
|
|
1145
|
+
abstract canKeywordBeSeenMultipleTimes: boolean;
|
|
1146
|
+
/**
|
|
1147
|
+
* The string to use to chain the keyword with the next keyword
|
|
1148
|
+
*/
|
|
1149
|
+
abstract chainsWith: string;
|
|
1150
|
+
/**
|
|
1151
|
+
* The folder to use for the query node, e.g. "select" is in the "select" folder inside the interpreter map
|
|
1152
|
+
*/
|
|
1153
|
+
abstract folder: string;
|
|
1154
|
+
/**
|
|
1155
|
+
* The file to use for the query node, e.g. "select" is in the "select" file inside the interpreter map
|
|
1156
|
+
*/
|
|
1157
|
+
abstract file: string;
|
|
1158
|
+
constructor(keyword: string, isRawValue?: boolean);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
declare class RawNode extends QueryNode {
|
|
1162
|
+
rawValue: string;
|
|
1163
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1164
|
+
chainsWith: string;
|
|
1165
|
+
currParamIndex: number;
|
|
1166
|
+
isRawValue: boolean;
|
|
1167
|
+
folder: string;
|
|
1168
|
+
file: string;
|
|
1169
|
+
constructor(value: string);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
type ConstraintType = "primary_key" | "foreign_key" | "unique" | "not_null" | "null" | "default";
|
|
1173
|
+
declare class ConstraintNode extends QueryNode {
|
|
1174
|
+
constraintType: ConstraintType;
|
|
1175
|
+
columns?: (string | (() => string))[];
|
|
1176
|
+
references?: {
|
|
1177
|
+
table: string;
|
|
1178
|
+
columns: (string | (() => string))[];
|
|
1179
|
+
};
|
|
1180
|
+
constraintName?: string;
|
|
1181
|
+
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1182
|
+
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1183
|
+
defaultValue?: string | RawNode | undefined;
|
|
1184
|
+
checkExpression?: string;
|
|
1185
|
+
chainsWith: string;
|
|
1186
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1187
|
+
folder: string;
|
|
1188
|
+
file: string;
|
|
1189
|
+
constructor(constraintType: ConstraintType, args?: {
|
|
1190
|
+
columns?: string[];
|
|
1191
|
+
references?: {
|
|
1192
|
+
table: string;
|
|
1193
|
+
columns: string[];
|
|
1194
|
+
};
|
|
1195
|
+
constraintName?: string;
|
|
1196
|
+
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1197
|
+
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1198
|
+
defaultValue?: string | RawNode | undefined;
|
|
1199
|
+
checkExpression?: string;
|
|
1200
|
+
}, isRawValue?: boolean);
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1113
1203
|
type Sqlite3ConnectionOptions = {
|
|
1114
1204
|
mode: number;
|
|
1115
1205
|
};
|
|
@@ -1327,60 +1417,6 @@ type RawQueryOptions = {
|
|
|
1327
1417
|
replicationMode?: ReplicationType;
|
|
1328
1418
|
};
|
|
1329
1419
|
|
|
1330
|
-
type AstParserType = {
|
|
1331
|
-
sql: string;
|
|
1332
|
-
bindings: any[];
|
|
1333
|
-
};
|
|
1334
|
-
|
|
1335
|
-
declare abstract class QueryNode {
|
|
1336
|
-
/**
|
|
1337
|
-
* Sql keyword to use for the query e.g. "select"
|
|
1338
|
-
*/
|
|
1339
|
-
keyword: string;
|
|
1340
|
-
/**
|
|
1341
|
-
* The current parameter index to use for the query
|
|
1342
|
-
*/
|
|
1343
|
-
currParamIndex: number;
|
|
1344
|
-
/**
|
|
1345
|
-
* Whether the query node is a raw value and should not be parsed by the interpreter
|
|
1346
|
-
*/
|
|
1347
|
-
isRawValue: boolean;
|
|
1348
|
-
/**
|
|
1349
|
-
* Whether the keyword can be seen multiple times in the query, e.g. "join" can be seen multiple times in a query
|
|
1350
|
-
*/
|
|
1351
|
-
abstract canKeywordBeSeenMultipleTimes: boolean;
|
|
1352
|
-
/**
|
|
1353
|
-
* The string to use to chain the keyword with the next keyword
|
|
1354
|
-
*/
|
|
1355
|
-
abstract chainsWith: string;
|
|
1356
|
-
/**
|
|
1357
|
-
* The folder to use for the query node, e.g. "select" is in the "select" folder inside the interpreter map
|
|
1358
|
-
*/
|
|
1359
|
-
abstract folder: string;
|
|
1360
|
-
/**
|
|
1361
|
-
* The file to use for the query node, e.g. "select" is in the "select" file inside the interpreter map
|
|
1362
|
-
*/
|
|
1363
|
-
abstract file: string;
|
|
1364
|
-
constructor(keyword: string, isRawValue?: boolean);
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
declare class AstParser {
|
|
1368
|
-
private readonly dbType;
|
|
1369
|
-
private readonly model;
|
|
1370
|
-
constructor(model: typeof Model, dbType: SqlDataSourceType);
|
|
1371
|
-
parse(nodes: (QueryNode | null)[], startBindingIndex?: number, isNestedCondition?: boolean): AstParserType;
|
|
1372
|
-
/**
|
|
1373
|
-
* Map the database type to a common type if shares the same driver (e.g. mysql and mariadb)
|
|
1374
|
-
*/
|
|
1375
|
-
private mapCommonDbType;
|
|
1376
|
-
/**
|
|
1377
|
-
* @description Generates MSSQL table hints from lock node
|
|
1378
|
-
* MSSQL uses WITH (UPDLOCK), WITH (HOLDLOCK), etc. as table hints
|
|
1379
|
-
* READPAST is the MSSQL equivalent of SKIP LOCKED
|
|
1380
|
-
*/
|
|
1381
|
-
private getMssqlTableHints;
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
1420
|
declare class ColumnTypeNode extends QueryNode {
|
|
1385
1421
|
column: string | (() => string);
|
|
1386
1422
|
dataType: string;
|
|
@@ -1406,48 +1442,6 @@ declare class ColumnTypeNode extends QueryNode {
|
|
|
1406
1442
|
});
|
|
1407
1443
|
}
|
|
1408
1444
|
|
|
1409
|
-
declare class RawNode extends QueryNode {
|
|
1410
|
-
rawValue: string;
|
|
1411
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1412
|
-
chainsWith: string;
|
|
1413
|
-
currParamIndex: number;
|
|
1414
|
-
isRawValue: boolean;
|
|
1415
|
-
folder: string;
|
|
1416
|
-
file: string;
|
|
1417
|
-
constructor(value: string);
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
type ConstraintType = "primary_key" | "foreign_key" | "unique" | "not_null" | "null" | "default";
|
|
1421
|
-
declare class ConstraintNode extends QueryNode {
|
|
1422
|
-
constraintType: ConstraintType;
|
|
1423
|
-
columns?: (string | (() => string))[];
|
|
1424
|
-
references?: {
|
|
1425
|
-
table: string;
|
|
1426
|
-
columns: (string | (() => string))[];
|
|
1427
|
-
};
|
|
1428
|
-
constraintName?: string;
|
|
1429
|
-
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1430
|
-
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1431
|
-
defaultValue?: string | RawNode | undefined;
|
|
1432
|
-
checkExpression?: string;
|
|
1433
|
-
chainsWith: string;
|
|
1434
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1435
|
-
folder: string;
|
|
1436
|
-
file: string;
|
|
1437
|
-
constructor(constraintType: ConstraintType, args?: {
|
|
1438
|
-
columns?: string[];
|
|
1439
|
-
references?: {
|
|
1440
|
-
table: string;
|
|
1441
|
-
columns: string[];
|
|
1442
|
-
};
|
|
1443
|
-
constraintName?: string;
|
|
1444
|
-
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1445
|
-
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1446
|
-
defaultValue?: string | RawNode | undefined;
|
|
1447
|
-
checkExpression?: string;
|
|
1448
|
-
}, isRawValue?: boolean);
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
1445
|
type LockType = "for_update" | "for_share" | "for_no_key_update" | "for_key_share";
|
|
1452
1446
|
declare class LockNode extends QueryNode {
|
|
1453
1447
|
lockType: LockType;
|
|
@@ -1481,109 +1475,10 @@ declare class WithNode extends QueryNode {
|
|
|
1481
1475
|
constructor(clause: string, alias: string, body: QueryNode | QueryNode[]);
|
|
1482
1476
|
}
|
|
1483
1477
|
|
|
1484
|
-
declare class
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
folder: string;
|
|
1489
|
-
file: string;
|
|
1490
|
-
alias?: string;
|
|
1491
|
-
constructor(table: string | QueryNode | QueryNode[], alias?: string);
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
declare class DeleteNode extends QueryNode {
|
|
1495
|
-
fromNode: FromNode;
|
|
1496
|
-
chainsWith: string;
|
|
1497
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1498
|
-
folder: string;
|
|
1499
|
-
file: string;
|
|
1500
|
-
constructor(fromNode: FromNode, isRawValue?: boolean);
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
declare class InsertNode extends QueryNode {
|
|
1504
|
-
fromNode: FromNode;
|
|
1505
|
-
records: Record<string, any>[];
|
|
1506
|
-
returning?: string[];
|
|
1507
|
-
disableReturning: boolean;
|
|
1508
|
-
chainsWith: string;
|
|
1509
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1510
|
-
folder: string;
|
|
1511
|
-
file: string;
|
|
1512
|
-
constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
declare class OnDuplicateNode extends QueryNode {
|
|
1516
|
-
table: string;
|
|
1517
|
-
conflictColumns: string[];
|
|
1518
|
-
columnsToUpdate: string[];
|
|
1519
|
-
returning?: string[];
|
|
1520
|
-
mode: "update" | "ignore";
|
|
1521
|
-
chainsWith: string;
|
|
1522
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1523
|
-
folder: string;
|
|
1524
|
-
file: string;
|
|
1525
|
-
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
declare class TruncateNode extends QueryNode {
|
|
1529
|
-
fromNode: FromNode | string;
|
|
1530
|
-
chainsWith: string;
|
|
1531
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1532
|
-
folder: string;
|
|
1533
|
-
file: string;
|
|
1534
|
-
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
declare class UpdateNode extends QueryNode {
|
|
1538
|
-
fromNode: FromNode;
|
|
1539
|
-
columns: string[];
|
|
1540
|
-
values: (any | RawNode)[];
|
|
1541
|
-
chainsWith: string;
|
|
1542
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1543
|
-
folder: string;
|
|
1544
|
-
file: string;
|
|
1545
|
-
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
declare class InterpreterUtils {
|
|
1549
|
-
private readonly model;
|
|
1550
|
-
private readonly modelColumnsMap;
|
|
1551
|
-
constructor(model: typeof Model);
|
|
1552
|
-
formatStringColumn(dbType: SqlDataSourceType, column: string): string;
|
|
1553
|
-
/**
|
|
1554
|
-
* @description Formats the table name for the database type, idempotent for quoting
|
|
1555
|
-
*/
|
|
1556
|
-
formatStringTable(dbType: SqlDataSourceType, table: string): string;
|
|
1557
|
-
prepareColumns(columns: string[], values: any[], mode?: "insert" | "update"): Promise<{
|
|
1558
|
-
columns: string[];
|
|
1559
|
-
values: any[];
|
|
1560
|
-
}>;
|
|
1561
|
-
/**
|
|
1562
|
-
* @description Formats the from node for write operations removing the "from" keyword
|
|
1563
|
-
*/
|
|
1564
|
-
getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
type OpenApiModelType = {
|
|
1568
|
-
type: "object";
|
|
1569
|
-
properties: Record<string, OpenApiModelPropertyType>;
|
|
1570
|
-
required?: string[];
|
|
1571
|
-
};
|
|
1572
|
-
type OpenApiModelPropertyType = {
|
|
1573
|
-
type: string;
|
|
1574
|
-
items?: OpenApiModelType;
|
|
1575
|
-
enum?: string[];
|
|
1576
|
-
format?: string;
|
|
1577
|
-
description?: string;
|
|
1578
|
-
example?: any;
|
|
1579
|
-
default?: any;
|
|
1580
|
-
nullable?: boolean;
|
|
1581
|
-
};
|
|
1582
|
-
|
|
1583
|
-
declare abstract class BaseBuilder {
|
|
1584
|
-
protected nodes: QueryNode[];
|
|
1585
|
-
constructor(nodes: QueryNode[]);
|
|
1586
|
-
getNodes(): QueryNode[];
|
|
1478
|
+
declare abstract class BaseBuilder {
|
|
1479
|
+
protected nodes: QueryNode[];
|
|
1480
|
+
constructor(nodes: QueryNode[]);
|
|
1481
|
+
getNodes(): QueryNode[];
|
|
1587
1482
|
}
|
|
1588
1483
|
|
|
1589
1484
|
declare class ConstraintBuilder extends BaseBuilder {
|
|
@@ -2165,71 +2060,147 @@ declare class Schema {
|
|
|
2165
2060
|
private generateAstInstance;
|
|
2166
2061
|
}
|
|
2167
2062
|
|
|
2168
|
-
type
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
type SoftDeleteOptions<T> = {
|
|
2172
|
-
column?: MongoCollectionKey<T>;
|
|
2173
|
-
value?: string | number | boolean;
|
|
2174
|
-
ignoreBeforeUpdateHook?: boolean;
|
|
2063
|
+
type AstParserType = {
|
|
2064
|
+
sql: string;
|
|
2065
|
+
bindings: any[];
|
|
2175
2066
|
};
|
|
2176
2067
|
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
many(): this;
|
|
2183
|
-
/**
|
|
2184
|
-
* @description Builds the insert query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
2185
|
-
* @param args The arguments to pass to the insert method
|
|
2186
|
-
* @warning This method does not run model or column hooks
|
|
2187
|
-
* @returns The query builder
|
|
2188
|
-
*/
|
|
2189
|
-
insert(...args: Parameters<typeof QueryBuilder.prototype.insert>): this;
|
|
2190
|
-
/**
|
|
2191
|
-
* @description Builds the insert many query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
2192
|
-
* @param args The arguments to pass to the insert many method
|
|
2193
|
-
* @warning This method does not run model or column hooks
|
|
2194
|
-
* @returns The query builder
|
|
2195
|
-
*/
|
|
2196
|
-
insertMany(...args: Parameters<typeof QueryBuilder.prototype.insertMany>): this;
|
|
2197
|
-
/**
|
|
2198
|
-
* @description Builds the upsert query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
2199
|
-
* @param args The arguments to pass to the upsert method
|
|
2200
|
-
* @warning This method does not run model or column hooks
|
|
2201
|
-
* @returns The query builder
|
|
2202
|
-
*/
|
|
2203
|
-
upsert(...args: Parameters<typeof QueryBuilder.prototype.upsert>): this;
|
|
2204
|
-
upsertMany(...args: Parameters<typeof QueryBuilder.prototype.upsertMany>): this;
|
|
2068
|
+
declare class AstParser {
|
|
2069
|
+
private readonly dbType;
|
|
2070
|
+
private readonly model;
|
|
2071
|
+
constructor(model: typeof Model, dbType: SqlDataSourceType);
|
|
2072
|
+
parse(nodes: (QueryNode | null)[], startBindingIndex?: number, isNestedCondition?: boolean): AstParserType;
|
|
2205
2073
|
/**
|
|
2206
|
-
*
|
|
2207
|
-
* @param data The data to update
|
|
2208
|
-
* @warning This method does not run model or column hooks
|
|
2209
|
-
* @returns The query builder
|
|
2074
|
+
* Map the database type to a common type if shares the same driver (e.g. mysql and mariadb)
|
|
2210
2075
|
*/
|
|
2211
|
-
|
|
2076
|
+
private mapCommonDbType;
|
|
2212
2077
|
/**
|
|
2213
|
-
* @description
|
|
2214
|
-
*
|
|
2215
|
-
*
|
|
2078
|
+
* @description Generates MSSQL table hints from lock node
|
|
2079
|
+
* MSSQL uses WITH (UPDLOCK), WITH (HOLDLOCK), etc. as table hints
|
|
2080
|
+
* READPAST is the MSSQL equivalent of SKIP LOCKED
|
|
2216
2081
|
*/
|
|
2217
|
-
|
|
2082
|
+
private getMssqlTableHints;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
declare class FromNode extends QueryNode {
|
|
2086
|
+
table: string | QueryNode | QueryNode[];
|
|
2087
|
+
chainsWith: string;
|
|
2088
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2089
|
+
folder: string;
|
|
2090
|
+
file: string;
|
|
2091
|
+
alias?: string;
|
|
2092
|
+
constructor(table: string | QueryNode | QueryNode[], alias?: string);
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
declare class InterpreterUtils {
|
|
2096
|
+
private readonly model;
|
|
2097
|
+
private readonly modelColumnsMap;
|
|
2098
|
+
constructor(model: typeof Model);
|
|
2099
|
+
formatStringColumn(dbType: SqlDataSourceType, column: string): string;
|
|
2218
2100
|
/**
|
|
2219
|
-
* @description
|
|
2220
|
-
* @warning This method does not run model or column hooks
|
|
2221
|
-
* @returns The query builder
|
|
2101
|
+
* @description Formats the table name for the database type, idempotent for quoting
|
|
2222
2102
|
*/
|
|
2223
|
-
|
|
2103
|
+
formatStringTable(dbType: SqlDataSourceType, table: string): string;
|
|
2104
|
+
prepareColumns(columns: string[], values: any[], mode?: "insert" | "update"): Promise<{
|
|
2105
|
+
columns: string[];
|
|
2106
|
+
values: any[];
|
|
2107
|
+
}>;
|
|
2224
2108
|
/**
|
|
2225
|
-
* @description
|
|
2226
|
-
* @param options Soft delete options
|
|
2227
|
-
* @warning This method does not run model or column hooks
|
|
2228
|
-
* @returns The query builder
|
|
2109
|
+
* @description Formats the from node for write operations removing the "from" keyword
|
|
2229
2110
|
*/
|
|
2230
|
-
|
|
2111
|
+
getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
type DeleteOptions = {
|
|
2115
|
+
ignoreBeforeDeleteHook?: boolean;
|
|
2116
|
+
};
|
|
2117
|
+
type SoftDeleteOptions<T> = {
|
|
2118
|
+
column?: MongoCollectionKey<T>;
|
|
2119
|
+
value?: string | number | boolean;
|
|
2120
|
+
ignoreBeforeUpdateHook?: boolean;
|
|
2121
|
+
};
|
|
2122
|
+
|
|
2123
|
+
declare class DeleteNode extends QueryNode {
|
|
2124
|
+
fromNode: FromNode;
|
|
2125
|
+
chainsWith: string;
|
|
2126
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2127
|
+
folder: string;
|
|
2128
|
+
file: string;
|
|
2129
|
+
constructor(fromNode: FromNode, isRawValue?: boolean);
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
declare class InsertNode extends QueryNode {
|
|
2133
|
+
fromNode: FromNode;
|
|
2134
|
+
records: Record<string, any>[];
|
|
2135
|
+
returning?: string[];
|
|
2136
|
+
disableReturning: boolean;
|
|
2137
|
+
chainsWith: string;
|
|
2138
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2139
|
+
folder: string;
|
|
2140
|
+
file: string;
|
|
2141
|
+
constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
declare class OnDuplicateNode extends QueryNode {
|
|
2145
|
+
table: string;
|
|
2146
|
+
conflictColumns: string[];
|
|
2147
|
+
columnsToUpdate: string[];
|
|
2148
|
+
returning?: string[];
|
|
2149
|
+
mode: "update" | "ignore";
|
|
2150
|
+
chainsWith: string;
|
|
2151
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2152
|
+
folder: string;
|
|
2153
|
+
file: string;
|
|
2154
|
+
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
2158
|
+
|
|
2159
|
+
declare class TruncateNode extends QueryNode {
|
|
2160
|
+
fromNode: FromNode | string;
|
|
2161
|
+
chainsWith: string;
|
|
2162
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2163
|
+
folder: string;
|
|
2164
|
+
file: string;
|
|
2165
|
+
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
declare class UpdateNode extends QueryNode {
|
|
2169
|
+
fromNode: FromNode;
|
|
2170
|
+
columns: string[];
|
|
2171
|
+
values: (any | RawNode)[];
|
|
2172
|
+
chainsWith: string;
|
|
2173
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
2174
|
+
folder: string;
|
|
2175
|
+
file: string;
|
|
2176
|
+
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
2231
2177
|
}
|
|
2232
2178
|
|
|
2179
|
+
type PaginationMetadata = {
|
|
2180
|
+
perPage: number;
|
|
2181
|
+
currentPage: number;
|
|
2182
|
+
firstPage: number;
|
|
2183
|
+
isEmpty: boolean;
|
|
2184
|
+
total: number;
|
|
2185
|
+
lastPage: number;
|
|
2186
|
+
hasMorePages: boolean;
|
|
2187
|
+
hasPages: boolean;
|
|
2188
|
+
};
|
|
2189
|
+
type CursorPaginationMetadata = {
|
|
2190
|
+
perPage: number;
|
|
2191
|
+
firstPage: number;
|
|
2192
|
+
isEmpty: boolean;
|
|
2193
|
+
total: number;
|
|
2194
|
+
};
|
|
2195
|
+
type PaginatedData<T extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = {
|
|
2196
|
+
paginationMetadata: PaginationMetadata;
|
|
2197
|
+
data: ([keyof S] extends [never] ? T & R : SelectedModel<S, R>)[];
|
|
2198
|
+
};
|
|
2199
|
+
type CursorPaginatedData<T extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = {
|
|
2200
|
+
paginationMetadata: CursorPaginationMetadata;
|
|
2201
|
+
data: ([keyof S] extends [never] ? T & R : SelectedModel<S, R>)[];
|
|
2202
|
+
};
|
|
2203
|
+
|
|
2233
2204
|
type BaseValues$1 = string | number | boolean | null;
|
|
2234
2205
|
type BinaryOperatorType$1 = "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "like" | "ilike" | "in";
|
|
2235
2206
|
declare class HavingNode extends QueryNode {
|
|
@@ -2628,7 +2599,7 @@ declare abstract class FooterQueryBuilder<T extends Model> {
|
|
|
2628
2599
|
* @description Adds a group by query
|
|
2629
2600
|
*/
|
|
2630
2601
|
groupBy(...columns: ModelKey<T>[]): this;
|
|
2631
|
-
groupBy<S extends string>(...columns: SelectableColumn<S>[]): this;
|
|
2602
|
+
groupBy<S extends string>(...columns: SelectableColumn$1<S>[]): this;
|
|
2632
2603
|
/**
|
|
2633
2604
|
* @description Adds a raw group by query, GROUP BY clause is not necessary and will be added automatically
|
|
2634
2605
|
*/
|
|
@@ -2637,7 +2608,7 @@ declare abstract class FooterQueryBuilder<T extends Model> {
|
|
|
2637
2608
|
* @description Adds an order by query
|
|
2638
2609
|
*/
|
|
2639
2610
|
orderBy(column: ModelKey<T>, order: OrderByChoices): this;
|
|
2640
|
-
orderBy<S extends string>(column: SelectableColumn<S>, order: OrderByChoices): this;
|
|
2611
|
+
orderBy<S extends string>(column: SelectableColumn$1<S>, order: OrderByChoices): this;
|
|
2641
2612
|
/**
|
|
2642
2613
|
* @description Adds a raw order by query, ORDER BY clause is not necessary and will be added automatically
|
|
2643
2614
|
*/
|
|
@@ -2664,180 +2635,180 @@ declare class JoinOnQueryBuilder {
|
|
|
2664
2635
|
/**
|
|
2665
2636
|
* @description Adds a WHERE condition to the query.
|
|
2666
2637
|
*/
|
|
2667
|
-
where(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2638
|
+
where(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2668
2639
|
where(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
2669
|
-
where(column: SelectableColumn<string>, value: BaseValues): this;
|
|
2640
|
+
where(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2670
2641
|
/**
|
|
2671
2642
|
* @description Adds an AND WHERE condition to the query.
|
|
2672
2643
|
*/
|
|
2673
|
-
andWhere(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2674
|
-
andWhere(column: SelectableColumn<string>, value: BaseValues): this;
|
|
2644
|
+
andWhere(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2645
|
+
andWhere(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2675
2646
|
andWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
2676
2647
|
/**
|
|
2677
2648
|
* @description Adds an OR WHERE condition to the query.
|
|
2678
2649
|
*/
|
|
2679
|
-
orWhere(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2680
|
-
orWhere(column: SelectableColumn<string>, value: BaseValues): this;
|
|
2650
|
+
orWhere(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2651
|
+
orWhere(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2681
2652
|
orWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
|
|
2682
2653
|
/**
|
|
2683
2654
|
* @description Adds a negated WHERE condition to the query.
|
|
2684
2655
|
*/
|
|
2685
|
-
whereNot(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2686
|
-
whereNot(column: SelectableColumn<string>, value: BaseValues): this;
|
|
2656
|
+
whereNot(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2657
|
+
whereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2687
2658
|
/**
|
|
2688
2659
|
* @description Adds a negated AND WHERE condition to the query.
|
|
2689
2660
|
*/
|
|
2690
|
-
andWhereNot(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2691
|
-
andWhereNot(column: SelectableColumn<string>, value: BaseValues): this;
|
|
2661
|
+
andWhereNot(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2662
|
+
andWhereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2692
2663
|
/**
|
|
2693
2664
|
* @description Adds a negated OR WHERE condition to the query.
|
|
2694
2665
|
*/
|
|
2695
|
-
orWhereNot(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2696
|
-
orWhereNot(column: SelectableColumn<string>, value: BaseValues): this;
|
|
2666
|
+
orWhereNot(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
2667
|
+
orWhereNot(column: SelectableColumn$1<string>, value: BaseValues): this;
|
|
2697
2668
|
/**
|
|
2698
2669
|
* @description Adds a WHERE BETWEEN condition to the query.
|
|
2699
2670
|
*/
|
|
2700
|
-
whereBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
|
|
2671
|
+
whereBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
2701
2672
|
/**
|
|
2702
2673
|
* @description Adds an AND WHERE BETWEEN condition to the query.
|
|
2703
2674
|
*/
|
|
2704
|
-
andWhereBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
|
|
2675
|
+
andWhereBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
2705
2676
|
/**
|
|
2706
2677
|
* @description Adds an OR WHERE BETWEEN condition to the query.
|
|
2707
2678
|
*/
|
|
2708
|
-
orWhereBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
|
|
2679
|
+
orWhereBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
2709
2680
|
/**
|
|
2710
2681
|
* @description Adds a WHERE NOT BETWEEN condition to the query.
|
|
2711
2682
|
*/
|
|
2712
|
-
whereNotBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
|
|
2683
|
+
whereNotBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
2713
2684
|
/**
|
|
2714
2685
|
* @description Adds an AND WHERE NOT BETWEEN condition to the query.
|
|
2715
2686
|
*/
|
|
2716
|
-
andWhereNotBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
|
|
2687
|
+
andWhereNotBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
2717
2688
|
/**
|
|
2718
2689
|
* @description Adds an OR WHERE NOT BETWEEN condition to the query.
|
|
2719
2690
|
*/
|
|
2720
|
-
orWhereNotBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
|
|
2691
|
+
orWhereNotBetween(column: SelectableColumn$1<string>, min: BaseValues, max: BaseValues): this;
|
|
2721
2692
|
/**
|
|
2722
2693
|
* @description Adds a WHERE LIKE condition to the query.
|
|
2723
2694
|
*/
|
|
2724
|
-
whereLike(column: SelectableColumn<string>, value: string): this;
|
|
2695
|
+
whereLike(column: SelectableColumn$1<string>, value: string): this;
|
|
2725
2696
|
/**
|
|
2726
2697
|
* @description Adds an AND WHERE LIKE condition to the query.
|
|
2727
2698
|
*/
|
|
2728
|
-
andWhereLike(column: SelectableColumn<string>, value: string): this;
|
|
2699
|
+
andWhereLike(column: SelectableColumn$1<string>, value: string): this;
|
|
2729
2700
|
/**
|
|
2730
2701
|
* @description Adds an OR WHERE LIKE condition to the query.
|
|
2731
2702
|
*/
|
|
2732
|
-
orWhereLike(column: SelectableColumn<string>, value: string): this;
|
|
2703
|
+
orWhereLike(column: SelectableColumn$1<string>, value: string): this;
|
|
2733
2704
|
/**
|
|
2734
2705
|
* @description Adds a WHERE ILIKE condition to the query.
|
|
2735
2706
|
*/
|
|
2736
|
-
whereILike(column: SelectableColumn<string>, value: string): this;
|
|
2707
|
+
whereILike(column: SelectableColumn$1<string>, value: string): this;
|
|
2737
2708
|
/**
|
|
2738
2709
|
* @description Adds an AND WHERE ILIKE condition to the query.
|
|
2739
2710
|
*/
|
|
2740
|
-
andWhereILike(column: SelectableColumn<string>, value: string): this;
|
|
2711
|
+
andWhereILike(column: SelectableColumn$1<string>, value: string): this;
|
|
2741
2712
|
/**
|
|
2742
2713
|
* @description Adds an OR WHERE ILIKE condition to the query.
|
|
2743
2714
|
*/
|
|
2744
|
-
orWhereILike(column: SelectableColumn<string>, value: string): this;
|
|
2715
|
+
orWhereILike(column: SelectableColumn$1<string>, value: string): this;
|
|
2745
2716
|
/**
|
|
2746
2717
|
* @description Adds a WHERE NOT LIKE condition to the query.
|
|
2747
2718
|
*/
|
|
2748
|
-
whereNotLike(column: SelectableColumn<string>, value: string): this;
|
|
2719
|
+
whereNotLike(column: SelectableColumn$1<string>, value: string): this;
|
|
2749
2720
|
/**
|
|
2750
2721
|
* @description Adds an AND WHERE NOT LIKE condition to the query.
|
|
2751
2722
|
*/
|
|
2752
|
-
andWhereNotLike(column: SelectableColumn<string>, value: string): this;
|
|
2723
|
+
andWhereNotLike(column: SelectableColumn$1<string>, value: string): this;
|
|
2753
2724
|
/**
|
|
2754
2725
|
* @description Adds an OR WHERE NOT LIKE condition to the query.
|
|
2755
2726
|
*/
|
|
2756
|
-
orWhereNotLike(column: SelectableColumn<string>, value: string): this;
|
|
2727
|
+
orWhereNotLike(column: SelectableColumn$1<string>, value: string): this;
|
|
2757
2728
|
/**
|
|
2758
2729
|
* @description Adds a WHERE NOT ILIKE condition to the query.
|
|
2759
2730
|
*/
|
|
2760
|
-
whereNotILike(column: SelectableColumn<string>, value: string): this;
|
|
2731
|
+
whereNotILike(column: SelectableColumn$1<string>, value: string): this;
|
|
2761
2732
|
/**
|
|
2762
2733
|
* @description Adds an AND WHERE NOT ILIKE condition to the query.
|
|
2763
2734
|
*/
|
|
2764
|
-
andWhereNotILike(column: SelectableColumn<string>, value: string): this;
|
|
2735
|
+
andWhereNotILike(column: SelectableColumn$1<string>, value: string): this;
|
|
2765
2736
|
/**
|
|
2766
2737
|
* @description Adds an OR WHERE NOT ILIKE condition to the query.
|
|
2767
2738
|
*/
|
|
2768
|
-
orWhereNotILike(column: SelectableColumn<string>, value: string): this;
|
|
2739
|
+
orWhereNotILike(column: SelectableColumn$1<string>, value: string): this;
|
|
2769
2740
|
/**
|
|
2770
2741
|
* @description Adds a WHERE IN condition to the query.
|
|
2771
2742
|
*/
|
|
2772
|
-
whereIn(column: SelectableColumn<string>, values: BaseValues[]): this;
|
|
2743
|
+
whereIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
2773
2744
|
/**
|
|
2774
2745
|
* @description Adds an AND WHERE IN condition to the query.
|
|
2775
2746
|
*/
|
|
2776
|
-
andWhereIn(column: SelectableColumn<string>, values: BaseValues[]): this;
|
|
2747
|
+
andWhereIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
2777
2748
|
/**
|
|
2778
2749
|
* @description Adds an OR WHERE IN condition to the query.
|
|
2779
2750
|
*/
|
|
2780
|
-
orWhereIn(column: SelectableColumn<string>, values: BaseValues[]): this;
|
|
2751
|
+
orWhereIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
2781
2752
|
/**
|
|
2782
2753
|
* @description Adds a WHERE NOT IN condition to the query.
|
|
2783
2754
|
*/
|
|
2784
|
-
whereNotIn(column: SelectableColumn<string>, values: BaseValues[]): this;
|
|
2755
|
+
whereNotIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
2785
2756
|
/**
|
|
2786
2757
|
* @description Adds an AND WHERE NOT IN condition to the query.
|
|
2787
2758
|
*/
|
|
2788
|
-
andWhereNotIn(column: SelectableColumn<string>, values: BaseValues[]): this;
|
|
2759
|
+
andWhereNotIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
2789
2760
|
/**
|
|
2790
2761
|
* @description Adds an OR WHERE NOT IN condition to the query.
|
|
2791
2762
|
*/
|
|
2792
|
-
orWhereNotIn(column: SelectableColumn<string>, values: BaseValues[]): this;
|
|
2763
|
+
orWhereNotIn(column: SelectableColumn$1<string>, values: BaseValues[]): this;
|
|
2793
2764
|
/**
|
|
2794
2765
|
* @description Adds a WHERE NULL condition to the query.
|
|
2795
2766
|
*/
|
|
2796
|
-
whereNull(column: SelectableColumn<string>): this;
|
|
2767
|
+
whereNull(column: SelectableColumn$1<string>): this;
|
|
2797
2768
|
/**
|
|
2798
2769
|
* @description Adds an AND WHERE NULL condition to the query.
|
|
2799
2770
|
*/
|
|
2800
|
-
andWhereNull(column: SelectableColumn<string>): this;
|
|
2771
|
+
andWhereNull(column: SelectableColumn$1<string>): this;
|
|
2801
2772
|
/**
|
|
2802
2773
|
* @description Adds an OR WHERE NULL condition to the query.
|
|
2803
2774
|
*/
|
|
2804
|
-
orWhereNull(column: SelectableColumn<string>): this;
|
|
2775
|
+
orWhereNull(column: SelectableColumn$1<string>): this;
|
|
2805
2776
|
/**
|
|
2806
2777
|
* @description Adds a WHERE NOT NULL condition to the query.
|
|
2807
2778
|
*/
|
|
2808
|
-
whereNotNull(column: SelectableColumn<string>): this;
|
|
2779
|
+
whereNotNull(column: SelectableColumn$1<string>): this;
|
|
2809
2780
|
/**
|
|
2810
2781
|
* @description Adds an AND WHERE NOT NULL condition to the query.
|
|
2811
2782
|
*/
|
|
2812
|
-
andWhereNotNull(column: SelectableColumn<string>): this;
|
|
2783
|
+
andWhereNotNull(column: SelectableColumn$1<string>): this;
|
|
2813
2784
|
/**
|
|
2814
2785
|
* @description Adds an OR WHERE NOT NULL condition to the query.
|
|
2815
2786
|
*/
|
|
2816
|
-
orWhereNotNull(column: SelectableColumn<string>): this;
|
|
2787
|
+
orWhereNotNull(column: SelectableColumn$1<string>): this;
|
|
2817
2788
|
/**
|
|
2818
2789
|
* @description Adds a WHERE REGEXP condition to the query.
|
|
2819
2790
|
*/
|
|
2820
|
-
whereRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
|
|
2791
|
+
whereRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
2821
2792
|
/**
|
|
2822
2793
|
* @description Adds an AND WHERE REGEXP condition to the query.
|
|
2823
2794
|
*/
|
|
2824
|
-
andWhereRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
|
|
2795
|
+
andWhereRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
2825
2796
|
/**
|
|
2826
2797
|
* @description Adds an OR WHERE REGEXP condition to the query.
|
|
2827
2798
|
*/
|
|
2828
|
-
orWhereRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
|
|
2799
|
+
orWhereRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
2829
2800
|
/**
|
|
2830
2801
|
* @description Adds a WHERE NOT REGEXP condition to the query.
|
|
2831
2802
|
*/
|
|
2832
|
-
whereNotRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
|
|
2803
|
+
whereNotRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
2833
2804
|
/**
|
|
2834
2805
|
* @description Adds an AND WHERE NOT REGEXP condition to the query.
|
|
2835
2806
|
*/
|
|
2836
|
-
andWhereNotRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
|
|
2807
|
+
andWhereNotRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
2837
2808
|
/**
|
|
2838
2809
|
* @description Adds an OR WHERE NOT REGEXP condition to the query.
|
|
2839
2810
|
*/
|
|
2840
|
-
orWhereNotRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
|
|
2811
|
+
orWhereNotRegexp(column: SelectableColumn$1<string>, regexp: RegExp): this;
|
|
2841
2812
|
/**
|
|
2842
2813
|
* @description Adds a WHERE group condition with AND.
|
|
2843
2814
|
*/
|
|
@@ -2973,7 +2944,6 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
|
|
|
2973
2944
|
declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
2974
2945
|
protected dbType: SqlDataSourceType;
|
|
2975
2946
|
protected modelSelectedColumns: string[];
|
|
2976
|
-
protected modelAnnotatedColumns: string[];
|
|
2977
2947
|
protected withQuery?: string;
|
|
2978
2948
|
protected fromNode: FromNode;
|
|
2979
2949
|
protected distinctNode: DistinctNode | null;
|
|
@@ -2983,18 +2953,29 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
2983
2953
|
/**
|
|
2984
2954
|
* @description Adds a SELECT condition to the query.
|
|
2985
2955
|
* @description Can be stacked multiple times
|
|
2986
|
-
* @
|
|
2956
|
+
* @description Supports: "column", "table.column", "column as alias", "*", "table.*"
|
|
2987
2957
|
* @example
|
|
2988
2958
|
* ```ts
|
|
2989
2959
|
* const user = await User.query().select("name", "age").one(); // SELECT name, age FROM users
|
|
2990
2960
|
* const user = await User.query().select("name", "users.age").one(); // SELECT name, users.age FROM users
|
|
2961
|
+
* const user = await User.query().select("name as userName").one(); // SELECT name as userName FROM users
|
|
2991
2962
|
* ```
|
|
2992
2963
|
*/
|
|
2993
|
-
select<S extends string>(...columns: SelectableColumn<S>[]): this;
|
|
2964
|
+
select<S extends string>(...columns: SelectableColumn$1<S>[]): this;
|
|
2994
2965
|
select(...columns: (ModelKey<T> | "*")[]): this;
|
|
2995
2966
|
/**
|
|
2996
|
-
* @description
|
|
2997
|
-
* @
|
|
2967
|
+
* @description Parses a column string that may contain an alias (e.g., "column as alias")
|
|
2968
|
+
* @returns The column part and optional alias part
|
|
2969
|
+
*/
|
|
2970
|
+
private parseColumnAlias;
|
|
2971
|
+
/**
|
|
2972
|
+
* @description Adds a raw SELECT statement to the query
|
|
2973
|
+
* @description Useful for SQL functions, expressions, or complex selections
|
|
2974
|
+
* @example
|
|
2975
|
+
* ```ts
|
|
2976
|
+
* const result = await User.query().selectRaw("count(*) as total").one();
|
|
2977
|
+
* const result = await User.query().selectRaw("sum(amount) as total_amount").one();
|
|
2978
|
+
* ```
|
|
2998
2979
|
*/
|
|
2999
2980
|
selectRaw(statement: string): this;
|
|
3000
2981
|
/**
|
|
@@ -3013,19 +2994,6 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
3013
2994
|
* @description Clears the DISTINCT ON clause
|
|
3014
2995
|
*/
|
|
3015
2996
|
clearDistinctOn(): this;
|
|
3016
|
-
/**
|
|
3017
|
-
* @description Annotates a column with a SQL method or a simple alias
|
|
3018
|
-
* @description If using a model, the result will be available in the $annotations property of the model, else it will be available in the result of the query
|
|
3019
|
-
* @example
|
|
3020
|
-
* ```ts
|
|
3021
|
-
* const user = await User.query().annotate("max", "id", "maxId").one(); // max(id) as maxId
|
|
3022
|
-
* const user = await User.query().annotate("id", "superId").one(); // id as superId
|
|
3023
|
-
* const user = await User.query().annotate("id", "superId").one(); // id as superId
|
|
3024
|
-
* ```
|
|
3025
|
-
*/
|
|
3026
|
-
annotate<A extends string>(column: string, alias: A): this;
|
|
3027
|
-
annotate<A extends string>(sqlMethod: SqlMethod, column: string, alias: A): this;
|
|
3028
|
-
annotate<A extends string>(sqlMethod: string, column: string, alias: A): this;
|
|
3029
2997
|
/**
|
|
3030
2998
|
* @description Sets the table to select from, by default is the table defined in the Model
|
|
3031
2999
|
* @description Can be used on non select queries too, it will only specify the table name (es. INSERT INTO $table)
|
|
@@ -3048,19 +3016,17 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
3048
3016
|
* @postgresql Only usable with PostgreSQL
|
|
3049
3017
|
*/
|
|
3050
3018
|
distinctOn(...columns: ModelKey<T>[]): this;
|
|
3051
|
-
distinctOn<S extends string>(...columns: SelectableColumn<S>[]): this;
|
|
3019
|
+
distinctOn<S extends string>(...columns: SelectableColumn$1<S>[]): this;
|
|
3052
3020
|
/**
|
|
3053
3021
|
* @description Selects a JSON value at the specified path and returns it as JSON
|
|
3054
3022
|
* @param column The column containing JSON data
|
|
3055
3023
|
* @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
|
|
3056
3024
|
* @param alias The alias for the selected value
|
|
3057
3025
|
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3058
|
-
* @description Result will be available in model.$annotations[alias]
|
|
3059
3026
|
* @example
|
|
3060
3027
|
* ```ts
|
|
3061
3028
|
* // All databases accept the same path format:
|
|
3062
3029
|
* const user = await User.query().selectJson("data", "$.user.name", "userName").one();
|
|
3063
|
-
* console.log(user?.$annotations?.userName); // Typed!
|
|
3064
3030
|
*
|
|
3065
3031
|
* await User.query().selectJson("data", "user.name", "userName").one(); // $ is optional
|
|
3066
3032
|
* await User.query().selectJson("data", ["user", "name"], "userName").one();
|
|
@@ -3078,12 +3044,10 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
3078
3044
|
* @param path The JSON path to extract (standardized format)
|
|
3079
3045
|
* @param alias The alias for the selected value
|
|
3080
3046
|
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3081
|
-
* @description Result will be available in model.$annotations[alias]
|
|
3082
3047
|
* @example
|
|
3083
3048
|
* ```ts
|
|
3084
3049
|
* // All databases accept the same path format:
|
|
3085
3050
|
* const user = await User.query().selectJsonText("data", "$.user.name", "userName").one();
|
|
3086
|
-
* console.log(user?.$annotations?.userName); // Typed!
|
|
3087
3051
|
*
|
|
3088
3052
|
* await User.query().selectJsonText("data", ["user", "name"], "userName").one();
|
|
3089
3053
|
* ```
|
|
@@ -3096,12 +3060,10 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
3096
3060
|
* @param path The JSON path to the array (standardized format, use "$" or "" for root)
|
|
3097
3061
|
* @param alias The alias for the length value
|
|
3098
3062
|
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3099
|
-
* @description Result will be available in model.$annotations[alias]
|
|
3100
3063
|
* @example
|
|
3101
3064
|
* ```ts
|
|
3102
3065
|
* // All databases accept the same path format:
|
|
3103
3066
|
* const user = await User.query().selectJsonArrayLength("data", "$.items", "itemCount").one();
|
|
3104
|
-
* console.log(user?.$annotations?.itemCount); // Typed!
|
|
3105
3067
|
*
|
|
3106
3068
|
* await User.query().selectJsonArrayLength("data", "items", "itemCount").one();
|
|
3107
3069
|
* await User.query().selectJsonArrayLength("data", "$", "totalCount").one(); // root array
|
|
@@ -3115,14 +3077,12 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
3115
3077
|
* @param path The JSON path to the object (standardized format, use "$" or "" for root)
|
|
3116
3078
|
* @param alias The alias for the keys
|
|
3117
3079
|
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3118
|
-
* @description Result will be available in model.$annotations[alias]
|
|
3119
3080
|
* @postgres Returns an array of keys
|
|
3120
3081
|
* @mysql Returns a JSON array of keys
|
|
3121
3082
|
* @example
|
|
3122
3083
|
* ```ts
|
|
3123
3084
|
* // All databases accept the same path format:
|
|
3124
3085
|
* const user = await User.query().selectJsonKeys("data", "$.user", "userKeys").one();
|
|
3125
|
-
* console.log(user?.$annotations?.userKeys); // Typed!
|
|
3126
3086
|
*
|
|
3127
3087
|
* await User.query().selectJsonKeys("data", "user", "userKeys").one();
|
|
3128
3088
|
* await User.query().selectJsonKeys("data", "$", "rootKeys").one(); // root object
|
|
@@ -3134,14 +3094,73 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
3134
3094
|
* @description Adds a raw JSON select expression
|
|
3135
3095
|
* @param raw The raw SQL expression
|
|
3136
3096
|
* @param alias The alias for the selected value
|
|
3137
|
-
* @description Result will be available in model.$annotations[alias]
|
|
3138
3097
|
* @example
|
|
3139
3098
|
* ```ts
|
|
3140
3099
|
* const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
|
|
3141
|
-
* console.log(user?.$annotations?.userEmail); // Typed!
|
|
3142
3100
|
* ```
|
|
3143
3101
|
*/
|
|
3144
3102
|
selectJsonRaw<A extends string>(raw: string, alias: A): this;
|
|
3103
|
+
/**
|
|
3104
|
+
* @description Selects COUNT(column) with an alias
|
|
3105
|
+
* @param column The column to count (use "*" for COUNT(*))
|
|
3106
|
+
* @param alias The alias for the count result
|
|
3107
|
+
* @example
|
|
3108
|
+
* ```ts
|
|
3109
|
+
* const result = await User.query().selectCount("id", "totalUsers").one();
|
|
3110
|
+
*
|
|
3111
|
+
* const result = await User.query().selectCount("*", "total").one();
|
|
3112
|
+
* ```
|
|
3113
|
+
*/
|
|
3114
|
+
selectCount<A extends string>(column: ModelKey<T> | "*", alias: A): this;
|
|
3115
|
+
selectCount<A extends string>(column: string, alias: A): this;
|
|
3116
|
+
/**
|
|
3117
|
+
* @description Selects SUM(column) with an alias
|
|
3118
|
+
* @param column The column to sum
|
|
3119
|
+
* @param alias The alias for the sum result
|
|
3120
|
+
* @example
|
|
3121
|
+
* ```ts
|
|
3122
|
+
* const result = await Order.query().selectSum("amount", "totalAmount").one();
|
|
3123
|
+
* console.log(result?.totalAmount); // number
|
|
3124
|
+
* ```
|
|
3125
|
+
*/
|
|
3126
|
+
selectSum<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3127
|
+
selectSum<A extends string>(column: string, alias: A): this;
|
|
3128
|
+
/**
|
|
3129
|
+
* @description Selects AVG(column) with an alias
|
|
3130
|
+
* @param column The column to average
|
|
3131
|
+
* @param alias The alias for the average result
|
|
3132
|
+
* @example
|
|
3133
|
+
* ```ts
|
|
3134
|
+
* const result = await User.query().selectAvg("age", "averageAge").one();
|
|
3135
|
+
* console.log(result?.averageAge); // number
|
|
3136
|
+
* ```
|
|
3137
|
+
*/
|
|
3138
|
+
selectAvg<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3139
|
+
selectAvg<A extends string>(column: string, alias: A): this;
|
|
3140
|
+
/**
|
|
3141
|
+
* @description Selects MIN(column) with an alias
|
|
3142
|
+
* @param column The column to get minimum value
|
|
3143
|
+
* @param alias The alias for the min result
|
|
3144
|
+
* @example
|
|
3145
|
+
* ```ts
|
|
3146
|
+
* const result = await User.query().selectMin("age", "youngestAge").one();
|
|
3147
|
+
* console.log(result?.youngestAge); // number
|
|
3148
|
+
* ```
|
|
3149
|
+
*/
|
|
3150
|
+
selectMin<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3151
|
+
selectMin<A extends string>(column: string, alias: A): this;
|
|
3152
|
+
/**
|
|
3153
|
+
* @description Selects MAX(column) with an alias
|
|
3154
|
+
* @param column The column to get maximum value
|
|
3155
|
+
* @param alias The alias for the max result
|
|
3156
|
+
* @example
|
|
3157
|
+
* ```ts
|
|
3158
|
+
* const result = await User.query().selectMax("age", "oldestAge").one();
|
|
3159
|
+
* console.log(result?.oldestAge); // number
|
|
3160
|
+
* ```
|
|
3161
|
+
*/
|
|
3162
|
+
selectMax<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3163
|
+
selectMax<A extends string>(column: string, alias: A): this;
|
|
3145
3164
|
}
|
|
3146
3165
|
|
|
3147
3166
|
declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBuilder<T> {
|
|
@@ -3165,251 +3184,251 @@ declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBui
|
|
|
3165
3184
|
* @description Adds a WHERE condition to the query.
|
|
3166
3185
|
*/
|
|
3167
3186
|
where(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3168
|
-
where<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3187
|
+
where<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3169
3188
|
where(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
|
|
3170
|
-
where(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3171
|
-
where(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3172
|
-
where(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
|
|
3189
|
+
where(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3190
|
+
where(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3191
|
+
where(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3173
3192
|
/**
|
|
3174
3193
|
* @description Adds an AND WHERE condition to the query.
|
|
3175
3194
|
*/
|
|
3176
3195
|
andWhere(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3177
|
-
andWhere(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3178
|
-
andWhere(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
|
|
3196
|
+
andWhere(column: SelectableColumn$1<string>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3197
|
+
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3179
3198
|
andWhere(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
|
|
3180
|
-
andWhere(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3181
|
-
andWhere(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3199
|
+
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3200
|
+
andWhere(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3182
3201
|
/**
|
|
3183
3202
|
* @description Adds an OR WHERE condition to the query.
|
|
3184
3203
|
*/
|
|
3185
3204
|
orWhere(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3186
|
-
orWhere<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3187
|
-
orWhere<S extends string>(column: ModelKey<T> | SelectableColumn<S>, value: BaseValues): this;
|
|
3205
|
+
orWhere<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3206
|
+
orWhere<S extends string>(column: ModelKey<T> | SelectableColumn$1<S>, value: BaseValues): this;
|
|
3188
3207
|
orWhere(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
|
|
3189
|
-
orWhere(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3190
|
-
orWhere(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3208
|
+
orWhere(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3209
|
+
orWhere(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3191
3210
|
/**
|
|
3192
3211
|
* @description Adds a negated WHERE condition to the query.
|
|
3193
3212
|
*/
|
|
3194
3213
|
whereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3195
|
-
whereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3196
|
-
whereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
|
|
3197
|
-
whereNot(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3198
|
-
whereNot(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3214
|
+
whereNot<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3215
|
+
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3216
|
+
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3217
|
+
whereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3199
3218
|
/**
|
|
3200
3219
|
* @description Adds a negated AND WHERE condition to the query.
|
|
3201
3220
|
*/
|
|
3202
3221
|
andWhereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3203
|
-
andWhereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3204
|
-
andWhereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
|
|
3205
|
-
andWhereNot(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3206
|
-
andWhereNot(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3222
|
+
andWhereNot<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3223
|
+
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3224
|
+
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3225
|
+
andWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3207
3226
|
/**
|
|
3208
3227
|
* @description Adds a negated OR WHERE condition to the query.
|
|
3209
3228
|
*/
|
|
3210
3229
|
orWhereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3211
|
-
orWhereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3212
|
-
orWhereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
|
|
3213
|
-
orWhereNot(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3214
|
-
orWhereNot(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3230
|
+
orWhereNot<S extends string>(column: SelectableColumn$1<S>, operator: BinaryOperatorType, value: BaseValues): this;
|
|
3231
|
+
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, value: BaseValues): this;
|
|
3232
|
+
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3233
|
+
orWhereNot(column: ModelKey<T> | SelectableColumn$1<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
|
|
3215
3234
|
/**
|
|
3216
3235
|
* @description Adds a WHERE BETWEEN condition to the query.
|
|
3217
3236
|
*/
|
|
3218
3237
|
whereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3219
|
-
whereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
|
|
3238
|
+
whereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3220
3239
|
/**
|
|
3221
3240
|
* @description Adds an AND WHERE BETWEEN condition to the query.
|
|
3222
3241
|
*/
|
|
3223
3242
|
andWhereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3224
|
-
andWhereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
|
|
3243
|
+
andWhereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3225
3244
|
/**
|
|
3226
3245
|
* @description Adds an OR WHERE BETWEEN condition to the query.
|
|
3227
3246
|
*/
|
|
3228
3247
|
orWhereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3229
|
-
orWhereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
|
|
3248
|
+
orWhereBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3230
3249
|
/**
|
|
3231
3250
|
* @description Adds a WHERE NOT BETWEEN condition to the query.
|
|
3232
3251
|
*/
|
|
3233
3252
|
whereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3234
|
-
whereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
|
|
3253
|
+
whereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3235
3254
|
/**
|
|
3236
3255
|
* @description Adds an AND WHERE NOT BETWEEN condition to the query.
|
|
3237
3256
|
*/
|
|
3238
3257
|
andWhereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3239
|
-
andWhereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
|
|
3258
|
+
andWhereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3240
3259
|
/**
|
|
3241
3260
|
* @description Adds an OR WHERE NOT BETWEEN condition to the query.
|
|
3242
3261
|
*/
|
|
3243
3262
|
orWhereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
|
|
3244
|
-
orWhereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
|
|
3263
|
+
orWhereNotBetween<S extends string>(column: SelectableColumn$1<S>, min: BaseValues, max: BaseValues): this;
|
|
3245
3264
|
/**
|
|
3246
3265
|
* @description Adds a WHERE LIKE condition to the query.
|
|
3247
3266
|
*/
|
|
3248
3267
|
whereLike(column: ModelKey<T>, value: string): this;
|
|
3249
|
-
whereLike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3268
|
+
whereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3250
3269
|
/**
|
|
3251
3270
|
* @description Adds an AND WHERE LIKE condition to the query.
|
|
3252
3271
|
*/
|
|
3253
3272
|
andWhereLike(column: ModelKey<T>, value: string): this;
|
|
3254
|
-
andWhereLike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3273
|
+
andWhereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3255
3274
|
/**
|
|
3256
3275
|
* @description Adds an OR WHERE LIKE condition to the query.
|
|
3257
3276
|
*/
|
|
3258
3277
|
orWhereLike(column: ModelKey<T>, value: string): this;
|
|
3259
|
-
orWhereLike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3278
|
+
orWhereLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3260
3279
|
/**
|
|
3261
3280
|
* @description Adds a WHERE ILIKE condition to the query.
|
|
3262
3281
|
*/
|
|
3263
3282
|
whereILike(column: ModelKey<T>, value: string): this;
|
|
3264
|
-
whereILike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3283
|
+
whereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3265
3284
|
/**
|
|
3266
3285
|
* @description Adds an AND WHERE ILIKE condition to the query.
|
|
3267
3286
|
*/
|
|
3268
3287
|
andWhereILike(column: ModelKey<T>, value: string): this;
|
|
3269
|
-
andWhereILike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3288
|
+
andWhereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3270
3289
|
/**
|
|
3271
3290
|
* @description Adds an OR WHERE ILIKE condition to the query.
|
|
3272
3291
|
*/
|
|
3273
3292
|
orWhereILike(column: ModelKey<T>, value: string): this;
|
|
3274
|
-
orWhereILike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3293
|
+
orWhereILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3275
3294
|
/**
|
|
3276
3295
|
* @description Adds a WHERE NOT LIKE condition to the query.
|
|
3277
3296
|
*/
|
|
3278
3297
|
whereNotLike(column: ModelKey<T>, value: string): this;
|
|
3279
|
-
whereNotLike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3298
|
+
whereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3280
3299
|
/**
|
|
3281
3300
|
* @description Adds an AND WHERE NOT LIKE condition to the query.
|
|
3282
3301
|
*/
|
|
3283
3302
|
andWhereNotLike(column: ModelKey<T>, value: string): this;
|
|
3284
|
-
andWhereNotLike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3303
|
+
andWhereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3285
3304
|
/**
|
|
3286
3305
|
* @description Adds an OR WHERE NOT LIKE condition to the query.
|
|
3287
3306
|
*/
|
|
3288
3307
|
orWhereNotLike(column: ModelKey<T>, value: string): this;
|
|
3289
|
-
orWhereNotLike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3308
|
+
orWhereNotLike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3290
3309
|
/**
|
|
3291
3310
|
* @description Adds a WHERE NOT ILIKE condition to the query.
|
|
3292
3311
|
*/
|
|
3293
3312
|
whereNotILike(column: ModelKey<T>, value: string): this;
|
|
3294
|
-
whereNotILike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3313
|
+
whereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3295
3314
|
/**
|
|
3296
3315
|
* @description Adds an AND WHERE NOT ILIKE condition to the query.
|
|
3297
3316
|
*/
|
|
3298
3317
|
andWhereNotILike(column: ModelKey<T>, value: string): this;
|
|
3299
|
-
andWhereNotILike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3318
|
+
andWhereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3300
3319
|
/**
|
|
3301
3320
|
* @description Adds an OR WHERE NOT ILIKE condition to the query.
|
|
3302
3321
|
*/
|
|
3303
3322
|
orWhereNotILike(column: ModelKey<T>, value: string): this;
|
|
3304
|
-
orWhereNotILike<S extends string>(column: SelectableColumn<S>, value: string): this;
|
|
3323
|
+
orWhereNotILike<S extends string>(column: SelectableColumn$1<S>, value: string): this;
|
|
3305
3324
|
/**
|
|
3306
3325
|
* @description Adds a WHERE IN condition to the query.
|
|
3307
3326
|
* @warning If the array is empty, it will add an impossible condition.
|
|
3308
3327
|
*/
|
|
3309
3328
|
whereIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3310
|
-
whereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
|
|
3329
|
+
whereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3311
3330
|
/**
|
|
3312
3331
|
* @description Adds an AND WHERE IN condition to the query.
|
|
3313
3332
|
* @warning If the array is empty, it will add an impossible condition.
|
|
3314
3333
|
*/
|
|
3315
3334
|
andWhereIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3316
|
-
andWhereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
|
|
3335
|
+
andWhereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3317
3336
|
/**
|
|
3318
3337
|
* @description Adds an OR WHERE IN condition to the query.
|
|
3319
3338
|
* @warning If the array is empty, it will add an impossible condition.
|
|
3320
3339
|
*/
|
|
3321
3340
|
orWhereIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3322
|
-
orWhereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
|
|
3341
|
+
orWhereIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3323
3342
|
/**
|
|
3324
3343
|
* @description Adds a WHERE NOT IN condition to the query.
|
|
3325
3344
|
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3326
3345
|
*/
|
|
3327
3346
|
whereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3328
|
-
whereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
|
|
3347
|
+
whereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3329
3348
|
/**
|
|
3330
3349
|
* @description Adds an OR WHERE NOT IN condition to the query.
|
|
3331
3350
|
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3332
3351
|
*/
|
|
3333
3352
|
andWhereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3334
|
-
andWhereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
|
|
3353
|
+
andWhereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3335
3354
|
/**
|
|
3336
3355
|
* @description Adds an OR WHERE NOT IN condition to the query.
|
|
3337
3356
|
* @warning If the array is empty, it will add an obvious condition to make it true.
|
|
3338
3357
|
*/
|
|
3339
3358
|
orWhereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
|
|
3340
|
-
orWhereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
|
|
3359
|
+
orWhereNotIn<S extends string>(column: SelectableColumn$1<S>, values: BaseValues[]): this;
|
|
3341
3360
|
/**
|
|
3342
3361
|
* @description Adds a WHERE NULL condition to the query.
|
|
3343
3362
|
*/
|
|
3344
3363
|
whereNull(column: ModelKey<T>): this;
|
|
3345
|
-
whereNull<S extends string>(column: SelectableColumn<S>): this;
|
|
3364
|
+
whereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3346
3365
|
/**
|
|
3347
3366
|
* @description Adds an AND WHERE NULL condition to the query.
|
|
3348
3367
|
*/
|
|
3349
3368
|
andWhereNull(column: ModelKey<T>): this;
|
|
3350
|
-
andWhereNull<S extends string>(column: SelectableColumn<S>): this;
|
|
3369
|
+
andWhereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3351
3370
|
/**
|
|
3352
3371
|
* @description Adds an OR WHERE NULL condition to the query.
|
|
3353
3372
|
*/
|
|
3354
3373
|
orWhereNull(column: ModelKey<T>): this;
|
|
3355
|
-
orWhereNull<S extends string>(column: SelectableColumn<S>): this;
|
|
3374
|
+
orWhereNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3356
3375
|
/**
|
|
3357
3376
|
* @description Adds a WHERE NOT NULL condition to the query.
|
|
3358
3377
|
*/
|
|
3359
3378
|
whereNotNull(column: ModelKey<T>): this;
|
|
3360
|
-
whereNotNull<S extends string>(column: SelectableColumn<S>): this;
|
|
3379
|
+
whereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3361
3380
|
/**
|
|
3362
3381
|
* @description Adds an AND WHERE NOT NULL condition to the query.
|
|
3363
3382
|
*/
|
|
3364
3383
|
andWhereNotNull(column: ModelKey<T>): this;
|
|
3365
|
-
andWhereNotNull<S extends string>(column: SelectableColumn<S>): this;
|
|
3384
|
+
andWhereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3366
3385
|
/**
|
|
3367
3386
|
* @description Adds an OR WHERE NOT NULL condition to the query.
|
|
3368
3387
|
*/
|
|
3369
3388
|
orWhereNotNull(column: ModelKey<T>): this;
|
|
3370
|
-
orWhereNotNull<S extends string>(column: SelectableColumn<S>): this;
|
|
3389
|
+
orWhereNotNull<S extends string>(column: SelectableColumn$1<S>): this;
|
|
3371
3390
|
/**
|
|
3372
3391
|
* @description Adds a WHERE REGEXP condition to the query.
|
|
3373
3392
|
* @mssql doesn't support REGEXP syntax
|
|
3374
3393
|
* @sqlite doesn't support REGEXP syntax
|
|
3375
3394
|
*/
|
|
3376
3395
|
whereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3377
|
-
whereRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
3396
|
+
whereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3378
3397
|
/**
|
|
3379
3398
|
* @description Adds an AND WHERE REGEXP condition to the query.
|
|
3380
3399
|
* @mssql doesn't support REGEXP syntax
|
|
3381
3400
|
* @sqlite doesn't support REGEXP syntax
|
|
3382
3401
|
*/
|
|
3383
3402
|
andWhereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3384
|
-
andWhereRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
3403
|
+
andWhereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3385
3404
|
/**
|
|
3386
3405
|
* @description Adds an OR WHERE REGEXP condition to the query.
|
|
3387
3406
|
* @mssql doesn't support REGEXP syntax
|
|
3388
3407
|
* @sqlite doesn't support REGEXP syntax
|
|
3389
3408
|
*/
|
|
3390
3409
|
orWhereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3391
|
-
orWhereRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
3410
|
+
orWhereRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3392
3411
|
/**
|
|
3393
3412
|
* @description Adds a WHERE NOT REGEXP condition to the query.
|
|
3394
3413
|
* @mssql doesn't support REGEXP syntax
|
|
3395
3414
|
* @sqlite doesn't support REGEXP syntax
|
|
3396
3415
|
*/
|
|
3397
3416
|
whereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3398
|
-
whereNotRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
3417
|
+
whereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3399
3418
|
/**
|
|
3400
3419
|
* @description Adds an AND WHERE NOT REGEXP condition to the query.
|
|
3401
3420
|
* @mssql doesn't support REGEXP syntax
|
|
3402
3421
|
* @sqlite doesn't support REGEXP syntax
|
|
3403
3422
|
*/
|
|
3404
3423
|
andWhereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3405
|
-
andWhereNotRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
3424
|
+
andWhereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3406
3425
|
/**
|
|
3407
3426
|
* @description Adds an OR WHERE NOT REGEXP condition to the query.
|
|
3408
3427
|
* @mssql doesn't support REGEXP syntax
|
|
3409
3428
|
* @sqlite doesn't support REGEXP syntax
|
|
3410
3429
|
*/
|
|
3411
3430
|
orWhereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
3412
|
-
orWhereNotRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
3431
|
+
orWhereNotRegexp<S extends string>(column: SelectableColumn$1<S>, regexp: RegExp): this;
|
|
3413
3432
|
/**
|
|
3414
3433
|
* @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.
|
|
3415
3434
|
*/
|
|
@@ -3449,17 +3468,17 @@ declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBui
|
|
|
3449
3468
|
/**
|
|
3450
3469
|
* @description Adds a HAVING condition to the query.
|
|
3451
3470
|
*/
|
|
3452
|
-
having<S extends string>(column: SelectableColumn<S>, value: any): this;
|
|
3471
|
+
having<S extends string>(column: SelectableColumn$1<S>, value: any): this;
|
|
3453
3472
|
having(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3454
3473
|
/**
|
|
3455
3474
|
* @description Adds an AND HAVING condition to the query.
|
|
3456
3475
|
*/
|
|
3457
|
-
andHaving<S extends string>(column: SelectableColumn<S>, value: any): this;
|
|
3476
|
+
andHaving<S extends string>(column: SelectableColumn$1<S>, value: any): this;
|
|
3458
3477
|
andHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3459
3478
|
/**
|
|
3460
3479
|
* @description Adds an OR HAVING condition to the query.
|
|
3461
3480
|
*/
|
|
3462
|
-
orHaving<S extends string>(column: SelectableColumn<S>, value: any): this;
|
|
3481
|
+
orHaving<S extends string>(column: SelectableColumn$1<S>, value: any): this;
|
|
3463
3482
|
orHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
|
|
3464
3483
|
/**
|
|
3465
3484
|
* @description Adds a raw HAVING condition to the query.
|
|
@@ -3570,133 +3589,46 @@ declare class JsonQueryBuilder<T extends Model> extends WhereQueryBuilder<T> {
|
|
|
3570
3589
|
orWhereJsonRaw(raw: string, params?: any[]): this;
|
|
3571
3590
|
}
|
|
3572
3591
|
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
/**
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
batchSize?: number;
|
|
3591
|
-
/** Postgres only */
|
|
3592
|
-
types?: any;
|
|
3593
|
-
/** Mysql only */
|
|
3594
|
-
objectMode?: boolean;
|
|
3595
|
-
};
|
|
3596
|
-
type Cursor<T extends Model, K extends ModelKey<T>> = {
|
|
3597
|
-
key: K;
|
|
3598
|
-
value: string | number;
|
|
3599
|
-
};
|
|
3600
|
-
type PaginateWithCursorOptions<T extends Model, K extends ModelKey<T>> = {
|
|
3601
|
-
discriminator: K;
|
|
3602
|
-
operator?: "<" | ">";
|
|
3603
|
-
orderBy?: "asc" | "desc";
|
|
3604
|
-
};
|
|
3605
|
-
type UpsertOptionsRawBuilder = {
|
|
3606
|
-
updateOnConflict?: boolean;
|
|
3607
|
-
returning?: string[];
|
|
3608
|
-
};
|
|
3609
|
-
type DryQueryBuilderWithoutReadOperations = Omit<DryQueryBuilder, "many" | "one" | "oneOrFail" | "first" | "firstOrFail" | "paginate" | "paginateWithCursor" | "exists" | "pluck" | "increment" | "decrement" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "stream" | "chunk" | "paginate" | "paginateWithCursor" | "exists">;
|
|
3610
|
-
type DryModelQueryBuilderWithoutReadOperations<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<DryModelQueryBuilder<T, A, R>, "many" | "one" | "oneOrFail" | "first" | "firstOrFail" | "paginate" | "paginateWithCursor" | "exists" | "pluck" | "upsert" | "upsertMany" | "increment" | "decrement" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "stream" | "chunk" | "paginate" | "paginateWithCursor" | "exists">;
|
|
3611
|
-
type WriteQueryParam$1 = string | number | boolean | Date | RawNode | object | null | undefined;
|
|
3612
|
-
|
|
3613
|
-
declare class SqlModelManagerUtils<T extends Model> {
|
|
3614
|
-
protected dbType: SqlDataSourceType;
|
|
3615
|
-
protected sqlDataSource: SqlDataSource;
|
|
3616
|
-
protected modelRelations: Relation[];
|
|
3617
|
-
protected modelRelationsMap: Map<string, Relation>;
|
|
3618
|
-
constructor(typeofModel: typeof Model, dbType: SqlDataSourceType, sqlDataSource: SqlDataSource);
|
|
3619
|
-
getRelationFromModel(relation: ModelRelation<T>): Relation;
|
|
3620
|
-
}
|
|
3621
|
-
|
|
3622
|
-
type PaginationMetadata = {
|
|
3623
|
-
perPage: number;
|
|
3624
|
-
currentPage: number;
|
|
3625
|
-
firstPage: number;
|
|
3626
|
-
isEmpty: boolean;
|
|
3627
|
-
total: number;
|
|
3628
|
-
lastPage: number;
|
|
3629
|
-
hasMorePages: boolean;
|
|
3630
|
-
hasPages: boolean;
|
|
3631
|
-
};
|
|
3632
|
-
type CursorPaginationMetadata = {
|
|
3633
|
-
perPage: number;
|
|
3634
|
-
firstPage: number;
|
|
3635
|
-
isEmpty: boolean;
|
|
3636
|
-
total: number;
|
|
3637
|
-
};
|
|
3638
|
-
type PaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
|
|
3639
|
-
paginationMetadata: PaginationMetadata;
|
|
3640
|
-
data: AnnotatedModel<T, A, R>[];
|
|
3641
|
-
};
|
|
3642
|
-
type CursorPaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
|
|
3643
|
-
paginationMetadata: CursorPaginationMetadata;
|
|
3644
|
-
data: AnnotatedModel<T, A, R>[];
|
|
3645
|
-
};
|
|
3646
|
-
|
|
3647
|
-
type UpdateOptions = {
|
|
3648
|
-
ignoreBeforeUpdateHook?: boolean;
|
|
3649
|
-
};
|
|
3650
|
-
|
|
3651
|
-
/**
|
|
3652
|
-
* @description Due to query limitations some query builder methods may not be available in a RelationQueryBuilder
|
|
3653
|
-
*/
|
|
3654
|
-
type RelationQueryBuilderType<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<ModelQueryBuilder<T, A, R>, "increment" | "decrement" | "first" | "firstOrFail" | "paginate" | "pluck" | "truncate" | "many" | "one" | "oneOrFail" | "insert" | "insertMany" | "update" | "delete" | "softDelete" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "getMin" | "getMax" | "getCount">;
|
|
3655
|
-
|
|
3656
|
-
/**
|
|
3657
|
-
* Helper type to determine if annotation overrides model field or goes to $annotations
|
|
3658
|
-
* If K is a key of the model T, it overrides that field in the model.
|
|
3659
|
-
* Otherwise, it goes into the annotations object A.
|
|
3660
|
-
*/
|
|
3661
|
-
type AnnotationResult<T extends Model, A extends Record<string, any>, R extends Record<string, any>, K extends string, V> = K extends keyof T ? ModelQueryBuilder<T & {
|
|
3662
|
-
[P in K]: V;
|
|
3663
|
-
}, A, R> : ModelQueryBuilder<T, A & {
|
|
3664
|
-
[P in K]: V;
|
|
3665
|
-
}, R>;
|
|
3666
|
-
declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends QueryBuilder<T> {
|
|
3667
|
-
relation: Relation;
|
|
3668
|
-
protected sqlModelManagerUtils: SqlModelManagerUtils<T>;
|
|
3669
|
-
protected relationQueryBuilders: ModelQueryBuilder<any>[];
|
|
3670
|
-
protected modelSelectedColumns: string[];
|
|
3671
|
-
private modelColumnsMap;
|
|
3672
|
-
private modelColumnsDatabaseNames;
|
|
3673
|
-
protected limitValue?: number;
|
|
3674
|
-
protected offsetValue?: number;
|
|
3592
|
+
declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
3593
|
+
model: typeof Model;
|
|
3594
|
+
protected astParser: AstParser;
|
|
3595
|
+
protected unionNodes: UnionNode[];
|
|
3596
|
+
protected withNodes: WithNode[];
|
|
3597
|
+
protected lockQueryNodes: LockNode[];
|
|
3598
|
+
protected isNestedCondition: boolean;
|
|
3599
|
+
protected interpreterUtils: InterpreterUtils;
|
|
3600
|
+
protected insertNode: InsertNode | null;
|
|
3601
|
+
protected onDuplicateNode: OnDuplicateNode | null;
|
|
3602
|
+
protected updateNode: UpdateNode | null;
|
|
3603
|
+
protected deleteNode: DeleteNode | null;
|
|
3604
|
+
protected truncateNode: TruncateNode | null;
|
|
3605
|
+
protected replicationMode: ReplicationType | null;
|
|
3606
|
+
/**
|
|
3607
|
+
* @description Performance methods that return the time that took to execute the query with the result
|
|
3608
|
+
*/
|
|
3675
3609
|
performance: {
|
|
3676
|
-
many: (
|
|
3677
|
-
data:
|
|
3610
|
+
many: (returnType?: "millis" | "seconds") => Promise<{
|
|
3611
|
+
data: T[];
|
|
3678
3612
|
time: number;
|
|
3679
3613
|
}>;
|
|
3680
|
-
one: (
|
|
3681
|
-
data:
|
|
3614
|
+
one: (returnType?: "millis" | "seconds") => Promise<{
|
|
3615
|
+
data: T | null;
|
|
3682
3616
|
time: number;
|
|
3683
3617
|
}>;
|
|
3684
|
-
oneOrFail: (
|
|
3685
|
-
data:
|
|
3618
|
+
oneOrFail: (returnType?: "millis" | "seconds") => Promise<{
|
|
3619
|
+
data: T;
|
|
3686
3620
|
time: number;
|
|
3687
3621
|
}>;
|
|
3688
|
-
paginate: (page: number, perPage: number,
|
|
3689
|
-
|
|
3690
|
-
}, returnType?: "millis" | "seconds") => Promise<{
|
|
3691
|
-
data: PaginatedData<T, A, R>;
|
|
3622
|
+
paginate: (page: number, perPage: number, returnType?: "millis" | "seconds") => Promise<{
|
|
3623
|
+
data: PaginatedData<T>;
|
|
3692
3624
|
time: number;
|
|
3693
3625
|
}>;
|
|
3694
|
-
|
|
3695
|
-
data:
|
|
3626
|
+
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
3627
|
+
data: [CursorPaginatedData<T>, Cursor<T, ModelKey<T>>];
|
|
3696
3628
|
time: number;
|
|
3697
3629
|
}>;
|
|
3698
|
-
|
|
3699
|
-
data:
|
|
3630
|
+
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
3631
|
+
data: boolean;
|
|
3700
3632
|
time: number;
|
|
3701
3633
|
}>;
|
|
3702
3634
|
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
@@ -3707,7 +3639,15 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
|
|
|
3707
3639
|
data: number;
|
|
3708
3640
|
time: number;
|
|
3709
3641
|
}>;
|
|
3710
|
-
|
|
3642
|
+
insert: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
3643
|
+
data: T;
|
|
3644
|
+
time: number;
|
|
3645
|
+
}>;
|
|
3646
|
+
insertMany: (data: Record<string, any>[], returnType?: "millis" | "seconds") => Promise<{
|
|
3647
|
+
data: T[];
|
|
3648
|
+
time: number;
|
|
3649
|
+
}>;
|
|
3650
|
+
update: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
3711
3651
|
data: number;
|
|
3712
3652
|
time: number;
|
|
3713
3653
|
}>;
|
|
@@ -3720,1472 +3660,1709 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
|
|
|
3720
3660
|
time: number;
|
|
3721
3661
|
}>;
|
|
3722
3662
|
};
|
|
3723
|
-
constructor(model: typeof Model, sqlDataSource
|
|
3663
|
+
constructor(model: typeof Model, sqlDataSource?: SqlDataSource);
|
|
3724
3664
|
/**
|
|
3725
|
-
* @description
|
|
3726
|
-
* @
|
|
3665
|
+
* @description Sets the replication mode for the query builder
|
|
3666
|
+
* @param replicationMode - The replication mode to use for the query builder
|
|
3667
|
+
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
3668
|
+
* @description If set to "master", all operations will use master
|
|
3669
|
+
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
3727
3670
|
*/
|
|
3728
|
-
|
|
3671
|
+
setReplicationMode(replicationMode: ReplicationType): this;
|
|
3729
3672
|
/**
|
|
3730
|
-
* @description
|
|
3673
|
+
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
3731
3674
|
*/
|
|
3732
|
-
|
|
3733
|
-
one(options?: OneOptions): Promise<AnnotatedModel<T, A, R> | null>;
|
|
3734
|
-
oneOrFail(options?: {
|
|
3735
|
-
ignoreHooks?: OneOptions["ignoreHooks"] & {
|
|
3736
|
-
customError?: Error;
|
|
3737
|
-
};
|
|
3738
|
-
}): Promise<AnnotatedModel<T, A, R>>;
|
|
3739
|
-
firstOrFail(options?: {
|
|
3740
|
-
ignoreHooks?: OneOptions["ignoreHooks"] & {
|
|
3741
|
-
customError?: Error;
|
|
3742
|
-
};
|
|
3743
|
-
}): Promise<AnnotatedModel<T, A, R>>;
|
|
3744
|
-
many(options?: ManyOptions): Promise<AnnotatedModel<T, A, R>[]>;
|
|
3745
|
-
chunk(chunkSize: number, options?: ManyOptions): AsyncGenerator<AnnotatedModel<T, A, R>[]>;
|
|
3746
|
-
stream(options?: ManyOptions & StreamOptions): Promise<PassThrough & AsyncGenerator<AnnotatedModel<T, A, R>>>;
|
|
3747
|
-
paginateWithCursor<K extends ModelKey<T>>(page: number, options?: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[CursorPaginatedData<T, A, R>, Cursor<T, K>]>;
|
|
3675
|
+
exists(): Promise<boolean>;
|
|
3748
3676
|
/**
|
|
3749
|
-
* @description
|
|
3677
|
+
* @description Executes the query and retrieves multiple results.
|
|
3750
3678
|
*/
|
|
3751
|
-
|
|
3679
|
+
many(): Promise<T[]>;
|
|
3752
3680
|
/**
|
|
3753
|
-
* @description
|
|
3681
|
+
* @description Executes the query and retrieves a single column from the results.
|
|
3682
|
+
* @param key - The column to retrieve from the results, must be a Model Column
|
|
3754
3683
|
*/
|
|
3755
|
-
|
|
3756
|
-
update(data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions): Promise<number>;
|
|
3757
|
-
softDelete(options?: SoftDeleteOptions<T>): Promise<number>;
|
|
3758
|
-
delete(options?: DeleteOptions): Promise<number>;
|
|
3759
|
-
getCount(column?: string, options?: {
|
|
3760
|
-
ignoreHooks: boolean;
|
|
3761
|
-
}): Promise<number>;
|
|
3762
|
-
getMax(column: string, options?: {
|
|
3763
|
-
ignoreHooks: boolean;
|
|
3764
|
-
}): Promise<number>;
|
|
3765
|
-
getMin(column: string, options?: {
|
|
3766
|
-
ignoreHooks: boolean;
|
|
3767
|
-
}): Promise<number>;
|
|
3768
|
-
getAvg(column: string, options?: {
|
|
3769
|
-
ignoreHooks: boolean;
|
|
3770
|
-
}): Promise<number>;
|
|
3771
|
-
getSum(column: string, options?: {
|
|
3772
|
-
ignoreHooks: boolean;
|
|
3773
|
-
}): Promise<number>;
|
|
3774
|
-
paginate(page: number, perPage: number, options?: {
|
|
3775
|
-
ignoreHooks: boolean;
|
|
3776
|
-
}): Promise<PaginatedData<T, A, R>>;
|
|
3777
|
-
select<S extends string>(...columns: SelectableColumn<S>[]): this;
|
|
3778
|
-
select(...columns: (ModelKey<T> | "*")[]): this;
|
|
3684
|
+
pluck<K extends ModelKey<T>>(key: K): Promise<PluckReturnType<T, K>>;
|
|
3779
3685
|
/**
|
|
3780
|
-
* @description
|
|
3781
|
-
* @description If the alias matches a model field name, it overrides that field. Otherwise, it's available in $annotations
|
|
3782
|
-
* @example
|
|
3783
|
-
* ```ts
|
|
3784
|
-
* const user = await User.query().annotate("max", "id", "maxId").one(); // max(id) as maxId
|
|
3785
|
-
* const user = await User.query().annotate("id", "superId").one(); // id as superId
|
|
3786
|
-
* // If alias matches model field, it overrides it:
|
|
3787
|
-
* const user = await User.query().annotate("COUNT(*)", "email").one(); // user.email is now a number
|
|
3788
|
-
* ```
|
|
3686
|
+
* @description Executes the query and retrieves a single result.
|
|
3789
3687
|
*/
|
|
3790
|
-
|
|
3791
|
-
annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: string, column: string, alias: K): AnnotationResult<T, A, R, K, V>;
|
|
3792
|
-
annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): AnnotationResult<T, A, R, K, V>;
|
|
3793
|
-
annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): AnnotationResult<T, A, R, K, V>;
|
|
3688
|
+
one(): Promise<T | null>;
|
|
3794
3689
|
/**
|
|
3795
|
-
* @description
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
* @description
|
|
3800
|
-
* @description If
|
|
3690
|
+
* @description Executes the query and retrieves the first result. Fail if no result is found.
|
|
3691
|
+
*/
|
|
3692
|
+
oneOrFail(): Promise<T>;
|
|
3693
|
+
/**
|
|
3694
|
+
* @description Executes the query and returns a node readable stream.
|
|
3695
|
+
* @description If used by a model query builder, it will serialize the models and apply the hooks and relations.
|
|
3696
|
+
* @postgres needs the pg-query-stream package in order to work
|
|
3697
|
+
* @throws If using postgres and the `pg-query-stream` package is not installed
|
|
3698
|
+
*/
|
|
3699
|
+
stream<M extends Model = T>(options?: StreamOptions): Promise<PassThrough & AsyncGenerator<M>>;
|
|
3700
|
+
/**
|
|
3701
|
+
* @description Chunks the query into smaller queries, it returns a generator of the chunks
|
|
3702
|
+
* @description It will continue to yield chunks until the query returns no results
|
|
3703
|
+
* @description Useful for large queries that need to be processed in chunks
|
|
3704
|
+
* @warning overrides limit and offset set before in the query builder
|
|
3705
|
+
* @param chunkSize - The size of the chunk
|
|
3706
|
+
* @returns a generator of the chunks
|
|
3801
3707
|
* @example
|
|
3802
|
-
*
|
|
3803
|
-
* //
|
|
3804
|
-
*
|
|
3805
|
-
*
|
|
3806
|
-
*
|
|
3807
|
-
*
|
|
3808
|
-
*
|
|
3809
|
-
*
|
|
3810
|
-
*
|
|
3811
|
-
*
|
|
3812
|
-
* await User.query().selectJson("data", ["user", "name"], "userName").one();
|
|
3813
|
-
*
|
|
3814
|
-
* // 4. Array indices with dot notation
|
|
3815
|
-
* await User.query().selectJson("data", "items.0.name", "firstItemName").one();
|
|
3816
|
-
*
|
|
3817
|
-
* // 5. Array indices with array format
|
|
3818
|
-
* await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").one();
|
|
3819
|
-
*
|
|
3820
|
-
* // 6. Root object
|
|
3821
|
-
* await User.query().selectJson("data", "$", "allData").one();
|
|
3708
|
+
* const chunks = await queryBuilder.chunk(100);
|
|
3709
|
+
* // first chunk
|
|
3710
|
+
* const firstChunk = await chunks.next();
|
|
3711
|
+
* console.log(firstChunk.value);
|
|
3712
|
+
* // second chunk
|
|
3713
|
+
* const secondChunk = await chunks.next();
|
|
3714
|
+
* console.log(secondChunk.value);
|
|
3715
|
+
* // third chunk
|
|
3716
|
+
* const thirdChunk = await chunks.next();
|
|
3717
|
+
* console.log(thirdChunk.value);
|
|
3822
3718
|
*
|
|
3823
|
-
*
|
|
3824
|
-
* const
|
|
3825
|
-
*
|
|
3719
|
+
* @example
|
|
3720
|
+
* const chunkSize = 3;
|
|
3721
|
+
* const chunks = [];
|
|
3722
|
+
* const query = sql.query("users").orderBy("name", "asc");
|
|
3723
|
+
* for await (const chunk of sql.chunk(chunkSize)) {
|
|
3724
|
+
* chunks.push(chunk);
|
|
3725
|
+
* }
|
|
3826
3726
|
*
|
|
3827
|
-
*
|
|
3828
|
-
* const user2 = await User.query().selectJson("data", "$.name", "email").one();
|
|
3829
|
-
* console.log(user2?.email); // Overrides model's email field
|
|
3830
|
-
* ```
|
|
3727
|
+
* console.log(chunks);
|
|
3831
3728
|
*/
|
|
3832
|
-
|
|
3833
|
-
selectJson<K extends string>(column: string, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, any>;
|
|
3729
|
+
chunk(chunkSize: number): AsyncGenerator<T[], void, unknown>;
|
|
3834
3730
|
/**
|
|
3835
|
-
* @description
|
|
3836
|
-
* @
|
|
3837
|
-
* @
|
|
3838
|
-
* @
|
|
3839
|
-
* @
|
|
3840
|
-
* @
|
|
3841
|
-
* @
|
|
3842
|
-
*
|
|
3843
|
-
*
|
|
3844
|
-
*
|
|
3845
|
-
*
|
|
3846
|
-
* await User.query().selectJsonText("data", "$.user.email", "userEmail").one();
|
|
3847
|
-
*
|
|
3848
|
-
* // 2. Without $ prefix
|
|
3849
|
-
* await User.query().selectJsonText("data", "user.email", "userEmail").one();
|
|
3850
|
-
*
|
|
3851
|
-
* // 3. Array format
|
|
3852
|
-
* await User.query().selectJsonText("data", ["user", "email"], "userEmail").one();
|
|
3853
|
-
*
|
|
3854
|
-
* // 4. Array indices
|
|
3855
|
-
* await User.query().selectJsonText("data", "tags.0", "firstTag").one();
|
|
3856
|
-
* await User.query().selectJsonText("data", ["tags", 0], "firstTag").one();
|
|
3857
|
-
*
|
|
3858
|
-
* // 5. Deep nesting
|
|
3859
|
-
* await User.query().selectJsonText("data", "user.profile.bio", "biography").one();
|
|
3860
|
-
*
|
|
3861
|
-
* // Access the result - in $annotations if not a model field
|
|
3862
|
-
* const user = await User.query().selectJsonText("data", "user.email", "userEmail").one();
|
|
3863
|
-
* console.log(user?.$annotations?.userEmail); // Typed as string
|
|
3864
|
-
* ```
|
|
3731
|
+
* @description Executes the query and retrieves multiple paginated results.
|
|
3732
|
+
* @description Overrides the limit and offset clauses in order to paginate the results.
|
|
3733
|
+
* @description Allows to avoid offset clause that can be inefficient for large datasets
|
|
3734
|
+
* @description If using a model query builder, primary key is used as discriminator by default
|
|
3735
|
+
* @param options - The options for the paginate with cursor
|
|
3736
|
+
* @param options.discriminator - The discriminator to use for the paginate with Cursor pagination
|
|
3737
|
+
* @param options.operator - The operator to use for the paginate with Cursor pagination
|
|
3738
|
+
* @param options.orderBy - The order by to use for the paginate with Cursor pagination
|
|
3739
|
+
* @param cursor - The cursor to use for the paginate with Cursor pagination
|
|
3740
|
+
* @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")`
|
|
3741
|
+
* @returns the pagination metadata and the cursor for the next page
|
|
3865
3742
|
*/
|
|
3866
|
-
|
|
3867
|
-
selectJsonText<K extends string>(column: string, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, string>;
|
|
3743
|
+
paginateWithCursor<K extends ModelKey<T>>(limit: number, options: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[CursorPaginatedData<T>, Cursor<T, K>]>;
|
|
3868
3744
|
/**
|
|
3869
|
-
* @description Selects
|
|
3870
|
-
* @param column The column containing JSON array data
|
|
3871
|
-
* @param path The JSON path to the array (standardized format, use "$" or "" for root)
|
|
3872
|
-
* @param alias The alias for the length value
|
|
3873
|
-
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3874
|
-
* @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
|
|
3875
|
-
* @warning Not supported in SQLite
|
|
3876
|
-
* @example
|
|
3877
|
-
* ```ts
|
|
3878
|
-
* // All these path formats are supported:
|
|
3879
|
-
*
|
|
3880
|
-
* // 1. With $ prefix
|
|
3881
|
-
* await User.query().selectJsonArrayLength("data", "$.items", "itemCount").one();
|
|
3882
|
-
*
|
|
3883
|
-
* // 2. Without $ prefix
|
|
3884
|
-
* await User.query().selectJsonArrayLength("data", "items", "itemCount").one();
|
|
3885
|
-
*
|
|
3886
|
-
* // 3. Array format
|
|
3887
|
-
* await User.query().selectJsonArrayLength("data", ["items"], "itemCount").one();
|
|
3888
|
-
*
|
|
3889
|
-
* // 4. Root array (use "$" or "")
|
|
3890
|
-
* await User.query().selectJsonArrayLength("data", "$", "totalCount").one();
|
|
3891
|
-
* await User.query().selectJsonArrayLength("data", "", "totalCount").one();
|
|
3892
|
-
*
|
|
3893
|
-
* // 5. Nested arrays
|
|
3894
|
-
* await User.query().selectJsonArrayLength("data", "user.roles", "roleCount").one();
|
|
3895
|
-
* await User.query().selectJsonArrayLength("data", ["user", "roles"], "roleCount").one();
|
|
3896
|
-
*
|
|
3897
|
-
* // 6. Deeply nested arrays
|
|
3898
|
-
* await User.query().selectJsonArrayLength("data", "level1.level2.items", "deepCount").one();
|
|
3899
|
-
*
|
|
3900
|
-
* // Access the result - in $annotations if not a model field
|
|
3901
|
-
* const user = await User.query().selectJsonArrayLength("data", "items", "count").one();
|
|
3902
|
-
* console.log(user?.$annotations?.count); // Typed as number
|
|
3903
|
-
* ```
|
|
3745
|
+
* @description Selects a subquery, subquery must return a single column
|
|
3904
3746
|
*/
|
|
3905
|
-
|
|
3906
|
-
selectJsonArrayLength<K extends string>(column: string, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, number>;
|
|
3747
|
+
selectSubQuery(cbOrQueryBuilder: ((subQuery: QueryBuilder<T>) => void) | QueryBuilder<any>, alias: string): this;
|
|
3907
3748
|
/**
|
|
3908
|
-
* @description
|
|
3909
|
-
* @param
|
|
3910
|
-
* @
|
|
3911
|
-
* @param alias The alias for the keys
|
|
3912
|
-
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3913
|
-
* @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
|
|
3914
|
-
* @warning Not supported in SQLite or MSSQL
|
|
3915
|
-
* @postgresql Returns a native array of keys
|
|
3916
|
-
* @mysql Returns a JSON array of keys
|
|
3917
|
-
* @example
|
|
3918
|
-
* ```ts
|
|
3919
|
-
* // All these path formats are supported:
|
|
3920
|
-
*
|
|
3921
|
-
* // 1. With $ prefix
|
|
3922
|
-
* await User.query().selectJsonKeys("data", "$.settings", "settingKeys").one();
|
|
3923
|
-
*
|
|
3924
|
-
* // 2. Without $ prefix
|
|
3925
|
-
* await User.query().selectJsonKeys("data", "settings", "settingKeys").one();
|
|
3926
|
-
*
|
|
3927
|
-
* // 3. Array format
|
|
3928
|
-
* await User.query().selectJsonKeys("data", ["settings"], "settingKeys").one();
|
|
3929
|
-
*
|
|
3930
|
-
* // 4. Root object (use "$" or "")
|
|
3931
|
-
* await User.query().selectJsonKeys("data", "$", "rootKeys").one();
|
|
3932
|
-
* await User.query().selectJsonKeys("data", "", "rootKeys").one();
|
|
3933
|
-
*
|
|
3934
|
-
* // 5. Nested objects
|
|
3935
|
-
* await User.query().selectJsonKeys("data", "user.profile", "profileKeys").one();
|
|
3936
|
-
* await User.query().selectJsonKeys("data", ["user", "profile"], "profileKeys").one();
|
|
3937
|
-
*
|
|
3938
|
-
* // 6. Deeply nested objects
|
|
3939
|
-
* await User.query().selectJsonKeys("data", "settings.display.theme", "themeKeys").one();
|
|
3940
|
-
*
|
|
3941
|
-
* // Access the result - in $annotations if not a model field
|
|
3942
|
-
* const user = await User.query().selectJsonKeys("data", "settings", "keys").one();
|
|
3943
|
-
* console.log(user?.$annotations?.keys); // Typed as any[] - ["theme", "fontSize", "autoSave"]
|
|
3944
|
-
* ```
|
|
3749
|
+
* @description Locks the table for update
|
|
3750
|
+
* @param skipLocked - If true, the query will skip locked rows
|
|
3751
|
+
* @sqlite does not support skipping locked rows, it will be ignored
|
|
3945
3752
|
*/
|
|
3946
|
-
|
|
3947
|
-
|
|
3753
|
+
lockForUpdate(options?: {
|
|
3754
|
+
skipLocked?: boolean;
|
|
3755
|
+
noWait?: boolean;
|
|
3756
|
+
}): this;
|
|
3948
3757
|
/**
|
|
3949
|
-
* @description
|
|
3950
|
-
* @param
|
|
3951
|
-
* @
|
|
3952
|
-
* @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
|
|
3953
|
-
* @description Use this for advanced JSON operations not covered by other selectJson* methods
|
|
3954
|
-
* @warning This bypasses path standardization - you must write database-specific SQL
|
|
3955
|
-
* @example
|
|
3956
|
-
* ```ts
|
|
3957
|
-
* // PostgreSQL - Extract as text with ->> operator
|
|
3958
|
-
* await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
|
|
3959
|
-
*
|
|
3960
|
-
* // PostgreSQL - Extract nested JSON with -> operator
|
|
3961
|
-
* await User.query().selectJsonRaw("data->'user'->'profile'->>'name'", "profileName").one();
|
|
3962
|
-
*
|
|
3963
|
-
* // PostgreSQL - Array element access
|
|
3964
|
-
* await User.query().selectJsonRaw("data->'items'->0->>'name'", "firstName").one();
|
|
3965
|
-
*
|
|
3966
|
-
* // MySQL - Extract value with JSON_EXTRACT and ->>
|
|
3967
|
-
* await User.query().selectJsonRaw("data->>'$.email'", "userEmail").one();
|
|
3968
|
-
*
|
|
3969
|
-
* // MySQL - Array length with JSON_LENGTH
|
|
3970
|
-
* await User.query().selectJsonRaw("JSON_LENGTH(data, '$.items')", "itemCount").one();
|
|
3971
|
-
*
|
|
3972
|
-
* // MSSQL - Extract value with JSON_VALUE
|
|
3973
|
-
* await User.query().selectJsonRaw("JSON_VALUE(data, '$.email')", "userEmail").one();
|
|
3974
|
-
*
|
|
3975
|
-
* // SQLite - Extract value with json_extract
|
|
3976
|
-
* await User.query().selectJsonRaw("json_extract(data, '$.email')", "userEmail").one();
|
|
3977
|
-
*
|
|
3978
|
-
* // Access the result - in $annotations if not a model field
|
|
3979
|
-
* const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
|
|
3980
|
-
* console.log(user?.$annotations?.userEmail); // Typed as any
|
|
3981
|
-
* ```
|
|
3758
|
+
* @description Locks the table for share
|
|
3759
|
+
* @param skipLocked - If true, the query will skip locked rows
|
|
3760
|
+
* @sqlite does not support skipping locked rows, it will be ignored
|
|
3982
3761
|
*/
|
|
3983
|
-
|
|
3762
|
+
forShare(options?: {
|
|
3763
|
+
skipLocked?: boolean;
|
|
3764
|
+
noWait?: boolean;
|
|
3765
|
+
}): this;
|
|
3984
3766
|
/**
|
|
3985
|
-
* @description
|
|
3767
|
+
* @description Adds a UNION to the query.
|
|
3986
3768
|
*/
|
|
3987
|
-
|
|
3769
|
+
union(query: string, bindings?: any[]): this;
|
|
3770
|
+
union(cb: UnionCallBack<T>): this;
|
|
3988
3771
|
/**
|
|
3989
|
-
* @description
|
|
3990
|
-
* @warning Many to many relations have special behavior, since they require a join, a join clause will always be added to the query.
|
|
3991
|
-
* @warning Many to many relations uses the model foreign key for mapping in the `$annotations` property, this property will be removed from the model after the relation is filled.
|
|
3992
|
-
* @warning Foreign keys should always be selected in the relation query builder, otherwise the relation will not be filled.
|
|
3993
|
-
* @mssql HasMany relations with limit/offset and orderByRaw may fail with "Ambiguous column name" error - use fully qualified column names (e.g., `table.column`) in orderByRaw
|
|
3994
|
-
* @cockroachdb HasMany relations with limit/offset and orderByRaw may fail with "Ambiguous column name" error - use fully qualified column names (e.g., `table.column`) in orderByRaw
|
|
3772
|
+
* @description Adds a UNION ALL to the query.
|
|
3995
3773
|
*/
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
load<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: RelationQueryBuilderType<RelatedInstance<T, RelationKey>>) => void): ModelQueryBuilder<T, A, R & {
|
|
4000
|
-
[K in RelationKey]: Awaited<ReturnType<ModelQueryBuilder<RelatedInstance<T, K>, {}, {}>[RelationRetrieveMethod<T[K]>]>>;
|
|
4001
|
-
}>;
|
|
3774
|
+
unionAll(query: string, bindings?: any[]): this;
|
|
3775
|
+
unionAll(cb: UnionCallBack<T>): this;
|
|
3776
|
+
unionAll(queryBuilder: QueryBuilder<any>): this;
|
|
4002
3777
|
/**
|
|
4003
|
-
* @description
|
|
3778
|
+
* @description Increments the value of a column by a given amount
|
|
3779
|
+
* @typeSafe - In typescript, only numeric columns of the model will be accepted if using a Model
|
|
3780
|
+
* @default value + 1
|
|
3781
|
+
* @returns the number of affected rows
|
|
4004
3782
|
*/
|
|
4005
|
-
|
|
3783
|
+
increment(column: string, value: number): Promise<number>;
|
|
3784
|
+
increment(column: NumberModelKey<T>, value: number): Promise<number>;
|
|
4006
3785
|
/**
|
|
4007
|
-
* @description
|
|
4008
|
-
* @
|
|
3786
|
+
* @description Decrements the value of a column by a given amount
|
|
3787
|
+
* @typeSafe - In typescript, only numeric columns of the model will be accepted if using a Model
|
|
3788
|
+
* @default value - 1
|
|
3789
|
+
* @returns the number of affected rows
|
|
4009
3790
|
*/
|
|
4010
|
-
|
|
4011
|
-
|
|
3791
|
+
decrement(column: string, value: number): Promise<number>;
|
|
3792
|
+
decrement(column: NumberModelKey<T>, value: number): Promise<number>;
|
|
4012
3793
|
/**
|
|
4013
|
-
* @description
|
|
4014
|
-
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
3794
|
+
* @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.
|
|
4015
3795
|
*/
|
|
4016
|
-
|
|
4017
|
-
andHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
3796
|
+
getCount(column?: string): Promise<number>;
|
|
4018
3797
|
/**
|
|
4019
|
-
* @description
|
|
4020
|
-
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
3798
|
+
* @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.
|
|
4021
3799
|
*/
|
|
4022
|
-
|
|
4023
|
-
orHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
3800
|
+
getMax(column: string): Promise<number>;
|
|
4024
3801
|
/**
|
|
4025
|
-
* @description
|
|
4026
|
-
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
3802
|
+
* @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.
|
|
4027
3803
|
*/
|
|
4028
|
-
|
|
4029
|
-
notHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
3804
|
+
getMin(column: string): Promise<number>;
|
|
4030
3805
|
/**
|
|
4031
|
-
* @description
|
|
4032
|
-
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
3806
|
+
* @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.
|
|
4033
3807
|
*/
|
|
4034
|
-
|
|
4035
|
-
andNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
3808
|
+
getAvg(column: string): Promise<number>;
|
|
4036
3809
|
/**
|
|
4037
|
-
* @description
|
|
4038
|
-
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
3810
|
+
* @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.
|
|
4039
3811
|
*/
|
|
4040
|
-
|
|
4041
|
-
orNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
3812
|
+
getSum(column: string): Promise<number>;
|
|
4042
3813
|
/**
|
|
4043
|
-
* @description
|
|
3814
|
+
* @description Executes the query and retrieves multiple paginated results.
|
|
3815
|
+
* @description Overrides the limit and offset clauses in order to paginate the results.
|
|
4044
3816
|
*/
|
|
4045
|
-
|
|
3817
|
+
paginate(page: number, perPage: number): Promise<PaginatedData<T>>;
|
|
4046
3818
|
/**
|
|
4047
|
-
* @description
|
|
3819
|
+
* @description Overrides the from clause in the query.
|
|
4048
3820
|
*/
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
protected getRelatedModelsForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): Promise<ModelWithoutRelations<T>[]>;
|
|
4052
|
-
protected getRelatedModelsQueryForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): ModelQueryBuilder<T>;
|
|
4053
|
-
protected getFilterValuesFromModelsForRelation(relation: Relation, models: T[]): any[];
|
|
4054
|
-
protected applyHavingRelatedFilter(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, operator?: BinaryOperatorType, value?: BaseValues): void;
|
|
4055
|
-
protected addAdditionalColumnsToModel(row: any, typeofModel: typeof Model): Record<string, any>;
|
|
4056
|
-
private manyWithPerformance;
|
|
4057
|
-
private oneWithPerformance;
|
|
4058
|
-
private oneOrFailWithPerformance;
|
|
4059
|
-
private firstOrFailWithPerformance;
|
|
4060
|
-
private paginateWithPerformance;
|
|
4061
|
-
private paginateWithCursorWithPerformance;
|
|
4062
|
-
private existsWithPerformance;
|
|
4063
|
-
private pluckWithPerformance;
|
|
4064
|
-
private softDeleteWithPerformance;
|
|
4065
|
-
private updateWithPerformance;
|
|
4066
|
-
private deleteWithPerformance;
|
|
4067
|
-
private truncateWithPerformance;
|
|
4068
|
-
}
|
|
4069
|
-
|
|
4070
|
-
/**
|
|
4071
|
-
* Allows to get model queries without executing them
|
|
4072
|
-
*/
|
|
4073
|
-
declare class DryModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends ModelQueryBuilder<T, A, R> {
|
|
4074
|
-
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
4075
|
-
many(): this;
|
|
3821
|
+
from<S extends string>(table: TableFormat<S>, alias?: string): this;
|
|
3822
|
+
from(cb: (qb: QueryBuilder<T>) => void, alias: string): this;
|
|
4076
3823
|
/**
|
|
4077
|
-
* @description
|
|
4078
|
-
* @param args The arguments to pass to the insert method
|
|
4079
|
-
* @warning This method does not run model or column hooks
|
|
4080
|
-
* @returns The query builder
|
|
3824
|
+
* @description Adds a CTE to the query using a callback to build the subquery.
|
|
4081
3825
|
*/
|
|
4082
|
-
|
|
3826
|
+
with(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
4083
3827
|
/**
|
|
4084
|
-
* @description
|
|
4085
|
-
* @
|
|
4086
|
-
* @warning This method does not run model or column hooks
|
|
4087
|
-
* @returns The query builder
|
|
3828
|
+
* @description Adds a recursive CTE to the query using a callback to build the subquery.
|
|
3829
|
+
* @mssql not supported
|
|
4088
3830
|
*/
|
|
4089
|
-
|
|
3831
|
+
withRecursive(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
4090
3832
|
/**
|
|
4091
|
-
* @description
|
|
4092
|
-
* @
|
|
4093
|
-
* @
|
|
4094
|
-
* @returns The query builder
|
|
3833
|
+
* @description Adds a materialized CTE to the query using a callback to build the subquery.
|
|
3834
|
+
* @postgres only
|
|
3835
|
+
* @throws HysteriaError if the database type is not postgres
|
|
4095
3836
|
*/
|
|
4096
|
-
|
|
4097
|
-
/**
|
|
4098
|
-
* @description Builds the delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4099
|
-
* @param options Delete options
|
|
4100
|
-
* @returns The query builder
|
|
4101
|
-
*/
|
|
4102
|
-
delete(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["delete"]>): this;
|
|
4103
|
-
/**
|
|
4104
|
-
* @description Builds the truncate query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4105
|
-
* @returns The query builder
|
|
4106
|
-
*/
|
|
4107
|
-
truncate(): this;
|
|
4108
|
-
/**
|
|
4109
|
-
* @description Builds the soft delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4110
|
-
* @param options Soft delete options
|
|
4111
|
-
* @warning This method does not run model or column hooks
|
|
4112
|
-
* @returns The query builder
|
|
4113
|
-
*/
|
|
4114
|
-
softDelete(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["softDelete"]>): this;
|
|
4115
|
-
}
|
|
4116
|
-
|
|
4117
|
-
declare class ModelManager<T extends Model> {
|
|
4118
|
-
protected sqlDataSource: SqlDataSource;
|
|
4119
|
-
protected sqlType: SqlDataSourceType;
|
|
4120
|
-
protected logs: boolean;
|
|
4121
|
-
protected model: typeof Model;
|
|
4122
|
-
protected modelInstance: T;
|
|
4123
|
-
protected astParser: AstParser;
|
|
4124
|
-
protected interpreterUtils: InterpreterUtils;
|
|
4125
|
-
protected replicationMode: "master" | "slave" | null;
|
|
3837
|
+
withMaterialized(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
4126
3838
|
/**
|
|
4127
|
-
* @description
|
|
3839
|
+
* @description Insert record into a table, you can use raw statements in the data object for literal references to other columns
|
|
3840
|
+
* @param returning - The columns to return from the query, only supported by postgres and cockroachdb - default is "*"
|
|
3841
|
+
* @returns raw driver response
|
|
4128
3842
|
*/
|
|
4129
|
-
|
|
3843
|
+
insert(data: Record<string, WriteQueryParam$1>, returning?: string[]): Promise<T>;
|
|
4130
3844
|
/**
|
|
4131
|
-
* @description
|
|
3845
|
+
* @description Insert multiple records into a table
|
|
3846
|
+
* @param returning - The columns to return from the query, only supported by postgres and cockroachdb - default is "*"
|
|
3847
|
+
* @returns raw driver response
|
|
3848
|
+
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
4132
3849
|
*/
|
|
4133
|
-
|
|
3850
|
+
insertMany(data: Record<string, WriteQueryParam$1>[], returning?: string[]): Promise<T[]>;
|
|
4134
3851
|
/**
|
|
4135
|
-
* @description
|
|
3852
|
+
* @description Updates or creates a new record using upsert functionality
|
|
3853
|
+
* @param data The data to insert or update
|
|
3854
|
+
* @param searchCriteria The criteria to search for existing records
|
|
3855
|
+
* @param options Upsert options including updateOnConflict and returning columns
|
|
3856
|
+
* @returns The upserted record
|
|
4136
3857
|
*/
|
|
4137
|
-
|
|
3858
|
+
upsert<O extends Record<string, any>>(data: O, searchCriteria: Partial<O>, options?: UpsertOptionsRawBuilder): Promise<T[]>;
|
|
4138
3859
|
/**
|
|
4139
|
-
* @description
|
|
3860
|
+
* @description Updates or creates multiple records using upsert functionality
|
|
3861
|
+
* @param conflictColumns The columns to check for conflicts
|
|
3862
|
+
* @param columnsToUpdate The columns to update on conflict
|
|
3863
|
+
* @param data Array of data objects to insert or update
|
|
3864
|
+
* @param options Upsert options including updateOnConflict and returning columns
|
|
4140
3865
|
*/
|
|
4141
|
-
|
|
3866
|
+
upsertMany<O extends Record<string, any>>(conflictColumns: string[], columnsToUpdate: string[], data: O[], options?: UpsertOptionsRawBuilder): Promise<T[]>;
|
|
4142
3867
|
/**
|
|
4143
|
-
* @description
|
|
3868
|
+
* @description Executes a MERGE statement for MSSQL upsert operations (raw query builder)
|
|
4144
3869
|
*/
|
|
4145
|
-
|
|
3870
|
+
private executeMssqlMergeRaw;
|
|
4146
3871
|
/**
|
|
4147
|
-
* @description
|
|
4148
|
-
* @
|
|
4149
|
-
* @throws {HysteriaError} if the model has no primary key
|
|
3872
|
+
* @description Updates records from a table, you can use raw statements in the data object for literal references to other columns
|
|
3873
|
+
* @returns the number of affected rows
|
|
4150
3874
|
*/
|
|
4151
|
-
|
|
3875
|
+
update(data: Record<string, WriteQueryParam$1>): Promise<number>;
|
|
4152
3876
|
/**
|
|
4153
|
-
* @description
|
|
3877
|
+
* @description Deletes all records from a table
|
|
3878
|
+
* @warning This operation does not trigger any hook
|
|
4154
3879
|
*/
|
|
4155
|
-
|
|
3880
|
+
truncate(): Promise<void>;
|
|
4156
3881
|
/**
|
|
4157
|
-
* @description
|
|
3882
|
+
* @description Deletes records from a table
|
|
3883
|
+
* @returns the number of affected rows
|
|
4158
3884
|
*/
|
|
4159
|
-
|
|
4160
|
-
upsertMany(conflictColumns: string[], columnsToUpdate: string[], data: ModelWithoutRelations<T>[], options?: UpsertOptions<T>): Promise<AnnotatedModel<T, {}>[]>;
|
|
3885
|
+
delete(): Promise<number>;
|
|
4161
3886
|
/**
|
|
4162
|
-
* @description
|
|
3887
|
+
* @description Soft deletes records from a table
|
|
3888
|
+
* @default column - 'deletedAt'
|
|
3889
|
+
* @default value - The current date and time in UTC timezone in the format "YYYY-MM-DD HH:mm:ss"
|
|
3890
|
+
* @returns the number of affected rows
|
|
4163
3891
|
*/
|
|
4164
|
-
|
|
3892
|
+
softDelete(options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">): Promise<number>;
|
|
4165
3893
|
/**
|
|
4166
|
-
* @description
|
|
4167
|
-
* @description Model is retrieved from the database using the primary key regardless of any model hooks
|
|
4168
|
-
* @description Can only be used if the model has a primary key, use a massive update if the model has no primary key
|
|
3894
|
+
* @description Returns the query with the parameters bound to the query
|
|
4169
3895
|
*/
|
|
4170
|
-
|
|
4171
|
-
returning?: ModelKey<T>[];
|
|
4172
|
-
}): Promise<AnnotatedModel<T, {}>>;
|
|
3896
|
+
toQuery(): string;
|
|
4173
3897
|
/**
|
|
4174
|
-
* @description
|
|
4175
|
-
* @description Can only be used if the model has a primary key, use a massive delete if the model has no primary key
|
|
3898
|
+
* @description Returns the query with database driver placeholders and the params
|
|
4176
3899
|
*/
|
|
4177
|
-
|
|
3900
|
+
unWrap(): ReturnType<typeof AstParser.prototype.parse>;
|
|
4178
3901
|
/**
|
|
4179
|
-
* @description Returns a query builder instance
|
|
3902
|
+
* @description Returns a deep clone of the query builder instance.
|
|
4180
3903
|
*/
|
|
4181
|
-
|
|
3904
|
+
clone(): this;
|
|
4182
3905
|
/**
|
|
4183
|
-
* @description
|
|
4184
|
-
* @description The dry query builder instance will not execute the query, it will return the query statement
|
|
3906
|
+
* @description Gives a fresh instance of the query builder
|
|
4185
3907
|
*/
|
|
4186
|
-
|
|
3908
|
+
clear(): QueryBuilder<any>;
|
|
4187
3909
|
/**
|
|
4188
|
-
* @description
|
|
3910
|
+
* @description Removes the lock query
|
|
4189
3911
|
*/
|
|
4190
|
-
|
|
3912
|
+
clearLockQuery(): this;
|
|
4191
3913
|
/**
|
|
4192
|
-
* @description
|
|
4193
|
-
* This method inserts records one at a time to avoid duplicate ID issues.
|
|
4194
|
-
* After each insert, it queries the row back using unique columns to get the generated ID.
|
|
3914
|
+
* @description Removes any union query
|
|
4195
3915
|
*/
|
|
4196
|
-
|
|
4197
|
-
private handleWhereCondition;
|
|
4198
|
-
private applyFieldCondition;
|
|
4199
|
-
}
|
|
4200
|
-
|
|
4201
|
-
type TableColumnInfo = {
|
|
4202
|
-
name: string;
|
|
4203
|
-
dataType: string;
|
|
4204
|
-
isNullable: boolean;
|
|
4205
|
-
defaultValue: string | number | boolean | null;
|
|
4206
|
-
length?: number | null;
|
|
4207
|
-
precision?: number | null;
|
|
4208
|
-
scale?: number | null;
|
|
4209
|
-
withTimezone?: boolean | null;
|
|
4210
|
-
};
|
|
4211
|
-
type TableIndexInfo = {
|
|
4212
|
-
name: string;
|
|
4213
|
-
columns: string[];
|
|
4214
|
-
isUnique: boolean;
|
|
4215
|
-
};
|
|
4216
|
-
type TablePrimaryKeyInfo = {
|
|
4217
|
-
name?: string;
|
|
4218
|
-
columns: string[];
|
|
4219
|
-
};
|
|
4220
|
-
type TableSchemaInfo = {
|
|
4221
|
-
columns: TableColumnInfo[];
|
|
4222
|
-
indexes: TableIndexInfo[];
|
|
4223
|
-
foreignKeys: TableForeignKeyInfo[];
|
|
4224
|
-
primaryKey?: TablePrimaryKeyInfo;
|
|
4225
|
-
};
|
|
4226
|
-
type TableForeignKeyInfo = {
|
|
4227
|
-
name?: string;
|
|
4228
|
-
columns: string[];
|
|
4229
|
-
referencedTable: string;
|
|
4230
|
-
referencedColumns: string[];
|
|
4231
|
-
onDelete?: string | null;
|
|
4232
|
-
onUpdate?: string | null;
|
|
4233
|
-
};
|
|
4234
|
-
|
|
4235
|
-
/**
|
|
4236
|
-
* @description Maps a SqlDataSourceType to the raw driver response type
|
|
4237
|
-
*/
|
|
4238
|
-
type RawQueryResponseType<D extends SqlDataSourceType> = D extends "mysql" | "mariadb" ? QueryResult : D extends "postgres" | "cockroachdb" ? QueryResult$1 : D extends "sqlite" ? RunResult : D extends "mssql" ? IResult<any> : D extends "oracledb" ? Result<any> : any;
|
|
4239
|
-
|
|
4240
|
-
type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
4241
|
-
type StartTransactionOptions = {
|
|
4242
|
-
isolationLevel?: TransactionIsolationLevel;
|
|
4243
|
-
};
|
|
4244
|
-
/**
|
|
4245
|
-
* @description Options for the transaction execution
|
|
4246
|
-
*/
|
|
4247
|
-
type TransactionExecutionOptions = {
|
|
3916
|
+
clearUnionQuery(): this;
|
|
4248
3917
|
/**
|
|
4249
|
-
* @description
|
|
3918
|
+
* @description Removes any with query
|
|
4250
3919
|
*/
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
/**
|
|
4255
|
-
* @description Transaction class, not meant to be used directly, use sql.transaction() instead
|
|
4256
|
-
*/
|
|
4257
|
-
declare class Transaction {
|
|
3920
|
+
clearWithQuery(): this;
|
|
3921
|
+
extractQueryNodes(): QueryNode[];
|
|
3922
|
+
protected clearForFunctions(): this;
|
|
4258
3923
|
/**
|
|
4259
|
-
* @description
|
|
4260
|
-
* @example
|
|
4261
|
-
* ```ts
|
|
4262
|
-
* import { sql } from "hysteria-orm";
|
|
4263
|
-
* import { User } from "./models/user";
|
|
4264
|
-
*
|
|
4265
|
-
* // Raw queries
|
|
4266
|
-
* const trx = await sql.transaction();
|
|
4267
|
-
* await trx.rawQuery("SELECT * FROM users");
|
|
4268
|
-
*
|
|
4269
|
-
* // Model manager
|
|
4270
|
-
* const modelManager = trx.sql.getModelManager(User);
|
|
4271
|
-
* await modelManager.insert({ name: "John Doe" });
|
|
4272
|
-
*
|
|
4273
|
-
* // Query builder
|
|
4274
|
-
* await trx.query(User.table).insert({ name: "John Doe" });
|
|
4275
|
-
*
|
|
4276
|
-
* await trx.commit();
|
|
4277
|
-
* ```
|
|
3924
|
+
* @description Makes a many query and returns the time that took to execute that query
|
|
4278
3925
|
*/
|
|
4279
|
-
|
|
3926
|
+
private manyWithPerformance;
|
|
4280
3927
|
/**
|
|
4281
|
-
* @description
|
|
3928
|
+
* @description Makes a one query and returns the time that took to execute that query
|
|
4282
3929
|
*/
|
|
4283
|
-
|
|
3930
|
+
private oneWithPerformance;
|
|
4284
3931
|
/**
|
|
4285
|
-
* @
|
|
3932
|
+
* @alias oneOrFailWithPerformance
|
|
4286
3933
|
*/
|
|
4287
|
-
|
|
4288
|
-
private
|
|
4289
|
-
private
|
|
4290
|
-
private isNested;
|
|
4291
|
-
private nestingDepth;
|
|
4292
|
-
constructor(sql: SqlDataSource, isolationLevel?: TransactionIsolationLevel, isNested?: boolean, nestingDepth?: number);
|
|
3934
|
+
private firstOrFailWithPerformance;
|
|
3935
|
+
private paginateWithPerformance;
|
|
3936
|
+
private paginateWithCursorWithPerformance;
|
|
4293
3937
|
/**
|
|
4294
|
-
* @description
|
|
4295
|
-
* @description If a callback is provided, it will execute the callback and commit or rollback the nested transaction save points based on the callback's success or failure
|
|
3938
|
+
* @description Makes a one or fail query and returns the time that took to execute that query
|
|
4296
3939
|
*/
|
|
4297
|
-
|
|
4298
|
-
nestedTransaction(cb: (trx: Transaction) => Promise<void>): Promise<void>;
|
|
3940
|
+
private oneOrFailWithPerformance;
|
|
4299
3941
|
/**
|
|
4300
|
-
* @description
|
|
3942
|
+
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
3943
|
+
* @description Returns the time that took to execute the query
|
|
4301
3944
|
*/
|
|
4302
|
-
|
|
3945
|
+
private existsWithPerformance;
|
|
3946
|
+
private pluckWithPerformance;
|
|
3947
|
+
private updateWithPerformance;
|
|
3948
|
+
private insertWithPerformance;
|
|
3949
|
+
private insertManyWithPerformance;
|
|
3950
|
+
private softDeleteWithPerformance;
|
|
3951
|
+
private deleteWithPerformance;
|
|
3952
|
+
private truncateWithPerformance;
|
|
4303
3953
|
/**
|
|
4304
|
-
* @description
|
|
4305
|
-
* @
|
|
4306
|
-
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
3954
|
+
* @description Checks if the current context is an MSSQL transaction
|
|
3955
|
+
* @description MSSQL transactions can only handle one request at a time
|
|
4307
3956
|
*/
|
|
4308
|
-
|
|
3957
|
+
protected isMssqlTransaction(): boolean;
|
|
4309
3958
|
/**
|
|
4310
|
-
* @description
|
|
4311
|
-
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
4312
|
-
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
3959
|
+
* @description Executes pagination queries, serializing them for MSSQL transactions
|
|
4313
3960
|
*/
|
|
4314
|
-
|
|
3961
|
+
protected executePaginateQueries<M, C>(modelsQuery: () => Promise<M>, countQuery: () => Promise<C>): Promise<[M, C]>;
|
|
3962
|
+
protected getSqlDataSource(mode: "read" | "write"): Promise<SqlDataSource>;
|
|
4315
3963
|
/**
|
|
4316
|
-
* @description
|
|
3964
|
+
* @description Executes SQL with slave failure handling
|
|
3965
|
+
* @param mode The operation mode (read or write)
|
|
3966
|
+
* @param operation The execSql operation to perform
|
|
3967
|
+
* @returns The result of the operation
|
|
4317
3968
|
*/
|
|
4318
|
-
|
|
4319
|
-
private getIsolationLevelQuery;
|
|
4320
|
-
private getSavePointName;
|
|
4321
|
-
private getMssqlTransactionLevel;
|
|
3969
|
+
protected execSqlWithSlaveHandling<R>(mode: "read" | "write", operation: (dataSource: SqlDataSource) => Promise<R>): Promise<R>;
|
|
4322
3970
|
}
|
|
4323
3971
|
|
|
4324
3972
|
/**
|
|
4325
|
-
*
|
|
4326
|
-
* @example
|
|
4327
|
-
* ```ts
|
|
4328
|
-
* // Create and connect to a database
|
|
4329
|
-
* const sql = new SqlDataSource({
|
|
4330
|
-
* type: "mysql",
|
|
4331
|
-
* host: "localhost",
|
|
4332
|
-
* username: "root",
|
|
4333
|
-
* password: "password",
|
|
4334
|
-
* database: "mydb",
|
|
4335
|
-
* models: { User, Post }
|
|
4336
|
-
* });
|
|
4337
|
-
* await sql.connect();
|
|
4338
|
-
*
|
|
4339
|
-
* // Now you can use the connection
|
|
4340
|
-
* const users = await sql.query("users").many();
|
|
4341
|
-
* ```
|
|
3973
|
+
* Allows to get queries without executing them
|
|
4342
3974
|
*/
|
|
4343
|
-
declare class
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
private sqlType;
|
|
4347
|
-
private _models;
|
|
4348
|
-
private ownsPool;
|
|
3975
|
+
declare class DryQueryBuilder extends QueryBuilder {
|
|
3976
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3977
|
+
many(): this;
|
|
4349
3978
|
/**
|
|
4350
|
-
* @description
|
|
3979
|
+
* @description Builds the insert query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
3980
|
+
* @param args The arguments to pass to the insert method
|
|
3981
|
+
* @warning This method does not run model or column hooks
|
|
3982
|
+
* @returns The query builder
|
|
4351
3983
|
*/
|
|
4352
|
-
|
|
3984
|
+
insert(...args: Parameters<typeof QueryBuilder.prototype.insert>): this;
|
|
4353
3985
|
/**
|
|
4354
|
-
* @description
|
|
4355
|
-
* @
|
|
4356
|
-
* @
|
|
3986
|
+
* @description Builds the insert many query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
3987
|
+
* @param args The arguments to pass to the insert many method
|
|
3988
|
+
* @warning This method does not run model or column hooks
|
|
3989
|
+
* @returns The query builder
|
|
4357
3990
|
*/
|
|
4358
|
-
|
|
3991
|
+
insertMany(...args: Parameters<typeof QueryBuilder.prototype.insertMany>): this;
|
|
4359
3992
|
/**
|
|
4360
|
-
* @description
|
|
4361
|
-
* @
|
|
3993
|
+
* @description Builds the upsert query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
3994
|
+
* @param args The arguments to pass to the upsert method
|
|
3995
|
+
* @warning This method does not run model or column hooks
|
|
3996
|
+
* @returns The query builder
|
|
4362
3997
|
*/
|
|
4363
|
-
|
|
3998
|
+
upsert(...args: Parameters<typeof QueryBuilder.prototype.upsert>): this;
|
|
3999
|
+
upsertMany(...args: Parameters<typeof QueryBuilder.prototype.upsertMany>): this;
|
|
4364
4000
|
/**
|
|
4365
|
-
* @description
|
|
4001
|
+
* @description Builds the update query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4002
|
+
* @param data The data to update
|
|
4003
|
+
* @warning This method does not run model or column hooks
|
|
4004
|
+
* @returns The query builder
|
|
4366
4005
|
*/
|
|
4367
|
-
|
|
4006
|
+
update(data: Record<string, WriteQueryParam>): this;
|
|
4368
4007
|
/**
|
|
4369
|
-
* @description
|
|
4370
|
-
* @
|
|
4008
|
+
* @description Builds the delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4009
|
+
* @warning This method does not run model or column hooks
|
|
4010
|
+
* @returns The query builder
|
|
4371
4011
|
*/
|
|
4372
|
-
|
|
4012
|
+
delete(): this;
|
|
4373
4013
|
/**
|
|
4374
|
-
* @description
|
|
4014
|
+
* @description Builds the truncate query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4015
|
+
* @warning This method does not run model or column hooks
|
|
4016
|
+
* @returns The query builder
|
|
4017
|
+
*/
|
|
4018
|
+
truncate(): this;
|
|
4019
|
+
/**
|
|
4020
|
+
* @description Builds the soft delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4021
|
+
* @param options Soft delete options
|
|
4022
|
+
* @warning This method does not run model or column hooks
|
|
4023
|
+
* @returns The query builder
|
|
4024
|
+
*/
|
|
4025
|
+
softDelete(options?: Omit<SoftDeleteOptions<any>, "ignoreBeforeDeleteHook">): this;
|
|
4026
|
+
}
|
|
4027
|
+
|
|
4028
|
+
type PluckReturnType<T extends Model, K extends ModelKey<T>> = T[K] extends infer U ? U[] : never;
|
|
4029
|
+
type WhereOnlyQueryBuilder<T extends Model> = Pick<WhereQueryBuilder<T>, "where" | "andWhere" | "orWhere" | "whereNot" | "andWhereNot" | "orWhereNot" | "whereIn" | "andWhereIn" | "orWhereIn" | "whereNotIn" | "andWhereNotIn" | "orWhereNotIn" | "whereBetween" | "andWhereBetween" | "orWhereBetween" | "whereNotBetween" | "andWhereNotBetween" | "orWhereNotBetween" | "whereNull" | "andWhereNull" | "orWhereNull" | "whereNotNull" | "andWhereNotNull" | "orWhereNotNull" | "whereLike" | "andWhereLike" | "orWhereLike" | "whereILike" | "andWhereILike" | "orWhereILike" | "whereNotLike" | "andWhereNotLike" | "orWhereNotLike" | "whereNotILike" | "andWhereNotILike" | "orWhereNotILike" | "whereRegexp" | "andWhereRegexp" | "orWhereRegexp" | "whereNotRegexp" | "andWhereNotRegexp" | "orWhereNotRegexp" | "whereRaw" | "andWhereRaw" | "orWhereRaw" | "whereExists" | "orWhereExists" | "andWhereExists"> & Pick<JsonQueryBuilder<T>, "whereJson" | "andWhereJson" | "orWhereJson" | "whereJsonContains" | "andWhereJsonContains" | "orWhereJsonContains" | "whereJsonNotContains" | "andWhereJsonNotContains" | "orWhereJsonNotContains" | "whereJsonNotContains" | "andWhereJsonNotContains" | "orWhereJsonNotContains" | "whereJsonRaw" | "andWhereJsonRaw" | "orWhereJsonRaw" | "whereJsonNotContains" | "andWhereJsonNotContains" | "orWhereJsonNotContains">;
|
|
4030
|
+
type RelationRetrieveMethod<P extends any> = P extends any[] ? "many" : "one";
|
|
4031
|
+
type SelectableColumn$1<T extends string = string> = T extends `${infer Table}.${infer Column}.${string}` ? never : T extends `${string}(${string})` ? T : T extends `${string} as ${string}` ? T : T extends `${string} ${string}` ? never : T extends `.${string}` | `${string}.` ? never : T extends `${string}-${string}` ? never : T extends `${string}.${string}` ? T : T;
|
|
4032
|
+
/**
|
|
4033
|
+
* @description A column that can be used in a join statement e.g. `users.id`
|
|
4034
|
+
*/
|
|
4035
|
+
type JoinableColumn = `${string}.${string}`;
|
|
4036
|
+
/**
|
|
4037
|
+
* @description Options for streaming queries
|
|
4038
|
+
* @sqlite Ignores the options below
|
|
4039
|
+
*/
|
|
4040
|
+
type StreamOptions = {
|
|
4041
|
+
highWaterMark?: number;
|
|
4042
|
+
/** Postgres only */
|
|
4043
|
+
rowMode?: "array";
|
|
4044
|
+
/** Postgres only */
|
|
4045
|
+
batchSize?: number;
|
|
4046
|
+
/** Postgres only */
|
|
4047
|
+
types?: any;
|
|
4048
|
+
/** Mysql only */
|
|
4049
|
+
objectMode?: boolean;
|
|
4050
|
+
};
|
|
4051
|
+
type Cursor<T extends Model, K extends ModelKey<T>> = {
|
|
4052
|
+
key: K;
|
|
4053
|
+
value: string | number;
|
|
4054
|
+
};
|
|
4055
|
+
type PaginateWithCursorOptions<T extends Model, K extends ModelKey<T>> = {
|
|
4056
|
+
discriminator: K;
|
|
4057
|
+
operator?: "<" | ">";
|
|
4058
|
+
orderBy?: "asc" | "desc";
|
|
4059
|
+
};
|
|
4060
|
+
type UpsertOptionsRawBuilder = {
|
|
4061
|
+
updateOnConflict?: boolean;
|
|
4062
|
+
returning?: string[];
|
|
4063
|
+
};
|
|
4064
|
+
type DryQueryBuilderWithoutReadOperations = Omit<DryQueryBuilder, "many" | "one" | "oneOrFail" | "first" | "firstOrFail" | "paginate" | "paginateWithCursor" | "exists" | "pluck" | "increment" | "decrement" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "stream" | "chunk" | "paginate" | "paginateWithCursor" | "exists">;
|
|
4065
|
+
type DryModelQueryBuilderWithoutReadOperations<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<DryModelQueryBuilder<T, A, R>, "many" | "one" | "oneOrFail" | "first" | "firstOrFail" | "paginate" | "paginateWithCursor" | "exists" | "pluck" | "upsert" | "upsertMany" | "increment" | "decrement" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "stream" | "chunk" | "paginate" | "paginateWithCursor" | "exists">;
|
|
4066
|
+
type WriteQueryParam$1 = string | number | boolean | Date | RawNode | object | null | undefined;
|
|
4067
|
+
|
|
4068
|
+
declare class SqlModelManagerUtils<T extends Model> {
|
|
4069
|
+
protected dbType: SqlDataSourceType;
|
|
4070
|
+
protected sqlDataSource: SqlDataSource;
|
|
4071
|
+
protected modelRelations: Relation[];
|
|
4072
|
+
protected modelRelationsMap: Map<string, Relation>;
|
|
4073
|
+
constructor(typeofModel: typeof Model, dbType: SqlDataSourceType, sqlDataSource: SqlDataSource);
|
|
4074
|
+
getRelationFromModel(relation: ModelRelation<T>): Relation;
|
|
4075
|
+
}
|
|
4076
|
+
|
|
4077
|
+
type UpdateOptions = {
|
|
4078
|
+
ignoreBeforeUpdateHook?: boolean;
|
|
4079
|
+
};
|
|
4080
|
+
|
|
4081
|
+
/**
|
|
4082
|
+
* @description Due to query limitations some query builder methods may not be available in a RelationQueryBuilder
|
|
4083
|
+
*/
|
|
4084
|
+
type RelationQueryBuilderType<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<ModelQueryBuilder<T, A, R>, "increment" | "decrement" | "first" | "firstOrFail" | "paginate" | "pluck" | "truncate" | "many" | "one" | "oneOrFail" | "insert" | "insertMany" | "update" | "delete" | "softDelete" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "getMin" | "getMax" | "getCount">;
|
|
4085
|
+
|
|
4086
|
+
declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> = ModelWithoutRelations<T>, R extends Record<string, any> = {}> extends QueryBuilder<T> {
|
|
4087
|
+
relation: Relation;
|
|
4088
|
+
protected sqlModelManagerUtils: SqlModelManagerUtils<T>;
|
|
4089
|
+
protected relationQueryBuilders: ModelQueryBuilder<any>[];
|
|
4090
|
+
protected modelSelectedColumns: string[];
|
|
4091
|
+
private modelColumnsMap;
|
|
4092
|
+
private modelColumnsDatabaseNames;
|
|
4093
|
+
protected limitValue?: number;
|
|
4094
|
+
protected offsetValue?: number;
|
|
4095
|
+
performance: {
|
|
4096
|
+
many: (options?: ManyOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
4097
|
+
data: SelectedModel<S, R>[];
|
|
4098
|
+
time: number;
|
|
4099
|
+
}>;
|
|
4100
|
+
one: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
4101
|
+
data: SelectedModel<S, R> | null;
|
|
4102
|
+
time: number;
|
|
4103
|
+
}>;
|
|
4104
|
+
oneOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
4105
|
+
data: SelectedModel<S, R>;
|
|
4106
|
+
time: number;
|
|
4107
|
+
}>;
|
|
4108
|
+
paginate: (page: number, perPage: number, options?: {
|
|
4109
|
+
ignoreHooks?: boolean;
|
|
4110
|
+
}, returnType?: "millis" | "seconds") => Promise<{
|
|
4111
|
+
data: PaginatedData<T, S, R>;
|
|
4112
|
+
time: number;
|
|
4113
|
+
}>;
|
|
4114
|
+
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
4115
|
+
data: boolean;
|
|
4116
|
+
time: number;
|
|
4117
|
+
}>;
|
|
4118
|
+
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
4119
|
+
data: [CursorPaginatedData<T, S, R>, Cursor<T, ModelKey<T>>];
|
|
4120
|
+
time: number;
|
|
4121
|
+
}>;
|
|
4122
|
+
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
4123
|
+
data: void;
|
|
4124
|
+
time: number;
|
|
4125
|
+
}>;
|
|
4126
|
+
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
4127
|
+
data: number;
|
|
4128
|
+
time: number;
|
|
4129
|
+
}>;
|
|
4130
|
+
update: (data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
4131
|
+
data: number;
|
|
4132
|
+
time: number;
|
|
4133
|
+
}>;
|
|
4134
|
+
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
4135
|
+
data: number;
|
|
4136
|
+
time: number;
|
|
4137
|
+
}>;
|
|
4138
|
+
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
4139
|
+
data: PluckReturnType<T, ModelKey<T>>;
|
|
4140
|
+
time: number;
|
|
4141
|
+
}>;
|
|
4142
|
+
};
|
|
4143
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
4144
|
+
/**
|
|
4145
|
+
* @description Returns true if the query builder is a relation query builder, this changes the behavior of the query builder like limit, offset, etc.
|
|
4146
|
+
* @internal
|
|
4147
|
+
*/
|
|
4148
|
+
protected get isRelationQueryBuilder(): boolean;
|
|
4149
|
+
/**
|
|
4150
|
+
* @description Creates a new ModelQueryBuilder instance from a model. Will use the main connection to the database by default.
|
|
4151
|
+
*/
|
|
4152
|
+
static from(model: typeof Model, options?: BaseModelMethodOptions): ModelQueryBuilder<InstanceType<typeof model>>;
|
|
4153
|
+
one(options?: OneOptions): Promise<SelectedModel<S, R> | null>;
|
|
4154
|
+
oneOrFail(options?: {
|
|
4155
|
+
ignoreHooks?: OneOptions["ignoreHooks"] & {
|
|
4156
|
+
customError?: Error;
|
|
4157
|
+
};
|
|
4158
|
+
}): Promise<SelectedModel<S, R>>;
|
|
4159
|
+
firstOrFail(options?: {
|
|
4160
|
+
ignoreHooks?: OneOptions["ignoreHooks"] & {
|
|
4161
|
+
customError?: Error;
|
|
4162
|
+
};
|
|
4163
|
+
}): Promise<SelectedModel<S, R>>;
|
|
4164
|
+
many(options?: ManyOptions): Promise<SelectedModel<S, R>[]>;
|
|
4165
|
+
chunk(chunkSize: number, options?: ManyOptions): AsyncGenerator<SelectedModel<S, R>[]>;
|
|
4166
|
+
stream(options?: ManyOptions & StreamOptions): Promise<PassThrough & AsyncGenerator<SelectedModel<S, R>>>;
|
|
4167
|
+
paginateWithCursor<K extends ModelKey<T>>(page: number, options?: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[CursorPaginatedData<T, S, R>, Cursor<T, K>]>;
|
|
4168
|
+
/**
|
|
4169
|
+
* @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.
|
|
4170
|
+
*/
|
|
4171
|
+
insert(...args: Parameters<typeof this$1.model.insert<T>>): ReturnType<typeof this$1.model.insert>;
|
|
4172
|
+
/**
|
|
4173
|
+
* @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.
|
|
4174
|
+
*/
|
|
4175
|
+
insertMany(...args: Parameters<typeof this$1.model.insertMany<T>>): ReturnType<typeof this$1.model.insertMany>;
|
|
4176
|
+
update(data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions): Promise<number>;
|
|
4177
|
+
softDelete(options?: SoftDeleteOptions<T>): Promise<number>;
|
|
4178
|
+
delete(options?: DeleteOptions): Promise<number>;
|
|
4179
|
+
getCount(column?: string, options?: {
|
|
4180
|
+
ignoreHooks: boolean;
|
|
4181
|
+
}): Promise<number>;
|
|
4182
|
+
getMax(column: string, options?: {
|
|
4183
|
+
ignoreHooks: boolean;
|
|
4184
|
+
}): Promise<number>;
|
|
4185
|
+
getMin(column: string, options?: {
|
|
4186
|
+
ignoreHooks: boolean;
|
|
4187
|
+
}): Promise<number>;
|
|
4188
|
+
getAvg(column: string, options?: {
|
|
4189
|
+
ignoreHooks: boolean;
|
|
4190
|
+
}): Promise<number>;
|
|
4191
|
+
getSum(column: string, options?: {
|
|
4192
|
+
ignoreHooks: boolean;
|
|
4193
|
+
}): Promise<number>;
|
|
4194
|
+
paginate(page: number, perPage: number, options?: {
|
|
4195
|
+
ignoreHooks: boolean;
|
|
4196
|
+
}): Promise<PaginatedData<T, S, R>>;
|
|
4197
|
+
/**
|
|
4198
|
+
* @description Adds columns to the SELECT clause with full type safety.
|
|
4199
|
+
* @description Supports formats: "column", "table.column", "column as alias", "*", "table.*"
|
|
4200
|
+
* @description When columns are selected, the return type reflects only those columns
|
|
4201
|
+
* @example
|
|
4202
|
+
* ```ts
|
|
4203
|
+
* // Select specific columns - return type is { id: number, name: string }
|
|
4204
|
+
* const users = await User.query().select("id", "name").many();
|
|
4205
|
+
*
|
|
4206
|
+
* // Select with alias - return type includes the alias
|
|
4207
|
+
* const users = await User.query().select("id as userId").many();
|
|
4208
|
+
*
|
|
4209
|
+
* // Select all - return type is the full model
|
|
4210
|
+
* const users = await User.query().select("*").many();
|
|
4211
|
+
* ```
|
|
4212
|
+
*/
|
|
4213
|
+
select<Columns extends readonly SelectableColumn<T>[]>(...columns: Columns): ModelQueryBuilder<T, ComposeBuildSelect<S, T, Columns extends readonly string[] ? Columns : readonly string[]>, R>;
|
|
4214
|
+
/**
|
|
4215
|
+
* @description Adds a raw SELECT statement with type-safe return type.
|
|
4216
|
+
* @description Use the generic parameter to specify the type of the selected columns.
|
|
4217
|
+
* @example
|
|
4218
|
+
* ```ts
|
|
4219
|
+
* // Select raw with type - return type includes the typed columns
|
|
4220
|
+
* const users = await User.query()
|
|
4221
|
+
* .selectRaw<{ count: number }>("count(*) as count")
|
|
4222
|
+
* .many();
|
|
4223
|
+
* // users[0].count is typed as number
|
|
4224
|
+
*
|
|
4225
|
+
* // Can be chained with other selects
|
|
4226
|
+
* const users = await User.query()
|
|
4227
|
+
* .select("id")
|
|
4228
|
+
* .selectRaw<{ total: number }>("sum(amount) as total")
|
|
4229
|
+
* .many();
|
|
4230
|
+
* // users[0] is { id: number, total: number }
|
|
4231
|
+
* ```
|
|
4232
|
+
*/
|
|
4233
|
+
selectRaw<Added extends Record<string, any> = Record<string, any>>(statement: string): ModelQueryBuilder<T, ComposeSelect<S, Added>, R>;
|
|
4234
|
+
/**
|
|
4235
|
+
* @description Selects a subquery with a typed alias
|
|
4236
|
+
* @param cbOrQueryBuilder A callback that receives a QueryBuilder or a QueryBuilder instance
|
|
4237
|
+
* @param alias The alias for the subquery result
|
|
4238
|
+
* @description Subquery must return a single column
|
|
4239
|
+
* @example
|
|
4240
|
+
* ```ts
|
|
4241
|
+
* const users = await User.query()
|
|
4242
|
+
* .select("id")
|
|
4243
|
+
* .selectSubQuery<number, "postCount">((subQuery) => {
|
|
4244
|
+
* subQuery
|
|
4245
|
+
* .select("COUNT(*)")
|
|
4246
|
+
* .from("posts")
|
|
4247
|
+
* .whereColumn("posts.user_id", "users.id");
|
|
4248
|
+
* }, "postCount")
|
|
4249
|
+
* .many();
|
|
4250
|
+
* // users[0].postCount is typed as number
|
|
4251
|
+
* ```
|
|
4252
|
+
*/
|
|
4253
|
+
selectSubQuery<ValueType = any, Alias extends string = string>(cbOrQueryBuilder: ((subQuery: QueryBuilder<T>) => void) | QueryBuilder<any>, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4254
|
+
[K in Alias]: ValueType;
|
|
4255
|
+
}>, R>;
|
|
4256
|
+
/**
|
|
4257
|
+
* @description Clears the SELECT clause and resets to default model type
|
|
4258
|
+
* @example
|
|
4259
|
+
* ```ts
|
|
4260
|
+
* const users = await User.query()
|
|
4261
|
+
* .select("id")
|
|
4262
|
+
* .clearSelect() // Resets to selecting all model columns
|
|
4263
|
+
* .many();
|
|
4264
|
+
* ```
|
|
4265
|
+
*/
|
|
4266
|
+
clearSelect(): ModelQueryBuilder<T, ModelWithoutRelations<T>, R>;
|
|
4267
|
+
/**
|
|
4268
|
+
* @description Selects a JSON value at the specified path and returns it as JSON
|
|
4269
|
+
* @param column The column containing JSON data
|
|
4270
|
+
* @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
|
|
4271
|
+
* @param alias The alias for the selected value
|
|
4272
|
+
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
4273
|
+
* @description Result is available as a direct property on the model with the alias name
|
|
4274
|
+
* @example
|
|
4275
|
+
* ```ts
|
|
4276
|
+
* // All these path formats are supported:
|
|
4277
|
+
*
|
|
4278
|
+
* // 1. With $ prefix (standard JSON path)
|
|
4279
|
+
* await User.query().selectJson("data", "$.user.name", "userName").one();
|
|
4280
|
+
*
|
|
4281
|
+
* // 2. Without $ prefix ($ is optional)
|
|
4282
|
+
* await User.query().selectJson("data", "user.name", "userName").one();
|
|
4283
|
+
*
|
|
4284
|
+
* // 3. Array format
|
|
4285
|
+
* await User.query().selectJson("data", ["user", "name"], "userName").one();
|
|
4286
|
+
*
|
|
4287
|
+
* // 4. Array indices with dot notation
|
|
4288
|
+
* await User.query().selectJson("data", "items.0.name", "firstItemName").one();
|
|
4289
|
+
*
|
|
4290
|
+
* // 5. Array indices with array format
|
|
4291
|
+
* await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").one();
|
|
4292
|
+
*
|
|
4293
|
+
* // 6. Root object
|
|
4294
|
+
* await User.query().selectJson("data", "$", "allData").one();
|
|
4295
|
+
*
|
|
4296
|
+
* // Access the result directly on the model
|
|
4297
|
+
* const user = await User.query().selectJson<string, "userName">("data", "user.name", "userName").one();
|
|
4298
|
+
* console.log(user?.userName); // Typed as string
|
|
4299
|
+
* ```
|
|
4300
|
+
*/
|
|
4301
|
+
selectJson<ValueType = any, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4302
|
+
[K in Alias]: ValueType;
|
|
4303
|
+
}>, R>;
|
|
4304
|
+
/**
|
|
4305
|
+
* @description Selects a JSON value at the specified path and returns it as text
|
|
4306
|
+
* @param column The column containing JSON data
|
|
4307
|
+
* @param path The JSON path to extract (standardized format)
|
|
4308
|
+
* @param alias The alias for the selected value
|
|
4309
|
+
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
4310
|
+
* @description Result is available as a direct property on the model with the alias name
|
|
4311
|
+
* @example
|
|
4312
|
+
* ```ts
|
|
4313
|
+
* // All these path formats are supported:
|
|
4314
|
+
*
|
|
4315
|
+
* // 1. With $ prefix
|
|
4316
|
+
* await User.query().selectJsonText("data", "$.user.email", "userEmail").one();
|
|
4317
|
+
*
|
|
4318
|
+
* // 2. Without $ prefix
|
|
4319
|
+
* await User.query().selectJsonText("data", "user.email", "userEmail").one();
|
|
4320
|
+
*
|
|
4321
|
+
* // 3. Array format
|
|
4322
|
+
* await User.query().selectJsonText("data", ["user", "email"], "userEmail").one();
|
|
4323
|
+
*
|
|
4324
|
+
* // 4. Array indices
|
|
4325
|
+
* await User.query().selectJsonText("data", "tags.0", "firstTag").one();
|
|
4326
|
+
* await User.query().selectJsonText("data", ["tags", 0], "firstTag").one();
|
|
4327
|
+
*
|
|
4328
|
+
* // 5. Deep nesting
|
|
4329
|
+
* await User.query().selectJsonText("data", "user.profile.bio", "biography").one();
|
|
4330
|
+
*
|
|
4331
|
+
* // Access the result directly on the model
|
|
4332
|
+
* const user = await User.query().selectJsonText<string, "userEmail">("data", "user.email", "userEmail").one();
|
|
4333
|
+
* console.log(user?.userEmail); // Typed as string
|
|
4334
|
+
* ```
|
|
4335
|
+
*/
|
|
4336
|
+
selectJsonText<ValueType = string, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4337
|
+
[K in Alias]: ValueType;
|
|
4338
|
+
}>, R>;
|
|
4339
|
+
/**
|
|
4340
|
+
* @description Selects the length of a JSON array
|
|
4341
|
+
* @param column The column containing JSON array data
|
|
4342
|
+
* @param path The JSON path to the array (standardized format, use "$" or "" for root)
|
|
4343
|
+
* @param alias The alias for the length value
|
|
4344
|
+
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
4345
|
+
* @description Result is available as a direct property on the model with the alias name
|
|
4346
|
+
* @warning Not supported in SQLite
|
|
4347
|
+
* @example
|
|
4348
|
+
* ```ts
|
|
4349
|
+
* // All these path formats are supported:
|
|
4350
|
+
*
|
|
4351
|
+
* // 1. With $ prefix
|
|
4352
|
+
* await User.query().selectJsonArrayLength("data", "$.items", "itemCount").one();
|
|
4353
|
+
*
|
|
4354
|
+
* // 2. Without $ prefix
|
|
4355
|
+
* await User.query().selectJsonArrayLength("data", "items", "itemCount").one();
|
|
4356
|
+
*
|
|
4357
|
+
* // 3. Array format
|
|
4358
|
+
* await User.query().selectJsonArrayLength("data", ["items"], "itemCount").one();
|
|
4359
|
+
*
|
|
4360
|
+
* // 4. Root array (use "$" or "")
|
|
4361
|
+
* await User.query().selectJsonArrayLength("data", "$", "totalCount").one();
|
|
4362
|
+
* await User.query().selectJsonArrayLength("data", "", "totalCount").one();
|
|
4363
|
+
*
|
|
4364
|
+
* // 5. Nested arrays
|
|
4365
|
+
* await User.query().selectJsonArrayLength("data", "user.roles", "roleCount").one();
|
|
4366
|
+
* await User.query().selectJsonArrayLength("data", ["user", "roles"], "roleCount").one();
|
|
4367
|
+
*
|
|
4368
|
+
* // 6. Deeply nested arrays
|
|
4369
|
+
* await User.query().selectJsonArrayLength("data", "level1.level2.items", "deepCount").one();
|
|
4370
|
+
*
|
|
4371
|
+
* // Access the result directly on the model
|
|
4372
|
+
* const user = await User.query().selectJsonArrayLength<number, "count">("data", "items", "count").one();
|
|
4373
|
+
* console.log(user?.count); // Typed as number
|
|
4374
|
+
* ```
|
|
4375
|
+
*/
|
|
4376
|
+
selectJsonArrayLength<ValueType = number, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4377
|
+
[K in Alias]: ValueType;
|
|
4378
|
+
}>, R>;
|
|
4379
|
+
/**
|
|
4380
|
+
* @description Selects the keys of a JSON object
|
|
4381
|
+
* @param column The column containing JSON object data
|
|
4382
|
+
* @param path The JSON path to the object (standardized format, use "$" or "" for root)
|
|
4383
|
+
* @param alias The alias for the keys
|
|
4384
|
+
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
4385
|
+
* @description Result is available as a direct property on the model with the alias name
|
|
4386
|
+
* @warning Not supported in SQLite or MSSQL
|
|
4387
|
+
* @postgresql Returns a native array of keys
|
|
4388
|
+
* @mysql Returns a JSON array of keys
|
|
4389
|
+
* @example
|
|
4390
|
+
* ```ts
|
|
4391
|
+
* // All these path formats are supported:
|
|
4392
|
+
*
|
|
4393
|
+
* // 1. With $ prefix
|
|
4394
|
+
* await User.query().selectJsonKeys("data", "$.settings", "settingKeys").one();
|
|
4395
|
+
*
|
|
4396
|
+
* // 2. Without $ prefix
|
|
4397
|
+
* await User.query().selectJsonKeys("data", "settings", "settingKeys").one();
|
|
4398
|
+
*
|
|
4399
|
+
* // 3. Array format
|
|
4400
|
+
* await User.query().selectJsonKeys("data", ["settings"], "settingKeys").one();
|
|
4401
|
+
*
|
|
4402
|
+
* // 4. Root object (use "$" or "")
|
|
4403
|
+
* await User.query().selectJsonKeys("data", "$", "rootKeys").one();
|
|
4404
|
+
* await User.query().selectJsonKeys("data", "", "rootKeys").one();
|
|
4405
|
+
*
|
|
4406
|
+
* // 5. Nested objects
|
|
4407
|
+
* await User.query().selectJsonKeys("data", "user.profile", "profileKeys").one();
|
|
4408
|
+
* await User.query().selectJsonKeys("data", ["user", "profile"], "profileKeys").one();
|
|
4409
|
+
*
|
|
4410
|
+
* // 6. Deeply nested objects
|
|
4411
|
+
* await User.query().selectJsonKeys("data", "settings.display.theme", "themeKeys").one();
|
|
4412
|
+
*
|
|
4413
|
+
* // Access the result directly on the model
|
|
4414
|
+
* const user = await User.query().selectJsonKeys<string[], "keys">("data", "settings", "keys").one();
|
|
4415
|
+
* console.log(user?.keys); // Typed as string[] - ["theme", "fontSize", "autoSave"]
|
|
4416
|
+
* ```
|
|
4375
4417
|
*/
|
|
4376
|
-
|
|
4418
|
+
selectJsonKeys<ValueType = string[], Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4419
|
+
[K in Alias]: ValueType;
|
|
4420
|
+
}>, R>;
|
|
4377
4421
|
/**
|
|
4378
|
-
* @description
|
|
4422
|
+
* @description Adds a raw JSON select expression for database-specific operations
|
|
4423
|
+
* @param raw The raw SQL expression (database-specific syntax)
|
|
4424
|
+
* @param alias The alias for the selected value
|
|
4425
|
+
* @description Result is available as a direct property on the model with the alias name
|
|
4426
|
+
* @description Use this for advanced JSON operations not covered by other selectJson* methods
|
|
4427
|
+
* @warning This bypasses path standardization - you must write database-specific SQL
|
|
4428
|
+
* @example
|
|
4429
|
+
* ```ts
|
|
4430
|
+
* // PostgreSQL - Extract as text with ->> operator
|
|
4431
|
+
* await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
|
|
4432
|
+
*
|
|
4433
|
+
* // PostgreSQL - Extract nested JSON with -> operator
|
|
4434
|
+
* await User.query().selectJsonRaw("data->'user'->'profile'->>'name'", "profileName").one();
|
|
4435
|
+
*
|
|
4436
|
+
* // PostgreSQL - Array element access
|
|
4437
|
+
* await User.query().selectJsonRaw("data->'items'->0->>'name'", "firstName").one();
|
|
4438
|
+
*
|
|
4439
|
+
* // MySQL - Extract value with json_extract and ->>
|
|
4440
|
+
* await User.query().selectJsonRaw("data->>'$.email'", "userEmail").one();
|
|
4441
|
+
*
|
|
4442
|
+
* // MySQL - Array length with json_length
|
|
4443
|
+
* await User.query().selectJsonRaw("json_length(data, '$.items')", "itemCount").one();
|
|
4444
|
+
*
|
|
4445
|
+
* // MSSQL - Extract value with json_value
|
|
4446
|
+
* await User.query().selectJsonRaw("json_value(data, '$.email')", "userEmail").one();
|
|
4447
|
+
*
|
|
4448
|
+
* // SQLite - Extract value with json_extract
|
|
4449
|
+
* await User.query().selectJsonRaw("json_extract(data, '$.email')", "userEmail").one();
|
|
4450
|
+
*
|
|
4451
|
+
* // Access the result directly on the model
|
|
4452
|
+
* const user = await User.query().selectJsonRaw<string, "userEmail">("data->>'email'", "userEmail").one();
|
|
4453
|
+
* console.log(user?.userEmail); // Typed as string
|
|
4454
|
+
* ```
|
|
4379
4455
|
*/
|
|
4380
|
-
|
|
4456
|
+
selectJsonRaw<ValueType = any, Alias extends string = string>(raw: string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4457
|
+
[K in Alias]: ValueType;
|
|
4458
|
+
}>, R>;
|
|
4381
4459
|
/**
|
|
4382
|
-
* @description
|
|
4460
|
+
* @description Selects COUNT(column) with a typed alias
|
|
4461
|
+
* @param column The column to count (use "*" for COUNT(*), supports "table.column" format)
|
|
4462
|
+
* @param alias The alias for the count result
|
|
4463
|
+
* @example
|
|
4464
|
+
* ```ts
|
|
4465
|
+
* // Count all rows
|
|
4466
|
+
* const result = await User.query().selectCount("*", "totalUsers").one();
|
|
4467
|
+
* console.log(result?.totalUsers); // Typed as number
|
|
4468
|
+
*
|
|
4469
|
+
* // Count specific column
|
|
4470
|
+
* const result = await User.query().selectCount("id", "userCount").one();
|
|
4471
|
+
*
|
|
4472
|
+
* // With table prefix
|
|
4473
|
+
* const result = await User.query().selectCount("users.id", "total").one();
|
|
4474
|
+
* ```
|
|
4383
4475
|
*/
|
|
4384
|
-
|
|
4476
|
+
selectCount<Alias extends string>(column: ModelKey<T> | "*" | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4477
|
+
[K in Alias]: number;
|
|
4478
|
+
}>, R>;
|
|
4385
4479
|
/**
|
|
4386
|
-
* @description
|
|
4480
|
+
* @description Selects SUM(column) with a typed alias
|
|
4481
|
+
* @param column The column to sum (supports "table.column" format)
|
|
4482
|
+
* @param alias The alias for the sum result
|
|
4483
|
+
* @example
|
|
4484
|
+
* ```ts
|
|
4485
|
+
* const result = await Order.query().selectSum("amount", "totalAmount").one();
|
|
4486
|
+
* console.log(result?.totalAmount); // Typed as number
|
|
4487
|
+
*
|
|
4488
|
+
* // With table prefix
|
|
4489
|
+
* const result = await Order.query().selectSum("orders.amount", "total").one();
|
|
4490
|
+
* ```
|
|
4387
4491
|
*/
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
lock: boolean;
|
|
4392
|
-
transactional: boolean;
|
|
4393
|
-
lockTimeout?: number;
|
|
4394
|
-
};
|
|
4492
|
+
selectSum<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4493
|
+
[K in Alias]: number;
|
|
4494
|
+
}>, R>;
|
|
4395
4495
|
/**
|
|
4396
|
-
* @description
|
|
4496
|
+
* @description Selects AVG(column) with a typed alias
|
|
4497
|
+
* @param column The column to average (supports "table.column" format)
|
|
4498
|
+
* @param alias The alias for the average result
|
|
4499
|
+
* @example
|
|
4500
|
+
* ```ts
|
|
4501
|
+
* const result = await User.query().selectAvg("age", "averageAge").one();
|
|
4502
|
+
* console.log(result?.averageAge); // Typed as number
|
|
4503
|
+
*
|
|
4504
|
+
* // With table prefix
|
|
4505
|
+
* const result = await User.query().selectAvg("users.age", "avgAge").one();
|
|
4506
|
+
* ```
|
|
4397
4507
|
*/
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
};
|
|
4508
|
+
selectAvg<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4509
|
+
[K in Alias]: number;
|
|
4510
|
+
}>, R>;
|
|
4402
4511
|
/**
|
|
4403
|
-
* @description
|
|
4512
|
+
* @description Selects MIN(column) with a typed alias
|
|
4513
|
+
* @param column The column to get minimum value (supports "table.column" format)
|
|
4514
|
+
* @param alias The alias for the min result
|
|
4515
|
+
* @example
|
|
4516
|
+
* ```ts
|
|
4517
|
+
* const result = await User.query().selectMin("age", "youngestAge").one();
|
|
4518
|
+
* console.log(result?.youngestAge); // Typed as number
|
|
4519
|
+
*
|
|
4520
|
+
* // With table prefix
|
|
4521
|
+
* const result = await User.query().selectMin("users.age", "minAge").one();
|
|
4522
|
+
* ```
|
|
4404
4523
|
*/
|
|
4405
|
-
|
|
4524
|
+
selectMin<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4525
|
+
[K in Alias]: number;
|
|
4526
|
+
}>, R>;
|
|
4406
4527
|
/**
|
|
4407
|
-
* @description
|
|
4528
|
+
* @description Selects MAX(column) with a typed alias
|
|
4529
|
+
* @param column The column to get maximum value (supports "table.column" format)
|
|
4530
|
+
* @param alias The alias for the max result
|
|
4531
|
+
* @example
|
|
4532
|
+
* ```ts
|
|
4533
|
+
* const result = await User.query().selectMax("age", "oldestAge").one();
|
|
4534
|
+
* console.log(result?.oldestAge); // Typed as number
|
|
4535
|
+
*
|
|
4536
|
+
* // With table prefix
|
|
4537
|
+
* const result = await User.query().selectMax("users.age", "maxAge").one();
|
|
4538
|
+
* ```
|
|
4408
4539
|
*/
|
|
4409
|
-
|
|
4540
|
+
selectMax<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4541
|
+
[K in Alias]: number;
|
|
4542
|
+
}>, R>;
|
|
4410
4543
|
/**
|
|
4411
|
-
* @description
|
|
4544
|
+
* @description Fills the relations in the model in the serialized response. Relation must be defined in the model.
|
|
4545
|
+
* @warning Many to many relations have special behavior, since they require a join, a join clause will always be added to the query.
|
|
4546
|
+
* @warning Many to many relations uses the model foreign key for mapping, this property will be removed from the model after the relation is filled.
|
|
4547
|
+
* @warning Foreign keys should always be selected in the relation query builder, otherwise the relation will not be filled.
|
|
4548
|
+
* @mssql HasMany relations with limit/offset and orderByRaw may fail with "Ambiguous column name" error - use fully qualified column names (e.g., `table.column`) in orderByRaw
|
|
4549
|
+
* @cockroachdb HasMany relations with limit/offset and orderByRaw may fail with "Ambiguous column name" error - use fully qualified column names (e.g., `table.column`) in orderByRaw
|
|
4412
4550
|
*/
|
|
4413
|
-
|
|
4551
|
+
load<RelationKey extends ModelRelation<T>, IS extends Record<string, any> = ModelWithoutRelations<RelatedInstance<T, RelationKey>>, IR extends Record<string, any> = {}>(relation: RelationKey, cb: (queryBuilder: RelationQueryBuilderType<RelatedInstance<T, RelationKey>, ModelWithoutRelations<RelatedInstance<T, RelationKey>>, {}>) => RelationQueryBuilderType<RelatedInstance<T, RelationKey>, IS, IR>): ModelQueryBuilder<T, S, R & {
|
|
4552
|
+
[K in RelationKey]: Awaited<ReturnType<ModelQueryBuilder<RelatedInstance<T, K>, IS, IR>[RelationRetrieveMethod<T[K]>]>>;
|
|
4553
|
+
}>;
|
|
4554
|
+
load<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: RelationQueryBuilderType<RelatedInstance<T, RelationKey>, ModelWithoutRelations<RelatedInstance<T, RelationKey>>, {}>) => void): ModelQueryBuilder<T, S, R & {
|
|
4555
|
+
[K in RelationKey]: Awaited<ReturnType<ModelQueryBuilder<RelatedInstance<T, K>, ModelWithoutRelations<RelatedInstance<T, K>>, {}>[RelationRetrieveMethod<T[K]>]>>;
|
|
4556
|
+
}>;
|
|
4414
4557
|
/**
|
|
4415
|
-
* @description
|
|
4558
|
+
* @description Clears the relations from the query builder
|
|
4416
4559
|
*/
|
|
4417
|
-
|
|
4560
|
+
clearRelations(): this;
|
|
4418
4561
|
/**
|
|
4419
|
-
* @description
|
|
4420
|
-
* All
|
|
4562
|
+
* @description Checks if the relation exists in the models and has the given filters, if no callback is provided, it only check if there is at least one record for the relation
|
|
4563
|
+
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
4421
4564
|
*/
|
|
4422
|
-
|
|
4565
|
+
havingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
|
|
4566
|
+
havingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
4423
4567
|
/**
|
|
4424
|
-
* @description
|
|
4425
|
-
* @
|
|
4426
|
-
* @example
|
|
4427
|
-
* ```ts
|
|
4428
|
-
* const secondaryDb = await SqlDataSource.connectToSecondarySource({
|
|
4429
|
-
* type: "postgres",
|
|
4430
|
-
* host: "replica.db.com",
|
|
4431
|
-
* ...
|
|
4432
|
-
* });
|
|
4433
|
-
*
|
|
4434
|
-
* const user = await User.query({ connection: secondaryDb }).many();
|
|
4435
|
-
* ```
|
|
4568
|
+
* @description Checks if the relation exists in the models and has the given filters, if no callback is provided, it only check if there is at least one record for the relation
|
|
4569
|
+
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
4436
4570
|
*/
|
|
4437
|
-
|
|
4571
|
+
andHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
|
|
4572
|
+
andHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
4438
4573
|
/**
|
|
4439
|
-
* @description
|
|
4440
|
-
* @
|
|
4441
|
-
* ```ts
|
|
4442
|
-
* await SqlDataSource.useConnection({
|
|
4443
|
-
* type: "mysql",
|
|
4444
|
-
* ...connectionData
|
|
4445
|
-
* }, async (sql) => {
|
|
4446
|
-
* const user = await User.query({ connection: sql }).many();
|
|
4447
|
-
* });
|
|
4448
|
-
* // Connection is automatically closed here
|
|
4449
|
-
* ```
|
|
4574
|
+
* @description Checks if the relation exists in the models and has the given filters, if no callback is provided, it only check if there is at least one record for the relation,
|
|
4575
|
+
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
4450
4576
|
*/
|
|
4451
|
-
|
|
4577
|
+
orHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
|
|
4578
|
+
orHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
4452
4579
|
/**
|
|
4453
|
-
* @description
|
|
4580
|
+
* @description Checks if the relation does not exist in the models and has the given filters, if no callback is provided, it only check if there is no record for the Relation
|
|
4581
|
+
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
4454
4582
|
*/
|
|
4455
|
-
|
|
4583
|
+
notHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
|
|
4584
|
+
notHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
4456
4585
|
/**
|
|
4457
|
-
* @description
|
|
4458
|
-
* @
|
|
4586
|
+
* @description Checks if the relation does not exist in the models and has the given filters, if no callback is provided, it only check if there is no record for the relation
|
|
4587
|
+
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
4459
4588
|
*/
|
|
4460
|
-
|
|
4589
|
+
andNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
|
|
4590
|
+
andNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
4461
4591
|
/**
|
|
4462
|
-
* @description
|
|
4463
|
-
* @
|
|
4592
|
+
* @description Checks if the relation does not exist in the models and has the given filters, if no callback is provided, it only check if there is no record for the Relation
|
|
4593
|
+
* @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
|
|
4464
4594
|
*/
|
|
4465
|
-
|
|
4595
|
+
orNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
|
|
4596
|
+
orNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
|
|
4466
4597
|
/**
|
|
4467
|
-
* @description
|
|
4468
|
-
* @throws {HysteriaError} If the global transaction is not started
|
|
4598
|
+
* @description Returns a copy of the query builder instance.
|
|
4469
4599
|
*/
|
|
4470
|
-
|
|
4600
|
+
clone(): this;
|
|
4471
4601
|
/**
|
|
4472
|
-
* @description
|
|
4602
|
+
* @description Recursively processes all relations, including nested ones
|
|
4473
4603
|
*/
|
|
4474
|
-
|
|
4604
|
+
protected processRelationsRecursively(models: T[]): Promise<void>;
|
|
4605
|
+
protected mapRelatedModelsToModels<R extends ModelWithoutRelations<T>>(relation: Relation, modelsToFillWithRelations: T[], relatedModels: R[]): void;
|
|
4606
|
+
protected getRelatedModelsForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): Promise<ModelWithoutRelations<T>[]>;
|
|
4607
|
+
protected getRelatedModelsQueryForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): ModelQueryBuilder<any, any, any>;
|
|
4608
|
+
protected getFilterValuesFromModelsForRelation(relation: Relation, models: T[]): any[];
|
|
4609
|
+
protected applyHavingRelatedFilter(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, operator?: BinaryOperatorType, value?: BaseValues): void;
|
|
4610
|
+
protected addAdditionalColumnsToModel(row: any, typeofModel: typeof Model): Record<string, any>;
|
|
4611
|
+
private manyWithPerformance;
|
|
4612
|
+
private oneWithPerformance;
|
|
4613
|
+
private oneOrFailWithPerformance;
|
|
4614
|
+
private firstOrFailWithPerformance;
|
|
4615
|
+
private paginateWithPerformance;
|
|
4616
|
+
private paginateWithCursorWithPerformance;
|
|
4617
|
+
private existsWithPerformance;
|
|
4618
|
+
private pluckWithPerformance;
|
|
4619
|
+
private softDeleteWithPerformance;
|
|
4620
|
+
private updateWithPerformance;
|
|
4621
|
+
private deleteWithPerformance;
|
|
4622
|
+
private truncateWithPerformance;
|
|
4623
|
+
}
|
|
4624
|
+
|
|
4625
|
+
/**
|
|
4626
|
+
* Allows to get model queries without executing them
|
|
4627
|
+
*/
|
|
4628
|
+
declare class DryModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends ModelQueryBuilder<T, A, R> {
|
|
4629
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
4630
|
+
many(): this;
|
|
4475
4631
|
/**
|
|
4476
|
-
* @description
|
|
4477
|
-
* @param
|
|
4478
|
-
* @
|
|
4479
|
-
*
|
|
4480
|
-
* // With explicit config
|
|
4481
|
-
* const sql = new SqlDataSource({
|
|
4482
|
-
* type: "mysql",
|
|
4483
|
-
* host: "localhost",
|
|
4484
|
-
* username: "root",
|
|
4485
|
-
* password: "password",
|
|
4486
|
-
* database: "mydb",
|
|
4487
|
-
* models: { User, Post }
|
|
4488
|
-
* });
|
|
4489
|
-
* await sql.connect();
|
|
4490
|
-
*
|
|
4491
|
-
* // Using env variables
|
|
4492
|
-
* const sql = new SqlDataSource();
|
|
4493
|
-
* await sql.connect();
|
|
4494
|
-
* ```
|
|
4632
|
+
* @description Builds the insert query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4633
|
+
* @param args The arguments to pass to the insert method
|
|
4634
|
+
* @warning This method does not run model or column hooks
|
|
4635
|
+
* @returns The query builder
|
|
4495
4636
|
*/
|
|
4496
|
-
|
|
4637
|
+
insert(...args: Parameters<typeof this$1.model.insert<T>>): this;
|
|
4497
4638
|
/**
|
|
4498
|
-
* @description
|
|
4499
|
-
* @
|
|
4500
|
-
* @
|
|
4501
|
-
*
|
|
4502
|
-
* const sql = new SqlDataSource({ type: "mysql", ... });
|
|
4503
|
-
* await sql.connect();
|
|
4504
|
-
* ```
|
|
4639
|
+
* @description Builds the insert many query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4640
|
+
* @param args The arguments to pass to the insert many method
|
|
4641
|
+
* @warning This method does not run model or column hooks
|
|
4642
|
+
* @returns The query builder
|
|
4505
4643
|
*/
|
|
4506
|
-
|
|
4644
|
+
insertMany(...args: Parameters<typeof this$1.model.insertMany<T>>): this;
|
|
4507
4645
|
/**
|
|
4508
|
-
* @description
|
|
4646
|
+
* @description Builds the update query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4647
|
+
* @param data The data to update
|
|
4648
|
+
* @warning This method does not run model or column hooks
|
|
4649
|
+
* @returns The query builder
|
|
4509
4650
|
*/
|
|
4510
|
-
|
|
4651
|
+
update(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["update"]>): this;
|
|
4511
4652
|
/**
|
|
4512
|
-
* @description
|
|
4653
|
+
* @description Builds the delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4654
|
+
* @param options Delete options
|
|
4655
|
+
* @returns The query builder
|
|
4513
4656
|
*/
|
|
4514
|
-
|
|
4657
|
+
delete(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["delete"]>): this;
|
|
4515
4658
|
/**
|
|
4516
|
-
* @description
|
|
4659
|
+
* @description Builds the truncate query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4660
|
+
* @returns The query builder
|
|
4517
4661
|
*/
|
|
4518
|
-
|
|
4662
|
+
truncate(): this;
|
|
4519
4663
|
/**
|
|
4520
|
-
* @description
|
|
4521
|
-
* @
|
|
4664
|
+
* @description Builds the soft delete query statement without executing it, use 'unWrap' or 'toQuery' to get the query statement
|
|
4665
|
+
* @param options Soft delete options
|
|
4666
|
+
* @warning This method does not run model or column hooks
|
|
4667
|
+
* @returns The query builder
|
|
4522
4668
|
*/
|
|
4523
|
-
|
|
4669
|
+
softDelete(...args: Parameters<ReturnType<typeof this$1.model.query<T>>["softDelete"]>): this;
|
|
4670
|
+
}
|
|
4671
|
+
|
|
4672
|
+
declare class ModelManager<T extends Model> {
|
|
4673
|
+
protected sqlDataSource: SqlDataSource;
|
|
4674
|
+
protected sqlType: SqlDataSourceType;
|
|
4675
|
+
protected logs: boolean;
|
|
4676
|
+
protected model: typeof Model;
|
|
4677
|
+
protected modelInstance: T;
|
|
4678
|
+
protected astParser: AstParser;
|
|
4679
|
+
protected interpreterUtils: InterpreterUtils;
|
|
4680
|
+
protected replicationMode: "master" | "slave" | null;
|
|
4524
4681
|
/**
|
|
4525
|
-
* @description
|
|
4526
|
-
* @param key The key to get the value from
|
|
4527
|
-
* @param args The arguments to pass to the key handler
|
|
4682
|
+
* @description Constructor for ModelManager class.
|
|
4528
4683
|
*/
|
|
4529
|
-
|
|
4684
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
4530
4685
|
/**
|
|
4531
|
-
* @description
|
|
4532
|
-
* @param key The key to get the value from
|
|
4533
|
-
* @param ttl The time to live for the value in milliseconds
|
|
4534
|
-
* @param args The arguments to pass to the key handler
|
|
4686
|
+
* @description Sets the replication mode for queries created by this model manager
|
|
4535
4687
|
*/
|
|
4536
|
-
|
|
4688
|
+
setReplicationMode(mode: "master" | "slave"): this;
|
|
4537
4689
|
/**
|
|
4538
|
-
* @description
|
|
4539
|
-
* @param key The key to invalidate the value from
|
|
4540
|
-
* @param args The arguments to pass to the key handler (required if the handler expects arguments)
|
|
4690
|
+
* @description Finds all records that match the input
|
|
4541
4691
|
*/
|
|
4542
|
-
|
|
4543
|
-
invalidCache<K extends keyof C>(key: K): Promise<void>;
|
|
4692
|
+
find<S extends ModelKey<T>[] = never[], R extends ModelRelation<T>[] = never[]>(input?: FindType<T, S, R>): Promise<ModelWithoutRelations<T>[]>;
|
|
4544
4693
|
/**
|
|
4545
|
-
* @description
|
|
4546
|
-
* @param key The key to invalidate the values from
|
|
4694
|
+
* @description Finds the first record that matches the input
|
|
4547
4695
|
*/
|
|
4548
|
-
|
|
4696
|
+
findOne<S extends ModelKey<T>[] = never[], R extends ModelRelation<T>[] = never[]>(input: FindOneType<T, S, R>): Promise<ModelWithoutRelations<T> | null>;
|
|
4549
4697
|
/**
|
|
4550
|
-
* @description
|
|
4551
|
-
* @param options.shouldRecreatePool Whether to recreate the pool of connections for the given driver, by default it's false
|
|
4552
|
-
* @sqlite ignores the shouldRecreatePool option
|
|
4553
|
-
* @returns A new SqlDataSource instance with the same input details
|
|
4698
|
+
* @description Finds the first record that matches the input or throws an error
|
|
4554
4699
|
*/
|
|
4555
|
-
|
|
4700
|
+
findOneOrFail<S extends ModelKey<T>[] = never[], R extends ModelRelation<T>[] = never[]>(input: FindOneType<T, S, R>): Promise<ModelWithoutRelations<T>>;
|
|
4556
4701
|
/**
|
|
4557
|
-
* @description
|
|
4702
|
+
* @description Finds a record by its primary key
|
|
4703
|
+
* @description Ignores all model hooks
|
|
4704
|
+
* @throws {HysteriaError} if the model has no primary key
|
|
4558
4705
|
*/
|
|
4559
|
-
|
|
4706
|
+
findOneByPrimaryKey(value: string | number, returning?: ModelKey<T>[]): Promise<ModelWithoutRelations<T> | null>;
|
|
4560
4707
|
/**
|
|
4561
|
-
* @description
|
|
4562
|
-
* @description Query builder from the SqlDataSource instance returns raw data from the database
|
|
4563
|
-
* @param table The table name to query from
|
|
4708
|
+
* @description Creates a new record in the database
|
|
4564
4709
|
*/
|
|
4565
|
-
|
|
4710
|
+
insert(model: Partial<T>, options?: InsertOptions<T>): Promise<ModelWithoutRelations<T>>;
|
|
4566
4711
|
/**
|
|
4567
|
-
* @description
|
|
4712
|
+
* @description Creates multiple records in the database
|
|
4568
4713
|
*/
|
|
4569
|
-
|
|
4714
|
+
insertMany(models: Partial<T>[], options?: InsertOptions<T>): Promise<ModelWithoutRelations<T>[]>;
|
|
4715
|
+
upsertMany(conflictColumns: string[], columnsToUpdate: string[], data: ModelWithoutRelations<T>[], options?: UpsertOptions<T>): Promise<ModelWithoutRelations<T>[]>;
|
|
4570
4716
|
/**
|
|
4571
|
-
* @description
|
|
4717
|
+
* @description Executes a MERGE statement for MSSQL upsert operations
|
|
4572
4718
|
*/
|
|
4573
|
-
|
|
4719
|
+
private executeMssqlMerge;
|
|
4574
4720
|
/**
|
|
4575
|
-
* @description
|
|
4721
|
+
* @description Updates a record, returns the updated record
|
|
4722
|
+
* @description Model is retrieved from the database using the primary key regardless of any model hooks
|
|
4723
|
+
* @description Can only be used if the model has a primary key, use a massive update if the model has no primary key
|
|
4576
4724
|
*/
|
|
4577
|
-
|
|
4725
|
+
updateRecord(model: Partial<T>, options?: {
|
|
4726
|
+
returning?: ModelKey<T>[];
|
|
4727
|
+
}): Promise<ModelWithoutRelations<T>>;
|
|
4578
4728
|
/**
|
|
4579
|
-
* @description
|
|
4580
|
-
* @description
|
|
4729
|
+
* @description Deletes a record
|
|
4730
|
+
* @description Can only be used if the model has a primary key, use a massive delete if the model has no primary key
|
|
4581
4731
|
*/
|
|
4582
|
-
|
|
4732
|
+
deleteRecord(model: T): Promise<void>;
|
|
4583
4733
|
/**
|
|
4584
|
-
* @description
|
|
4585
|
-
* @throws {HysteriaError} If the global transaction is not started
|
|
4734
|
+
* @description Returns a query builder instance
|
|
4586
4735
|
*/
|
|
4587
|
-
|
|
4736
|
+
query(): Omit<ModelQueryBuilder<T>, "insert" | "insertMany">;
|
|
4588
4737
|
/**
|
|
4589
|
-
* @description
|
|
4738
|
+
* @description Returns a dry query builder instance
|
|
4739
|
+
* @description The dry query builder instance will not execute the query, it will return the query statement
|
|
4590
4740
|
*/
|
|
4591
|
-
|
|
4741
|
+
dryQuery(): Omit<DryModelQueryBuilder<T>, "insert" | "insertMany">;
|
|
4592
4742
|
/**
|
|
4593
|
-
* @description
|
|
4594
|
-
* @param cb if a callback is provided, it will execute the callback and commit or rollback the transaction based on the callback's success or failure
|
|
4595
|
-
* @param options.isolationLevel The isolation level to use for the transaction
|
|
4596
|
-
* @sqlite ignores the isolation level
|
|
4743
|
+
* @description Mysql does not return the inserted model, so we need to get the inserted model from the database
|
|
4597
4744
|
*/
|
|
4598
|
-
|
|
4599
|
-
transaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
4745
|
+
private handleMysqlInsert;
|
|
4600
4746
|
/**
|
|
4601
|
-
* @description
|
|
4747
|
+
* @description Oracle with identity columns doesn't support INSERT ALL properly.
|
|
4748
|
+
* This method inserts records one at a time to avoid duplicate ID issues.
|
|
4749
|
+
* After each insert, it queries the row back using unique columns to get the generated ID.
|
|
4602
4750
|
*/
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4751
|
+
private handleOracleIdentityInsert;
|
|
4752
|
+
private handleWhereCondition;
|
|
4753
|
+
private applyFieldCondition;
|
|
4754
|
+
}
|
|
4755
|
+
|
|
4756
|
+
type TableColumnInfo = {
|
|
4757
|
+
name: string;
|
|
4758
|
+
dataType: string;
|
|
4759
|
+
isNullable: boolean;
|
|
4760
|
+
defaultValue: string | number | boolean | null;
|
|
4761
|
+
length?: number | null;
|
|
4762
|
+
precision?: number | null;
|
|
4763
|
+
scale?: number | null;
|
|
4764
|
+
withTimezone?: boolean | null;
|
|
4765
|
+
};
|
|
4766
|
+
type TableIndexInfo = {
|
|
4767
|
+
name: string;
|
|
4768
|
+
columns: string[];
|
|
4769
|
+
isUnique: boolean;
|
|
4770
|
+
};
|
|
4771
|
+
type TablePrimaryKeyInfo = {
|
|
4772
|
+
name?: string;
|
|
4773
|
+
columns: string[];
|
|
4774
|
+
};
|
|
4775
|
+
type TableSchemaInfo = {
|
|
4776
|
+
columns: TableColumnInfo[];
|
|
4777
|
+
indexes: TableIndexInfo[];
|
|
4778
|
+
foreignKeys: TableForeignKeyInfo[];
|
|
4779
|
+
primaryKey?: TablePrimaryKeyInfo;
|
|
4780
|
+
};
|
|
4781
|
+
type TableForeignKeyInfo = {
|
|
4782
|
+
name?: string;
|
|
4783
|
+
columns: string[];
|
|
4784
|
+
referencedTable: string;
|
|
4785
|
+
referencedColumns: string[];
|
|
4786
|
+
onDelete?: string | null;
|
|
4787
|
+
onUpdate?: string | null;
|
|
4788
|
+
};
|
|
4789
|
+
|
|
4790
|
+
/**
|
|
4791
|
+
* @description Maps a SqlDataSourceType to the raw driver response type
|
|
4792
|
+
*/
|
|
4793
|
+
type RawQueryResponseType<D extends SqlDataSourceType> = D extends "mysql" | "mariadb" ? QueryResult : D extends "postgres" | "cockroachdb" ? QueryResult$1 : D extends "sqlite" ? RunResult : D extends "mssql" ? IResult<any> : D extends "oracledb" ? Result<any> : any;
|
|
4794
|
+
|
|
4795
|
+
type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
4796
|
+
type StartTransactionOptions = {
|
|
4797
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
4798
|
+
};
|
|
4799
|
+
/**
|
|
4800
|
+
* @description Options for the transaction execution
|
|
4801
|
+
*/
|
|
4802
|
+
type TransactionExecutionOptions = {
|
|
4606
4803
|
/**
|
|
4607
|
-
* @description
|
|
4608
|
-
* @throws {HysteriaError} If the connection pool is not established
|
|
4804
|
+
* @description If true, the transaction will throw an error if it is inactive
|
|
4609
4805
|
*/
|
|
4610
|
-
|
|
4806
|
+
throwErrorOnInactiveTransaction?: boolean;
|
|
4807
|
+
};
|
|
4808
|
+
|
|
4809
|
+
/**
|
|
4810
|
+
* @description Transaction class, not meant to be used directly, use sql.transaction() instead
|
|
4811
|
+
*/
|
|
4812
|
+
declare class Transaction {
|
|
4611
4813
|
/**
|
|
4612
|
-
* @description
|
|
4613
|
-
* @
|
|
4814
|
+
* @description The sql data source instance that the transaction is running on here you can both query or execute raw queries
|
|
4815
|
+
* @example
|
|
4816
|
+
* ```ts
|
|
4817
|
+
* import { sql } from "hysteria-orm";
|
|
4818
|
+
* import { User } from "./models/user";
|
|
4819
|
+
*
|
|
4820
|
+
* // Raw queries
|
|
4821
|
+
* const trx = await sql.transaction();
|
|
4822
|
+
* await trx.rawQuery("SELECT * FROM users");
|
|
4823
|
+
*
|
|
4824
|
+
* // Model manager
|
|
4825
|
+
* const modelManager = trx.sql.getModelManager(User);
|
|
4826
|
+
* await modelManager.insert({ name: "John Doe" });
|
|
4827
|
+
*
|
|
4828
|
+
* // Query builder
|
|
4829
|
+
* await trx.query(User.table).insert({ name: "John Doe" });
|
|
4830
|
+
*
|
|
4831
|
+
* await trx.commit();
|
|
4832
|
+
* ```
|
|
4614
4833
|
*/
|
|
4615
|
-
|
|
4834
|
+
sql: Omit<SqlDataSource, "transaction" | "startGlobalTransaction">;
|
|
4616
4835
|
/**
|
|
4617
|
-
* @description
|
|
4618
|
-
* @description If there is an active global transaction, it will be rolled back
|
|
4619
|
-
* @description Also disconnects all slave connections if any are configured
|
|
4836
|
+
* @description Whether the transaction is active
|
|
4620
4837
|
*/
|
|
4621
|
-
|
|
4838
|
+
isActive: boolean;
|
|
4622
4839
|
/**
|
|
4623
|
-
* @description
|
|
4840
|
+
* @description The transaction unique identifier
|
|
4624
4841
|
*/
|
|
4625
|
-
|
|
4842
|
+
transactionId: string;
|
|
4843
|
+
private connectionReleased;
|
|
4844
|
+
private isolationLevel?;
|
|
4845
|
+
private isNested;
|
|
4846
|
+
private nestingDepth;
|
|
4847
|
+
constructor(sql: SqlDataSource, isolationLevel?: TransactionIsolationLevel, isNested?: boolean, nestingDepth?: number);
|
|
4626
4848
|
/**
|
|
4627
|
-
* @description
|
|
4628
|
-
* @
|
|
4629
|
-
* @sqlite Not supported but won't throw an error
|
|
4849
|
+
* @description Creates a new transaction with the same isolation level and same connection using save points
|
|
4850
|
+
* @description If a callback is provided, it will execute the callback and commit or rollback the nested transaction save points based on the callback's success or failure
|
|
4630
4851
|
*/
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
}): Promise<void>;
|
|
4852
|
+
nestedTransaction(): Promise<Transaction>;
|
|
4853
|
+
nestedTransaction(cb: (trx: Transaction) => Promise<void>): Promise<void>;
|
|
4634
4854
|
/**
|
|
4635
|
-
* @description
|
|
4636
|
-
* MySQL/MariaDB returns [rows, fields], Postgres returns {rows: []}, others return rows directly
|
|
4855
|
+
* @description Starts a transaction, automatically handled from the sql data source instance in the `transaction` method
|
|
4637
4856
|
*/
|
|
4638
|
-
|
|
4857
|
+
transaction(): Promise<void>;
|
|
4639
4858
|
/**
|
|
4640
|
-
* @description
|
|
4859
|
+
* @description Commit the transaction releasing the connection
|
|
4860
|
+
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
4861
|
+
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
4641
4862
|
*/
|
|
4642
|
-
|
|
4863
|
+
commit(options?: TransactionExecutionOptions): Promise<void>;
|
|
4643
4864
|
/**
|
|
4644
|
-
* @description
|
|
4645
|
-
* @
|
|
4646
|
-
*
|
|
4647
|
-
* await sql.query("users").where("name", sql.rawStatement("LOWER(name)"));
|
|
4648
|
-
* await sql.query("users").update({
|
|
4649
|
-
* name: sql.rawStatement("LOWER(name)"),
|
|
4650
|
-
* });
|
|
4651
|
-
* await sql.query("users").insert({
|
|
4652
|
-
* name: sql.rawStatement("LOWER(name)"),
|
|
4653
|
-
* });
|
|
4654
|
-
* ```
|
|
4865
|
+
* @description Rollback the transaction releasing the connection
|
|
4866
|
+
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
4867
|
+
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
4655
4868
|
*/
|
|
4656
|
-
|
|
4869
|
+
rollback(options?: TransactionExecutionOptions): Promise<void>;
|
|
4657
4870
|
/**
|
|
4658
|
-
* @description
|
|
4871
|
+
* @description Release the connection, does nothing if the connection is already released
|
|
4659
4872
|
*/
|
|
4660
|
-
|
|
4873
|
+
private releaseConnection;
|
|
4874
|
+
private getIsolationLevelQuery;
|
|
4875
|
+
private getSavePointName;
|
|
4876
|
+
private getMssqlTransactionLevel;
|
|
4877
|
+
}
|
|
4878
|
+
|
|
4879
|
+
/**
|
|
4880
|
+
* @description The SqlDataSource class is the main class for interacting with the database, it's used to create connections, execute queries, and manage transactions
|
|
4881
|
+
* @example
|
|
4882
|
+
* ```ts
|
|
4883
|
+
* // Create and connect to a database
|
|
4884
|
+
* const sql = new SqlDataSource({
|
|
4885
|
+
* type: "mysql",
|
|
4886
|
+
* host: "localhost",
|
|
4887
|
+
* username: "root",
|
|
4888
|
+
* password: "password",
|
|
4889
|
+
* database: "mydb",
|
|
4890
|
+
* models: { User, Post }
|
|
4891
|
+
* });
|
|
4892
|
+
* await sql.connect();
|
|
4893
|
+
*
|
|
4894
|
+
* // Now you can use the connection
|
|
4895
|
+
* const users = await sql.query("users").many();
|
|
4896
|
+
* ```
|
|
4897
|
+
*/
|
|
4898
|
+
declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> extends DataSource {
|
|
4899
|
+
#private;
|
|
4900
|
+
private globalTransaction;
|
|
4901
|
+
private sqlType;
|
|
4902
|
+
private _models;
|
|
4903
|
+
private ownsPool;
|
|
4661
4904
|
/**
|
|
4662
|
-
* @description
|
|
4663
|
-
* @experimental
|
|
4905
|
+
* @description The slaves data sources to use for the sql data source, slaves are automatically used for read operations unless specified otherwise
|
|
4664
4906
|
*/
|
|
4665
|
-
|
|
4666
|
-
modelName: string;
|
|
4667
|
-
$id?: string;
|
|
4668
|
-
})[];
|
|
4907
|
+
slaves: SqlDataSource<D, T, C>[];
|
|
4669
4908
|
/**
|
|
4670
|
-
* @description
|
|
4671
|
-
* @
|
|
4909
|
+
* @description The algorithm to use for selecting the slave for read operations
|
|
4910
|
+
* @default "roundRobin" - Distributes requests evenly across all slaves in sequence
|
|
4911
|
+
* @option "random" - Randomly selects a slave for each request
|
|
4672
4912
|
*/
|
|
4673
|
-
|
|
4913
|
+
slaveAlgorithm: SlaveAlgorithm;
|
|
4674
4914
|
/**
|
|
4675
|
-
* @description
|
|
4676
|
-
* @
|
|
4915
|
+
* @description The current index for round-robin slave selection
|
|
4916
|
+
* @private
|
|
4677
4917
|
*/
|
|
4678
|
-
|
|
4918
|
+
private roundRobinIndex;
|
|
4679
4919
|
/**
|
|
4680
|
-
* @description
|
|
4920
|
+
* @description The pool of connections for the database
|
|
4681
4921
|
*/
|
|
4682
|
-
|
|
4922
|
+
sqlPool: SqlPoolType | null;
|
|
4683
4923
|
/**
|
|
4684
|
-
* @description
|
|
4924
|
+
* @description Only used in transaction context to specify the connection, not meant to be used directly
|
|
4925
|
+
* @private
|
|
4685
4926
|
*/
|
|
4686
|
-
|
|
4927
|
+
sqlConnection: GetConnectionReturnType<D> | null;
|
|
4687
4928
|
/**
|
|
4688
|
-
* @description
|
|
4929
|
+
* @description Options provided in the sql data source initialization
|
|
4689
4930
|
*/
|
|
4690
|
-
|
|
4931
|
+
inputDetails: SqlDataSourceInput<D, T, C>;
|
|
4691
4932
|
/**
|
|
4692
|
-
* @description
|
|
4933
|
+
* @description Adapter for `useCache`, uses an in memory strategy by default
|
|
4693
4934
|
*/
|
|
4694
|
-
|
|
4935
|
+
cacheAdapter: CacheAdapter;
|
|
4695
4936
|
/**
|
|
4696
|
-
* @description
|
|
4937
|
+
* @description Maps global keys to specific handlers for cache handling
|
|
4697
4938
|
*/
|
|
4698
|
-
|
|
4939
|
+
cacheKeys: C;
|
|
4699
4940
|
/**
|
|
4700
|
-
* @description
|
|
4941
|
+
* @description Migration configuration for the sql data source
|
|
4701
4942
|
*/
|
|
4702
|
-
|
|
4943
|
+
migrationConfig: {
|
|
4944
|
+
path: string;
|
|
4945
|
+
tsconfig?: string;
|
|
4946
|
+
lock: boolean;
|
|
4947
|
+
transactional: boolean;
|
|
4948
|
+
lockTimeout?: number;
|
|
4949
|
+
};
|
|
4703
4950
|
/**
|
|
4704
|
-
* @description
|
|
4951
|
+
* @description Seeder configuration for the sql data source
|
|
4705
4952
|
*/
|
|
4706
|
-
|
|
4953
|
+
seederConfig: {
|
|
4954
|
+
path: string;
|
|
4955
|
+
tsconfig?: string;
|
|
4956
|
+
};
|
|
4707
4957
|
/**
|
|
4708
|
-
* @description
|
|
4709
|
-
* @description Useful for preventing concurrent operations from running simultaneously
|
|
4710
|
-
* @param lockKey - The lock identifier (defaults to 'hysteria_lock')
|
|
4711
|
-
* @param timeoutMs - Maximum time to wait for lock in milliseconds (postgres/mssql only)
|
|
4712
|
-
* @returns true if lock was acquired, false otherwise
|
|
4958
|
+
* @description AdminJS configuration options
|
|
4713
4959
|
*/
|
|
4714
|
-
|
|
4960
|
+
private adminJsOptions?;
|
|
4715
4961
|
/**
|
|
4716
|
-
* @description
|
|
4717
|
-
* @param lockKey - The lock identifier (defaults to 'hysteria_lock')
|
|
4718
|
-
* @returns true if lock was released, false otherwise
|
|
4962
|
+
* @description Cached AdminJS instance
|
|
4719
4963
|
*/
|
|
4720
|
-
|
|
4964
|
+
private adminJsInstance?;
|
|
4721
4965
|
/**
|
|
4722
|
-
* @description
|
|
4966
|
+
* @description Callback to handle slave server failures
|
|
4723
4967
|
*/
|
|
4724
|
-
private
|
|
4968
|
+
private onSlaveServerFailure?;
|
|
4725
4969
|
/**
|
|
4726
|
-
* @description
|
|
4727
|
-
* @param operation The operation to execute on the slave
|
|
4728
|
-
* @returns The result of the operation, or falls back to master if slave fails
|
|
4970
|
+
* @description Returns the configured slave failure callback
|
|
4729
4971
|
*/
|
|
4730
|
-
|
|
4972
|
+
getOnSlaveServerFailure(): ((error: Error, context: SlaveContext) => void | Promise<void>) | undefined;
|
|
4731
4973
|
/**
|
|
4732
|
-
* @description
|
|
4733
|
-
*
|
|
4974
|
+
* @description Returns the primary instance of the SqlDataSource (set via connect with setPrimary: true)
|
|
4975
|
+
* All models by default will use this instance to execute queries unless you pass a different connection/transaction in the query options
|
|
4734
4976
|
*/
|
|
4735
|
-
|
|
4736
|
-
}
|
|
4737
|
-
|
|
4738
|
-
type ModelWithoutRelations<T extends Model> = Pick<Omit<T, "*">, ExcludeRelations<Omit<T, "*">>> & Pick<Model, keyof Model>;
|
|
4739
|
-
type NumberModelKey<T extends Model> = {
|
|
4740
|
-
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
4741
|
-
}[keyof T];
|
|
4742
|
-
type BaseModelMethodOptions = {
|
|
4977
|
+
static get instance(): SqlDataSource;
|
|
4743
4978
|
/**
|
|
4744
|
-
* @description
|
|
4745
|
-
* @description
|
|
4979
|
+
* @description Creates a secondary database connection that won't be set as the primary instance
|
|
4980
|
+
* @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
|
|
4746
4981
|
* @example
|
|
4747
4982
|
* ```ts
|
|
4748
|
-
*
|
|
4749
|
-
* const customConnection = await SqlDataSource.connectToSecondarySource({
|
|
4983
|
+
* const secondaryDb = await SqlDataSource.connectToSecondarySource({
|
|
4750
4984
|
* type: "postgres",
|
|
4751
|
-
* host: "
|
|
4752
|
-
*
|
|
4753
|
-
* password: "root",
|
|
4754
|
-
* database: "test",
|
|
4755
|
-
* port: 5432,
|
|
4985
|
+
* host: "replica.db.com",
|
|
4986
|
+
* ...
|
|
4756
4987
|
* });
|
|
4757
4988
|
*
|
|
4758
|
-
* const user = await User.query({ connection:
|
|
4989
|
+
* const user = await User.query({ connection: secondaryDb }).many();
|
|
4759
4990
|
* ```
|
|
4760
4991
|
*/
|
|
4761
|
-
|
|
4762
|
-
/**
|
|
4763
|
-
* @description The transaction instance to use for the model
|
|
4764
|
-
*/
|
|
4765
|
-
trx?: Transaction;
|
|
4766
|
-
/**
|
|
4767
|
-
* @description Whether to ignore the hooks for the model
|
|
4768
|
-
*/
|
|
4769
|
-
ignoreHooks?: boolean;
|
|
4770
|
-
/**
|
|
4771
|
-
* @description The replication mode to use for the model
|
|
4772
|
-
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
4773
|
-
* @description If set to "master", all operations will use master
|
|
4774
|
-
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
4775
|
-
*/
|
|
4776
|
-
replicationMode?: ReplicationType;
|
|
4777
|
-
};
|
|
4778
|
-
/**
|
|
4779
|
-
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
4780
|
-
*/
|
|
4781
|
-
type RawModelOptions = {
|
|
4992
|
+
static connectToSecondarySource<U extends SqlDataSourceType, M extends Record<string, SqlDataSourceModel> = {}, K extends CacheKeys = {}>(input: Omit<SqlDataSourceInput<U, M, K>, "slaves">, cb?: (sqlDataSource: SqlDataSource<U, M, K>) => Promise<void> | void): Promise<SqlDataSource<U, M, K>>;
|
|
4782
4993
|
/**
|
|
4783
|
-
*
|
|
4994
|
+
* @description Creates a temporary connection that is automatically closed after the callback is executed
|
|
4995
|
+
* @example
|
|
4996
|
+
* ```ts
|
|
4997
|
+
* await SqlDataSource.useConnection({
|
|
4998
|
+
* type: "mysql",
|
|
4999
|
+
* ...connectionData
|
|
5000
|
+
* }, async (sql) => {
|
|
5001
|
+
* const user = await User.query({ connection: sql }).many();
|
|
5002
|
+
* });
|
|
5003
|
+
* // Connection is automatically closed here
|
|
5004
|
+
* ```
|
|
4784
5005
|
*/
|
|
4785
|
-
|
|
5006
|
+
static useConnection<U extends SqlDataSourceType, M extends Record<string, SqlDataSourceModel> = {}, K extends CacheKeys = {}>(connectionDetails: UseConnectionInput<U, M, K>, cb: (sqlDataSource: SqlDataSource<U, M, K>) => Promise<void>): Promise<void>;
|
|
4786
5007
|
/**
|
|
4787
|
-
* @description
|
|
5008
|
+
* @description Closes the primary connection (singleton instance)
|
|
4788
5009
|
*/
|
|
4789
|
-
|
|
5010
|
+
static disconnect(): Promise<void>;
|
|
4790
5011
|
/**
|
|
4791
|
-
*
|
|
5012
|
+
* @description Starts a global transaction on the primary database connection
|
|
5013
|
+
* @description Intended for testing purposes - wraps all operations in a transaction that can be rolled back
|
|
4792
5014
|
*/
|
|
4793
|
-
|
|
5015
|
+
static startGlobalTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
4794
5016
|
/**
|
|
4795
|
-
*
|
|
5017
|
+
* @description Commits a global transaction on the primary database connection
|
|
5018
|
+
* @throws {HysteriaError} If the global transaction is not started
|
|
4796
5019
|
*/
|
|
4797
|
-
|
|
4798
|
-
};
|
|
4799
|
-
|
|
4800
|
-
declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
4801
|
-
model: typeof Model;
|
|
4802
|
-
protected astParser: AstParser;
|
|
4803
|
-
protected unionNodes: UnionNode[];
|
|
4804
|
-
protected withNodes: WithNode[];
|
|
4805
|
-
protected lockQueryNodes: LockNode[];
|
|
4806
|
-
protected isNestedCondition: boolean;
|
|
4807
|
-
protected mustRemoveAnnotations: boolean;
|
|
4808
|
-
protected interpreterUtils: InterpreterUtils;
|
|
4809
|
-
protected insertNode: InsertNode | null;
|
|
4810
|
-
protected onDuplicateNode: OnDuplicateNode | null;
|
|
4811
|
-
protected updateNode: UpdateNode | null;
|
|
4812
|
-
protected deleteNode: DeleteNode | null;
|
|
4813
|
-
protected truncateNode: TruncateNode | null;
|
|
4814
|
-
protected replicationMode: ReplicationType | null;
|
|
5020
|
+
static commitGlobalTransaction(): Promise<void>;
|
|
4815
5021
|
/**
|
|
4816
|
-
* @description
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
data: AnnotatedModel<T, any, any>[];
|
|
4821
|
-
time: number;
|
|
4822
|
-
}>;
|
|
4823
|
-
one: (returnType?: "millis" | "seconds") => Promise<{
|
|
4824
|
-
data: AnnotatedModel<T, any, any> | null;
|
|
4825
|
-
time: number;
|
|
4826
|
-
}>;
|
|
4827
|
-
oneOrFail: (returnType?: "millis" | "seconds") => Promise<{
|
|
4828
|
-
data: any;
|
|
4829
|
-
time: number;
|
|
4830
|
-
}>;
|
|
4831
|
-
paginate: (page: number, perPage: number, returnType?: "millis" | "seconds") => Promise<{
|
|
4832
|
-
data: PaginatedData<T>;
|
|
4833
|
-
time: number;
|
|
4834
|
-
}>;
|
|
4835
|
-
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
4836
|
-
data: [CursorPaginatedData<T>, Cursor<T, ModelKey<T>>];
|
|
4837
|
-
time: number;
|
|
4838
|
-
}>;
|
|
4839
|
-
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
4840
|
-
data: boolean;
|
|
4841
|
-
time: number;
|
|
4842
|
-
}>;
|
|
4843
|
-
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
4844
|
-
data: void;
|
|
4845
|
-
time: number;
|
|
4846
|
-
}>;
|
|
4847
|
-
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
4848
|
-
data: number;
|
|
4849
|
-
time: number;
|
|
4850
|
-
}>;
|
|
4851
|
-
insert: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
4852
|
-
data: T;
|
|
4853
|
-
time: number;
|
|
4854
|
-
}>;
|
|
4855
|
-
insertMany: (data: Record<string, any>[], returnType?: "millis" | "seconds") => Promise<{
|
|
4856
|
-
data: T[];
|
|
4857
|
-
time: number;
|
|
4858
|
-
}>;
|
|
4859
|
-
update: (data: Record<string, any>, returnType?: "millis" | "seconds") => Promise<{
|
|
4860
|
-
data: number;
|
|
4861
|
-
time: number;
|
|
4862
|
-
}>;
|
|
4863
|
-
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
4864
|
-
data: number;
|
|
4865
|
-
time: number;
|
|
4866
|
-
}>;
|
|
4867
|
-
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
4868
|
-
data: PluckReturnType<T, ModelKey<T>>;
|
|
4869
|
-
time: number;
|
|
4870
|
-
}>;
|
|
4871
|
-
};
|
|
4872
|
-
constructor(model: typeof Model, sqlDataSource?: SqlDataSource);
|
|
5022
|
+
* @description Rolls back a global transaction on the primary database connection
|
|
5023
|
+
* @throws {HysteriaError} If the global transaction is not started
|
|
5024
|
+
*/
|
|
5025
|
+
static rollbackGlobalTransaction(): Promise<void>;
|
|
4873
5026
|
/**
|
|
4874
|
-
* @description
|
|
4875
|
-
* @param replicationMode - The replication mode to use for the query builder
|
|
4876
|
-
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
4877
|
-
* @description If set to "master", all operations will use master
|
|
4878
|
-
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
5027
|
+
* @description Returns true if the primary instance is in a global transaction
|
|
4879
5028
|
*/
|
|
4880
|
-
|
|
5029
|
+
static get isInGlobalTransaction(): boolean;
|
|
4881
5030
|
/**
|
|
4882
|
-
* @description
|
|
5031
|
+
* @description Creates a new SqlDataSource instance. Call `.connect()` to establish the connection.
|
|
5032
|
+
* @param input Configuration options for the database connection. If not provided, uses env variables.
|
|
5033
|
+
* @example
|
|
5034
|
+
* ```ts
|
|
5035
|
+
* // With explicit config
|
|
5036
|
+
* const sql = new SqlDataSource({
|
|
5037
|
+
* type: "mysql",
|
|
5038
|
+
* host: "localhost",
|
|
5039
|
+
* username: "root",
|
|
5040
|
+
* password: "password",
|
|
5041
|
+
* database: "mydb",
|
|
5042
|
+
* models: { User, Post }
|
|
5043
|
+
* });
|
|
5044
|
+
* await sql.connect();
|
|
5045
|
+
*
|
|
5046
|
+
* // Using env variables
|
|
5047
|
+
* const sql = new SqlDataSource();
|
|
5048
|
+
* await sql.connect();
|
|
5049
|
+
* ```
|
|
4883
5050
|
*/
|
|
4884
|
-
|
|
5051
|
+
constructor(input?: SqlDataSourceInput<D, T, C>);
|
|
4885
5052
|
/**
|
|
4886
|
-
* @description
|
|
5053
|
+
* @description Establishes the database connection and sets this instance as the primary connection, it also connects to the slaves if any are configured
|
|
5054
|
+
* @throws {HysteriaError} If the connection is already established, use `SqlDataSource.useConnection` or `SqlDataSource.connectToSecondarySource` for auxiliary connections
|
|
5055
|
+
* @example
|
|
5056
|
+
* ```ts
|
|
5057
|
+
* const sql = new SqlDataSource({ type: "mysql", ... });
|
|
5058
|
+
* await sql.connect();
|
|
5059
|
+
* ```
|
|
4887
5060
|
*/
|
|
4888
|
-
|
|
5061
|
+
connect(): Promise<void>;
|
|
4889
5062
|
/**
|
|
4890
|
-
* @description
|
|
4891
|
-
* @param key - The column to retrieve from the results, must be a Model Column
|
|
5063
|
+
* @description Returns true if the connection is established
|
|
4892
5064
|
*/
|
|
4893
|
-
|
|
5065
|
+
get isConnected(): boolean;
|
|
4894
5066
|
/**
|
|
4895
|
-
* @description
|
|
5067
|
+
* @description Returns true if this instance is in a global transaction
|
|
4896
5068
|
*/
|
|
4897
|
-
|
|
5069
|
+
get isInGlobalTransaction(): boolean;
|
|
4898
5070
|
/**
|
|
4899
|
-
* @description
|
|
5071
|
+
* @description Returns the models configured on this SqlDataSource instance
|
|
4900
5072
|
*/
|
|
4901
|
-
|
|
5073
|
+
get models(): T;
|
|
4902
5074
|
/**
|
|
4903
|
-
* @
|
|
5075
|
+
* @description Selects a slave from the pool using the configured algorithm
|
|
5076
|
+
* @returns A slave SqlDataSource instance or null if no slaves are available
|
|
4904
5077
|
*/
|
|
4905
|
-
|
|
5078
|
+
getSlave(): SqlDataSource<D, T, C> | null;
|
|
4906
5079
|
/**
|
|
4907
|
-
* @description
|
|
4908
|
-
* @
|
|
4909
|
-
* @
|
|
4910
|
-
* @throws If using postgres and the `pg-query-stream` package is not installed
|
|
5080
|
+
* @description Uses the cache adapter to get a value from the cache
|
|
5081
|
+
* @param key The key to get the value from
|
|
5082
|
+
* @param args The arguments to pass to the key handler
|
|
4911
5083
|
*/
|
|
4912
|
-
|
|
5084
|
+
useCache<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
4913
5085
|
/**
|
|
4914
|
-
* @description
|
|
4915
|
-
* @
|
|
4916
|
-
* @
|
|
4917
|
-
* @
|
|
4918
|
-
* @param chunkSize - The size of the chunk
|
|
4919
|
-
* @returns a generator of the chunks
|
|
4920
|
-
* @example
|
|
4921
|
-
* const chunks = await queryBuilder.chunk(100);
|
|
4922
|
-
* // first chunk
|
|
4923
|
-
* const firstChunk = await chunks.next();
|
|
4924
|
-
* console.log(firstChunk.value);
|
|
4925
|
-
* // second chunk
|
|
4926
|
-
* const secondChunk = await chunks.next();
|
|
4927
|
-
* console.log(secondChunk.value);
|
|
4928
|
-
* // third chunk
|
|
4929
|
-
* const thirdChunk = await chunks.next();
|
|
4930
|
-
* console.log(thirdChunk.value);
|
|
4931
|
-
*
|
|
4932
|
-
* @example
|
|
4933
|
-
* const chunkSize = 3;
|
|
4934
|
-
* const chunks = [];
|
|
4935
|
-
* const query = sql.query("users").orderBy("name", "asc");
|
|
4936
|
-
* for await (const chunk of sql.chunk(chunkSize)) {
|
|
4937
|
-
* chunks.push(chunk);
|
|
4938
|
-
* }
|
|
4939
|
-
*
|
|
4940
|
-
* console.log(chunks);
|
|
5086
|
+
* @description Uses the cache adapter to get a value from the cache
|
|
5087
|
+
* @param key The key to get the value from
|
|
5088
|
+
* @param ttl The time to live for the value in milliseconds
|
|
5089
|
+
* @param args The arguments to pass to the key handler
|
|
4941
5090
|
*/
|
|
4942
|
-
|
|
5091
|
+
useCache<K extends keyof C>(key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
4943
5092
|
/**
|
|
4944
|
-
* @description
|
|
4945
|
-
* @
|
|
4946
|
-
* @
|
|
4947
|
-
* @description If using a model query builder, primary key is used as discriminator by default
|
|
4948
|
-
* @param options - The options for the paginate with cursor
|
|
4949
|
-
* @param options.discriminator - The discriminator to use for the paginate with Cursor pagination
|
|
4950
|
-
* @param options.operator - The operator to use for the paginate with Cursor pagination
|
|
4951
|
-
* @param options.orderBy - The order by to use for the paginate with Cursor pagination
|
|
4952
|
-
* @param cursor - The cursor to use for the paginate with Cursor pagination
|
|
4953
|
-
* @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")`
|
|
4954
|
-
* @returns the pagination metadata and the cursor for the next page
|
|
5093
|
+
* @description Invalidates a value from the cache
|
|
5094
|
+
* @param key The key to invalidate the value from
|
|
5095
|
+
* @param args The arguments to pass to the key handler (required if the handler expects arguments)
|
|
4955
5096
|
*/
|
|
4956
|
-
|
|
5097
|
+
invalidCache<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<void>;
|
|
5098
|
+
invalidCache<K extends keyof C>(key: K): Promise<void>;
|
|
4957
5099
|
/**
|
|
4958
|
-
* @description
|
|
5100
|
+
* @description Invalidates all values from the cache starting with the given key
|
|
5101
|
+
* @param key The key to invalidate the values from
|
|
4959
5102
|
*/
|
|
4960
|
-
|
|
5103
|
+
invalidateAllCache(key: string): Promise<void>;
|
|
4961
5104
|
/**
|
|
4962
|
-
* @description
|
|
4963
|
-
* @param
|
|
4964
|
-
* @sqlite
|
|
5105
|
+
* @description Clones the SqlDataSource instance
|
|
5106
|
+
* @param options.shouldRecreatePool Whether to recreate the pool of connections for the given driver, by default it's false
|
|
5107
|
+
* @sqlite ignores the shouldRecreatePool option
|
|
5108
|
+
* @returns A new SqlDataSource instance with the same input details
|
|
4965
5109
|
*/
|
|
4966
|
-
|
|
4967
|
-
skipLocked?: boolean;
|
|
4968
|
-
noWait?: boolean;
|
|
4969
|
-
}): this;
|
|
5110
|
+
clone(options?: SqlCloneOptions): Promise<this>;
|
|
4970
5111
|
/**
|
|
4971
|
-
* @description
|
|
4972
|
-
* @param skipLocked - If true, the query will skip locked rows
|
|
4973
|
-
* @sqlite does not support skipping locked rows, it will be ignored
|
|
5112
|
+
* @description Returns the type of the database
|
|
4974
5113
|
*/
|
|
4975
|
-
|
|
4976
|
-
skipLocked?: boolean;
|
|
4977
|
-
noWait?: boolean;
|
|
4978
|
-
}): this;
|
|
5114
|
+
getDbType(): D;
|
|
4979
5115
|
/**
|
|
4980
|
-
* @description
|
|
5116
|
+
* @description Returns a QueryBuilder instance for raw queries
|
|
5117
|
+
* @description Query builder from the SqlDataSource instance returns raw data from the database
|
|
5118
|
+
* @param table The table name to query from
|
|
4981
5119
|
*/
|
|
4982
|
-
|
|
4983
|
-
union(cb: UnionCallBack<T>): this;
|
|
5120
|
+
query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
|
|
4984
5121
|
/**
|
|
4985
|
-
* @description
|
|
5122
|
+
* @description Returns a DryQueryBuilder instance that returns the query statement without executing
|
|
4986
5123
|
*/
|
|
4987
|
-
|
|
4988
|
-
unionAll(cb: UnionCallBack<T>): this;
|
|
4989
|
-
unionAll(queryBuilder: QueryBuilder<any>): this;
|
|
5124
|
+
dryQuery<S extends string>(table: TableFormat<S>, options?: RawModelOptions): DryQueryBuilderWithoutReadOperations;
|
|
4990
5125
|
/**
|
|
4991
|
-
* @description
|
|
4992
|
-
* @typeSafe - In typescript, only numeric columns of the model will be accepted if using a Model
|
|
4993
|
-
* @default value + 1
|
|
4994
|
-
* @returns the number of affected rows
|
|
5126
|
+
* @description Return the query to alter the given table schema
|
|
4995
5127
|
*/
|
|
4996
|
-
|
|
4997
|
-
increment(column: NumberModelKey<T>, value: number): Promise<number>;
|
|
5128
|
+
alterTable(...args: Parameters<Schema["alterTable"]>): string[];
|
|
4998
5129
|
/**
|
|
4999
|
-
* @description
|
|
5000
|
-
* @typeSafe - In typescript, only numeric columns of the model will be accepted if using a Model
|
|
5001
|
-
* @default value - 1
|
|
5002
|
-
* @returns the number of affected rows
|
|
5130
|
+
* @description Return the query to create the given table schema
|
|
5003
5131
|
*/
|
|
5004
|
-
|
|
5005
|
-
decrement(column: NumberModelKey<T>, value: number): Promise<number>;
|
|
5132
|
+
createTable(...args: Parameters<Schema["createTable"]>): string;
|
|
5006
5133
|
/**
|
|
5007
|
-
* @description
|
|
5134
|
+
* @description Starts a global transaction on the database
|
|
5135
|
+
* @description Intended for testing purposes - wraps all operations in a transaction that can be rolled back
|
|
5008
5136
|
*/
|
|
5009
|
-
|
|
5137
|
+
startGlobalTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
5010
5138
|
/**
|
|
5011
|
-
* @description
|
|
5139
|
+
* @description Commits a global transaction on the database
|
|
5140
|
+
* @throws {HysteriaError} If the global transaction is not started
|
|
5012
5141
|
*/
|
|
5013
|
-
|
|
5142
|
+
commitGlobalTransaction(options?: TransactionExecutionOptions): Promise<void>;
|
|
5014
5143
|
/**
|
|
5015
|
-
* @description
|
|
5144
|
+
* @description Rolls back a global transaction on the database
|
|
5016
5145
|
*/
|
|
5017
|
-
|
|
5146
|
+
rollbackGlobalTransaction(options?: TransactionExecutionOptions): Promise<void>;
|
|
5018
5147
|
/**
|
|
5019
|
-
* @description
|
|
5148
|
+
* @description Starts a transaction on a dedicated connection from the pool
|
|
5149
|
+
* @param cb if a callback is provided, it will execute the callback and commit or rollback the transaction based on the callback's success or failure
|
|
5150
|
+
* @param options.isolationLevel The isolation level to use for the transaction
|
|
5151
|
+
* @sqlite ignores the isolation level
|
|
5020
5152
|
*/
|
|
5021
|
-
|
|
5153
|
+
transaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
5154
|
+
transaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
5022
5155
|
/**
|
|
5023
|
-
* @description
|
|
5156
|
+
* @description Returns a ModelManager instance for the given model
|
|
5024
5157
|
*/
|
|
5025
|
-
|
|
5158
|
+
getModelManager<M extends Model>(model: {
|
|
5159
|
+
new (): M;
|
|
5160
|
+
} | typeof Model): ModelManager<M>;
|
|
5026
5161
|
/**
|
|
5027
|
-
* @description
|
|
5028
|
-
* @
|
|
5162
|
+
* @description Returns the current raw driver Pool
|
|
5163
|
+
* @throws {HysteriaError} If the connection pool is not established
|
|
5029
5164
|
*/
|
|
5030
|
-
|
|
5165
|
+
getPool(): getPoolReturnType<D>;
|
|
5031
5166
|
/**
|
|
5032
|
-
* @description
|
|
5167
|
+
* @description Returns a connection from the pool
|
|
5168
|
+
* @throws {HysteriaError} If the connection is not established
|
|
5033
5169
|
*/
|
|
5034
|
-
|
|
5035
|
-
from(cb: (qb: QueryBuilder<T>) => void, alias: string): this;
|
|
5170
|
+
getConnection(): Promise<GetConnectionReturnType<D>>;
|
|
5036
5171
|
/**
|
|
5037
|
-
* @description
|
|
5172
|
+
* @description Closes the current connection
|
|
5173
|
+
* @description If there is an active global transaction, it will be rolled back
|
|
5174
|
+
* @description Also disconnects all slave connections if any are configured
|
|
5038
5175
|
*/
|
|
5039
|
-
|
|
5176
|
+
disconnect(): Promise<void>;
|
|
5040
5177
|
/**
|
|
5041
|
-
* @description
|
|
5042
|
-
* @mssql not supported
|
|
5178
|
+
* @description Returns the connection details
|
|
5043
5179
|
*/
|
|
5044
|
-
|
|
5180
|
+
getConnectionDetails(): SqlDataSourceInput<D, T, C>;
|
|
5045
5181
|
/**
|
|
5046
|
-
* @description
|
|
5047
|
-
* @
|
|
5048
|
-
* @
|
|
5182
|
+
* @description Syncs the schema of the database with the models metadata
|
|
5183
|
+
* @warning This will drop and recreate all the indexes and constraints, use with caution
|
|
5184
|
+
* @sqlite Not supported but won't throw an error
|
|
5049
5185
|
*/
|
|
5050
|
-
|
|
5186
|
+
syncSchema(options?: {
|
|
5187
|
+
transactional: boolean;
|
|
5188
|
+
}): Promise<void>;
|
|
5051
5189
|
/**
|
|
5052
|
-
* @description
|
|
5053
|
-
*
|
|
5054
|
-
* @returns raw driver response
|
|
5190
|
+
* @description Extracts rows from raw query result based on database type
|
|
5191
|
+
* MySQL/MariaDB returns [rows, fields], Postgres returns {rows: []}, others return rows directly
|
|
5055
5192
|
*/
|
|
5056
|
-
|
|
5193
|
+
private extractRowsFromRawResult;
|
|
5194
|
+
/**
|
|
5195
|
+
* @description Executes a raw query on the database and returns the raw driver result
|
|
5196
|
+
*/
|
|
5197
|
+
rawQuery<R = RawQueryResponseType<D>>(query: string, params?: any[], options?: RawQueryOptions): Promise<R>;
|
|
5198
|
+
/**
|
|
5199
|
+
* @description Adds a raw statement to an operation that will be executed as is
|
|
5200
|
+
* @example
|
|
5201
|
+
* ```ts
|
|
5202
|
+
* await sql.query("users").where("name", sql.rawStatement("LOWER(name)"));
|
|
5203
|
+
* await sql.query("users").update({
|
|
5204
|
+
* name: sql.rawStatement("LOWER(name)"),
|
|
5205
|
+
* });
|
|
5206
|
+
* await sql.query("users").insert({
|
|
5207
|
+
* name: sql.rawStatement("LOWER(name)"),
|
|
5208
|
+
* });
|
|
5209
|
+
* ```
|
|
5210
|
+
*/
|
|
5211
|
+
rawStatement(value: string): RawNode;
|
|
5212
|
+
/**
|
|
5213
|
+
* @description Retrieves information from the database for the given table
|
|
5214
|
+
*/
|
|
5215
|
+
getTableSchema(table: string): Promise<TableSchemaInfo>;
|
|
5057
5216
|
/**
|
|
5058
|
-
* @description
|
|
5059
|
-
* @
|
|
5060
|
-
* @returns raw driver response
|
|
5061
|
-
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
5217
|
+
* @description Models provided inside the connection method will always be used for openapi schema generation
|
|
5218
|
+
* @experimental
|
|
5062
5219
|
*/
|
|
5063
|
-
|
|
5220
|
+
getModelOpenApiSchema(): (OpenApiModelType & {
|
|
5221
|
+
modelName: string;
|
|
5222
|
+
$id?: string;
|
|
5223
|
+
})[];
|
|
5064
5224
|
/**
|
|
5065
|
-
* @description
|
|
5066
|
-
* @
|
|
5067
|
-
* @param searchCriteria The criteria to search for existing records
|
|
5068
|
-
* @param options Upsert options including updateOnConflict and returning columns
|
|
5069
|
-
* @returns The upserted record
|
|
5225
|
+
* @description Initializes AdminJS with the configured options
|
|
5226
|
+
* @throws {HysteriaError} If AdminJS is not enabled in the configuration
|
|
5070
5227
|
*/
|
|
5071
|
-
|
|
5228
|
+
initializeAdminJs(): Promise<AdminJsAdminInstance>;
|
|
5072
5229
|
/**
|
|
5073
|
-
* @description
|
|
5074
|
-
* @
|
|
5075
|
-
* @param columnsToUpdate The columns to update on conflict
|
|
5076
|
-
* @param data Array of data objects to insert or update
|
|
5077
|
-
* @param options Upsert options including updateOnConflict and returning columns
|
|
5230
|
+
* @description Initializes AdminJS with Express router
|
|
5231
|
+
* @throws {HysteriaError} If AdminJS is not enabled in the configuration
|
|
5078
5232
|
*/
|
|
5079
|
-
|
|
5233
|
+
initializeAdminJsExpress(): Promise<Required<AdminJsInstance>>;
|
|
5080
5234
|
/**
|
|
5081
|
-
* @description
|
|
5235
|
+
* @description Returns the AdminJS instance if initialized
|
|
5082
5236
|
*/
|
|
5083
|
-
|
|
5237
|
+
getAdminJs(): AdminJsInstance | undefined;
|
|
5084
5238
|
/**
|
|
5085
|
-
* @description
|
|
5086
|
-
* @returns the number of affected rows
|
|
5239
|
+
* @description Returns the AdminJS configuration options
|
|
5087
5240
|
*/
|
|
5088
|
-
|
|
5241
|
+
getAdminJsOptions(): AdminJsOptions | undefined;
|
|
5089
5242
|
/**
|
|
5090
|
-
* @description
|
|
5091
|
-
* @warning This operation does not trigger any hook
|
|
5243
|
+
* @description Checks if AdminJS is enabled
|
|
5092
5244
|
*/
|
|
5093
|
-
|
|
5245
|
+
isAdminJsEnabled(): boolean;
|
|
5094
5246
|
/**
|
|
5095
|
-
* @description
|
|
5096
|
-
* @returns the number of affected rows
|
|
5247
|
+
* @description Introspects table columns metadata
|
|
5097
5248
|
*/
|
|
5098
|
-
|
|
5249
|
+
getTableInfo(table: string): Promise<TableColumnInfo[]>;
|
|
5099
5250
|
/**
|
|
5100
|
-
* @description
|
|
5101
|
-
* @default column - 'deletedAt'
|
|
5102
|
-
* @default value - The current date and time in UTC timezone in the format "YYYY-MM-DD HH:mm:ss"
|
|
5103
|
-
* @returns the number of affected rows
|
|
5251
|
+
* @description Introspects table indexes metadata
|
|
5104
5252
|
*/
|
|
5105
|
-
|
|
5253
|
+
getIndexInfo(table: string): Promise<TableIndexInfo[]>;
|
|
5106
5254
|
/**
|
|
5107
|
-
* @description
|
|
5255
|
+
* @description Introspects table foreign keys metadata
|
|
5108
5256
|
*/
|
|
5109
|
-
|
|
5257
|
+
getForeignKeyInfo(table: string): Promise<TableForeignKeyInfo[]>;
|
|
5110
5258
|
/**
|
|
5111
|
-
* @description
|
|
5259
|
+
* @description Introspects table primary key from the database
|
|
5112
5260
|
*/
|
|
5113
|
-
|
|
5261
|
+
getPrimaryKeyInfo(table: string): Promise<TablePrimaryKeyInfo | undefined>;
|
|
5114
5262
|
/**
|
|
5115
|
-
* @description
|
|
5263
|
+
* @description Acquires an advisory lock
|
|
5264
|
+
* @description Useful for preventing concurrent operations from running simultaneously
|
|
5265
|
+
* @param lockKey - The lock identifier (defaults to 'hysteria_lock')
|
|
5266
|
+
* @param timeoutMs - Maximum time to wait for lock in milliseconds (postgres/mssql only)
|
|
5267
|
+
* @returns true if lock was acquired, false otherwise
|
|
5116
5268
|
*/
|
|
5117
|
-
|
|
5269
|
+
acquireLock(lockKey?: string, timeoutMs?: number): Promise<boolean>;
|
|
5118
5270
|
/**
|
|
5119
|
-
* @description
|
|
5271
|
+
* @description Releases an advisory lock
|
|
5272
|
+
* @param lockKey - The lock identifier (defaults to 'hysteria_lock')
|
|
5273
|
+
* @returns true if lock was released, false otherwise
|
|
5120
5274
|
*/
|
|
5121
|
-
|
|
5275
|
+
releaseLock(lockKey?: string): Promise<boolean>;
|
|
5122
5276
|
/**
|
|
5123
|
-
* @description
|
|
5277
|
+
* @description Converts a string to a numeric lock ID for databases that require it
|
|
5124
5278
|
*/
|
|
5125
|
-
|
|
5279
|
+
private hashStringToLockId;
|
|
5126
5280
|
/**
|
|
5127
|
-
* @description
|
|
5281
|
+
* @description Executes an operation on a slave, handling failures with the configured callback
|
|
5282
|
+
* @param operation The operation to execute on the slave
|
|
5283
|
+
* @returns The result of the operation, or falls back to master if slave fails
|
|
5128
5284
|
*/
|
|
5129
|
-
|
|
5285
|
+
private executeOnSlave;
|
|
5130
5286
|
/**
|
|
5131
|
-
* @description
|
|
5287
|
+
* @description Internal method to establish connection without setting as primary instance
|
|
5288
|
+
* @description Used by connectToSecondarySource and useConnection
|
|
5132
5289
|
*/
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5290
|
+
private connectWithoutSettingPrimary;
|
|
5291
|
+
}
|
|
5292
|
+
|
|
5293
|
+
type ModelWithoutRelations<T extends Model> = Pick<Omit<T, "*">, ExcludeRelations<Omit<T, "*">>> & Pick<Model, keyof Model>;
|
|
5294
|
+
type NumberModelKey<T extends Model> = {
|
|
5295
|
+
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
5296
|
+
}[keyof T];
|
|
5297
|
+
type BaseModelMethodOptions = {
|
|
5136
5298
|
/**
|
|
5137
|
-
* @description
|
|
5299
|
+
* @description The connection to use for the model, by default the main connection will be used
|
|
5300
|
+
* @description The main connection is the one created via `new SqlDataSource().connect()`
|
|
5301
|
+
* @example
|
|
5302
|
+
* ```ts
|
|
5303
|
+
* import { SqlDataSource } from "hysteria-orm";
|
|
5304
|
+
* const customConnection = await SqlDataSource.connectToSecondarySource({
|
|
5305
|
+
* type: "postgres",
|
|
5306
|
+
* host: "localhost",
|
|
5307
|
+
* username: "root",
|
|
5308
|
+
* password: "root",
|
|
5309
|
+
* database: "test",
|
|
5310
|
+
* port: 5432,
|
|
5311
|
+
* });
|
|
5312
|
+
*
|
|
5313
|
+
* const user = await User.query({ connection: customConnection }).one();
|
|
5314
|
+
* ```
|
|
5138
5315
|
*/
|
|
5139
|
-
|
|
5316
|
+
connection?: SqlDataSource;
|
|
5140
5317
|
/**
|
|
5141
|
-
* @description
|
|
5318
|
+
* @description The transaction instance to use for the model
|
|
5142
5319
|
*/
|
|
5143
|
-
|
|
5320
|
+
trx?: Transaction;
|
|
5144
5321
|
/**
|
|
5145
|
-
* @
|
|
5322
|
+
* @description Whether to ignore the hooks for the model
|
|
5146
5323
|
*/
|
|
5147
|
-
|
|
5148
|
-
private paginateWithPerformance;
|
|
5149
|
-
private paginateWithCursorWithPerformance;
|
|
5324
|
+
ignoreHooks?: boolean;
|
|
5150
5325
|
/**
|
|
5151
|
-
* @description
|
|
5326
|
+
* @description The replication mode to use for the model
|
|
5327
|
+
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
5328
|
+
* @description If set to "master", all operations will use master
|
|
5329
|
+
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
5152
5330
|
*/
|
|
5153
|
-
|
|
5331
|
+
replicationMode?: ReplicationType;
|
|
5332
|
+
};
|
|
5333
|
+
/**
|
|
5334
|
+
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
5335
|
+
*/
|
|
5336
|
+
type RawModelOptions = {
|
|
5154
5337
|
/**
|
|
5155
|
-
*
|
|
5156
|
-
* @description Returns the time that took to execute the query
|
|
5338
|
+
* Alias for the table
|
|
5157
5339
|
*/
|
|
5158
|
-
|
|
5159
|
-
private pluckWithPerformance;
|
|
5160
|
-
private updateWithPerformance;
|
|
5161
|
-
private insertWithPerformance;
|
|
5162
|
-
private insertManyWithPerformance;
|
|
5163
|
-
private softDeleteWithPerformance;
|
|
5164
|
-
private deleteWithPerformance;
|
|
5165
|
-
private truncateWithPerformance;
|
|
5340
|
+
alias?: string;
|
|
5166
5341
|
/**
|
|
5167
|
-
* @description
|
|
5168
|
-
* @description MSSQL transactions can only handle one request at a time
|
|
5342
|
+
* @description Convert the column casing before making a Database query, by default preserves what is provided
|
|
5169
5343
|
*/
|
|
5170
|
-
|
|
5344
|
+
databaseCaseConvention?: CaseConvention;
|
|
5171
5345
|
/**
|
|
5172
|
-
*
|
|
5346
|
+
* Column to use for soft deleted, by default is `deleted_at`
|
|
5173
5347
|
*/
|
|
5174
|
-
|
|
5175
|
-
protected getSqlDataSource(mode: "read" | "write"): Promise<SqlDataSource>;
|
|
5348
|
+
softDeleteColumn?: string;
|
|
5176
5349
|
/**
|
|
5177
|
-
*
|
|
5178
|
-
* @param mode The operation mode (read or write)
|
|
5179
|
-
* @param operation The execSql operation to perform
|
|
5180
|
-
* @returns The result of the operation
|
|
5350
|
+
* Column to use for soft deleted, by default is date in format: "YYYY-MM-DD HH:mm:ss" in UTC timezone
|
|
5181
5351
|
*/
|
|
5182
|
-
|
|
5183
|
-
}
|
|
5184
|
-
|
|
5185
|
-
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
5186
|
-
type SqlMethod = "sum" | "avg" | "max" | "min" | "count" | "upper" | "lower" | "trim" | "length" | "cast" | "convert" | "abs" | "round" | "floor" | "ceil";
|
|
5352
|
+
softDeleteValue?: string | boolean;
|
|
5353
|
+
};
|
|
5187
5354
|
|
|
5355
|
+
/**
|
|
5356
|
+
* Extracts the instance type from a Model class type.
|
|
5357
|
+
*
|
|
5358
|
+
* @example
|
|
5359
|
+
* type UserInstance = ModelInstanceType<typeof User>; // User
|
|
5360
|
+
*/
|
|
5188
5361
|
type ModelInstanceType<O> = O extends typeof Model ? InstanceType<O> : never;
|
|
5362
|
+
/**
|
|
5363
|
+
* Available fetch hook combinations for query execution.
|
|
5364
|
+
* Hooks can be selectively ignored when fetching data.
|
|
5365
|
+
*/
|
|
5189
5366
|
type FetchHooks = ["afterFetch"] | ["beforeFetch"] | ["afterFetch", "beforeFetch"] | ["beforeFetch", "afterFetch"] | [];
|
|
5190
5367
|
type OneOptions = {
|
|
5191
5368
|
ignoreHooks?: FetchHooks;
|
|
@@ -5193,11 +5370,206 @@ type OneOptions = {
|
|
|
5193
5370
|
type ManyOptions = {
|
|
5194
5371
|
ignoreHooks?: FetchHooks;
|
|
5195
5372
|
};
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5373
|
+
/**
|
|
5374
|
+
* Extracts the related Model type from a relation key.
|
|
5375
|
+
*
|
|
5376
|
+
* @example
|
|
5377
|
+
* // If User has: posts: Post[]
|
|
5378
|
+
* type PostModel = RelatedInstance<User, "posts">; // Post
|
|
5379
|
+
*
|
|
5380
|
+
* // If User has: profile: Profile
|
|
5381
|
+
* type ProfileModel = RelatedInstance<User, "profile">; // Profile
|
|
5382
|
+
*/
|
|
5200
5383
|
type RelatedInstance<M extends Model, K extends ModelRelation<M>> = NonNullable<M[K]> extends (infer R)[] ? R extends Model ? R : never : NonNullable<M[K]> extends Model ? NonNullable<M[K]> : never;
|
|
5384
|
+
/**
|
|
5385
|
+
* Utility type to convert a union to an intersection.
|
|
5386
|
+
* Used internally to combine multiple select column types.
|
|
5387
|
+
*
|
|
5388
|
+
* @internal
|
|
5389
|
+
*/
|
|
5390
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
5391
|
+
/**
|
|
5392
|
+
* Represents all valid column selection formats with intellisense support.
|
|
5393
|
+
*
|
|
5394
|
+
* ## Supported Formats
|
|
5395
|
+
*
|
|
5396
|
+
* | Format | Example | Description |
|
|
5397
|
+
* |---------------------------|--------------------------|--------------------------------|
|
|
5398
|
+
* | Model column | `"name"` | Direct column with intellisense |
|
|
5399
|
+
* | Qualified column | `"users.name"` | Table-prefixed column |
|
|
5400
|
+
* | Aliased column | `"name as userName"` | Column with custom alias |
|
|
5401
|
+
* | Wildcard | `"*"` | Select all from primary table |
|
|
5402
|
+
* | Table wildcard | `"users.*"` | Select all from specific table |
|
|
5403
|
+
*
|
|
5404
|
+
* @example
|
|
5405
|
+
* User.query().select(
|
|
5406
|
+
* "name", // Model column with intellisense
|
|
5407
|
+
* "users.email", // Qualified column
|
|
5408
|
+
* "age as userAge", // Aliased column
|
|
5409
|
+
* "*" // All columns
|
|
5410
|
+
* );
|
|
5411
|
+
*/
|
|
5412
|
+
type SelectableColumn<T extends Model> = ModelKey<T> | `${string}.${string}` | `${string} as ${string}` | `${string}(${string}) as ${string}` | "*";
|
|
5413
|
+
/**
|
|
5414
|
+
* Extracts the final property name from a column selection string.
|
|
5415
|
+
*
|
|
5416
|
+
* This type determines what property name will be available on the result:
|
|
5417
|
+
* - Plain columns use their name directly
|
|
5418
|
+
* - Aliased columns use the alias
|
|
5419
|
+
* - Wildcards return `never` (handled specially to return full model)
|
|
5420
|
+
*
|
|
5421
|
+
* ## Extraction Rules
|
|
5422
|
+
*
|
|
5423
|
+
* | Input | Output | Explanation |
|
|
5424
|
+
* |--------------------------|---------------|--------------------------------|
|
|
5425
|
+
* | `"name"` | `"name"` | Direct column |
|
|
5426
|
+
* | `"users.name"` | `"name"` | Extract column from qualified |
|
|
5427
|
+
* | `"name as userName"` | `"userName"` | Use alias |
|
|
5428
|
+
* | `"users.name as author"` | `"author"` | Alias takes precedence |
|
|
5429
|
+
* | `"*"` | `never` | Wildcard - full model |
|
|
5430
|
+
* | `"users.*"` | `never` | Table wildcard - Record<> |
|
|
5431
|
+
*/
|
|
5432
|
+
type ExtractColumnName<S extends string> = S extends `${string} as ${infer Alias}` ? Alias : S extends "*" ? never : S extends `${string}.*` ? never : S extends `${string}.${infer Column}` ? Column extends "*" ? never : Column : S;
|
|
5433
|
+
/**
|
|
5434
|
+
* Resolves the TypeScript type for a selected column.
|
|
5435
|
+
*
|
|
5436
|
+
* If the column exists in the model, its type is used.
|
|
5437
|
+
* Otherwise, `any` is used (for aliased columns, joins, etc.).
|
|
5438
|
+
*
|
|
5439
|
+
* @example
|
|
5440
|
+
* // If User.age is `number`:
|
|
5441
|
+
* GetColumnType<User, "age"> // number
|
|
5442
|
+
* GetColumnType<User, "custom"> // any (not a model column)
|
|
5443
|
+
*/
|
|
5444
|
+
type GetColumnType<T extends Model, ColumnName extends string> = ColumnName extends keyof ModelWithoutRelations<T> ? ModelWithoutRelations<T>[ColumnName] : any;
|
|
5445
|
+
/**
|
|
5446
|
+
* Builds the type for a single selected column.
|
|
5447
|
+
*
|
|
5448
|
+
* ## Type Resolution
|
|
5449
|
+
*
|
|
5450
|
+
* | Selection | Result Type |
|
|
5451
|
+
* |--------------------|---------------------------------------|
|
|
5452
|
+
* | `"*"` | `ModelWithoutRelations<T>` (full) |
|
|
5453
|
+
* | `"table.*"` | `Record<string, any>` (unknown shape) |
|
|
5454
|
+
* | `"column"` | `{ column: ColumnType }` |
|
|
5455
|
+
* | `"col as alias"` | `{ alias: ColumnType }` |
|
|
5456
|
+
*
|
|
5457
|
+
* @internal
|
|
5458
|
+
*/
|
|
5459
|
+
type BuildSingleSelectType<T extends Model, S extends string> = S extends "*" ? ModelWithoutRelations<T> : S extends `${string}.*` ? Record<string, any> : ExtractColumnName<S> extends never ? {} : {
|
|
5460
|
+
[K in ExtractColumnName<S>]: GetColumnType<T, ExtractColumnName<S>>;
|
|
5461
|
+
};
|
|
5462
|
+
/**
|
|
5463
|
+
* Checks if a column selection includes wildcards or is empty.
|
|
5464
|
+
* Used to determine if the full model type should be returned.
|
|
5465
|
+
*
|
|
5466
|
+
* @internal
|
|
5467
|
+
*/
|
|
5468
|
+
type HasStarOrEmpty<Columns extends readonly string[]> = Columns["length"] extends 0 ? true : "*" extends Columns[number] ? true : false;
|
|
5469
|
+
/**
|
|
5470
|
+
* Unique symbol used internally to mark that a select() has been called.
|
|
5471
|
+
*/
|
|
5472
|
+
declare const SELECT_BRAND: unique symbol;
|
|
5473
|
+
/**
|
|
5474
|
+
* Marker type to indicate that a select() has been called.
|
|
5475
|
+
* This brand is used to distinguish between:
|
|
5476
|
+
* - Initial state: ModelWithoutRelations<T> (no select called)
|
|
5477
|
+
* - After select: { selectedColumns } & Pick<Model, keyof Model> & SelectBrand
|
|
5478
|
+
*
|
|
5479
|
+
* @internal
|
|
5480
|
+
*/
|
|
5481
|
+
type SelectBrand = {
|
|
5482
|
+
[SELECT_BRAND]?: never;
|
|
5483
|
+
};
|
|
5484
|
+
/**
|
|
5485
|
+
* Builds the combined TypeScript type for multiple selected columns.
|
|
5486
|
+
*
|
|
5487
|
+
* This is the main type used to compute the return type of `select()` calls.
|
|
5488
|
+
* It handles all the complexity of combining multiple column selections into
|
|
5489
|
+
* a single coherent type.
|
|
5490
|
+
*
|
|
5491
|
+
* ## Rules
|
|
5492
|
+
*
|
|
5493
|
+
* 1. **Empty selection or `*`**: Returns full `ModelWithoutRelations<T>`
|
|
5494
|
+
* 2. **Specific columns**: Returns intersection of all selected column types
|
|
5495
|
+
* 3. **With `table.*`**: Adds `Record<string, any>` to allow unknown properties
|
|
5496
|
+
* 4. **Always includes**: Base `Model` methods (save, delete, etc.)
|
|
5497
|
+
*
|
|
5498
|
+
* @example
|
|
5499
|
+
* // .select("name", "age as userAge")
|
|
5500
|
+
* BuildSelectType<User, ["name", "age as userAge"]>
|
|
5501
|
+
* // Result: { name: string; userAge: number } & Pick<Model, keyof Model>
|
|
5502
|
+
*
|
|
5503
|
+
* @example
|
|
5504
|
+
* // .select("*")
|
|
5505
|
+
* BuildSelectType<User, ["*"]>
|
|
5506
|
+
* // Result: ModelWithoutRelations<User> (all columns)
|
|
5507
|
+
*/
|
|
5508
|
+
type BuildSelectType<T extends Model, Columns extends readonly string[]> = HasStarOrEmpty<Columns> extends true ? ModelWithoutRelations<T> : UnionToIntersection<{
|
|
5509
|
+
[K in keyof Columns]: Columns[K] extends string ? BuildSingleSelectType<T, Columns[K]> : {};
|
|
5510
|
+
}[number]> extends infer Result ? Result extends Record<string, any> ? keyof Result extends never ? ModelWithoutRelations<T> : Result & Pick<Model, keyof Model> & SelectBrand : ModelWithoutRelations<T> : ModelWithoutRelations<T>;
|
|
5511
|
+
/**
|
|
5512
|
+
* Composes a new selection with the existing selection state.
|
|
5513
|
+
*
|
|
5514
|
+
* - If S is the default ModelWithoutRelations (no previous select), drops default columns
|
|
5515
|
+
* and returns only the new selection with model methods
|
|
5516
|
+
* - If S already has SelectBrand (from a previous select), composes with new selection
|
|
5517
|
+
*
|
|
5518
|
+
* Uses SelectBrand (a unique symbol) as a marker to detect if a select has been called.
|
|
5519
|
+
*
|
|
5520
|
+
* @typeParam S - Current selection state
|
|
5521
|
+
* @typeParam Added - New fields being added by the select
|
|
5522
|
+
*
|
|
5523
|
+
* @example
|
|
5524
|
+
* // First select - drops default columns
|
|
5525
|
+
* ComposeSelect<ModelWithoutRelations<User>, { count: number }>
|
|
5526
|
+
* // Result: Pick<Model, keyof Model> & SelectBrand & { count: number }
|
|
5527
|
+
*
|
|
5528
|
+
* @example
|
|
5529
|
+
* // Chained select - composes with previous
|
|
5530
|
+
* ComposeSelect<{ count: number } & Pick<Model, keyof Model> & SelectBrand, { userName: string }>
|
|
5531
|
+
* // Result: { count: number } & Pick<Model, keyof Model> & SelectBrand & { userName: string }
|
|
5532
|
+
*/
|
|
5533
|
+
type ComposeSelect<S extends Record<string, any>, Added extends Record<string, any>> = (typeof SELECT_BRAND extends keyof S ? S : Pick<Model, keyof Model> & SelectBrand) & Added;
|
|
5534
|
+
/**
|
|
5535
|
+
* Composes a BuildSelectType result with the existing selection state.
|
|
5536
|
+
*
|
|
5537
|
+
* Similar to ComposeSelect but designed for use with BuildSelectType which already
|
|
5538
|
+
* includes Pick<Model, keyof Model> and SelectBrand in its result.
|
|
5539
|
+
*
|
|
5540
|
+
* - If S is the default ModelWithoutRelations (no previous select), returns just BuildSelectType
|
|
5541
|
+
* - If S already has SelectBrand (from a previous select), composes S with BuildSelectType
|
|
5542
|
+
* - This is checked using the SELECT_BRAND symbol to detect if another select was already used
|
|
5543
|
+
*
|
|
5544
|
+
* @typeParam S - Current selection state
|
|
5545
|
+
* @typeParam T - The Model type
|
|
5546
|
+
* @typeParam Columns - The columns being selected
|
|
5547
|
+
*
|
|
5548
|
+
* @example
|
|
5549
|
+
* // First select - returns BuildSelectType result
|
|
5550
|
+
* ComposeBuildSelect<ModelWithoutRelations<User>, User, ["id", "name"]>
|
|
5551
|
+
* // Result: { id: number; name: string } & Pick<Model, keyof Model> & SelectBrand
|
|
5552
|
+
*
|
|
5553
|
+
* @example
|
|
5554
|
+
* // Chained select - composes with previous
|
|
5555
|
+
* ComposeBuildSelect<{ count: number } & Pick<Model, keyof Model> & SelectBrand, User, ["id"]>
|
|
5556
|
+
* // Result: { count: number } & Pick<Model, keyof Model> & SelectBrand & { id: number }
|
|
5557
|
+
*/
|
|
5558
|
+
type ComposeBuildSelect<S extends Record<string, any>, T extends Model, Columns extends readonly string[]> = (typeof SELECT_BRAND extends keyof S ? S : {}) & BuildSelectType<T, Columns>;
|
|
5559
|
+
/**
|
|
5560
|
+
* The final result type for ModelQueryBuilder queries.
|
|
5561
|
+
*
|
|
5562
|
+
* Combines selected columns (S) with loaded relations (R) into a single type.
|
|
5563
|
+
*
|
|
5564
|
+
* @typeParam S - Selected columns type from `select()` calls
|
|
5565
|
+
* @typeParam R - Relations type from `load()` calls
|
|
5566
|
+
*
|
|
5567
|
+
* @example
|
|
5568
|
+
* // User.query().select("name").load("posts").one()
|
|
5569
|
+
* SelectedModel<{ name: string }, { posts: Post[] }>
|
|
5570
|
+
* // Result: { name: string; posts: Post[] }
|
|
5571
|
+
*/
|
|
5572
|
+
type SelectedModel<S extends Record<string, any> = {}, R extends Record<string, any> = {}> = S & R;
|
|
5201
5573
|
|
|
5202
5574
|
type NullableAndUndefinable<T> = T | (T | null) | (T | undefined) | (T | null | undefined);
|
|
5203
5575
|
type UpsertOptions<T extends Model> = {
|
|
@@ -5329,7 +5701,7 @@ declare abstract class Model extends Entity {
|
|
|
5329
5701
|
/**
|
|
5330
5702
|
* @description Returns all the records for the given model
|
|
5331
5703
|
*/
|
|
5332
|
-
static all<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<
|
|
5704
|
+
static all<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<ModelWithoutRelations<T>[]>;
|
|
5333
5705
|
/**
|
|
5334
5706
|
* @description Gives a query sqlInstance for the given model
|
|
5335
5707
|
*/
|
|
@@ -5343,7 +5715,7 @@ declare abstract class Model extends Entity {
|
|
|
5343
5715
|
* @description Finds the first record in the database
|
|
5344
5716
|
* @deprecated Used only for debugging purposes, use `.findOne` or `.query` instead
|
|
5345
5717
|
*/
|
|
5346
|
-
static first<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<
|
|
5718
|
+
static first<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<ModelWithoutRelations<T> | null>;
|
|
5347
5719
|
/**
|
|
5348
5720
|
* @description Finds records for the given model
|
|
5349
5721
|
*/
|
|
@@ -5373,26 +5745,24 @@ declare abstract class Model extends Entity {
|
|
|
5373
5745
|
/**
|
|
5374
5746
|
* @description Refreshes a model from the database, the model must have a primary key defined
|
|
5375
5747
|
*/
|
|
5376
|
-
static refresh<T extends Model>(this: new () => T | typeof Model, model: T, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<
|
|
5748
|
+
static refresh<T extends Model>(this: new () => T | typeof Model, model: T, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<ModelWithoutRelations<T> | null>;
|
|
5377
5749
|
/**
|
|
5378
5750
|
* @description Saves a new record to the database
|
|
5379
|
-
* @description $annotations will be ignored if set in the modelData and won't be returned in the response
|
|
5380
5751
|
* @warning If not using postgres and the model has no primary key, the model will be saved, but it won't be possible to retrieve it so at that point it will be returned as null, this is not typed as Model | null for type safety reasons
|
|
5381
5752
|
* @mysql If no Primary Key is present in the model definition, the model will be returned
|
|
5382
5753
|
* @sqlite If no Primary Key is present in the model definition, the model will be returned
|
|
5383
5754
|
* @sqlite Returning Not supported and won't have effect
|
|
5384
5755
|
*/
|
|
5385
|
-
static insert<T extends Model>(this: new () => T | typeof Model, modelData: Partial<ModelWithoutRelations<T>>, options?: BaseModelMethodOptions & InsertOptions<T>): Promise<
|
|
5756
|
+
static insert<T extends Model>(this: new () => T | typeof Model, modelData: Partial<ModelWithoutRelations<T>>, options?: BaseModelMethodOptions & InsertOptions<T>): Promise<ModelWithoutRelations<T>>;
|
|
5386
5757
|
/**
|
|
5387
5758
|
* @description Saves multiple records to the database
|
|
5388
|
-
* @description $annotations will be ignored if set in the modelData and won't be returned in the response
|
|
5389
5759
|
* @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
|
|
5390
5760
|
* @mysql If no Primary Key is present in the model definition, the model will be returned
|
|
5391
5761
|
* @sqlite If no Primary Key is present in the model definition, the model will be returned
|
|
5392
5762
|
* @sqlite Returning Not supported and won't have effect
|
|
5393
5763
|
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
5394
5764
|
*/
|
|
5395
|
-
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>): Promise<
|
|
5765
|
+
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>): Promise<ModelWithoutRelations<T>[]>;
|
|
5396
5766
|
/**
|
|
5397
5767
|
* @description Syncs in the through table the given models for the given relation
|
|
5398
5768
|
* @param relation The many to many relation to sync, this is not type safe since many to many relations defined at a decorator level
|
|
@@ -5414,7 +5784,7 @@ declare abstract class Model extends Entity {
|
|
|
5414
5784
|
* @description Can only be used if the model has a primary key, use a massive update if the model has no primary key
|
|
5415
5785
|
* @throws {HysteriaError} If the model has no primary key
|
|
5416
5786
|
*/
|
|
5417
|
-
static updateRecord<T extends Model>(this: new () => T | typeof Model, modelSqlInstance: Partial<T>, updatePayload?: Partial<ModelWithoutRelations<T>>, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<
|
|
5787
|
+
static updateRecord<T extends Model>(this: new () => T | typeof Model, modelSqlInstance: Partial<T>, updatePayload?: Partial<ModelWithoutRelations<T>>, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<ModelWithoutRelations<T>>;
|
|
5418
5788
|
/**
|
|
5419
5789
|
* @description Finds the first record or creates a new one if it doesn't exist
|
|
5420
5790
|
*/
|
|
@@ -5427,12 +5797,12 @@ declare abstract class Model extends Entity {
|
|
|
5427
5797
|
/**
|
|
5428
5798
|
* @description Updates or creates a new record, if no searchCriteria payload is provided, provided data will be inserted as is
|
|
5429
5799
|
*/
|
|
5430
|
-
static upsert<T extends Model>(this: new () => T | typeof Model, searchCriteria: Partial<ModelWithoutRelations<T>>, data: Partial<ModelWithoutRelations<T>>, options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<
|
|
5800
|
+
static upsert<T extends Model>(this: new () => T | typeof Model, searchCriteria: Partial<ModelWithoutRelations<T>>, data: Partial<ModelWithoutRelations<T>>, options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<ModelWithoutRelations<T>>;
|
|
5431
5801
|
/**
|
|
5432
5802
|
* @description Updates or creates multiple records
|
|
5433
5803
|
* @param {updateOnConflict} If true, the record will be updated if it exists, otherwise it will be ignored
|
|
5434
5804
|
*/
|
|
5435
|
-
static upsertMany<T extends Model>(this: new () => T | typeof Model, conflictColumns: ModelKey<T>[], data: Partial<ModelWithoutRelations<T>>[], options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<
|
|
5805
|
+
static upsertMany<T extends Model>(this: new () => T | typeof Model, conflictColumns: ModelKey<T>[], data: Partial<ModelWithoutRelations<T>>[], options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<ModelWithoutRelations<T>[]>;
|
|
5436
5806
|
/**
|
|
5437
5807
|
* @description Deletes a record to the database
|
|
5438
5808
|
*/
|
|
@@ -5446,7 +5816,7 @@ declare abstract class Model extends Entity {
|
|
|
5446
5816
|
static softDelete<T extends Model>(this: new () => T | typeof Model, modelSqlInstance: T, softDeleteOptions?: {
|
|
5447
5817
|
column?: ModelKey<T>;
|
|
5448
5818
|
value?: string | number | boolean | Date;
|
|
5449
|
-
}, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<
|
|
5819
|
+
}, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<ModelWithoutRelations<T>>;
|
|
5450
5820
|
/**
|
|
5451
5821
|
* @description Truncates the table for the given model
|
|
5452
5822
|
*/
|
|
@@ -5666,12 +6036,6 @@ declare abstract class Model extends Entity {
|
|
|
5666
6036
|
* @throws {HysteriaError} If the model has no primary key valorized in the instance
|
|
5667
6037
|
*/
|
|
5668
6038
|
refresh<T extends Model = this>(options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<T>;
|
|
5669
|
-
/**
|
|
5670
|
-
* @description Converts the model to a JSON object
|
|
5671
|
-
* @description Flattens all `$annotations` into the JSON object at first level including the relations
|
|
5672
|
-
* @warning Use with caution, this method flattens the `$annotations` into the JSON object at first level including the relations, so if you have conflicting column names between model columns and annotations, the annotation could override the model column value
|
|
5673
|
-
*/
|
|
5674
|
-
toJSON(): Record<string, any>;
|
|
5675
6039
|
}
|
|
5676
6040
|
|
|
5677
6041
|
type BaseModelRelationType = {
|
|
@@ -6939,4 +7303,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
6939
7303
|
$id?: string;
|
|
6940
7304
|
}>;
|
|
6941
7305
|
|
|
6942
|
-
export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type
|
|
7306
|
+
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 ExtractColumnName, 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 ModelInstanceType, ModelQueryBuilder, 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, 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 };
|