hysteria-orm 10.2.2 → 10.3.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.cjs +136 -28
- package/lib/cli.cjs.map +1 -1
- package/lib/cli.d.cts +2 -1
- package/lib/cli.d.ts +2 -1
- package/lib/cli.js +136 -28
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +115 -19
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +781 -710
- package/lib/index.d.ts +781 -710
- package/lib/index.js +115 -19
- package/lib/index.js.map +1 -1
- package/package.json +14 -2
package/lib/index.d.cts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { PoolAttributes, Pool, Connection, Result } from 'oracledb';
|
|
2
|
+
import * as mssql from 'mssql';
|
|
3
|
+
import { config, Transaction as Transaction$1, IResult } from 'mssql';
|
|
1
4
|
import * as mongodb from 'mongodb';
|
|
2
5
|
import { Collection as Collection$1 } from 'mongodb';
|
|
3
6
|
import * as sqlite3 from 'sqlite3';
|
|
7
|
+
import { RunResult } from 'sqlite3';
|
|
4
8
|
import * as pg from 'pg';
|
|
5
|
-
import { ClientConfig, PoolClient } from 'pg';
|
|
9
|
+
import { ClientConfig, PoolClient, QueryResult as QueryResult$1 } from 'pg';
|
|
6
10
|
import * as mysql2_promise from 'mysql2/promise';
|
|
7
|
-
import { PoolOptions, PoolConnection } from 'mysql2/promise';
|
|
11
|
+
import { PoolOptions, PoolConnection, QueryResult } from 'mysql2/promise';
|
|
8
12
|
import { RedisOptions, Redis } from 'ioredis';
|
|
9
13
|
import { PassThrough } from 'node:stream';
|
|
10
14
|
import { FormatOptionsWithLanguage } from 'sql-formatter';
|
|
15
|
+
import express from 'express';
|
|
11
16
|
|
|
12
17
|
type CaseConvention = "camel" | "snake" | "preserve" | RegExp | ((column: string) => string);
|
|
13
18
|
|
|
@@ -32,12 +37,28 @@ declare abstract class Entity {
|
|
|
32
37
|
/**
|
|
33
38
|
* @description Creates a datasource for the selected database type with the provided credentials
|
|
34
39
|
*/
|
|
35
|
-
type DataSourceType = "cockroachdb" | "mysql" | "postgres" | "mariadb" | "sqlite" | "mongo";
|
|
40
|
+
type DataSourceType = "oracledb" | "cockroachdb" | "mysql" | "postgres" | "mariadb" | "sqlite" | "mssql" | "mongo";
|
|
41
|
+
interface MssqlDataSourceInput extends CommonDataSourceInput {
|
|
42
|
+
readonly type: "mssql";
|
|
43
|
+
readonly host?: string;
|
|
44
|
+
readonly port?: number;
|
|
45
|
+
readonly username?: string;
|
|
46
|
+
readonly password?: string;
|
|
47
|
+
readonly database?: string;
|
|
48
|
+
}
|
|
49
|
+
interface OracleDBDataSourceInput extends CommonDataSourceInput {
|
|
50
|
+
readonly type: "oracledb";
|
|
51
|
+
readonly host?: string;
|
|
52
|
+
readonly port?: number;
|
|
53
|
+
readonly username?: string;
|
|
54
|
+
readonly password?: string;
|
|
55
|
+
readonly database?: string;
|
|
56
|
+
}
|
|
36
57
|
interface CommonDataSourceInput {
|
|
37
58
|
readonly type?: DataSourceType;
|
|
38
59
|
readonly logs?: boolean;
|
|
39
60
|
}
|
|
40
|
-
interface MongoDataSourceInput extends CommonDataSourceInput {
|
|
61
|
+
interface MongoDataSourceInput$1 extends CommonDataSourceInput {
|
|
41
62
|
readonly type: "mongo";
|
|
42
63
|
readonly mongoOptions?: MongoConnectionOptions;
|
|
43
64
|
readonly url?: string;
|
|
@@ -58,6 +79,22 @@ interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInp
|
|
|
58
79
|
readonly database: string;
|
|
59
80
|
readonly port?: number;
|
|
60
81
|
}
|
|
82
|
+
interface NotNullableOracleMssqlDataSourceInput extends MssqlDataSourceInput {
|
|
83
|
+
readonly type: "mssql";
|
|
84
|
+
readonly host: string;
|
|
85
|
+
readonly username: string;
|
|
86
|
+
readonly password: string;
|
|
87
|
+
readonly database: string;
|
|
88
|
+
readonly port?: number;
|
|
89
|
+
}
|
|
90
|
+
interface NotNullableOracleDBDataSourceInput extends OracleDBDataSourceInput {
|
|
91
|
+
readonly type: "oracledb";
|
|
92
|
+
readonly host: string;
|
|
93
|
+
readonly username: string;
|
|
94
|
+
readonly password: string;
|
|
95
|
+
readonly database: string;
|
|
96
|
+
readonly port?: number;
|
|
97
|
+
}
|
|
61
98
|
interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
|
|
62
99
|
readonly type?: "mysql" | "mariadb";
|
|
63
100
|
readonly host?: string;
|
|
@@ -85,16 +122,21 @@ interface NotNullableSqliteDataSourceInput extends SqliteDataSourceInput {
|
|
|
85
122
|
/**
|
|
86
123
|
* @description By default the connection details can be provided in the .env file, you can still override each prop with your actual connection details in the input
|
|
87
124
|
*/
|
|
88
|
-
type DataSourceInput = MysqlSqlDataSourceInput | SqliteDataSourceInput | PostgresSqlDataSourceInput | MongoDataSourceInput;
|
|
125
|
+
type DataSourceInput = OracleDBDataSourceInput | MssqlDataSourceInput | MysqlSqlDataSourceInput | SqliteDataSourceInput | PostgresSqlDataSourceInput | MongoDataSourceInput$1;
|
|
89
126
|
|
|
90
127
|
type Mysql2Import = typeof mysql2_promise;
|
|
91
128
|
type PgImport = typeof pg;
|
|
92
129
|
type Sqlite3Import = typeof sqlite3;
|
|
93
130
|
type MongoClientImport = typeof mongodb;
|
|
131
|
+
type MssqlImport = typeof mssql;
|
|
132
|
+
type OracleDBCreateConnectionOptions = PoolAttributes;
|
|
94
133
|
type MysqlCreateConnectionOptions = PoolOptions;
|
|
95
134
|
type PgClientOptions = ClientConfig;
|
|
135
|
+
type MssqlConnectionOptions = Omit<config, "options"> & {
|
|
136
|
+
options?: Omit<NonNullable<config["options"]>, "abortTransactionOnError" | "enableImplicitTransactions">;
|
|
137
|
+
};
|
|
96
138
|
type MongoConnectionOptions = NonNullable<ConstructorParameters<MongoClientImport["MongoClient"]>[1]>;
|
|
97
|
-
type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ? PgClientOptions : T extends "redis" ? RedisOptions : T extends "mysql" | "mariadb" ? MysqlCreateConnectionOptions : never;
|
|
139
|
+
type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ? PgClientOptions : T extends "redis" ? RedisOptions : T extends "mysql" | "mariadb" ? MysqlCreateConnectionOptions : T extends "mssql" ? MssqlConnectionOptions : T extends "oracledb" ? OracleDBCreateConnectionOptions : never;
|
|
98
140
|
|
|
99
141
|
type MongoCollectionKey<T> = T extends Collection ? T : never;
|
|
100
142
|
type BaseModelMethodOptions$1 = {
|
|
@@ -435,7 +477,9 @@ declare abstract class DataSource {
|
|
|
435
477
|
protected handlePostgresSource(input?: PostgresSqlDataSourceInput): void;
|
|
436
478
|
protected handleMysqlSource(input?: MysqlSqlDataSourceInput): void;
|
|
437
479
|
protected handleSqliteSource(input?: SqliteDataSourceInput): void;
|
|
438
|
-
protected handleMongoSource(input?: MongoDataSourceInput): void;
|
|
480
|
+
protected handleMongoSource(input?: MongoDataSourceInput$1): void;
|
|
481
|
+
protected handleMssqlSource(input?: MssqlDataSourceInput): void;
|
|
482
|
+
protected handleOracleDBSource(input?: MssqlDataSourceInput): void;
|
|
439
483
|
}
|
|
440
484
|
|
|
441
485
|
type MongoFindOneOptions<T extends Collection> = {
|
|
@@ -507,22 +551,34 @@ declare class CollectionManager<T extends Collection> {
|
|
|
507
551
|
}
|
|
508
552
|
|
|
509
553
|
type MongoClientInstance = InstanceType<MongoClientImport["MongoClient"]>;
|
|
554
|
+
interface MongoDataSourceInput {
|
|
555
|
+
url?: string;
|
|
556
|
+
options?: MongoConnectionOptions;
|
|
557
|
+
logs?: boolean;
|
|
558
|
+
}
|
|
510
559
|
declare class MongoDataSource extends DataSource {
|
|
511
560
|
url: string;
|
|
512
561
|
isConnected: boolean;
|
|
513
562
|
private mongoClient;
|
|
563
|
+
private mongoOptions?;
|
|
514
564
|
private static instance;
|
|
515
|
-
|
|
565
|
+
constructor(input?: MongoDataSourceInput);
|
|
566
|
+
/**
|
|
567
|
+
* @description Establishes the connection to MongoDB and sets this as the primary instance
|
|
568
|
+
*/
|
|
569
|
+
connect(): Promise<void>;
|
|
570
|
+
/**
|
|
571
|
+
* @description Establishes the connection without setting this as the primary instance
|
|
572
|
+
*/
|
|
573
|
+
private connectWithoutSettingPrimary;
|
|
516
574
|
/**
|
|
517
575
|
* @description Returns the current connection to the mongo client to execute direct statements using the mongo client from `mongodb` package
|
|
518
576
|
*/
|
|
519
577
|
getCurrentConnection(): MongoClientInstance;
|
|
520
578
|
/**
|
|
521
|
-
* @description
|
|
579
|
+
* @description Creates a secondary connection to MongoDB (does not become the primary instance)
|
|
522
580
|
*/
|
|
523
|
-
static
|
|
524
|
-
logs?: boolean;
|
|
525
|
-
}, cb?: (mongoDataSource: MongoDataSource) => Promise<void> | void): Promise<MongoDataSource>;
|
|
581
|
+
static connectToSecondarySource(input: MongoDataSourceInput): Promise<MongoDataSource>;
|
|
526
582
|
static getInstance(): MongoDataSource;
|
|
527
583
|
/**
|
|
528
584
|
* @description Starts a new session and transaction using the current connection
|
|
@@ -547,12 +603,9 @@ declare class MongoDataSource extends DataSource {
|
|
|
547
603
|
*/
|
|
548
604
|
static closeConnection(): Promise<void>;
|
|
549
605
|
/**
|
|
550
|
-
* @description Executes a callback function with the provided connection details
|
|
606
|
+
* @description Executes a callback function with the provided connection details, automatically closing the connection when done
|
|
551
607
|
*/
|
|
552
|
-
static useConnection(this: typeof MongoDataSource,
|
|
553
|
-
url: string;
|
|
554
|
-
options?: MongoConnectionOptions;
|
|
555
|
-
}, cb: (mongoDataSource: MongoDataSource) => Promise<void>): Promise<void>;
|
|
608
|
+
static useConnection(this: typeof MongoDataSource, input: MongoDataSourceInput, cb: (mongoDataSource: MongoDataSource) => Promise<void>): Promise<void>;
|
|
556
609
|
static query(collection: string): MongoQueryBuilder<Collection>;
|
|
557
610
|
query(collection: string): MongoQueryBuilder<Collection>;
|
|
558
611
|
getModelManager<T extends Collection>(model: typeof Collection, mongoDataSource: MongoDataSource, session?: InstanceType<MongoClientImport["ClientSession"]>): CollectionManager<T>;
|
|
@@ -1016,7 +1069,7 @@ type AdminJsInstance = {
|
|
|
1016
1069
|
/**
|
|
1017
1070
|
* @description Express router for AdminJS (if using express adapter)
|
|
1018
1071
|
*/
|
|
1019
|
-
router?:
|
|
1072
|
+
router?: ReturnType<typeof express.Router>;
|
|
1020
1073
|
};
|
|
1021
1074
|
|
|
1022
1075
|
interface CacheAdapter {
|
|
@@ -1026,23 +1079,133 @@ interface CacheAdapter {
|
|
|
1026
1079
|
disconnect?(): Promise<void>;
|
|
1027
1080
|
}
|
|
1028
1081
|
|
|
1029
|
-
type CacheKeys = Record<string, (...args: any[]) => Promise<any
|
|
1082
|
+
type CacheKeys = Record<string, (...args: any[]) => Promise<any> | any>;
|
|
1030
1083
|
type UseCacheReturnType<C extends CacheKeys, K extends keyof C> = K extends never ? never : Awaited<ReturnType<C[K]>>;
|
|
1031
1084
|
|
|
1032
|
-
type
|
|
1033
|
-
|
|
1034
|
-
properties: Record<string, OpenApiModelPropertyType>;
|
|
1035
|
-
required?: string[];
|
|
1085
|
+
type Sqlite3ConnectionOptions = {
|
|
1086
|
+
mode: number;
|
|
1036
1087
|
};
|
|
1037
|
-
type
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1088
|
+
type SqlDriverSpecificOptions<T extends DataSourceType> = Omit<DriverSpecificOptions<T>, "mongoOptions" | "redisOptions">;
|
|
1089
|
+
type MysqlConnectionInstance = Awaited<ReturnType<Mysql2Import["createPool"]>>;
|
|
1090
|
+
type PgPoolClientInstance = InstanceType<PgImport["Pool"]>;
|
|
1091
|
+
type SqliteConnectionInstance = InstanceType<Sqlite3Import["Database"]>;
|
|
1092
|
+
type OracleDBPoolInstance = Pool;
|
|
1093
|
+
type MssqlPoolInstance = InstanceType<MssqlImport["ConnectionPool"]>;
|
|
1094
|
+
type MssqlConnectionInstance = Awaited<ReturnType<MssqlPoolInstance["connect"]>>;
|
|
1095
|
+
type SqlPoolType = OracleDBPoolInstance | MysqlConnectionInstance | PgPoolClientInstance | SqliteConnectionInstance | MssqlPoolInstance;
|
|
1096
|
+
/**
|
|
1097
|
+
* @description The connection policies for the sql data source
|
|
1098
|
+
* @default the connection policies are not set, so no query will be retried
|
|
1099
|
+
*/
|
|
1100
|
+
type ConnectionPolicies = {
|
|
1101
|
+
/**
|
|
1102
|
+
* @description The retry policy for the sql data source, it allows to retry a query if it fails
|
|
1103
|
+
*/
|
|
1104
|
+
retry?: {
|
|
1105
|
+
maxRetries?: number;
|
|
1106
|
+
delay?: number;
|
|
1107
|
+
};
|
|
1108
|
+
};
|
|
1109
|
+
type SqlDataSourceModel = typeof Model;
|
|
1110
|
+
/**
|
|
1111
|
+
* @description Common input properties shared across all SqlDataSource types
|
|
1112
|
+
*/
|
|
1113
|
+
type SqlDataSourceInputBase<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
|
|
1114
|
+
/**
|
|
1115
|
+
* @description Whether to log the sql queries and other debug information
|
|
1116
|
+
*/
|
|
1117
|
+
readonly logs?: boolean;
|
|
1118
|
+
/**
|
|
1119
|
+
* @description The connection policies to use for the sql data source that are not configured in the driverOptions
|
|
1120
|
+
*/
|
|
1121
|
+
connectionPolicies?: ConnectionPolicies;
|
|
1122
|
+
/**
|
|
1123
|
+
* @description The query format options to use for the sql data source, it tells how the sql queries should be formatted before being executed and logged
|
|
1124
|
+
*/
|
|
1125
|
+
queryFormatOptions?: FormatOptionsWithLanguage;
|
|
1126
|
+
/**
|
|
1127
|
+
* @description The models to use for the sql data source, if used models will be registered in the sql data source instance and will be available for the models to use
|
|
1128
|
+
* @description Models can still be used as standalone entities, but they won't be available for the sql data source instance
|
|
1129
|
+
*/
|
|
1130
|
+
models?: T;
|
|
1131
|
+
/**
|
|
1132
|
+
* @description The path to the migrations folder for the sql data source, it's used to configure the migrations path for the sql data source
|
|
1133
|
+
* @default "database/migrations"
|
|
1134
|
+
*/
|
|
1135
|
+
migrationsPath?: string;
|
|
1136
|
+
/**
|
|
1137
|
+
* @description The cache strategy to use for the sql data source, it's used to configure the cache strategy for the sql data source
|
|
1138
|
+
*/
|
|
1139
|
+
cacheStrategy?: {
|
|
1140
|
+
cacheAdapter?: CacheAdapter;
|
|
1141
|
+
keys: C;
|
|
1142
|
+
};
|
|
1143
|
+
/**
|
|
1144
|
+
* @description AdminJS configuration for the admin panel
|
|
1145
|
+
* @description To use AdminJS, install: `npm install adminjs`
|
|
1146
|
+
*/
|
|
1147
|
+
adminJs?: AdminJsOptions;
|
|
1148
|
+
};
|
|
1149
|
+
/**
|
|
1150
|
+
* @description Maps a SqlDataSourceType to its corresponding input interface
|
|
1151
|
+
*/
|
|
1152
|
+
type MapSqlDataSourceTypeToInput<D extends SqlDataSourceType> = D extends "mysql" | "mariadb" ? MysqlSqlDataSourceInput : D extends "postgres" | "cockroachdb" ? PostgresSqlDataSourceInput : D extends "sqlite" ? SqliteDataSourceInput : D extends "mssql" ? MssqlDataSourceInput : D extends "oracledb" ? OracleDBDataSourceInput : never;
|
|
1153
|
+
/**
|
|
1154
|
+
* @description The input type for the SqlDataSource constructor
|
|
1155
|
+
* @description The connectionPolicies object is used to configure the connection policies for the sql data source
|
|
1156
|
+
*/
|
|
1157
|
+
type SqlDataSourceInput<D extends SqlDataSourceType = SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = SqlDataSourceInputBase<T, C> & {
|
|
1158
|
+
/**
|
|
1159
|
+
* @description The type of the database to connect to
|
|
1160
|
+
*/
|
|
1161
|
+
readonly type: D;
|
|
1162
|
+
/**
|
|
1163
|
+
* @description The driver specific options to use for the sql data source, it's used to configure the driver specific options for the sql data source
|
|
1164
|
+
* @warning For usage with types, you must have driver types installed if the driver handles types in a type package like e.g. `@types/pg`
|
|
1165
|
+
*/
|
|
1166
|
+
driverOptions?: SqlDriverSpecificOptions<D>;
|
|
1167
|
+
} & Omit<MapSqlDataSourceTypeToInput<D>, "type">;
|
|
1168
|
+
/**
|
|
1169
|
+
* @description Maps a SqlDataSourceType to its corresponding non-nullable input interface
|
|
1170
|
+
*/
|
|
1171
|
+
type MapSqlDataSourceTypeToNotNullableInput<D extends SqlDataSourceType> = D extends "mysql" | "mariadb" ? NotNullableMysqlSqlDataSourceInput : D extends "postgres" | "cockroachdb" ? NotNullablePostgresSqlDataSourceInput : D extends "sqlite" ? NotNullableSqliteDataSourceInput : D extends "mssql" ? NotNullableOracleMssqlDataSourceInput : D extends "oracledb" ? NotNullableOracleDBDataSourceInput : never;
|
|
1172
|
+
type UseConnectionInput<D extends SqlDataSourceType = SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
|
|
1173
|
+
/**
|
|
1174
|
+
* @description The type of the database to connect to
|
|
1175
|
+
*/
|
|
1176
|
+
readonly type: D;
|
|
1177
|
+
readonly logs?: boolean;
|
|
1178
|
+
readonly models?: T;
|
|
1179
|
+
readonly driverOptions?: SqlDriverSpecificOptions<D>;
|
|
1180
|
+
connectionPolicies?: ConnectionPolicies;
|
|
1181
|
+
queryFormatOptions?: FormatOptionsWithLanguage;
|
|
1182
|
+
cacheStrategy?: {
|
|
1183
|
+
cacheAdapter: CacheAdapter;
|
|
1184
|
+
keys: C;
|
|
1185
|
+
};
|
|
1186
|
+
/**
|
|
1187
|
+
* @description AdminJS configuration for the admin panel
|
|
1188
|
+
* @description AdminJS is completely optional - dependencies are loaded at runtime via dynamic import()
|
|
1189
|
+
*/
|
|
1190
|
+
adminJs?: AdminJsOptions;
|
|
1191
|
+
} & Omit<MapSqlDataSourceTypeToNotNullableInput<D>, "type">;
|
|
1192
|
+
type SqlDataSourceType = Exclude<DataSourceType, "mongo">;
|
|
1193
|
+
type SqlCloneOptions = {
|
|
1194
|
+
/**
|
|
1195
|
+
* @description Whether to recreate the pool of connections for the given driver, by default it's false
|
|
1196
|
+
* @warning If false, the pool of connections will be reused from the caller instance
|
|
1197
|
+
*/
|
|
1198
|
+
shouldRecreatePool?: boolean;
|
|
1199
|
+
};
|
|
1200
|
+
type getPoolReturnType<T = SqlDataSourceType> = T extends "mysql" ? MysqlConnectionInstance : T extends "mariadb" ? MysqlConnectionInstance : T extends "postgres" ? PgPoolClientInstance : T extends "cockroachdb" ? PgPoolClientInstance : T extends "sqlite" ? SqliteConnectionInstance : T extends "mssql" ? MssqlPoolInstance : T extends "oracledb" ? OracleDBPoolInstance : never;
|
|
1201
|
+
type GetConnectionReturnType<T = SqlDataSourceType> = T extends "mysql" ? PoolConnection : T extends "mariadb" ? PoolConnection : T extends "postgres" ? PoolClient : T extends "cockroachdb" ? PoolClient : T extends "sqlite" ? InstanceType<Sqlite3Import["Database"]> : T extends "mssql" ? Transaction$1 : T extends "oracledb" ? Connection : never;
|
|
1202
|
+
/** Only accepts formats `string` e `string as string` */
|
|
1203
|
+
type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
|
|
1204
|
+
type TableFormat<S extends string> = NoSpace<S> | (S extends `${infer L} as ${infer R}` ? `${NoSpace<L>} as ${NoSpace<R>}` : never);
|
|
1205
|
+
|
|
1206
|
+
type AstParserType = {
|
|
1207
|
+
sql: string;
|
|
1208
|
+
bindings: any[];
|
|
1046
1209
|
};
|
|
1047
1210
|
|
|
1048
1211
|
declare abstract class QueryNode {
|
|
@@ -1077,6 +1240,48 @@ declare abstract class QueryNode {
|
|
|
1077
1240
|
constructor(keyword: string, isRawValue?: boolean);
|
|
1078
1241
|
}
|
|
1079
1242
|
|
|
1243
|
+
declare class AstParser {
|
|
1244
|
+
private readonly dbType;
|
|
1245
|
+
private readonly model;
|
|
1246
|
+
constructor(model: typeof Model, dbType: SqlDataSourceType);
|
|
1247
|
+
parse(nodes: (QueryNode | null)[], startBindingIndex?: number, isNestedCondition?: boolean): AstParserType;
|
|
1248
|
+
/**
|
|
1249
|
+
* Map the database type to a common type if shares the same driver (e.g. mysql and mariadb)
|
|
1250
|
+
*/
|
|
1251
|
+
private mapCommonDbType;
|
|
1252
|
+
/**
|
|
1253
|
+
* @description Generates MSSQL table hints from lock node
|
|
1254
|
+
* MSSQL uses WITH (UPDLOCK), WITH (HOLDLOCK), etc. as table hints
|
|
1255
|
+
* READPAST is the MSSQL equivalent of SKIP LOCKED
|
|
1256
|
+
*/
|
|
1257
|
+
private getMssqlTableHints;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
declare class ColumnTypeNode extends QueryNode {
|
|
1261
|
+
column: string | (() => string);
|
|
1262
|
+
dataType: string;
|
|
1263
|
+
length?: number;
|
|
1264
|
+
precision?: number;
|
|
1265
|
+
scale?: number;
|
|
1266
|
+
enumValues?: readonly string[];
|
|
1267
|
+
autoIncrement?: boolean;
|
|
1268
|
+
withTimezone?: boolean;
|
|
1269
|
+
chainsWith: string;
|
|
1270
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1271
|
+
folder: string;
|
|
1272
|
+
file: string;
|
|
1273
|
+
isRawValue: boolean;
|
|
1274
|
+
constructor(column: string, dataType: string, opts?: {
|
|
1275
|
+
length?: number;
|
|
1276
|
+
precision?: number;
|
|
1277
|
+
scale?: number;
|
|
1278
|
+
enumValues?: readonly string[];
|
|
1279
|
+
withTimezone?: boolean;
|
|
1280
|
+
autoIncrement?: boolean;
|
|
1281
|
+
isRawValue?: boolean;
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1080
1285
|
declare class RawNode extends QueryNode {
|
|
1081
1286
|
rawValue: string;
|
|
1082
1287
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
@@ -1099,7 +1304,7 @@ declare class ConstraintNode extends QueryNode {
|
|
|
1099
1304
|
constraintName?: string;
|
|
1100
1305
|
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1101
1306
|
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1102
|
-
defaultValue?: string;
|
|
1307
|
+
defaultValue?: string | RawNode | undefined;
|
|
1103
1308
|
checkExpression?: string;
|
|
1104
1309
|
chainsWith: string;
|
|
1105
1310
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
@@ -1114,36 +1319,11 @@ declare class ConstraintNode extends QueryNode {
|
|
|
1114
1319
|
constraintName?: string;
|
|
1115
1320
|
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1116
1321
|
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1117
|
-
defaultValue?: string;
|
|
1322
|
+
defaultValue?: string | RawNode | undefined;
|
|
1118
1323
|
checkExpression?: string;
|
|
1119
1324
|
}, isRawValue?: boolean);
|
|
1120
1325
|
}
|
|
1121
1326
|
|
|
1122
|
-
declare class ColumnTypeNode extends QueryNode {
|
|
1123
|
-
column: string | (() => string);
|
|
1124
|
-
dataType: string;
|
|
1125
|
-
length?: number;
|
|
1126
|
-
precision?: number;
|
|
1127
|
-
scale?: number;
|
|
1128
|
-
enumValues?: readonly string[];
|
|
1129
|
-
autoIncrement?: boolean;
|
|
1130
|
-
withTimezone?: boolean;
|
|
1131
|
-
chainsWith: string;
|
|
1132
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1133
|
-
folder: string;
|
|
1134
|
-
file: string;
|
|
1135
|
-
isRawValue: boolean;
|
|
1136
|
-
constructor(column: string, dataType: string, opts?: {
|
|
1137
|
-
length?: number;
|
|
1138
|
-
precision?: number;
|
|
1139
|
-
scale?: number;
|
|
1140
|
-
enumValues?: readonly string[];
|
|
1141
|
-
withTimezone?: boolean;
|
|
1142
|
-
autoIncrement?: boolean;
|
|
1143
|
-
isRawValue?: boolean;
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
1327
|
type LockType = "for_update" | "for_share" | "for_no_key_update" | "for_key_share";
|
|
1148
1328
|
declare class LockNode extends QueryNode {
|
|
1149
1329
|
lockType: LockType;
|
|
@@ -1177,51 +1357,151 @@ declare class WithNode extends QueryNode {
|
|
|
1177
1357
|
constructor(clause: string, alias: string, body: QueryNode | QueryNode[]);
|
|
1178
1358
|
}
|
|
1179
1359
|
|
|
1180
|
-
declare
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1360
|
+
declare class FromNode extends QueryNode {
|
|
1361
|
+
table: string | QueryNode | QueryNode[];
|
|
1362
|
+
chainsWith: string;
|
|
1363
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1364
|
+
folder: string;
|
|
1365
|
+
file: string;
|
|
1366
|
+
alias?: string;
|
|
1367
|
+
constructor(table: string | QueryNode | QueryNode[], alias?: string);
|
|
1184
1368
|
}
|
|
1185
1369
|
|
|
1186
|
-
declare class
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
constructor(
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1370
|
+
declare class DeleteNode extends QueryNode {
|
|
1371
|
+
fromNode: FromNode;
|
|
1372
|
+
chainsWith: string;
|
|
1373
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1374
|
+
folder: string;
|
|
1375
|
+
file: string;
|
|
1376
|
+
constructor(fromNode: FromNode, isRawValue?: boolean);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
declare class InsertNode extends QueryNode {
|
|
1380
|
+
fromNode: FromNode;
|
|
1381
|
+
records: Record<string, any>[];
|
|
1382
|
+
returning?: string[];
|
|
1383
|
+
disableReturning: boolean;
|
|
1384
|
+
chainsWith: string;
|
|
1385
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1386
|
+
folder: string;
|
|
1387
|
+
file: string;
|
|
1388
|
+
constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
declare class OnDuplicateNode extends QueryNode {
|
|
1392
|
+
table: string;
|
|
1393
|
+
conflictColumns: string[];
|
|
1394
|
+
columnsToUpdate: string[];
|
|
1395
|
+
returning?: string[];
|
|
1396
|
+
mode: "update" | "ignore";
|
|
1397
|
+
chainsWith: string;
|
|
1398
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1399
|
+
folder: string;
|
|
1400
|
+
file: string;
|
|
1401
|
+
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
declare class TruncateNode extends QueryNode {
|
|
1405
|
+
fromNode: FromNode | string;
|
|
1406
|
+
chainsWith: string;
|
|
1407
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1408
|
+
folder: string;
|
|
1409
|
+
file: string;
|
|
1410
|
+
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
declare class UpdateNode extends QueryNode {
|
|
1414
|
+
fromNode: FromNode;
|
|
1415
|
+
columns: string[];
|
|
1416
|
+
values: (any | RawNode)[];
|
|
1417
|
+
chainsWith: string;
|
|
1418
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1419
|
+
folder: string;
|
|
1420
|
+
file: string;
|
|
1421
|
+
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
declare class InterpreterUtils {
|
|
1425
|
+
private readonly model;
|
|
1426
|
+
private readonly modelColumnsMap;
|
|
1427
|
+
constructor(model: typeof Model);
|
|
1428
|
+
formatStringColumn(dbType: SqlDataSourceType, column: string): string;
|
|
1429
|
+
/**
|
|
1430
|
+
* @description Formats the table name for the database type, idempotent for quoting
|
|
1431
|
+
*/
|
|
1432
|
+
formatStringTable(dbType: SqlDataSourceType, table: string): string;
|
|
1433
|
+
prepareColumns(columns: string[], values: any[], mode?: "insert" | "update"): Promise<{
|
|
1434
|
+
columns: string[];
|
|
1435
|
+
values: any[];
|
|
1436
|
+
}>;
|
|
1437
|
+
/**
|
|
1438
|
+
* @description Formats the from node for write operations removing the "from" keyword
|
|
1439
|
+
*/
|
|
1440
|
+
getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
type OpenApiModelType = {
|
|
1444
|
+
type: "object";
|
|
1445
|
+
properties: Record<string, OpenApiModelPropertyType>;
|
|
1446
|
+
required?: string[];
|
|
1447
|
+
};
|
|
1448
|
+
type OpenApiModelPropertyType = {
|
|
1449
|
+
type: string;
|
|
1450
|
+
items?: OpenApiModelType;
|
|
1451
|
+
enum?: string[];
|
|
1452
|
+
format?: string;
|
|
1453
|
+
description?: string;
|
|
1454
|
+
example?: any;
|
|
1455
|
+
default?: any;
|
|
1456
|
+
nullable?: boolean;
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
declare abstract class BaseBuilder {
|
|
1460
|
+
protected nodes: QueryNode[];
|
|
1461
|
+
constructor(nodes: QueryNode[]);
|
|
1462
|
+
getNodes(): QueryNode[];
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
declare class ConstraintBuilder extends BaseBuilder {
|
|
1466
|
+
private readonly columnNode;
|
|
1467
|
+
private readonly tableName?;
|
|
1468
|
+
private namedConstraints;
|
|
1469
|
+
private context;
|
|
1470
|
+
private sqlType;
|
|
1471
|
+
constructor(sqlType: SqlDataSourceType, nodes: QueryNode[], columnNode: ColumnTypeNode, tableName?: string, namedConstraints?: QueryNode[], context?: CreateTableContext);
|
|
1472
|
+
/**
|
|
1473
|
+
* @description Adds a primary key constraint to the column, if no constraint name is provided, it will be generated using the standard pattern: pk_${table}_${column}
|
|
1474
|
+
* @param options is the options for the primary key constraint
|
|
1475
|
+
*/
|
|
1476
|
+
primaryKey(options?: PrimaryKeyOptions): this;
|
|
1477
|
+
/**
|
|
1478
|
+
* @description Adds a foreign key constraint to the column, if no constraint name is provided, it will be generated using the standard pattern: fk_${table}_${leftColumn}_${rightColumn}
|
|
1479
|
+
* @param references is the table and column name to reference, e.g. "users.id"
|
|
1480
|
+
* @param options is the options for the foreign key constraint
|
|
1481
|
+
*/
|
|
1482
|
+
foreignKey(references: `${string}.${string}`, options?: ForeignKeyOptions): this;
|
|
1483
|
+
/**
|
|
1484
|
+
* @description Sets the column to auto increment
|
|
1485
|
+
*/
|
|
1486
|
+
increment(): this;
|
|
1487
|
+
/**
|
|
1488
|
+
* @description Sets the column to not nullable
|
|
1489
|
+
*/
|
|
1490
|
+
notNullable(): this;
|
|
1491
|
+
/**
|
|
1492
|
+
* @description Sets the column to nullable, by default it already is nullable, this method is only used for alter table
|
|
1493
|
+
*/
|
|
1494
|
+
nullable(): this;
|
|
1495
|
+
/**
|
|
1496
|
+
* @description Sets the default value for the column
|
|
1497
|
+
* @param value is the default value for the column
|
|
1498
|
+
* @oracle not supported must be defined manually in a separate statement
|
|
1499
|
+
*/
|
|
1500
|
+
default(value: string | number | boolean | null | RawNode): this;
|
|
1501
|
+
/**
|
|
1502
|
+
* @description Sets the column to unique
|
|
1503
|
+
* @param options is the options for the unique constraint
|
|
1504
|
+
*/
|
|
1225
1505
|
unique(options?: CommonConstraintOptions): this;
|
|
1226
1506
|
/**
|
|
1227
1507
|
* @description Sets the column to be after another column
|
|
@@ -1523,35 +1803,42 @@ declare class AlterTableBuilder extends BaseBuilder {
|
|
|
1523
1803
|
/**
|
|
1524
1804
|
* @description Adds a column to the table
|
|
1525
1805
|
* @param cb is the callback that will be used to build the column
|
|
1806
|
+
* @mssql Auto-generates default constraint names (DF__table__col__xxxxx) which are hard to drop later
|
|
1526
1807
|
*/
|
|
1527
1808
|
addColumn(cb: (col: CreateTableBuilder) => ConstraintBuilder): void;
|
|
1528
1809
|
/**
|
|
1529
1810
|
* @description Alters a column, can generate multiple sql statements depending on the constraints
|
|
1530
1811
|
* @throws HysteriaError if sqlite database
|
|
1812
|
+
* @mssql Cannot alter columns with DEFAULT/CHECK constraints or indexes - drop them first
|
|
1531
1813
|
*/
|
|
1532
1814
|
alterColumn(columnBuilder: (col: CreateTableBuilder) => ConstraintBuilder): void;
|
|
1533
1815
|
/**
|
|
1534
1816
|
* @description Drops a column
|
|
1817
|
+
* @mssql Must drop all dependent constraints and indexes before dropping the column
|
|
1535
1818
|
*/
|
|
1536
1819
|
dropColumn(name: string): void;
|
|
1537
1820
|
/**
|
|
1538
1821
|
* @description Renames a column
|
|
1822
|
+
* @mssql Uses sp_rename procedure; does not update references in views/procedures/triggers
|
|
1539
1823
|
*/
|
|
1540
1824
|
renameColumn(oldName: string, newName: string): void;
|
|
1541
1825
|
/**
|
|
1542
1826
|
* @description Drops a default value from a column
|
|
1543
1827
|
* @sqlite not supported and will throw error
|
|
1828
|
+
* @mssql Requires constraint name; use dropConstraint() with name from sys.default_constraints
|
|
1544
1829
|
*/
|
|
1545
1830
|
dropDefault(columnName: string): void;
|
|
1546
1831
|
/**
|
|
1547
1832
|
* @description Adds a primary key constraint to a column
|
|
1548
1833
|
* @param columnName is the column name to add the primary key to
|
|
1549
1834
|
* @sqlite not supported and will throw error
|
|
1835
|
+
* @mssql Column must be NOT NULL before adding primary key
|
|
1550
1836
|
*/
|
|
1551
1837
|
addPrimaryKey(columnName: string): void;
|
|
1552
1838
|
/**
|
|
1553
1839
|
* @description Raw non type safe way builder to add a constraint
|
|
1554
1840
|
* @sqlite not supported and will throw error
|
|
1841
|
+
* @mssql UNIQUE does not allow multiple NULLs (unlike PostgreSQL)
|
|
1555
1842
|
*/
|
|
1556
1843
|
addConstraint(...options: ConstructorParameters<typeof ConstraintNode>): void;
|
|
1557
1844
|
/**
|
|
@@ -1597,6 +1884,7 @@ declare class AlterTableBuilder extends BaseBuilder {
|
|
|
1597
1884
|
* @postgres not supported, use `dropConstraint` instead with the pk constraint name
|
|
1598
1885
|
* @sqlite not supported and will throw error
|
|
1599
1886
|
* @throws HysteriaError if postgres and table is not provided
|
|
1887
|
+
* @mssql Foreign keys referencing this primary key must be dropped first
|
|
1600
1888
|
*/
|
|
1601
1889
|
dropPrimaryKey(table?: string): void;
|
|
1602
1890
|
}
|
|
@@ -1616,12 +1904,14 @@ declare class Schema {
|
|
|
1616
1904
|
runFile(filePath: string): void;
|
|
1617
1905
|
/**
|
|
1618
1906
|
* @description Create table constructor
|
|
1907
|
+
* @mssql Does not support ifNotExists option
|
|
1619
1908
|
*/
|
|
1620
1909
|
createTable(table: string, cb: (table: CreateTableBuilder) => void, options?: {
|
|
1621
1910
|
ifNotExists?: boolean;
|
|
1622
1911
|
}): void;
|
|
1623
1912
|
/**
|
|
1624
1913
|
* @description Alter table constructor
|
|
1914
|
+
* @mssql Limited support - cannot modify columns with constraints; see AlterTableBuilder methods for details
|
|
1625
1915
|
*/
|
|
1626
1916
|
alterTable(table: string, cb: (t: AlterTableBuilder) => void): void;
|
|
1627
1917
|
/**
|
|
@@ -1630,6 +1920,7 @@ declare class Schema {
|
|
|
1630
1920
|
dropTable(table: string, ifExists?: boolean): void;
|
|
1631
1921
|
/**
|
|
1632
1922
|
* @description Rename table in the database
|
|
1923
|
+
* @mssql Uses sp_rename procedure; does not update references in views/procedures/triggers
|
|
1633
1924
|
*/
|
|
1634
1925
|
renameTable(oldTable: string, newTable: string): void;
|
|
1635
1926
|
/**
|
|
@@ -1678,35 +1969,6 @@ declare class Schema {
|
|
|
1678
1969
|
private generateAstInstance;
|
|
1679
1970
|
}
|
|
1680
1971
|
|
|
1681
|
-
declare class FromNode extends QueryNode {
|
|
1682
|
-
table: string | QueryNode | QueryNode[];
|
|
1683
|
-
chainsWith: string;
|
|
1684
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1685
|
-
folder: string;
|
|
1686
|
-
file: string;
|
|
1687
|
-
alias?: string;
|
|
1688
|
-
constructor(table: string | QueryNode | QueryNode[], alias?: string);
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
declare class InterpreterUtils {
|
|
1692
|
-
private readonly model;
|
|
1693
|
-
private readonly modelColumnsMap;
|
|
1694
|
-
constructor(model: typeof Model);
|
|
1695
|
-
formatStringColumn(dbType: SqlDataSourceType, column: string): string;
|
|
1696
|
-
/**
|
|
1697
|
-
* @description Formats the table name for the database type, idempotent for quoting
|
|
1698
|
-
*/
|
|
1699
|
-
formatStringTable(dbType: SqlDataSourceType, table: string): string;
|
|
1700
|
-
prepareColumns(columns: string[], values: any[], mode?: "insert" | "update"): Promise<{
|
|
1701
|
-
columns: string[];
|
|
1702
|
-
values: any[];
|
|
1703
|
-
}>;
|
|
1704
|
-
/**
|
|
1705
|
-
* @description Formats the from node for write operations removing the "from" keyword
|
|
1706
|
-
*/
|
|
1707
|
-
getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
1972
|
type DeleteOptions = {
|
|
1711
1973
|
ignoreBeforeDeleteHook?: boolean;
|
|
1712
1974
|
};
|
|
@@ -2582,23 +2844,44 @@ declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBui
|
|
|
2582
2844
|
orWhereNotNull<S extends string>(column: SelectableColumn<S>): this;
|
|
2583
2845
|
/**
|
|
2584
2846
|
* @description Adds a WHERE REGEXP condition to the query.
|
|
2847
|
+
* @mssql doesn't support REGEXP syntax
|
|
2848
|
+
* @sqlite doesn't support REGEXP syntax
|
|
2585
2849
|
*/
|
|
2586
2850
|
whereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
2587
2851
|
whereRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
2588
2852
|
/**
|
|
2589
2853
|
* @description Adds an AND WHERE REGEXP condition to the query.
|
|
2854
|
+
* @mssql doesn't support REGEXP syntax
|
|
2855
|
+
* @sqlite doesn't support REGEXP syntax
|
|
2590
2856
|
*/
|
|
2591
2857
|
andWhereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
2592
2858
|
andWhereRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
2593
2859
|
/**
|
|
2594
2860
|
* @description Adds an OR WHERE REGEXP condition to the query.
|
|
2861
|
+
* @mssql doesn't support REGEXP syntax
|
|
2862
|
+
* @sqlite doesn't support REGEXP syntax
|
|
2595
2863
|
*/
|
|
2596
2864
|
orWhereRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
2597
2865
|
orWhereRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
2866
|
+
/**
|
|
2867
|
+
* @description Adds a WHERE NOT REGEXP condition to the query.
|
|
2868
|
+
* @mssql doesn't support REGEXP syntax
|
|
2869
|
+
* @sqlite doesn't support REGEXP syntax
|
|
2870
|
+
*/
|
|
2598
2871
|
whereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
2599
2872
|
whereNotRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
2873
|
+
/**
|
|
2874
|
+
* @description Adds an AND WHERE NOT REGEXP condition to the query.
|
|
2875
|
+
* @mssql doesn't support REGEXP syntax
|
|
2876
|
+
* @sqlite doesn't support REGEXP syntax
|
|
2877
|
+
*/
|
|
2600
2878
|
andWhereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
2601
2879
|
andWhereNotRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
2880
|
+
/**
|
|
2881
|
+
* @description Adds an OR WHERE NOT REGEXP condition to the query.
|
|
2882
|
+
* @mssql doesn't support REGEXP syntax
|
|
2883
|
+
* @sqlite doesn't support REGEXP syntax
|
|
2884
|
+
*/
|
|
2602
2885
|
orWhereNotRegexp(column: ModelKey<T>, regexp: RegExp): this;
|
|
2603
2886
|
orWhereNotRegexp<S extends string>(column: SelectableColumn<S>, regexp: RegExp): this;
|
|
2604
2887
|
/**
|
|
@@ -2680,47 +2963,55 @@ declare class JsonQueryBuilder<T extends Model> extends WhereQueryBuilder<T> {
|
|
|
2680
2963
|
whereJson(column: string, value: JsonParam): this;
|
|
2681
2964
|
/**
|
|
2682
2965
|
* @description Filters records matching the given JSON value.
|
|
2966
|
+
* @mssql Partial JSON matching not supported - only exact matches work
|
|
2683
2967
|
*/
|
|
2684
2968
|
andWhereJson(column: ModelKey<T>, value: JsonParam): this;
|
|
2685
2969
|
andWhereJson(column: string, value: JsonParam): this;
|
|
2686
2970
|
/**
|
|
2687
2971
|
* @description Filters records matching the given JSON value.
|
|
2972
|
+
* @mssql Partial JSON matching not supported - only exact matches work
|
|
2688
2973
|
*/
|
|
2689
2974
|
orWhereJson(column: ModelKey<T>, value: JsonParam): this;
|
|
2690
2975
|
orWhereJson(column: string, value: JsonParam): this;
|
|
2691
2976
|
/**
|
|
2692
2977
|
* @description Filters records where JSON column does NOT contain the given value.
|
|
2693
2978
|
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
2979
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
2694
2980
|
*/
|
|
2695
2981
|
whereJsonNotContains(column: ModelKey<T>, value: JsonParam): this;
|
|
2696
2982
|
whereJsonNotContains(column: string, value: JsonParam): this;
|
|
2697
2983
|
/**
|
|
2698
2984
|
* @description Filters records where JSON column does NOT contain the given value (AND).
|
|
2699
2985
|
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
2986
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
2700
2987
|
*/
|
|
2701
2988
|
andWhereJsonNotContains(column: ModelKey<T>, value: JsonParam): this;
|
|
2702
2989
|
andWhereJsonNotContains(column: string, value: JsonParam): this;
|
|
2703
2990
|
/**
|
|
2704
2991
|
* @description Filters records where JSON column does NOT contain the given value (OR).
|
|
2705
2992
|
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
2993
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
2706
2994
|
*/
|
|
2707
2995
|
orWhereJsonNotContains(column: ModelKey<T>, value: JsonParam): this;
|
|
2708
2996
|
orWhereJsonNotContains(column: string, value: JsonParam): this;
|
|
2709
2997
|
/**
|
|
2710
2998
|
* @description Filters records where JSON column contains the given value.
|
|
2711
2999
|
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3000
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
2712
3001
|
*/
|
|
2713
3002
|
whereJsonContains(column: ModelKey<T>, value: JsonParam): this;
|
|
2714
3003
|
whereJsonContains(column: string, value: JsonParam): this;
|
|
2715
3004
|
/**
|
|
2716
3005
|
* @description Filters records where JSON column contains the given value (AND).
|
|
2717
3006
|
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3007
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
2718
3008
|
*/
|
|
2719
3009
|
andWhereJsonContains(column: ModelKey<T>, value: JsonParam): this;
|
|
2720
3010
|
andWhereJsonContains(column: string, value: JsonParam): this;
|
|
2721
3011
|
/**
|
|
2722
3012
|
* @description Filters records where JSON column contains the given value (OR).
|
|
2723
3013
|
* @sqlite might not work for all cases, suggest using the whereJsonRaw method instead
|
|
3014
|
+
* @mssql not supported - CHARINDEX cannot do partial JSON containment
|
|
2724
3015
|
*/
|
|
2725
3016
|
orWhereJsonContains(column: ModelKey<T>, value: JsonParam): this;
|
|
2726
3017
|
orWhereJsonContains(column: string, value: JsonParam): this;
|
|
@@ -2830,222 +3121,82 @@ type UpdateOptions = {
|
|
|
2830
3121
|
ignoreBeforeUpdateHook?: boolean;
|
|
2831
3122
|
};
|
|
2832
3123
|
|
|
2833
|
-
type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
2834
|
-
type StartTransactionOptions = {
|
|
2835
|
-
isolationLevel?: TransactionIsolationLevel;
|
|
2836
|
-
};
|
|
2837
3124
|
/**
|
|
2838
|
-
* @description
|
|
3125
|
+
* @description Due to query limitations some query builder methods may not be available in a RelationQueryBuilder
|
|
2839
3126
|
*/
|
|
2840
|
-
type
|
|
3127
|
+
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">;
|
|
3128
|
+
|
|
3129
|
+
declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends QueryBuilder<T> {
|
|
3130
|
+
relation: Relation;
|
|
3131
|
+
protected sqlModelManagerUtils: SqlModelManagerUtils<T>;
|
|
3132
|
+
protected relationQueryBuilders: ModelQueryBuilder<any>[];
|
|
3133
|
+
protected modelSelectedColumns: string[];
|
|
3134
|
+
private modelColumnsMap;
|
|
3135
|
+
private modelColumnsDatabaseNames;
|
|
3136
|
+
protected limitValue?: number;
|
|
3137
|
+
protected offsetValue?: number;
|
|
3138
|
+
performance: {
|
|
3139
|
+
many: (options?: ManyOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3140
|
+
data: AnnotatedModel<T, A, R>[];
|
|
3141
|
+
time: number;
|
|
3142
|
+
}>;
|
|
3143
|
+
one: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3144
|
+
data: AnnotatedModel<T, A, R> | null;
|
|
3145
|
+
time: number;
|
|
3146
|
+
}>;
|
|
3147
|
+
oneOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3148
|
+
data: AnnotatedModel<T, A, R>;
|
|
3149
|
+
time: number;
|
|
3150
|
+
}>;
|
|
3151
|
+
first: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3152
|
+
data: AnnotatedModel<T, A, R> | null;
|
|
3153
|
+
time: number;
|
|
3154
|
+
}>;
|
|
3155
|
+
firstOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3156
|
+
data: AnnotatedModel<T, A, R>;
|
|
3157
|
+
time: number;
|
|
3158
|
+
}>;
|
|
3159
|
+
paginate: (page: number, perPage: number, options?: {
|
|
3160
|
+
ignoreHooks?: boolean;
|
|
3161
|
+
}, returnType?: "millis" | "seconds") => Promise<{
|
|
3162
|
+
data: PaginatedData<T, A, R>;
|
|
3163
|
+
time: number;
|
|
3164
|
+
}>;
|
|
3165
|
+
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
3166
|
+
data: boolean;
|
|
3167
|
+
time: number;
|
|
3168
|
+
}>;
|
|
3169
|
+
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
3170
|
+
data: [CursorPaginatedData<T, A, R>, Cursor<T, ModelKey<T>>];
|
|
3171
|
+
time: number;
|
|
3172
|
+
}>;
|
|
3173
|
+
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
3174
|
+
data: void;
|
|
3175
|
+
time: number;
|
|
3176
|
+
}>;
|
|
3177
|
+
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
3178
|
+
data: number;
|
|
3179
|
+
time: number;
|
|
3180
|
+
}>;
|
|
3181
|
+
update: (data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3182
|
+
data: number;
|
|
3183
|
+
time: number;
|
|
3184
|
+
}>;
|
|
3185
|
+
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
3186
|
+
data: number;
|
|
3187
|
+
time: number;
|
|
3188
|
+
}>;
|
|
3189
|
+
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
3190
|
+
data: PluckReturnType<T, ModelKey<T>>;
|
|
3191
|
+
time: number;
|
|
3192
|
+
}>;
|
|
3193
|
+
};
|
|
3194
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
2841
3195
|
/**
|
|
2842
|
-
* @description
|
|
3196
|
+
* @description Returns true if the query builder is a relation query builder, this changes the behavior of the query builder like limit, offset, etc.
|
|
3197
|
+
* @internal
|
|
2843
3198
|
*/
|
|
2844
|
-
|
|
2845
|
-
};
|
|
2846
|
-
type TransactionOptionsOrCallback = StartTransactionOptions | ((trx: Transaction) => Promise<void>);
|
|
2847
|
-
type StartTransactionReturnType<T extends TransactionOptionsOrCallback> = T extends StartTransactionOptions ? Transaction : T extends (trx: Transaction) => Promise<void> ? void : Transaction;
|
|
2848
|
-
|
|
2849
|
-
/**
|
|
2850
|
-
* @description Transaction class, not meant to be used directly, use sql.startTransaction() instead
|
|
2851
|
-
*/
|
|
2852
|
-
declare class Transaction {
|
|
2853
|
-
/**
|
|
2854
|
-
* @description The sql data source instance that the transaction is running on here you can both query or execute raw queries
|
|
2855
|
-
* @example
|
|
2856
|
-
* ```ts
|
|
2857
|
-
* import { sql } from "hysteria-orm";
|
|
2858
|
-
* import { User } from "./models/user";
|
|
2859
|
-
*
|
|
2860
|
-
* // Raw queries
|
|
2861
|
-
* const trx = await sql.startTransaction();
|
|
2862
|
-
* await trx.rawQuery("SELECT * FROM users");
|
|
2863
|
-
*
|
|
2864
|
-
* // Model manager
|
|
2865
|
-
* const modelManager = trx.sql.getModelManager(User);
|
|
2866
|
-
* await modelManager.insert({ name: "John Doe" });
|
|
2867
|
-
*
|
|
2868
|
-
* // Query builder
|
|
2869
|
-
* await trx.query(User.table).insert({ name: "John Doe" });
|
|
2870
|
-
*
|
|
2871
|
-
* await trx.commit();
|
|
2872
|
-
* ```
|
|
2873
|
-
*/
|
|
2874
|
-
sql: SqlDataSourceWithoutTransaction;
|
|
2875
|
-
/**
|
|
2876
|
-
* @description Whether the transaction is active
|
|
2877
|
-
*/
|
|
2878
|
-
isActive: boolean;
|
|
2879
|
-
/**
|
|
2880
|
-
* @description The transaction unique identifier
|
|
2881
|
-
*/
|
|
2882
|
-
transactionId: string;
|
|
2883
|
-
private connectionReleased;
|
|
2884
|
-
private isolationLevel?;
|
|
2885
|
-
private isNested;
|
|
2886
|
-
private nestingDepth;
|
|
2887
|
-
constructor(sql: SqlDataSource, isolationLevel?: TransactionIsolationLevel, isNested?: boolean, nestingDepth?: number);
|
|
2888
|
-
/**
|
|
2889
|
-
* @description Creates a new transaction with the same isolation level and same connection using save points
|
|
2890
|
-
* @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
|
|
2891
|
-
*/
|
|
2892
|
-
nestedTransaction(): Promise<Transaction>;
|
|
2893
|
-
nestedTransaction(cb: (trx: Transaction) => Promise<void>): Promise<void>;
|
|
2894
|
-
/**
|
|
2895
|
-
* @description Starts a transaction, automatically handled from the sql data source instance in the `startTransaction` method
|
|
2896
|
-
*/
|
|
2897
|
-
startTransaction(): Promise<void>;
|
|
2898
|
-
/**
|
|
2899
|
-
* @description Commit the transaction releasing the connection
|
|
2900
|
-
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
2901
|
-
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
2902
|
-
*/
|
|
2903
|
-
commit(options?: TransactionExecutionOptions): Promise<void>;
|
|
2904
|
-
/**
|
|
2905
|
-
* @description Rollback the transaction releasing the connection
|
|
2906
|
-
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
2907
|
-
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
2908
|
-
*/
|
|
2909
|
-
rollback(options?: TransactionExecutionOptions): Promise<void>;
|
|
2910
|
-
/**
|
|
2911
|
-
* @description Release the connection, does nothing if the connection is already released
|
|
2912
|
-
*/
|
|
2913
|
-
private releaseConnection;
|
|
2914
|
-
private getIsolationLevelQuery;
|
|
2915
|
-
private getSavePointName;
|
|
2916
|
-
}
|
|
2917
|
-
|
|
2918
|
-
type ModelWithoutRelations<T extends Model> = Pick<T, ExcludeRelations<Omit<T, "*">>>;
|
|
2919
|
-
type NumberModelKey<T extends Model> = {
|
|
2920
|
-
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
2921
|
-
}[keyof T];
|
|
2922
|
-
type BaseModelMethodOptions = {
|
|
2923
|
-
/**
|
|
2924
|
-
* @description The connection to use for the model, by default the main connection will be used
|
|
2925
|
-
* @description The main connection is the one created by the `sql.connect` method
|
|
2926
|
-
* @example
|
|
2927
|
-
* ```ts
|
|
2928
|
-
* import { sql } from "hysteria-orm";
|
|
2929
|
-
* const customConnection = await sql.connectToSecondarySource({
|
|
2930
|
-
* type: "postgres",
|
|
2931
|
-
* host: "localhost",
|
|
2932
|
-
* username: "root",
|
|
2933
|
-
* password: "root",
|
|
2934
|
-
* database: "test",
|
|
2935
|
-
* port: 5432,
|
|
2936
|
-
* });
|
|
2937
|
-
*
|
|
2938
|
-
* const user = await User.query({ connection: customConnection }).first();
|
|
2939
|
-
* ```
|
|
2940
|
-
*/
|
|
2941
|
-
connection?: SqlDataSource | AugmentedSqlDataSource;
|
|
2942
|
-
/**
|
|
2943
|
-
* @description The transaction instance to use for the model
|
|
2944
|
-
*/
|
|
2945
|
-
trx?: Transaction;
|
|
2946
|
-
/**
|
|
2947
|
-
* @description Whether to ignore the hooks for the model
|
|
2948
|
-
*/
|
|
2949
|
-
ignoreHooks?: boolean;
|
|
2950
|
-
};
|
|
2951
|
-
/**
|
|
2952
|
-
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
2953
|
-
*/
|
|
2954
|
-
type RawModelOptions = {
|
|
2955
|
-
/**
|
|
2956
|
-
* Alias for the table
|
|
2957
|
-
*/
|
|
2958
|
-
alias?: string;
|
|
2959
|
-
/**
|
|
2960
|
-
* @description Convert the column casing before making a Database query, by default preserves what is provided
|
|
2961
|
-
*/
|
|
2962
|
-
databaseCaseConvention?: CaseConvention;
|
|
2963
|
-
/**
|
|
2964
|
-
* Column to use for soft deleted, by default is `deleted_at`
|
|
2965
|
-
*/
|
|
2966
|
-
softDeleteColumn?: string;
|
|
2967
|
-
/**
|
|
2968
|
-
* Column to use for soft deleted, by default is date in format: "YYYY-MM-DD HH:mm:ss" in UTC timezone
|
|
2969
|
-
*/
|
|
2970
|
-
softDeleteValue?: string | boolean;
|
|
2971
|
-
};
|
|
2972
|
-
|
|
2973
|
-
/**
|
|
2974
|
-
* @description Due to query limitations some query builder methods may not be available in a RelationQueryBuilder
|
|
2975
|
-
*/
|
|
2976
|
-
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">;
|
|
2977
|
-
|
|
2978
|
-
declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends QueryBuilder<T> {
|
|
2979
|
-
relation: Relation;
|
|
2980
|
-
protected sqlModelManagerUtils: SqlModelManagerUtils<T>;
|
|
2981
|
-
protected relationQueryBuilders: ModelQueryBuilder<any>[];
|
|
2982
|
-
protected modelSelectedColumns: string[];
|
|
2983
|
-
private modelColumnsMap;
|
|
2984
|
-
private modelColumnsDatabaseNames;
|
|
2985
|
-
protected limitValue?: number;
|
|
2986
|
-
protected offsetValue?: number;
|
|
2987
|
-
performance: {
|
|
2988
|
-
many: (options?: ManyOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
2989
|
-
data: AnnotatedModel<T, A, R>[];
|
|
2990
|
-
time: number;
|
|
2991
|
-
}>;
|
|
2992
|
-
one: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
2993
|
-
data: AnnotatedModel<T, A, R> | null;
|
|
2994
|
-
time: number;
|
|
2995
|
-
}>;
|
|
2996
|
-
oneOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
2997
|
-
data: AnnotatedModel<T, A, R>;
|
|
2998
|
-
time: number;
|
|
2999
|
-
}>;
|
|
3000
|
-
first: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3001
|
-
data: AnnotatedModel<T, A, R> | null;
|
|
3002
|
-
time: number;
|
|
3003
|
-
}>;
|
|
3004
|
-
firstOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3005
|
-
data: AnnotatedModel<T, A, R>;
|
|
3006
|
-
time: number;
|
|
3007
|
-
}>;
|
|
3008
|
-
paginate: (page: number, perPage: number, options?: {
|
|
3009
|
-
ignoreHooks?: boolean;
|
|
3010
|
-
}, returnType?: "millis" | "seconds") => Promise<{
|
|
3011
|
-
data: PaginatedData<T, A, R>;
|
|
3012
|
-
time: number;
|
|
3013
|
-
}>;
|
|
3014
|
-
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
3015
|
-
data: boolean;
|
|
3016
|
-
time: number;
|
|
3017
|
-
}>;
|
|
3018
|
-
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
3019
|
-
data: [CursorPaginatedData<T, A, R>, Cursor<T, ModelKey<T>>];
|
|
3020
|
-
time: number;
|
|
3021
|
-
}>;
|
|
3022
|
-
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
3023
|
-
data: void;
|
|
3024
|
-
time: number;
|
|
3025
|
-
}>;
|
|
3026
|
-
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
3027
|
-
data: number;
|
|
3028
|
-
time: number;
|
|
3029
|
-
}>;
|
|
3030
|
-
update: (data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3031
|
-
data: number;
|
|
3032
|
-
time: number;
|
|
3033
|
-
}>;
|
|
3034
|
-
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
3035
|
-
data: number;
|
|
3036
|
-
time: number;
|
|
3037
|
-
}>;
|
|
3038
|
-
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
3039
|
-
data: PluckReturnType<T, ModelKey<T>>;
|
|
3040
|
-
time: number;
|
|
3041
|
-
}>;
|
|
3042
|
-
};
|
|
3043
|
-
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3044
|
-
/**
|
|
3045
|
-
* @description Returns true if the query builder is a relation query builder, this changes the behavior of the query builder like limit, offset, etc.
|
|
3046
|
-
* @internal
|
|
3047
|
-
*/
|
|
3048
|
-
protected get isRelationQueryBuilder(): boolean;
|
|
3199
|
+
protected get isRelationQueryBuilder(): boolean;
|
|
3049
3200
|
/**
|
|
3050
3201
|
* @description Creates a new ModelQueryBuilder instance from a model. Will use the main connection to the database by default.
|
|
3051
3202
|
*/
|
|
@@ -3127,6 +3278,8 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
|
|
|
3127
3278
|
* @warning Many to many relations have special behavior, since they require a join, a join clause will always be added to the query.
|
|
3128
3279
|
* @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.
|
|
3129
3280
|
* @warning Foreign keys should always be selected in the relation query builder, otherwise the relation will not be filled.
|
|
3281
|
+
* @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
|
|
3282
|
+
* @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
|
|
3130
3283
|
*/
|
|
3131
3284
|
load<RelationKey extends ModelRelation<T>, IA extends Record<string, any> = {}, IR extends Record<string, any> = {}>(relation: RelationKey, cb: (queryBuilder: RelationQueryBuilderType<RelatedInstance<T, RelationKey>>) => RelationQueryBuilderType<RelatedInstance<T, RelationKey>, IA, IR>): ModelQueryBuilder<T, A, R & {
|
|
3132
3285
|
[K in RelationKey]: Awaited<ReturnType<ModelQueryBuilder<RelatedInstance<T, K>, IA, IR>[RelationRetrieveMethod<T[K]>]>>;
|
|
@@ -3292,6 +3445,10 @@ declare class ModelManager<T extends Model> {
|
|
|
3292
3445
|
*/
|
|
3293
3446
|
insertMany(models: Partial<T>[], options?: InsertOptions<T>): Promise<AnnotatedModel<T, {}>[]>;
|
|
3294
3447
|
upsertMany(conflictColumns: string[], columnsToUpdate: string[], data: ModelWithoutRelations<T>[], options?: UpsertOptions<T>): Promise<AnnotatedModel<T, {}>[]>;
|
|
3448
|
+
/**
|
|
3449
|
+
* @description Executes a MERGE statement for MSSQL upsert operations
|
|
3450
|
+
*/
|
|
3451
|
+
private executeMssqlMerge;
|
|
3295
3452
|
/**
|
|
3296
3453
|
* @description Updates a record, returns the updated record
|
|
3297
3454
|
* @description Model is retrieved from the database using the primary key regardless of any model hooks
|
|
@@ -3318,6 +3475,12 @@ declare class ModelManager<T extends Model> {
|
|
|
3318
3475
|
* @description Mysql does not return the inserted model, so we need to get the inserted model from the database
|
|
3319
3476
|
*/
|
|
3320
3477
|
private handleMysqlInsert;
|
|
3478
|
+
/**
|
|
3479
|
+
* @description Oracle with identity columns doesn't support INSERT ALL properly.
|
|
3480
|
+
* This method inserts records one at a time to avoid duplicate ID issues.
|
|
3481
|
+
* After each insert, it queries the row back using unique columns to get the generated ID.
|
|
3482
|
+
*/
|
|
3483
|
+
private handleOracleIdentityInsert;
|
|
3321
3484
|
}
|
|
3322
3485
|
|
|
3323
3486
|
type TableColumnInfo = {
|
|
@@ -3354,14 +3517,119 @@ type TableForeignKeyInfo = {
|
|
|
3354
3517
|
onUpdate?: string | null;
|
|
3355
3518
|
};
|
|
3356
3519
|
|
|
3520
|
+
/**
|
|
3521
|
+
* @description Maps a SqlDataSourceType to the raw driver response type
|
|
3522
|
+
*/
|
|
3523
|
+
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;
|
|
3524
|
+
|
|
3525
|
+
type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
3526
|
+
type StartTransactionOptions = {
|
|
3527
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
3528
|
+
};
|
|
3529
|
+
/**
|
|
3530
|
+
* @description Options for the transaction execution
|
|
3531
|
+
*/
|
|
3532
|
+
type TransactionExecutionOptions = {
|
|
3533
|
+
/**
|
|
3534
|
+
* @description If true, the transaction will throw an error if it is inactive
|
|
3535
|
+
*/
|
|
3536
|
+
throwErrorOnInactiveTransaction?: boolean;
|
|
3537
|
+
};
|
|
3538
|
+
|
|
3539
|
+
/**
|
|
3540
|
+
* @description Transaction class, not meant to be used directly, use sql.startTransaction() instead
|
|
3541
|
+
*/
|
|
3542
|
+
declare class Transaction {
|
|
3543
|
+
/**
|
|
3544
|
+
* @description The sql data source instance that the transaction is running on here you can both query or execute raw queries
|
|
3545
|
+
* @example
|
|
3546
|
+
* ```ts
|
|
3547
|
+
* import { sql } from "hysteria-orm";
|
|
3548
|
+
* import { User } from "./models/user";
|
|
3549
|
+
*
|
|
3550
|
+
* // Raw queries
|
|
3551
|
+
* const trx = await sql.startTransaction();
|
|
3552
|
+
* await trx.rawQuery("SELECT * FROM users");
|
|
3553
|
+
*
|
|
3554
|
+
* // Model manager
|
|
3555
|
+
* const modelManager = trx.sql.getModelManager(User);
|
|
3556
|
+
* await modelManager.insert({ name: "John Doe" });
|
|
3557
|
+
*
|
|
3558
|
+
* // Query builder
|
|
3559
|
+
* await trx.query(User.table).insert({ name: "John Doe" });
|
|
3560
|
+
*
|
|
3561
|
+
* await trx.commit();
|
|
3562
|
+
* ```
|
|
3563
|
+
*/
|
|
3564
|
+
sql: Omit<SqlDataSource, "transaction" | "startGlobalTransaction" | "startTransaction">;
|
|
3565
|
+
/**
|
|
3566
|
+
* @description Whether the transaction is active
|
|
3567
|
+
*/
|
|
3568
|
+
isActive: boolean;
|
|
3569
|
+
/**
|
|
3570
|
+
* @description The transaction unique identifier
|
|
3571
|
+
*/
|
|
3572
|
+
transactionId: string;
|
|
3573
|
+
private connectionReleased;
|
|
3574
|
+
private isolationLevel?;
|
|
3575
|
+
private isNested;
|
|
3576
|
+
private nestingDepth;
|
|
3577
|
+
constructor(sql: SqlDataSource, isolationLevel?: TransactionIsolationLevel, isNested?: boolean, nestingDepth?: number);
|
|
3578
|
+
/**
|
|
3579
|
+
* @description Creates a new transaction with the same isolation level and same connection using save points
|
|
3580
|
+
* @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
|
|
3581
|
+
*/
|
|
3582
|
+
nestedTransaction(): Promise<Transaction>;
|
|
3583
|
+
nestedTransaction(cb: (trx: Transaction) => Promise<void>): Promise<void>;
|
|
3584
|
+
/**
|
|
3585
|
+
* @description Starts a transaction, automatically handled from the sql data source instance in the `startTransaction` method
|
|
3586
|
+
*/
|
|
3587
|
+
startTransaction(): Promise<void>;
|
|
3588
|
+
/**
|
|
3589
|
+
* @description Commit the transaction releasing the connection
|
|
3590
|
+
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
3591
|
+
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
3592
|
+
*/
|
|
3593
|
+
commit(options?: TransactionExecutionOptions): Promise<void>;
|
|
3594
|
+
/**
|
|
3595
|
+
* @description Rollback the transaction releasing the connection
|
|
3596
|
+
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
3597
|
+
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
3598
|
+
*/
|
|
3599
|
+
rollback(options?: TransactionExecutionOptions): Promise<void>;
|
|
3600
|
+
/**
|
|
3601
|
+
* @description Release the connection, does nothing if the connection is already released
|
|
3602
|
+
*/
|
|
3603
|
+
private releaseConnection;
|
|
3604
|
+
private getIsolationLevelQuery;
|
|
3605
|
+
private getSavePointName;
|
|
3606
|
+
private getMssqlTransactionLevel;
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3357
3609
|
/**
|
|
3358
3610
|
* @description The SqlDataSource class is the main class for interacting with the database, it's used to create connections, execute queries, and manage transactions
|
|
3611
|
+
* @example
|
|
3612
|
+
* ```ts
|
|
3613
|
+
* // Create and connect to a database
|
|
3614
|
+
* const sql = new SqlDataSource({
|
|
3615
|
+
* type: "mysql",
|
|
3616
|
+
* host: "localhost",
|
|
3617
|
+
* username: "root",
|
|
3618
|
+
* password: "password",
|
|
3619
|
+
* database: "mydb",
|
|
3620
|
+
* models: { User, Post }
|
|
3621
|
+
* });
|
|
3622
|
+
* await sql.connect();
|
|
3623
|
+
*
|
|
3624
|
+
* // Now you can use the connection
|
|
3625
|
+
* const users = await sql.query("users").many();
|
|
3626
|
+
* ```
|
|
3359
3627
|
*/
|
|
3360
|
-
declare class SqlDataSource extends DataSource {
|
|
3361
|
-
private
|
|
3628
|
+
declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> extends DataSource {
|
|
3629
|
+
#private;
|
|
3362
3630
|
private globalTransaction;
|
|
3363
3631
|
private sqlType;
|
|
3364
|
-
private
|
|
3632
|
+
private _models;
|
|
3365
3633
|
private ownsPool;
|
|
3366
3634
|
/**
|
|
3367
3635
|
* @description The pool of connections for the database
|
|
@@ -3371,11 +3639,11 @@ declare class SqlDataSource extends DataSource {
|
|
|
3371
3639
|
* @description Only used in transaction context to specify the connection, not meant to be used directly
|
|
3372
3640
|
* @private
|
|
3373
3641
|
*/
|
|
3374
|
-
sqlConnection: GetConnectionReturnType<
|
|
3642
|
+
sqlConnection: GetConnectionReturnType<D> | null;
|
|
3375
3643
|
/**
|
|
3376
3644
|
* @description Options provided in the sql data source initialization
|
|
3377
3645
|
*/
|
|
3378
|
-
inputDetails: SqlDataSourceInput<
|
|
3646
|
+
inputDetails: SqlDataSourceInput<D, T, C>;
|
|
3379
3647
|
/**
|
|
3380
3648
|
* @description Adapter for `useCache`, uses an in memory strategy by default
|
|
3381
3649
|
*/
|
|
@@ -3383,7 +3651,11 @@ declare class SqlDataSource extends DataSource {
|
|
|
3383
3651
|
/**
|
|
3384
3652
|
* @description Maps global keys to specific handlers for cache handling
|
|
3385
3653
|
*/
|
|
3386
|
-
cacheKeys:
|
|
3654
|
+
cacheKeys: C;
|
|
3655
|
+
/**
|
|
3656
|
+
* @description The path to the migrations folder for the sql data source, it's used to configure the migrations path for the sql data source
|
|
3657
|
+
*/
|
|
3658
|
+
migrationsPath: string;
|
|
3387
3659
|
/**
|
|
3388
3660
|
* @description AdminJS configuration options
|
|
3389
3661
|
*/
|
|
@@ -3393,191 +3665,130 @@ declare class SqlDataSource extends DataSource {
|
|
|
3393
3665
|
*/
|
|
3394
3666
|
private adminJsInstance?;
|
|
3395
3667
|
/**
|
|
3396
|
-
* @description
|
|
3397
|
-
*
|
|
3398
|
-
* @throws {HysteriaError} If using models in input, and the model key is already used by the sql data source instance e.g. a model called `connect` is already used by the sql data source instance and will throw an error
|
|
3399
|
-
* @example
|
|
3400
|
-
* ```ts
|
|
3401
|
-
* import { sql } from "hysteria-orm";
|
|
3402
|
-
* const connection = await sql.connect();
|
|
3403
|
-
* // You can use both connection and sql from now own, since `sql` will use the default connection after being connected
|
|
3404
|
-
* connection.query();
|
|
3405
|
-
* sql.query();
|
|
3406
|
-
*
|
|
3407
|
-
* // Models will use the default connection after being connected
|
|
3408
|
-
* User.query(); // Will use the default connection
|
|
3409
|
-
* ```
|
|
3668
|
+
* @description Returns the primary instance of the SqlDataSource (set via connect with setPrimary: true)
|
|
3669
|
+
* All models by default will use this instance to execute queries unless you pass a different connection/transaction in the query options
|
|
3410
3670
|
*/
|
|
3411
|
-
static
|
|
3412
|
-
static connect<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
|
|
3671
|
+
static get instance(): SqlDataSource;
|
|
3413
3672
|
/**
|
|
3414
|
-
* @description
|
|
3673
|
+
* @description Creates a secondary database connection that won't be set as the primary instance
|
|
3415
3674
|
* @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
|
|
3416
|
-
* @throws {HysteriaError} If using models in input, and the model key is already used by the sql data source instance e.g. a model called `connect` is already used by the sql data source instance and will throw an error
|
|
3417
3675
|
* @example
|
|
3418
3676
|
* ```ts
|
|
3419
|
-
* const
|
|
3420
|
-
*
|
|
3677
|
+
* const secondaryDb = await SqlDataSource.connectToSecondarySource({
|
|
3678
|
+
* type: "postgres",
|
|
3679
|
+
* host: "replica.db.com",
|
|
3680
|
+
* ...
|
|
3421
3681
|
* });
|
|
3422
3682
|
*
|
|
3423
|
-
* const user = await User.query({ connection:
|
|
3424
|
-
* ```
|
|
3425
|
-
*/
|
|
3426
|
-
static connectToSecondarySource<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(input: SqlDataSourceInput<U, T, C>, cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
|
|
3427
|
-
static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
|
|
3428
|
-
/**
|
|
3429
|
-
* @description Creates a new connection and executes a callback with the new instance, the connection is automatically closed after the callback is executed, so it's lifespan is only inside the callback
|
|
3430
|
-
* @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
|
|
3431
|
-
* @throws {HysteriaError} If using models in input, and the model key is already used by the sql data source instance e.g. a model called `connect` is already used by the sql data source instance and will throw an error
|
|
3432
|
-
* @example
|
|
3433
|
-
* ```ts
|
|
3434
|
-
* await Sql.useConnection({
|
|
3435
|
-
* ...connectionData
|
|
3436
|
-
* }, (sql) => {
|
|
3437
|
-
* const user = await User.query({ connection: sql }).many();
|
|
3438
|
-
* });
|
|
3439
|
-
* ```
|
|
3440
|
-
*/
|
|
3441
|
-
static useConnection<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(connectionDetails: UseConnectionInput<U, T, C>, cb: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void>): Promise<void>;
|
|
3442
|
-
/**
|
|
3443
|
-
* @description Returns the instance of the SqlDataSource
|
|
3444
|
-
* @throws {HysteriaError} If the connection is not established
|
|
3445
|
-
*/
|
|
3446
|
-
static getInstance(): SqlDataSource;
|
|
3447
|
-
/**
|
|
3448
|
-
* @description Returns a QueryBuilder instance
|
|
3449
|
-
* @description Query builder from the SqlDataSource instance returns raw data from the database, the data is not parsed or serialized in any way
|
|
3450
|
-
* @description Optimal for performance-critical operations
|
|
3451
|
-
* @description Use Models to have type safety and serialization
|
|
3452
|
-
* @description Default soft delete column is "deleted_at" with stringed date value
|
|
3453
|
-
* @param table The table name to query from, must be in valid sql format `table` or `table as alias`
|
|
3683
|
+
* const user = await User.query({ connection: secondaryDb }).many();
|
|
3684
|
+
* ```
|
|
3454
3685
|
*/
|
|
3455
|
-
static
|
|
3686
|
+
static connectToSecondarySource<U extends SqlDataSourceType, M extends Record<string, SqlDataSourceModel> = {}, K extends CacheKeys = {}>(input: SqlDataSourceInput<U, M, K>, cb?: (sqlDataSource: SqlDataSource<U, M, K>) => Promise<void> | void): Promise<SqlDataSource<U, M, K>>;
|
|
3456
3687
|
/**
|
|
3457
|
-
* @description
|
|
3458
|
-
* @
|
|
3459
|
-
*
|
|
3688
|
+
* @description Creates a temporary connection that is automatically closed after the callback is executed
|
|
3689
|
+
* @example
|
|
3690
|
+
* ```ts
|
|
3691
|
+
* await SqlDataSource.useConnection({
|
|
3692
|
+
* type: "mysql",
|
|
3693
|
+
* ...connectionData
|
|
3694
|
+
* }, async (sql) => {
|
|
3695
|
+
* const user = await User.query({ connection: sql }).many();
|
|
3696
|
+
* });
|
|
3697
|
+
* // Connection is automatically closed here
|
|
3698
|
+
* ```
|
|
3460
3699
|
*/
|
|
3461
|
-
static
|
|
3700
|
+
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>;
|
|
3462
3701
|
/**
|
|
3463
|
-
* @description
|
|
3702
|
+
* @description Closes the primary connection (singleton instance)
|
|
3464
3703
|
*/
|
|
3465
|
-
static
|
|
3704
|
+
static closeConnection(): Promise<void>;
|
|
3466
3705
|
/**
|
|
3467
|
-
* @
|
|
3706
|
+
* @alias closeConnection
|
|
3468
3707
|
*/
|
|
3469
|
-
static
|
|
3708
|
+
static disconnect(): Promise<void>;
|
|
3470
3709
|
/**
|
|
3471
|
-
* @description Starts a global transaction on the database
|
|
3710
|
+
* @description Starts a global transaction on the primary database connection
|
|
3711
|
+
* @description Intended for testing purposes - wraps all operations in a transaction that can be rolled back
|
|
3472
3712
|
*/
|
|
3473
3713
|
static startGlobalTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3474
3714
|
/**
|
|
3475
|
-
* @description Commits a global transaction on the database
|
|
3715
|
+
* @description Commits a global transaction on the primary database connection
|
|
3476
3716
|
* @throws {HysteriaError} If the global transaction is not started
|
|
3477
3717
|
*/
|
|
3478
3718
|
static commitGlobalTransaction(): Promise<void>;
|
|
3479
3719
|
/**
|
|
3480
|
-
* @description Rolls back a global transaction on the database
|
|
3720
|
+
* @description Rolls back a global transaction on the primary database connection
|
|
3481
3721
|
* @throws {HysteriaError} If the global transaction is not started
|
|
3482
3722
|
*/
|
|
3483
3723
|
static rollbackGlobalTransaction(): Promise<void>;
|
|
3484
3724
|
/**
|
|
3485
|
-
* @description
|
|
3486
|
-
* @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
|
|
3487
|
-
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3488
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3489
|
-
* @param options.endConnection Whether to end the connection after the transaction is committed or rolled back (Default is true, better to leave it this way)
|
|
3490
|
-
* @sqlite ignores the isolation level
|
|
3491
|
-
*/
|
|
3492
|
-
static startTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3493
|
-
static startTransaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3494
|
-
/**
|
|
3495
|
-
* @alias startTransaction
|
|
3496
|
-
* @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
|
|
3497
|
-
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3498
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3499
|
-
* @param options.endConnection Whether to end the connection after the transaction is committed or rolled back (Default is true, better to leave it this way)
|
|
3500
|
-
* @sqlite ignores the isolation level
|
|
3501
|
-
*/
|
|
3502
|
-
static transaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3503
|
-
static transaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3504
|
-
static transaction(optionsOrCb?: StartTransactionOptions | ((trx: Transaction) => Promise<void>), maybeOptions?: StartTransactionOptions): Promise<StartTransactionReturnType<TransactionOptionsOrCallback>>;
|
|
3505
|
-
/**
|
|
3506
|
-
* @description Retrieves informations from the database for the given table
|
|
3507
|
-
*/
|
|
3508
|
-
static getTableSchema(table: string): Promise<TableSchemaInfo>;
|
|
3509
|
-
/**
|
|
3510
|
-
* @description Closes the current connection
|
|
3511
|
-
*/
|
|
3512
|
-
static closeConnection(): Promise<void>;
|
|
3513
|
-
/**
|
|
3514
|
-
* @alias closeConnection
|
|
3515
|
-
*/
|
|
3516
|
-
static disconnect(): Promise<void>;
|
|
3517
|
-
/**
|
|
3518
|
-
* @description Executes a raw query on the database
|
|
3725
|
+
* @description Returns true if the primary instance is in a global transaction
|
|
3519
3726
|
*/
|
|
3520
|
-
static
|
|
3727
|
+
static get isInGlobalTransaction(): boolean;
|
|
3521
3728
|
/**
|
|
3522
|
-
* @description
|
|
3729
|
+
* @description Creates a new SqlDataSource instance. Call `.connect()` to establish the connection.
|
|
3730
|
+
* @param input Configuration options for the database connection. If not provided, uses env variables.
|
|
3523
3731
|
* @example
|
|
3524
3732
|
* ```ts
|
|
3525
|
-
*
|
|
3733
|
+
* // With explicit config
|
|
3734
|
+
* const sql = new SqlDataSource({
|
|
3735
|
+
* type: "mysql",
|
|
3736
|
+
* host: "localhost",
|
|
3737
|
+
* username: "root",
|
|
3738
|
+
* password: "password",
|
|
3739
|
+
* database: "mydb",
|
|
3740
|
+
* models: { User, Post }
|
|
3741
|
+
* });
|
|
3742
|
+
* await sql.connect();
|
|
3526
3743
|
*
|
|
3527
|
-
*
|
|
3744
|
+
* // Using env variables
|
|
3745
|
+
* const sql = new SqlDataSource();
|
|
3746
|
+
* await sql.connect();
|
|
3528
3747
|
* ```
|
|
3529
3748
|
*/
|
|
3530
|
-
|
|
3749
|
+
constructor(input?: SqlDataSourceInput<D, T, C>);
|
|
3531
3750
|
/**
|
|
3532
|
-
* @description
|
|
3533
|
-
* @
|
|
3534
|
-
* @
|
|
3535
|
-
*
|
|
3536
|
-
*
|
|
3751
|
+
* @description Establishes the database connection and sets this instance as the primary connection
|
|
3752
|
+
* @throws {HysteriaError} If the connection is already established, use `SqlDataSource.useConnection` or `SqlDataSource.connectToSecondarySource` for auxiliary connections
|
|
3753
|
+
* @example
|
|
3754
|
+
* ```ts
|
|
3755
|
+
* const sql = new SqlDataSource({ type: "mysql", ... });
|
|
3756
|
+
* await sql.connect();
|
|
3757
|
+
* ```
|
|
3537
3758
|
*/
|
|
3538
|
-
|
|
3759
|
+
connect(): Promise<void>;
|
|
3539
3760
|
/**
|
|
3540
|
-
* @description
|
|
3541
|
-
* @description All AdminJS dependencies are loaded at runtime via dynamic import() to keep the plugin optional
|
|
3542
|
-
* @description To use AdminJS with Express, install: npm install adminjs @adminjs/express express express-formidable --save-dev
|
|
3543
|
-
* @throws {HysteriaError} If AdminJS is not enabled or connection not established
|
|
3544
|
-
* @returns The AdminJS instance with Express router
|
|
3761
|
+
* @description Returns true if the connection is established
|
|
3545
3762
|
*/
|
|
3546
|
-
|
|
3763
|
+
get isConnected(): boolean;
|
|
3547
3764
|
/**
|
|
3548
|
-
* @description Returns
|
|
3549
|
-
* @returns The AdminJS instance or undefined if not initialized
|
|
3765
|
+
* @description Returns true if this instance is in a global transaction
|
|
3550
3766
|
*/
|
|
3551
|
-
|
|
3767
|
+
get isInGlobalTransaction(): boolean;
|
|
3552
3768
|
/**
|
|
3553
|
-
* @description
|
|
3554
|
-
* @returns True if AdminJS is enabled
|
|
3769
|
+
* @description Returns the models configured on this SqlDataSource instance
|
|
3555
3770
|
*/
|
|
3556
|
-
|
|
3557
|
-
private constructor();
|
|
3771
|
+
get models(): T;
|
|
3558
3772
|
/**
|
|
3559
3773
|
* @description Uses the cache adapter to get a value from the cache
|
|
3560
3774
|
* @param key The key to get the value from
|
|
3561
3775
|
* @param args The arguments to pass to the key handler
|
|
3562
3776
|
*/
|
|
3563
|
-
useCache<
|
|
3777
|
+
useCache<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3564
3778
|
/**
|
|
3565
3779
|
* @description Uses the cache adapter to get a value from the cache
|
|
3566
3780
|
* @param key The key to get the value from
|
|
3567
3781
|
* @param ttl The time to live for the value in milliseconds
|
|
3568
3782
|
* @param args The arguments to pass to the key handler
|
|
3569
3783
|
*/
|
|
3570
|
-
useCache<
|
|
3784
|
+
useCache<K extends keyof C>(key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3571
3785
|
/**
|
|
3572
3786
|
* @description Invalidates a value from the cache
|
|
3573
3787
|
* @param key The key to invalidate the value from
|
|
3574
|
-
* @param args The arguments to pass to the key handler
|
|
3575
|
-
*/
|
|
3576
|
-
invalidCache<M extends Record<string, typeof Model>, C extends CacheKeys, K extends keyof C>(this: AugmentedSqlDataSource<M, C>, key: K, ...args: Parameters<C[K]>): Promise<void>;
|
|
3577
|
-
/**
|
|
3578
|
-
* @description Returns true if the connection is established
|
|
3788
|
+
* @param args The arguments to pass to the key handler (required if the handler expects arguments)
|
|
3579
3789
|
*/
|
|
3580
|
-
|
|
3790
|
+
invalidCache<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<void>;
|
|
3791
|
+
invalidCache<K extends keyof C>(key: K): Promise<void>;
|
|
3581
3792
|
/**
|
|
3582
3793
|
* @description Clones the SqlDataSource instance
|
|
3583
3794
|
* @param options.shouldRecreatePool Whether to recreate the pool of connections for the given driver, by default it's false
|
|
@@ -3588,20 +3799,15 @@ declare class SqlDataSource extends DataSource {
|
|
|
3588
3799
|
/**
|
|
3589
3800
|
* @description Returns the type of the database
|
|
3590
3801
|
*/
|
|
3591
|
-
getDbType():
|
|
3802
|
+
getDbType(): D;
|
|
3592
3803
|
/**
|
|
3593
|
-
* @description Returns a QueryBuilder instance
|
|
3594
|
-
* @description Query builder from the SqlDataSource instance
|
|
3595
|
-
* @
|
|
3596
|
-
* @description Use Models to have type safety and serialization
|
|
3597
|
-
* @description Default soft delete column is "deleted_at" with stringed date value
|
|
3598
|
-
* @param table The table name to query from, must be in valid sql format `table` or `table as alias`
|
|
3804
|
+
* @description Returns a QueryBuilder instance for raw queries
|
|
3805
|
+
* @description Query builder from the SqlDataSource instance returns raw data from the database
|
|
3806
|
+
* @param table The table name to query from
|
|
3599
3807
|
*/
|
|
3600
3808
|
query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
|
|
3601
3809
|
/**
|
|
3602
|
-
* @description Returns a DryQueryBuilder instance
|
|
3603
|
-
* @description The dry query builder instance will not execute the query, it will return the query statement
|
|
3604
|
-
* @returns The dry query builder instance
|
|
3810
|
+
* @description Returns a DryQueryBuilder instance that returns the query statement without executing
|
|
3605
3811
|
*/
|
|
3606
3812
|
dryQuery<S extends string>(table: TableFormat<S>, options?: RawModelOptions): DryQueryBuilderWithoutReadOperations;
|
|
3607
3813
|
/**
|
|
@@ -3613,94 +3819,77 @@ declare class SqlDataSource extends DataSource {
|
|
|
3613
3819
|
*/
|
|
3614
3820
|
createTable(...args: Parameters<Schema["createTable"]>): string;
|
|
3615
3821
|
/**
|
|
3616
|
-
* @description Starts a global transaction on the database
|
|
3822
|
+
* @description Starts a global transaction on the database
|
|
3823
|
+
* @description Intended for testing purposes - wraps all operations in a transaction that can be rolled back
|
|
3617
3824
|
*/
|
|
3618
3825
|
startGlobalTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3619
3826
|
/**
|
|
3620
|
-
* @description Commits a global transaction on the database
|
|
3827
|
+
* @description Commits a global transaction on the database
|
|
3621
3828
|
* @throws {HysteriaError} If the global transaction is not started
|
|
3622
3829
|
*/
|
|
3623
3830
|
commitGlobalTransaction(options?: TransactionExecutionOptions): Promise<void>;
|
|
3624
3831
|
/**
|
|
3625
|
-
* @description Rolls back a global transaction on the database
|
|
3626
|
-
* @throws {HysteriaError} If the global transaction is not started and options.throwErrorOnInactiveTransaction is true
|
|
3832
|
+
* @description Rolls back a global transaction on the database
|
|
3627
3833
|
*/
|
|
3628
3834
|
rollbackGlobalTransaction(options?: TransactionExecutionOptions): Promise<void>;
|
|
3629
3835
|
/**
|
|
3630
|
-
* @description
|
|
3836
|
+
* @description Starts a transaction on a dedicated connection from the pool
|
|
3631
3837
|
* @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
|
|
3632
3838
|
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3633
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3634
|
-
* @param options.endConnection Whether to end the connection after the transaction is committed or rolled back (Default is true, better to leave it this way)
|
|
3635
3839
|
* @sqlite ignores the isolation level
|
|
3636
3840
|
*/
|
|
3637
3841
|
startTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3638
3842
|
startTransaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3639
3843
|
/**
|
|
3640
3844
|
* @alias startTransaction
|
|
3641
|
-
* @description Get's a connection from the pool and starts a transaction on the database and returns an already started transaction instance
|
|
3642
|
-
* @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
|
|
3643
|
-
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3644
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3645
|
-
* @param options.endConnection Whether to end the connection after the transaction is committed or rolled back (Default is true, better to leave it this way)
|
|
3646
|
-
* @sqlite ignores the isolation level
|
|
3647
3845
|
*/
|
|
3648
3846
|
transaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3649
3847
|
transaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3650
3848
|
/**
|
|
3651
|
-
* @description Returns a ModelManager instance for the given model
|
|
3652
|
-
* @description This is intended to use only if you do not want to use active record pattern
|
|
3849
|
+
* @description Returns a ModelManager instance for the given model
|
|
3653
3850
|
*/
|
|
3654
|
-
getModelManager<
|
|
3655
|
-
new ():
|
|
3656
|
-
} | typeof Model): ModelManager<
|
|
3851
|
+
getModelManager<M extends Model>(model: {
|
|
3852
|
+
new (): M;
|
|
3853
|
+
} | typeof Model): ModelManager<M>;
|
|
3657
3854
|
/**
|
|
3658
|
-
* @description Returns the current raw driver Pool
|
|
3855
|
+
* @description Returns the current raw driver Pool
|
|
3659
3856
|
* @throws {HysteriaError} If the connection pool is not established
|
|
3660
|
-
* @example
|
|
3661
|
-
* const mysqlConnection = sql.getPool("mysql"); // mysql2 Pool
|
|
3662
|
-
* const pgConnection = sql.getPool("postgres"); // pg Pool
|
|
3663
|
-
* const sqliteConnection = sql.getPool("sqlite"); // sqlite3 Database
|
|
3664
3857
|
*/
|
|
3665
|
-
getPool
|
|
3858
|
+
getPool(): getPoolReturnType<D>;
|
|
3666
3859
|
/**
|
|
3667
|
-
* @description Returns a connection from the pool
|
|
3860
|
+
* @description Returns a connection from the pool
|
|
3668
3861
|
* @throws {HysteriaError} If the connection is not established
|
|
3669
|
-
* @example
|
|
3670
|
-
* const mysqlConnection = sql.getConnection("mysql"); // mysql2 PoolConnection
|
|
3671
|
-
* const pgConnection = sql.getConnection("postgres"); // pg PoolClient
|
|
3672
|
-
* const sqliteConnection = sql.getConnection("sqlite"); // sqlite3 Database
|
|
3673
3862
|
*/
|
|
3674
|
-
getConnection
|
|
3863
|
+
getConnection(): Promise<GetConnectionReturnType<D>>;
|
|
3675
3864
|
/**
|
|
3676
3865
|
* @description Closes the current connection
|
|
3677
3866
|
* @description If there is an active global transaction, it will be rolled back
|
|
3678
3867
|
*/
|
|
3679
3868
|
closeConnection(): Promise<void>;
|
|
3680
|
-
|
|
3869
|
+
/**
|
|
3870
|
+
* @description Returns the connection details
|
|
3871
|
+
*/
|
|
3872
|
+
getConnectionDetails(): SqlDataSourceInput<D, T, C>;
|
|
3681
3873
|
/**
|
|
3682
3874
|
* @alias closeConnection
|
|
3683
3875
|
*/
|
|
3684
3876
|
disconnect(): Promise<void>;
|
|
3685
3877
|
/**
|
|
3686
3878
|
* @description Syncs the schema of the database with the models metadata
|
|
3687
|
-
* @warning This will drop and recreate all the indexes and constraints, use with caution
|
|
3688
|
-
* @param options.transactional Whether to use a transaction to sync the schema, if true it will use a transaction for the entire sync operation, defaults to false
|
|
3879
|
+
* @warning This will drop and recreate all the indexes and constraints, use with caution
|
|
3689
3880
|
* @sqlite Not supported but won't throw an error
|
|
3690
3881
|
*/
|
|
3691
3882
|
syncSchema(options?: {
|
|
3692
3883
|
transactional: boolean;
|
|
3693
3884
|
}): Promise<void>;
|
|
3694
3885
|
/**
|
|
3695
|
-
* @description Executes a raw query on the database
|
|
3886
|
+
* @description Executes a raw query on the database and returns the raw driver result
|
|
3696
3887
|
*/
|
|
3697
|
-
rawQuery<
|
|
3888
|
+
rawQuery<R = RawQueryResponseType<D>>(query: string, params?: any[]): Promise<R>;
|
|
3698
3889
|
/**
|
|
3699
|
-
* @description Adds a raw statement to an operation like where or update
|
|
3890
|
+
* @description Adds a raw statement to an operation like where or update
|
|
3700
3891
|
* @example
|
|
3701
3892
|
* ```ts
|
|
3702
|
-
* import { sql } from "hysteria-orm";
|
|
3703
|
-
*
|
|
3704
3893
|
* await User.query().where("name", sql.rawStatement("LOWER(name)"));
|
|
3705
3894
|
* ```
|
|
3706
3895
|
*/
|
|
@@ -3719,33 +3908,24 @@ declare class SqlDataSource extends DataSource {
|
|
|
3719
3908
|
})[];
|
|
3720
3909
|
/**
|
|
3721
3910
|
* @description Initializes AdminJS with the configured options
|
|
3722
|
-
* @description All AdminJS dependencies are loaded at runtime via dynamic import() to keep the plugin optional
|
|
3723
|
-
* @description To use AdminJS, install: npm install adminjs
|
|
3724
3911
|
* @throws {HysteriaError} If AdminJS is not enabled in the configuration
|
|
3725
|
-
* @returns The AdminJS instance
|
|
3726
3912
|
*/
|
|
3727
3913
|
initializeAdminJs(): Promise<AdminJsAdminInstance>;
|
|
3728
3914
|
/**
|
|
3729
3915
|
* @description Initializes AdminJS with Express router
|
|
3730
|
-
* @description All AdminJS dependencies are loaded at runtime via dynamic import() to keep the plugin optional
|
|
3731
|
-
* @description To use AdminJS with Express, install: npm install adminjs @adminjs/express express express-formidable --save-dev
|
|
3732
3916
|
* @throws {HysteriaError} If AdminJS is not enabled in the configuration
|
|
3733
|
-
* @returns The AdminJS instance with Express router
|
|
3734
3917
|
*/
|
|
3735
|
-
initializeAdminJsExpress(): Promise<AdminJsInstance
|
|
3918
|
+
initializeAdminJsExpress(): Promise<Required<AdminJsInstance>>;
|
|
3736
3919
|
/**
|
|
3737
3920
|
* @description Returns the AdminJS instance if initialized
|
|
3738
|
-
* @returns The AdminJS instance or undefined if not initialized
|
|
3739
3921
|
*/
|
|
3740
3922
|
getAdminJs(): AdminJsInstance | undefined;
|
|
3741
3923
|
/**
|
|
3742
3924
|
* @description Returns the AdminJS configuration options
|
|
3743
|
-
* @returns The AdminJS configuration options or undefined if not configured
|
|
3744
3925
|
*/
|
|
3745
3926
|
getAdminJsOptions(): AdminJsOptions | undefined;
|
|
3746
3927
|
/**
|
|
3747
3928
|
* @description Checks if AdminJS is enabled
|
|
3748
|
-
* @returns True if AdminJS is enabled
|
|
3749
3929
|
*/
|
|
3750
3930
|
isAdminJsEnabled(): boolean;
|
|
3751
3931
|
/**
|
|
@@ -3753,204 +3933,79 @@ declare class SqlDataSource extends DataSource {
|
|
|
3753
3933
|
*/
|
|
3754
3934
|
getTableInfo(table: string): Promise<TableColumnInfo[]>;
|
|
3755
3935
|
/**
|
|
3756
|
-
* @description Introspects table indexes metadata
|
|
3936
|
+
* @description Introspects table indexes metadata
|
|
3757
3937
|
*/
|
|
3758
3938
|
getIndexInfo(table: string): Promise<TableIndexInfo[]>;
|
|
3939
|
+
/**
|
|
3940
|
+
* @description Introspects table foreign keys metadata
|
|
3941
|
+
*/
|
|
3759
3942
|
getForeignKeyInfo(table: string): Promise<TableForeignKeyInfo[]>;
|
|
3760
3943
|
/**
|
|
3761
3944
|
* @description Introspects table primary key from the database
|
|
3762
3945
|
*/
|
|
3763
3946
|
getPrimaryKeyInfo(table: string): Promise<TablePrimaryKeyInfo | undefined>;
|
|
3764
|
-
private testConnectionQuery;
|
|
3765
|
-
private sanitizeModelKeys;
|
|
3766
|
-
static get isInGlobalTransaction(): boolean;
|
|
3767
|
-
get isInGlobalTransaction(): boolean;
|
|
3768
3947
|
/**
|
|
3769
|
-
* @description
|
|
3948
|
+
* @description Internal method to establish connection without setting as primary instance
|
|
3949
|
+
* @description Used by connectToSecondarySource and useConnection
|
|
3770
3950
|
*/
|
|
3771
|
-
|
|
3951
|
+
private connectWithoutSettingPrimary;
|
|
3772
3952
|
}
|
|
3773
3953
|
|
|
3774
|
-
type
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
type
|
|
3779
|
-
type PgPoolClientInstance = InstanceType<PgImport["Pool"]>;
|
|
3780
|
-
type SqliteConnectionInstance = InstanceType<Sqlite3Import["Database"]>;
|
|
3781
|
-
type SqlPoolType = MysqlConnectionInstance | PgPoolClientInstance | SqliteConnectionInstance;
|
|
3782
|
-
/**
|
|
3783
|
-
* @description The connection policies for the sql data source
|
|
3784
|
-
* @default By default, the connection policies are not set, so no query will be retried
|
|
3785
|
-
*/
|
|
3786
|
-
type ConnectionPolicies = {
|
|
3787
|
-
/**
|
|
3788
|
-
* @description The retry policy for the sql data source, it allows to retry a query if it fails
|
|
3789
|
-
*/
|
|
3790
|
-
retry?: {
|
|
3791
|
-
maxRetries?: number;
|
|
3792
|
-
delay?: number;
|
|
3793
|
-
};
|
|
3794
|
-
};
|
|
3795
|
-
type SqlDataSourceModel = typeof Model;
|
|
3796
|
-
/**
|
|
3797
|
-
* @description The input type for the SqlDataSource constructor
|
|
3798
|
-
* @description The connectionPolicies object is used to configure the connection policies for the sql data source
|
|
3799
|
-
*/
|
|
3800
|
-
type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
|
|
3801
|
-
readonly type?: D;
|
|
3802
|
-
/**
|
|
3803
|
-
* @description Whether to log the sql queries and other debug information
|
|
3804
|
-
*/
|
|
3805
|
-
readonly logs?: boolean;
|
|
3806
|
-
/**
|
|
3807
|
-
* @description The connection policies to use for the sql data source that are not configured in the driverOptions
|
|
3808
|
-
*/
|
|
3809
|
-
connectionPolicies?: ConnectionPolicies;
|
|
3954
|
+
type ModelWithoutRelations<T extends Model> = Pick<T, ExcludeRelations<Omit<T, "*">>>;
|
|
3955
|
+
type NumberModelKey<T extends Model> = {
|
|
3956
|
+
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
3957
|
+
}[keyof T];
|
|
3958
|
+
type BaseModelMethodOptions = {
|
|
3810
3959
|
/**
|
|
3811
|
-
* @description The
|
|
3960
|
+
* @description The connection to use for the model, by default the main connection will be used
|
|
3961
|
+
* @description The main connection is the one created via `new SqlDataSource().connect()`
|
|
3962
|
+
* @example
|
|
3963
|
+
* ```ts
|
|
3964
|
+
* import { SqlDataSource } from "hysteria-orm";
|
|
3965
|
+
* const customConnection = await SqlDataSource.connectToSecondarySource({
|
|
3966
|
+
* type: "postgres",
|
|
3967
|
+
* host: "localhost",
|
|
3968
|
+
* username: "root",
|
|
3969
|
+
* password: "root",
|
|
3970
|
+
* database: "test",
|
|
3971
|
+
* port: 5432,
|
|
3972
|
+
* });
|
|
3973
|
+
*
|
|
3974
|
+
* const user = await User.query({ connection: customConnection }).first();
|
|
3975
|
+
* ```
|
|
3812
3976
|
*/
|
|
3813
|
-
|
|
3977
|
+
connection?: SqlDataSource;
|
|
3814
3978
|
/**
|
|
3815
|
-
* @description The
|
|
3816
|
-
* @description Models can still be used as standalone entities, but they won't be available for the sql data source instance
|
|
3979
|
+
* @description The transaction instance to use for the model
|
|
3817
3980
|
*/
|
|
3818
|
-
|
|
3981
|
+
trx?: Transaction;
|
|
3819
3982
|
/**
|
|
3820
|
-
* @description
|
|
3821
|
-
* @warning For usage with types, you must have driver types installed if the driver handles types in a type package like e.g. `@types/pg`
|
|
3983
|
+
* @description Whether to ignore the hooks for the model
|
|
3822
3984
|
*/
|
|
3823
|
-
|
|
3985
|
+
ignoreHooks?: boolean;
|
|
3986
|
+
};
|
|
3987
|
+
/**
|
|
3988
|
+
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
3989
|
+
*/
|
|
3990
|
+
type RawModelOptions = {
|
|
3824
3991
|
/**
|
|
3825
|
-
*
|
|
3992
|
+
* Alias for the table
|
|
3826
3993
|
*/
|
|
3827
|
-
|
|
3828
|
-
cacheAdapter?: CacheAdapter;
|
|
3829
|
-
keys: C;
|
|
3830
|
-
};
|
|
3994
|
+
alias?: string;
|
|
3831
3995
|
/**
|
|
3832
|
-
* @description
|
|
3833
|
-
* @description To use AdminJS, install: `npm install adminjs`
|
|
3996
|
+
* @description Convert the column casing before making a Database query, by default preserves what is provided
|
|
3834
3997
|
*/
|
|
3835
|
-
|
|
3836
|
-
} & (MysqlSqlDataSourceInput | PostgresSqlDataSourceInput | SqliteDataSourceInput);
|
|
3837
|
-
type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
|
|
3838
|
-
readonly type: Exclude<DataSourceType, "mongo">;
|
|
3839
|
-
readonly logs?: boolean;
|
|
3840
|
-
readonly models?: T;
|
|
3841
|
-
readonly driverOptions?: SqlDriverSpecificOptions<D>;
|
|
3842
|
-
connectionPolicies?: ConnectionPolicies;
|
|
3843
|
-
queryFormatOptions?: FormatOptionsWithLanguage;
|
|
3844
|
-
cacheStrategy?: {
|
|
3845
|
-
cacheAdapter: CacheAdapter;
|
|
3846
|
-
keys: C;
|
|
3847
|
-
};
|
|
3998
|
+
databaseCaseConvention?: CaseConvention;
|
|
3848
3999
|
/**
|
|
3849
|
-
*
|
|
3850
|
-
* @description AdminJS is completely optional - dependencies are loaded at runtime via dynamic import()
|
|
4000
|
+
* Column to use for soft deleted, by default is `deleted_at`
|
|
3851
4001
|
*/
|
|
3852
|
-
|
|
3853
|
-
} & (NotNullableMysqlSqlDataSourceInput | NotNullablePostgresSqlDataSourceInput | NotNullableSqliteDataSourceInput);
|
|
3854
|
-
type SqlDataSourceType = Exclude<DataSourceType, "mongo">;
|
|
3855
|
-
type SqlCloneOptions = {
|
|
4002
|
+
softDeleteColumn?: string;
|
|
3856
4003
|
/**
|
|
3857
|
-
*
|
|
3858
|
-
* @warning If false, the pool of connections will be reused from the caller instance
|
|
4004
|
+
* Column to use for soft deleted, by default is date in format: "YYYY-MM-DD HH:mm:ss" in UTC timezone
|
|
3859
4005
|
*/
|
|
3860
|
-
|
|
3861
|
-
};
|
|
3862
|
-
type getPoolReturnType<T = SqlDataSourceType> = T extends "mysql" ? MysqlConnectionInstance : T extends "mariadb" ? MysqlConnectionInstance : T extends "postgres" ? PgPoolClientInstance : T extends "cockroachdb" ? PgPoolClientInstance : T extends "sqlite" ? SqliteConnectionInstance : never;
|
|
3863
|
-
type GetConnectionReturnType<T = SqlDataSourceType> = T extends "mysql" ? PoolConnection : T extends "mariadb" ? PoolConnection : T extends "postgres" ? PoolClient : T extends "cockroachdb" ? PoolClient : T extends "sqlite" ? InstanceType<Sqlite3Import["Database"]> : never;
|
|
3864
|
-
type UseCacheOverloads<C extends CacheKeys> = {
|
|
3865
|
-
<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3866
|
-
<K extends keyof C>(key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3867
|
-
};
|
|
3868
|
-
type UseCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["useCache"] : UseCacheOverloads<C>;
|
|
3869
|
-
type InvalidCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["invalidCache"] : <K extends keyof C>(key: K) => Promise<void>;
|
|
3870
|
-
type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = Omit<SqlDataSource, "useCache" | "invalidCache" | "clone"> & {
|
|
3871
|
-
useCache: UseCacheType<C>;
|
|
3872
|
-
invalidCache: InvalidCacheType<C>;
|
|
3873
|
-
clone(options?: SqlCloneOptions): Promise<AugmentedSqlDataSource<T, C>>;
|
|
3874
|
-
} & {
|
|
3875
|
-
[key in keyof T]: T[key];
|
|
3876
|
-
};
|
|
3877
|
-
type SqlDataSourceWithoutTransaction<T extends Record<string, SqlDataSourceModel> = {}> = Pick<SqlDataSource, "sqlPool" | "sqlConnection" | "inputDetails" | "isConnected" | "getDbType" | "clone" | "getModelManager" | "getPool" | "getConnection" | "closeConnection" | "getConnectionDetails" | "disconnect" | "syncSchema" | "rawQuery" | "rawStatement" | "getTableSchema" | "getModelOpenApiSchema" | "getTableInfo" | "getIndexInfo" | "getForeignKeyInfo" | "getPrimaryKeyInfo" | "registeredModels" | "type" | "host" | "port" | "username" | "password" | "database" | "logs" | "query"> & {
|
|
3878
|
-
[key in keyof T]: T[key];
|
|
3879
|
-
};
|
|
3880
|
-
/** Only accepts formats `string` e `string as string` */
|
|
3881
|
-
type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
|
|
3882
|
-
type TableFormat<S extends string> = NoSpace<S> | (S extends `${infer L} as ${infer R}` ? `${NoSpace<L>} as ${NoSpace<R>}` : never);
|
|
3883
|
-
|
|
3884
|
-
type AstParserType = {
|
|
3885
|
-
sql: string;
|
|
3886
|
-
bindings: any[];
|
|
4006
|
+
softDeleteValue?: string | boolean;
|
|
3887
4007
|
};
|
|
3888
4008
|
|
|
3889
|
-
declare class AstParser {
|
|
3890
|
-
private readonly dbType;
|
|
3891
|
-
private readonly model;
|
|
3892
|
-
constructor(model: typeof Model, dbType: SqlDataSourceType);
|
|
3893
|
-
parse(nodes: (QueryNode | null)[], startBindingIndex?: number, isNestedCondition?: boolean): AstParserType;
|
|
3894
|
-
/**
|
|
3895
|
-
* Map the database type to a common type if shares the same driver (e.g. mysql and mariadb)
|
|
3896
|
-
*/
|
|
3897
|
-
private mapCommonDbType;
|
|
3898
|
-
}
|
|
3899
|
-
|
|
3900
|
-
declare class DeleteNode extends QueryNode {
|
|
3901
|
-
fromNode: FromNode;
|
|
3902
|
-
chainsWith: string;
|
|
3903
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
3904
|
-
folder: string;
|
|
3905
|
-
file: string;
|
|
3906
|
-
constructor(fromNode: FromNode, isRawValue?: boolean);
|
|
3907
|
-
}
|
|
3908
|
-
|
|
3909
|
-
declare class InsertNode extends QueryNode {
|
|
3910
|
-
fromNode: FromNode;
|
|
3911
|
-
records: Record<string, any>[];
|
|
3912
|
-
returning?: string[];
|
|
3913
|
-
disableReturning: boolean;
|
|
3914
|
-
chainsWith: string;
|
|
3915
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
3916
|
-
folder: string;
|
|
3917
|
-
file: string;
|
|
3918
|
-
constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
|
|
3919
|
-
}
|
|
3920
|
-
|
|
3921
|
-
declare class OnDuplicateNode extends QueryNode {
|
|
3922
|
-
table: string;
|
|
3923
|
-
conflictColumns: string[];
|
|
3924
|
-
columnsToUpdate: string[];
|
|
3925
|
-
returning?: string[];
|
|
3926
|
-
mode: "update" | "ignore";
|
|
3927
|
-
chainsWith: string;
|
|
3928
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
3929
|
-
folder: string;
|
|
3930
|
-
file: string;
|
|
3931
|
-
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
3932
|
-
}
|
|
3933
|
-
|
|
3934
|
-
declare class TruncateNode extends QueryNode {
|
|
3935
|
-
fromNode: FromNode | string;
|
|
3936
|
-
chainsWith: string;
|
|
3937
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
3938
|
-
folder: string;
|
|
3939
|
-
file: string;
|
|
3940
|
-
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
3941
|
-
}
|
|
3942
|
-
|
|
3943
|
-
declare class UpdateNode extends QueryNode {
|
|
3944
|
-
fromNode: FromNode;
|
|
3945
|
-
columns: string[];
|
|
3946
|
-
values: (any | RawNode)[];
|
|
3947
|
-
chainsWith: string;
|
|
3948
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
3949
|
-
folder: string;
|
|
3950
|
-
file: string;
|
|
3951
|
-
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
4009
|
declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
3955
4010
|
model: typeof Model;
|
|
3956
4011
|
protected astParser: AstParser;
|
|
@@ -4196,6 +4251,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4196
4251
|
with(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
4197
4252
|
/**
|
|
4198
4253
|
* @description Adds a recursive CTE to the query using a callback to build the subquery.
|
|
4254
|
+
* @mssql not supported
|
|
4199
4255
|
*/
|
|
4200
4256
|
withRecursive(alias: string, cb: (qb: QueryBuilder<T>) => void): this;
|
|
4201
4257
|
/**
|
|
@@ -4214,6 +4270,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4214
4270
|
* @description Insert multiple records into a table
|
|
4215
4271
|
* @param returning - The columns to return from the query, only supported by postgres and cockroachdb - default is "*"
|
|
4216
4272
|
* @returns raw driver response
|
|
4273
|
+
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
4217
4274
|
*/
|
|
4218
4275
|
insertMany(data: Record<string, any>[], returning?: string[]): Promise<T[]>;
|
|
4219
4276
|
/**
|
|
@@ -4232,6 +4289,10 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4232
4289
|
* @param options Upsert options including updateOnConflict and returning columns
|
|
4233
4290
|
*/
|
|
4234
4291
|
upsertMany<O extends Record<string, any>>(conflictColumns: string[], columnsToUpdate: string[], data: O[], options?: UpsertOptionsRawBuilder): Promise<T[]>;
|
|
4292
|
+
/**
|
|
4293
|
+
* @description Executes a MERGE statement for MSSQL upsert operations (raw query builder)
|
|
4294
|
+
*/
|
|
4295
|
+
private executeMssqlMergeRaw;
|
|
4235
4296
|
/**
|
|
4236
4297
|
* @description Updates records from a table
|
|
4237
4298
|
* @returns the number of affected rows
|
|
@@ -4318,6 +4379,15 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4318
4379
|
private softDeleteWithPerformance;
|
|
4319
4380
|
private deleteWithPerformance;
|
|
4320
4381
|
private truncateWithPerformance;
|
|
4382
|
+
/**
|
|
4383
|
+
* @description Checks if the current context is an MSSQL transaction
|
|
4384
|
+
* @description MSSQL transactions can only handle one request at a time
|
|
4385
|
+
*/
|
|
4386
|
+
protected isMssqlTransaction(): boolean;
|
|
4387
|
+
/**
|
|
4388
|
+
* @description Executes pagination queries, serializing them for MSSQL transactions
|
|
4389
|
+
*/
|
|
4390
|
+
protected executePaginateQueries<M, C>(modelsQuery: () => Promise<M>, countQuery: () => Promise<C>): Promise<[M, C]>;
|
|
4321
4391
|
}
|
|
4322
4392
|
|
|
4323
4393
|
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
@@ -4498,6 +4568,7 @@ declare abstract class Model extends Entity {
|
|
|
4498
4568
|
* @mysql If no Primary Key is present in the model definition, the model will be returned
|
|
4499
4569
|
* @sqlite If no Primary Key is present in the model definition, the model will be returned
|
|
4500
4570
|
* @sqlite Returning Not supported and won't have effect
|
|
4571
|
+
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
4501
4572
|
*/
|
|
4502
4573
|
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>): Promise<AnnotatedModel<T, {}>[]>;
|
|
4503
4574
|
/**
|
|
@@ -5717,7 +5788,7 @@ declare abstract class Migration {
|
|
|
5717
5788
|
/**
|
|
5718
5789
|
* @description This method is called after the migration has been run
|
|
5719
5790
|
*/
|
|
5720
|
-
afterMigration?(sqlDataSource: SqlDataSource
|
|
5791
|
+
afterMigration?(sqlDataSource: SqlDataSource): Promise<void>;
|
|
5721
5792
|
}
|
|
5722
5793
|
|
|
5723
5794
|
/**
|
|
@@ -5770,7 +5841,7 @@ type WithPerformanceResult<R = any> = [string, R];
|
|
|
5770
5841
|
*/
|
|
5771
5842
|
declare const withPerformance: <A extends any[], R>(fn: (...args: A) => Promise<R>, returnType?: "millis" | "seconds", fix?: number) => (...args: A) => Promise<WithPerformanceResult<R>>;
|
|
5772
5843
|
|
|
5773
|
-
type HysteriaErrorCode = "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `KEY_${string}_HAS_NO_HANDLER_IN_CACHE_KEYS_CONFIG` | `CACHE_ADAPTER_NOT_CONFIGURED` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `MODEL_HAS_NO_PRIMARY_KEY_VALUE` | `RELATION_NOT_MANY_TO_MANY` | "MATERIALIZED_CTE_NOT_SUPPORTED" | "DUPLICATE_MODEL_KEYS_WHILE_INSTANTIATING_MODELS" | "INVALID_ONE_PARAMETER_WHERE_CONDITION" | "INVALID_PAGINATION_PARAMETERS" | "MISSING_ALIAS_FOR_SUBQUERY" | "MODEL_HAS_NO_PRIMARY_KEY" | "PRIMARY_KEY_NOT_FOUND" | "SQLITE_ONLY_SUPPORTS_SERIALIZABLE_ISOLATION_LEVEL" | "MUST_CALL_BUILD_CTE_AT_LEAST_ONCE" | "REGEXP_NOT_SUPPORTED_IN_SQLITE" | "MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL" | "INSERT_FAILED" | "MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED" | "FILE_NOT_A_SQL_OR_TXT_FILE" | "CONNECTION_NOT_ESTABLISHED" | "TRANSACTION_NOT_ACTIVE" | "DEVELOPMENT_ERROR" | "MIGRATION_MODULE_NOT_FOUND" | "DRIVER_NOT_FOUND" | "FILE_NOT_FOUND_OR_NOT_ACCESSIBLE" | "ENV_NOT_SET" | "REQUIRED_VALUE_NOT_SET" | "SET_FAILED" | "GET_FAILED" | "REFERENCES_OPTION_REQUIRED" | "DELETE_FAILED" | "INVALID_DEFAULT_VALUE" | "DISCONNECT_FAILED" | "FLUSH_FAILED" | "LEFT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "RIGHT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "MODEL_HAS_NO_PRIMARY_KEY" | "GLOBAL_TRANSACTION_ALREADY_STARTED" | "GLOBAL_TRANSACTION_NOT_STARTED" | "MYSQL_REQUIRES_TABLE_NAME_FOR_INDEX_DROP" | "INVALID_DATE_OBJECT" | "INVALID_DATE_STRING" | "FAILED_TO_PARSE_DATE" | "MIGRATION_MODULE_REQUIRES_TS_NODE" | "FAILED_TO_ENCRYPT_SYMMETRICALLY" | "FAILED_TO_DECRYPT_SYMMETRICALLY" | "FAILED_TO_ENCRYPT_ASYMMETRICALLY" | "FAILED_TO_DECRYPT_ASYMMETRICALLY" | "UNSUPPORTED_RELATION_TYPE" | "LPUSH_FAILED" | "RPUSH_FAILED" | "LPOP_FAILED" | "RPOP_FAILED" | "LRANGE_FAILED" | "LLEN_FAILED" | "HSET_FAILED" | "HMSET_FAILED" | "HGET_FAILED" | "HGETALL_FAILED" | "HMGET_FAILED" | "HDEL_FAILED" | "HEXISTS_FAILED" | "HKEYS_FAILED" | "HLEN_FAILED" | "SADD_FAILED" | "SMEMBERS_FAILED" | "SREM_FAILED" | "SISMEMBER_FAILED" | "SCARD_FAILED" | "SINTER_FAILED" | "SUNION_FAILED" | "SDIFF_FAILED" | "ZADD_FAILED" | "ZRANGE_FAILED" | "ZREVRANGE_FAILED" | "ZREM_FAILED" | "ZSCORE_FAILED" | "ZCARD_FAILED" | "SUBSCRIBE_FAILED" | "UNSUBSCRIBE_FAILED" | "PUBLISH_FAILED" | "PSUBSCRIBE_FAILED" | "PUNSUBSCRIBE_FAILED" | "EXISTS_FAILED" | "EXPIRE_FAILED" | "EXPIREAT_FAILED" | "PEXPIRE_FAILED" | "TTL_FAILED" | "PTTL_FAILED" | "PERSIST_FAILED" | "KEYS_FAILED" | "RENAME_FAILED" | "TYPE_FAILED" | "SCAN_FAILED" | "ADMINJS_NOT_ENABLED" | "ADMINJS_INITIALIZATION_FAILED" | "ADMINJS_NO_MODELS_PROVIDED";
|
|
5844
|
+
type HysteriaErrorCode = "CONNECTION_ALREADY_ESTABLISHED" | `UNSUPPORTED_ISOLATION_LEVEL_${string}` | "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `KEY_${string}_HAS_NO_HANDLER_IN_CACHE_KEYS_CONFIG` | `CACHE_ADAPTER_NOT_CONFIGURED` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `MODEL_HAS_NO_PRIMARY_KEY_VALUE` | `RELATION_NOT_MANY_TO_MANY` | "MATERIALIZED_CTE_NOT_SUPPORTED" | "DUPLICATE_MODEL_KEYS_WHILE_INSTANTIATING_MODELS" | "INVALID_ONE_PARAMETER_WHERE_CONDITION" | "INVALID_PAGINATION_PARAMETERS" | "MISSING_ALIAS_FOR_SUBQUERY" | "MODEL_HAS_NO_PRIMARY_KEY" | "PRIMARY_KEY_NOT_FOUND" | "SQLITE_ONLY_SUPPORTS_SERIALIZABLE_ISOLATION_LEVEL" | "MUST_CALL_BUILD_CTE_AT_LEAST_ONCE" | "REGEXP_NOT_SUPPORTED_IN_SQLITE" | "MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL" | "INSERT_FAILED" | "MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED" | "FILE_NOT_A_SQL_OR_TXT_FILE" | "CONNECTION_NOT_ESTABLISHED" | "TRANSACTION_NOT_ACTIVE" | "DEVELOPMENT_ERROR" | "MIGRATION_MODULE_NOT_FOUND" | "DRIVER_NOT_FOUND" | "FILE_NOT_FOUND_OR_NOT_ACCESSIBLE" | "ENV_NOT_SET" | "REQUIRED_VALUE_NOT_SET" | "SET_FAILED" | "GET_FAILED" | "REFERENCES_OPTION_REQUIRED" | "DELETE_FAILED" | "INVALID_DEFAULT_VALUE" | "DISCONNECT_FAILED" | "FLUSH_FAILED" | "LEFT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "RIGHT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "MODEL_HAS_NO_PRIMARY_KEY" | "GLOBAL_TRANSACTION_ALREADY_STARTED" | "GLOBAL_TRANSACTION_NOT_STARTED" | "MYSQL_REQUIRES_TABLE_NAME_FOR_INDEX_DROP" | "INVALID_DATE_OBJECT" | "INVALID_DATE_STRING" | "FAILED_TO_PARSE_DATE" | "MIGRATION_MODULE_REQUIRES_TS_NODE" | "FAILED_TO_ENCRYPT_SYMMETRICALLY" | "FAILED_TO_DECRYPT_SYMMETRICALLY" | "FAILED_TO_ENCRYPT_ASYMMETRICALLY" | "FAILED_TO_DECRYPT_ASYMMETRICALLY" | "UNSUPPORTED_RELATION_TYPE" | "LPUSH_FAILED" | "RPUSH_FAILED" | "LPOP_FAILED" | "RPOP_FAILED" | "LRANGE_FAILED" | "LLEN_FAILED" | "HSET_FAILED" | "HMSET_FAILED" | "HGET_FAILED" | "HGETALL_FAILED" | "HMGET_FAILED" | "HDEL_FAILED" | "HEXISTS_FAILED" | "HKEYS_FAILED" | "HLEN_FAILED" | "SADD_FAILED" | "SMEMBERS_FAILED" | "SREM_FAILED" | "SISMEMBER_FAILED" | "SCARD_FAILED" | "SINTER_FAILED" | "SUNION_FAILED" | "SDIFF_FAILED" | "ZADD_FAILED" | "ZRANGE_FAILED" | "ZREVRANGE_FAILED" | "ZREM_FAILED" | "ZSCORE_FAILED" | "ZCARD_FAILED" | "SUBSCRIBE_FAILED" | "UNSUBSCRIBE_FAILED" | "PUBLISH_FAILED" | "PSUBSCRIBE_FAILED" | "PUNSUBSCRIBE_FAILED" | "EXISTS_FAILED" | "EXPIRE_FAILED" | "EXPIREAT_FAILED" | "PEXPIRE_FAILED" | "TTL_FAILED" | "PTTL_FAILED" | "PERSIST_FAILED" | "KEYS_FAILED" | "RENAME_FAILED" | "TYPE_FAILED" | "SCAN_FAILED" | "ADMINJS_NOT_ENABLED" | "ADMINJS_INITIALIZATION_FAILED" | "ADMINJS_NO_MODELS_PROVIDED";
|
|
5774
5845
|
|
|
5775
5846
|
declare class HysteriaError extends Error {
|
|
5776
5847
|
code: HysteriaErrorCode;
|
|
@@ -5795,4 +5866,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
5795
5866
|
$id?: string;
|
|
5796
5867
|
}>;
|
|
5797
5868
|
|
|
5798
|
-
export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnnotatedModel, type AsymmetricEncryptionOptions,
|
|
5869
|
+
export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnnotatedModel, type AsymmetricEncryptionOptions, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, 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 CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, 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, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, 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, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, unique, view, withPerformance };
|