hysteria-orm 10.2.3 → 10.3.1
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 +85 -33
- 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 +85 -33
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +71 -24
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +768 -722
- package/lib/index.d.ts +768 -722
- package/lib/index.js +71 -24
- package/lib/index.js.map +1 -1
- package/package.json +8 -2
package/lib/index.d.cts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import { PoolAttributes, Pool, Connection, Result } from 'oracledb';
|
|
1
2
|
import * as mssql from 'mssql';
|
|
2
|
-
import { config, Transaction as Transaction$1 } from 'mssql';
|
|
3
|
+
import { config, Transaction as Transaction$1, IResult } from 'mssql';
|
|
3
4
|
import * as mongodb from 'mongodb';
|
|
4
5
|
import { Collection as Collection$1 } from 'mongodb';
|
|
5
6
|
import * as sqlite3 from 'sqlite3';
|
|
7
|
+
import { RunResult } from 'sqlite3';
|
|
6
8
|
import * as pg from 'pg';
|
|
7
|
-
import { ClientConfig, PoolClient } from 'pg';
|
|
9
|
+
import { ClientConfig, PoolClient, QueryResult as QueryResult$1 } from 'pg';
|
|
8
10
|
import * as mysql2_promise from 'mysql2/promise';
|
|
9
|
-
import { PoolOptions, PoolConnection } from 'mysql2/promise';
|
|
11
|
+
import { PoolOptions, PoolConnection, QueryResult } from 'mysql2/promise';
|
|
10
12
|
import { RedisOptions, Redis } from 'ioredis';
|
|
11
13
|
import { PassThrough } from 'node:stream';
|
|
12
14
|
import { FormatOptionsWithLanguage } from 'sql-formatter';
|
|
15
|
+
import express from 'express';
|
|
13
16
|
|
|
14
17
|
type CaseConvention = "camel" | "snake" | "preserve" | RegExp | ((column: string) => string);
|
|
15
18
|
|
|
@@ -34,7 +37,7 @@ declare abstract class Entity {
|
|
|
34
37
|
/**
|
|
35
38
|
* @description Creates a datasource for the selected database type with the provided credentials
|
|
36
39
|
*/
|
|
37
|
-
type DataSourceType = "cockroachdb" | "mysql" | "postgres" | "mariadb" | "sqlite" | "mssql" | "mongo";
|
|
40
|
+
type DataSourceType = "oracledb" | "cockroachdb" | "mysql" | "postgres" | "mariadb" | "sqlite" | "mssql" | "mongo";
|
|
38
41
|
interface MssqlDataSourceInput extends CommonDataSourceInput {
|
|
39
42
|
readonly type: "mssql";
|
|
40
43
|
readonly host?: string;
|
|
@@ -43,11 +46,19 @@ interface MssqlDataSourceInput extends CommonDataSourceInput {
|
|
|
43
46
|
readonly password?: string;
|
|
44
47
|
readonly database?: string;
|
|
45
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
|
+
}
|
|
46
57
|
interface CommonDataSourceInput {
|
|
47
58
|
readonly type?: DataSourceType;
|
|
48
59
|
readonly logs?: boolean;
|
|
49
60
|
}
|
|
50
|
-
interface MongoDataSourceInput extends CommonDataSourceInput {
|
|
61
|
+
interface MongoDataSourceInput$1 extends CommonDataSourceInput {
|
|
51
62
|
readonly type: "mongo";
|
|
52
63
|
readonly mongoOptions?: MongoConnectionOptions;
|
|
53
64
|
readonly url?: string;
|
|
@@ -68,6 +79,22 @@ interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInp
|
|
|
68
79
|
readonly database: string;
|
|
69
80
|
readonly port?: number;
|
|
70
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
|
+
}
|
|
71
98
|
interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
|
|
72
99
|
readonly type?: "mysql" | "mariadb";
|
|
73
100
|
readonly host?: string;
|
|
@@ -95,20 +122,21 @@ interface NotNullableSqliteDataSourceInput extends SqliteDataSourceInput {
|
|
|
95
122
|
/**
|
|
96
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
|
|
97
124
|
*/
|
|
98
|
-
type DataSourceInput = MssqlDataSourceInput | MysqlSqlDataSourceInput | SqliteDataSourceInput | PostgresSqlDataSourceInput | MongoDataSourceInput;
|
|
125
|
+
type DataSourceInput = OracleDBDataSourceInput | MssqlDataSourceInput | MysqlSqlDataSourceInput | SqliteDataSourceInput | PostgresSqlDataSourceInput | MongoDataSourceInput$1;
|
|
99
126
|
|
|
100
127
|
type Mysql2Import = typeof mysql2_promise;
|
|
101
128
|
type PgImport = typeof pg;
|
|
102
129
|
type Sqlite3Import = typeof sqlite3;
|
|
103
130
|
type MongoClientImport = typeof mongodb;
|
|
104
131
|
type MssqlImport = typeof mssql;
|
|
132
|
+
type OracleDBCreateConnectionOptions = PoolAttributes;
|
|
105
133
|
type MysqlCreateConnectionOptions = PoolOptions;
|
|
106
134
|
type PgClientOptions = ClientConfig;
|
|
107
135
|
type MssqlConnectionOptions = Omit<config, "options"> & {
|
|
108
136
|
options?: Omit<NonNullable<config["options"]>, "abortTransactionOnError" | "enableImplicitTransactions">;
|
|
109
137
|
};
|
|
110
138
|
type MongoConnectionOptions = NonNullable<ConstructorParameters<MongoClientImport["MongoClient"]>[1]>;
|
|
111
|
-
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 : 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;
|
|
112
140
|
|
|
113
141
|
type MongoCollectionKey<T> = T extends Collection ? T : never;
|
|
114
142
|
type BaseModelMethodOptions$1 = {
|
|
@@ -449,8 +477,9 @@ declare abstract class DataSource {
|
|
|
449
477
|
protected handlePostgresSource(input?: PostgresSqlDataSourceInput): void;
|
|
450
478
|
protected handleMysqlSource(input?: MysqlSqlDataSourceInput): void;
|
|
451
479
|
protected handleSqliteSource(input?: SqliteDataSourceInput): void;
|
|
452
|
-
protected handleMongoSource(input?: MongoDataSourceInput): void;
|
|
480
|
+
protected handleMongoSource(input?: MongoDataSourceInput$1): void;
|
|
453
481
|
protected handleMssqlSource(input?: MssqlDataSourceInput): void;
|
|
482
|
+
protected handleOracleDBSource(input?: MssqlDataSourceInput): void;
|
|
454
483
|
}
|
|
455
484
|
|
|
456
485
|
type MongoFindOneOptions<T extends Collection> = {
|
|
@@ -522,22 +551,34 @@ declare class CollectionManager<T extends Collection> {
|
|
|
522
551
|
}
|
|
523
552
|
|
|
524
553
|
type MongoClientInstance = InstanceType<MongoClientImport["MongoClient"]>;
|
|
554
|
+
interface MongoDataSourceInput {
|
|
555
|
+
url?: string;
|
|
556
|
+
options?: MongoConnectionOptions;
|
|
557
|
+
logs?: boolean;
|
|
558
|
+
}
|
|
525
559
|
declare class MongoDataSource extends DataSource {
|
|
526
560
|
url: string;
|
|
527
561
|
isConnected: boolean;
|
|
528
562
|
private mongoClient;
|
|
563
|
+
private mongoOptions?;
|
|
529
564
|
private static instance;
|
|
530
|
-
|
|
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;
|
|
531
574
|
/**
|
|
532
575
|
* @description Returns the current connection to the mongo client to execute direct statements using the mongo client from `mongodb` package
|
|
533
576
|
*/
|
|
534
577
|
getCurrentConnection(): MongoClientInstance;
|
|
535
578
|
/**
|
|
536
|
-
* @description
|
|
579
|
+
* @description Creates a secondary connection to MongoDB (does not become the primary instance)
|
|
537
580
|
*/
|
|
538
|
-
static
|
|
539
|
-
logs?: boolean;
|
|
540
|
-
}, cb?: (mongoDataSource: MongoDataSource) => Promise<void> | void): Promise<MongoDataSource>;
|
|
581
|
+
static connectToSecondarySource(input: MongoDataSourceInput): Promise<MongoDataSource>;
|
|
541
582
|
static getInstance(): MongoDataSource;
|
|
542
583
|
/**
|
|
543
584
|
* @description Starts a new session and transaction using the current connection
|
|
@@ -562,12 +603,9 @@ declare class MongoDataSource extends DataSource {
|
|
|
562
603
|
*/
|
|
563
604
|
static closeConnection(): Promise<void>;
|
|
564
605
|
/**
|
|
565
|
-
* @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
|
|
566
607
|
*/
|
|
567
|
-
static useConnection(this: typeof MongoDataSource,
|
|
568
|
-
url: string;
|
|
569
|
-
options?: MongoConnectionOptions;
|
|
570
|
-
}, cb: (mongoDataSource: MongoDataSource) => Promise<void>): Promise<void>;
|
|
608
|
+
static useConnection(this: typeof MongoDataSource, input: MongoDataSourceInput, cb: (mongoDataSource: MongoDataSource) => Promise<void>): Promise<void>;
|
|
571
609
|
static query(collection: string): MongoQueryBuilder<Collection>;
|
|
572
610
|
query(collection: string): MongoQueryBuilder<Collection>;
|
|
573
611
|
getModelManager<T extends Collection>(model: typeof Collection, mongoDataSource: MongoDataSource, session?: InstanceType<MongoClientImport["ClientSession"]>): CollectionManager<T>;
|
|
@@ -1031,7 +1069,7 @@ type AdminJsInstance = {
|
|
|
1031
1069
|
/**
|
|
1032
1070
|
* @description Express router for AdminJS (if using express adapter)
|
|
1033
1071
|
*/
|
|
1034
|
-
router?:
|
|
1072
|
+
router?: ReturnType<typeof express.Router>;
|
|
1035
1073
|
};
|
|
1036
1074
|
|
|
1037
1075
|
interface CacheAdapter {
|
|
@@ -1041,23 +1079,158 @@ interface CacheAdapter {
|
|
|
1041
1079
|
disconnect?(): Promise<void>;
|
|
1042
1080
|
}
|
|
1043
1081
|
|
|
1044
|
-
type CacheKeys = Record<string, (...args: any[]) => Promise<any
|
|
1082
|
+
type CacheKeys = Record<string, (...args: any[]) => Promise<any> | any>;
|
|
1045
1083
|
type UseCacheReturnType<C extends CacheKeys, K extends keyof C> = K extends never ? never : Awaited<ReturnType<C[K]>>;
|
|
1046
1084
|
|
|
1047
|
-
type
|
|
1048
|
-
|
|
1049
|
-
properties: Record<string, OpenApiModelPropertyType>;
|
|
1050
|
-
required?: string[];
|
|
1085
|
+
type Sqlite3ConnectionOptions = {
|
|
1086
|
+
mode: number;
|
|
1051
1087
|
};
|
|
1052
|
-
type
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
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
|
+
/**
|
|
1168
|
+
* @description The replication configuration for the sql data source, it's used to configure the replication for the sql data source
|
|
1169
|
+
*/
|
|
1170
|
+
replication?: {
|
|
1171
|
+
/**
|
|
1172
|
+
* @description The slaves data sources to use for the sql data source, slaves are automatically used for read operations unless specified otherwise
|
|
1173
|
+
*/
|
|
1174
|
+
slaves?: Omit<UseConnectionInput<D, T, C>, "slaves" | "models" | "cacheStrategy" | "adminJs" | "logs" | "queryFormatOptions" | "migrationsPath">[];
|
|
1175
|
+
/**
|
|
1176
|
+
* @description The algorithm to use for selecting the slave for read operations
|
|
1177
|
+
* @default "roundRobin" - Distributes requests evenly across all slaves in sequence
|
|
1178
|
+
* @option "random" - Randomly selects a slave for each request
|
|
1179
|
+
*/
|
|
1180
|
+
slaveAlgorithm?: SlaveAlgorithm;
|
|
1181
|
+
};
|
|
1182
|
+
} & Omit<MapSqlDataSourceTypeToInput<D>, "type">;
|
|
1183
|
+
/**
|
|
1184
|
+
* @description Maps a SqlDataSourceType to its corresponding non-nullable input interface
|
|
1185
|
+
*/
|
|
1186
|
+
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;
|
|
1187
|
+
type UseConnectionInput<D extends SqlDataSourceType = SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
|
|
1188
|
+
/**
|
|
1189
|
+
* @description The type of the database to connect to
|
|
1190
|
+
*/
|
|
1191
|
+
readonly type: D;
|
|
1192
|
+
readonly logs?: boolean;
|
|
1193
|
+
readonly models?: T;
|
|
1194
|
+
readonly driverOptions?: SqlDriverSpecificOptions<D>;
|
|
1195
|
+
connectionPolicies?: ConnectionPolicies;
|
|
1196
|
+
queryFormatOptions?: FormatOptionsWithLanguage;
|
|
1197
|
+
cacheStrategy?: {
|
|
1198
|
+
cacheAdapter: CacheAdapter;
|
|
1199
|
+
keys: C;
|
|
1200
|
+
};
|
|
1201
|
+
/**
|
|
1202
|
+
* @description AdminJS configuration for the admin panel
|
|
1203
|
+
* @description AdminJS is completely optional - dependencies are loaded at runtime via dynamic import()
|
|
1204
|
+
*/
|
|
1205
|
+
adminJs?: AdminJsOptions;
|
|
1206
|
+
} & Omit<MapSqlDataSourceTypeToNotNullableInput<D>, "type">;
|
|
1207
|
+
type SqlDataSourceType = Exclude<DataSourceType, "mongo">;
|
|
1208
|
+
type SqlCloneOptions = {
|
|
1209
|
+
/**
|
|
1210
|
+
* @description Whether to recreate the pool of connections for the given driver, by default it's false
|
|
1211
|
+
* @warning If false, the pool of connections will be reused from the caller instance
|
|
1212
|
+
*/
|
|
1213
|
+
shouldRecreatePool?: boolean;
|
|
1214
|
+
};
|
|
1215
|
+
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;
|
|
1216
|
+
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;
|
|
1217
|
+
/** Only accepts formats `string` e `string as string` */
|
|
1218
|
+
type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
|
|
1219
|
+
type TableFormat<S extends string> = NoSpace<S> | (S extends `${infer L} as ${infer R}` ? `${NoSpace<L>} as ${NoSpace<R>}` : never);
|
|
1220
|
+
type ReplicationType = "master" | "slave";
|
|
1221
|
+
/**
|
|
1222
|
+
* @description Algorithm for selecting a slave database for read operations
|
|
1223
|
+
* @option "roundRobin" - Distributes requests evenly across all slaves in sequence
|
|
1224
|
+
* @option "random" - Randomly selects a slave for each request
|
|
1225
|
+
*/
|
|
1226
|
+
type SlaveAlgorithm = "roundRobin" | "random";
|
|
1227
|
+
type RawQueryOptions = {
|
|
1228
|
+
replicationMode?: ReplicationType;
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
type AstParserType = {
|
|
1232
|
+
sql: string;
|
|
1233
|
+
bindings: any[];
|
|
1061
1234
|
};
|
|
1062
1235
|
|
|
1063
1236
|
declare abstract class QueryNode {
|
|
@@ -1092,6 +1265,48 @@ declare abstract class QueryNode {
|
|
|
1092
1265
|
constructor(keyword: string, isRawValue?: boolean);
|
|
1093
1266
|
}
|
|
1094
1267
|
|
|
1268
|
+
declare class AstParser {
|
|
1269
|
+
private readonly dbType;
|
|
1270
|
+
private readonly model;
|
|
1271
|
+
constructor(model: typeof Model, dbType: SqlDataSourceType);
|
|
1272
|
+
parse(nodes: (QueryNode | null)[], startBindingIndex?: number, isNestedCondition?: boolean): AstParserType;
|
|
1273
|
+
/**
|
|
1274
|
+
* Map the database type to a common type if shares the same driver (e.g. mysql and mariadb)
|
|
1275
|
+
*/
|
|
1276
|
+
private mapCommonDbType;
|
|
1277
|
+
/**
|
|
1278
|
+
* @description Generates MSSQL table hints from lock node
|
|
1279
|
+
* MSSQL uses WITH (UPDLOCK), WITH (HOLDLOCK), etc. as table hints
|
|
1280
|
+
* READPAST is the MSSQL equivalent of SKIP LOCKED
|
|
1281
|
+
*/
|
|
1282
|
+
private getMssqlTableHints;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
declare class ColumnTypeNode extends QueryNode {
|
|
1286
|
+
column: string | (() => string);
|
|
1287
|
+
dataType: string;
|
|
1288
|
+
length?: number;
|
|
1289
|
+
precision?: number;
|
|
1290
|
+
scale?: number;
|
|
1291
|
+
enumValues?: readonly string[];
|
|
1292
|
+
autoIncrement?: boolean;
|
|
1293
|
+
withTimezone?: boolean;
|
|
1294
|
+
chainsWith: string;
|
|
1295
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1296
|
+
folder: string;
|
|
1297
|
+
file: string;
|
|
1298
|
+
isRawValue: boolean;
|
|
1299
|
+
constructor(column: string, dataType: string, opts?: {
|
|
1300
|
+
length?: number;
|
|
1301
|
+
precision?: number;
|
|
1302
|
+
scale?: number;
|
|
1303
|
+
enumValues?: readonly string[];
|
|
1304
|
+
withTimezone?: boolean;
|
|
1305
|
+
autoIncrement?: boolean;
|
|
1306
|
+
isRawValue?: boolean;
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1095
1310
|
declare class RawNode extends QueryNode {
|
|
1096
1311
|
rawValue: string;
|
|
1097
1312
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
@@ -1134,31 +1349,6 @@ declare class ConstraintNode extends QueryNode {
|
|
|
1134
1349
|
}, isRawValue?: boolean);
|
|
1135
1350
|
}
|
|
1136
1351
|
|
|
1137
|
-
declare class ColumnTypeNode extends QueryNode {
|
|
1138
|
-
column: string | (() => string);
|
|
1139
|
-
dataType: string;
|
|
1140
|
-
length?: number;
|
|
1141
|
-
precision?: number;
|
|
1142
|
-
scale?: number;
|
|
1143
|
-
enumValues?: readonly string[];
|
|
1144
|
-
autoIncrement?: boolean;
|
|
1145
|
-
withTimezone?: boolean;
|
|
1146
|
-
chainsWith: string;
|
|
1147
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1148
|
-
folder: string;
|
|
1149
|
-
file: string;
|
|
1150
|
-
isRawValue: boolean;
|
|
1151
|
-
constructor(column: string, dataType: string, opts?: {
|
|
1152
|
-
length?: number;
|
|
1153
|
-
precision?: number;
|
|
1154
|
-
scale?: number;
|
|
1155
|
-
enumValues?: readonly string[];
|
|
1156
|
-
withTimezone?: boolean;
|
|
1157
|
-
autoIncrement?: boolean;
|
|
1158
|
-
isRawValue?: boolean;
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
1352
|
type LockType = "for_update" | "for_share" | "for_no_key_update" | "for_key_share";
|
|
1163
1353
|
declare class LockNode extends QueryNode {
|
|
1164
1354
|
lockType: LockType;
|
|
@@ -1192,45 +1382,145 @@ declare class WithNode extends QueryNode {
|
|
|
1192
1382
|
constructor(clause: string, alias: string, body: QueryNode | QueryNode[]);
|
|
1193
1383
|
}
|
|
1194
1384
|
|
|
1195
|
-
declare
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1385
|
+
declare class FromNode extends QueryNode {
|
|
1386
|
+
table: string | QueryNode | QueryNode[];
|
|
1387
|
+
chainsWith: string;
|
|
1388
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1389
|
+
folder: string;
|
|
1390
|
+
file: string;
|
|
1391
|
+
alias?: string;
|
|
1392
|
+
constructor(table: string | QueryNode | QueryNode[], alias?: string);
|
|
1199
1393
|
}
|
|
1200
1394
|
|
|
1201
|
-
declare class
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
constructor(
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1395
|
+
declare class DeleteNode extends QueryNode {
|
|
1396
|
+
fromNode: FromNode;
|
|
1397
|
+
chainsWith: string;
|
|
1398
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1399
|
+
folder: string;
|
|
1400
|
+
file: string;
|
|
1401
|
+
constructor(fromNode: FromNode, isRawValue?: boolean);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
declare class InsertNode extends QueryNode {
|
|
1405
|
+
fromNode: FromNode;
|
|
1406
|
+
records: Record<string, any>[];
|
|
1407
|
+
returning?: string[];
|
|
1408
|
+
disableReturning: boolean;
|
|
1409
|
+
chainsWith: string;
|
|
1410
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1411
|
+
folder: string;
|
|
1412
|
+
file: string;
|
|
1413
|
+
constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
declare class OnDuplicateNode extends QueryNode {
|
|
1417
|
+
table: string;
|
|
1418
|
+
conflictColumns: string[];
|
|
1419
|
+
columnsToUpdate: string[];
|
|
1420
|
+
returning?: string[];
|
|
1421
|
+
mode: "update" | "ignore";
|
|
1422
|
+
chainsWith: string;
|
|
1423
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1424
|
+
folder: string;
|
|
1425
|
+
file: string;
|
|
1426
|
+
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
declare class TruncateNode extends QueryNode {
|
|
1430
|
+
fromNode: FromNode | string;
|
|
1431
|
+
chainsWith: string;
|
|
1432
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1433
|
+
folder: string;
|
|
1434
|
+
file: string;
|
|
1435
|
+
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
declare class UpdateNode extends QueryNode {
|
|
1439
|
+
fromNode: FromNode;
|
|
1440
|
+
columns: string[];
|
|
1441
|
+
values: (any | RawNode)[];
|
|
1442
|
+
chainsWith: string;
|
|
1443
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1444
|
+
folder: string;
|
|
1445
|
+
file: string;
|
|
1446
|
+
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
declare class InterpreterUtils {
|
|
1450
|
+
private readonly model;
|
|
1451
|
+
private readonly modelColumnsMap;
|
|
1452
|
+
constructor(model: typeof Model);
|
|
1453
|
+
formatStringColumn(dbType: SqlDataSourceType, column: string): string;
|
|
1454
|
+
/**
|
|
1455
|
+
* @description Formats the table name for the database type, idempotent for quoting
|
|
1456
|
+
*/
|
|
1457
|
+
formatStringTable(dbType: SqlDataSourceType, table: string): string;
|
|
1458
|
+
prepareColumns(columns: string[], values: any[], mode?: "insert" | "update"): Promise<{
|
|
1459
|
+
columns: string[];
|
|
1460
|
+
values: any[];
|
|
1461
|
+
}>;
|
|
1462
|
+
/**
|
|
1463
|
+
* @description Formats the from node for write operations removing the "from" keyword
|
|
1464
|
+
*/
|
|
1465
|
+
getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
type OpenApiModelType = {
|
|
1469
|
+
type: "object";
|
|
1470
|
+
properties: Record<string, OpenApiModelPropertyType>;
|
|
1471
|
+
required?: string[];
|
|
1472
|
+
};
|
|
1473
|
+
type OpenApiModelPropertyType = {
|
|
1474
|
+
type: string;
|
|
1475
|
+
items?: OpenApiModelType;
|
|
1476
|
+
enum?: string[];
|
|
1477
|
+
format?: string;
|
|
1478
|
+
description?: string;
|
|
1479
|
+
example?: any;
|
|
1480
|
+
default?: any;
|
|
1481
|
+
nullable?: boolean;
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1484
|
+
declare abstract class BaseBuilder {
|
|
1485
|
+
protected nodes: QueryNode[];
|
|
1486
|
+
constructor(nodes: QueryNode[]);
|
|
1487
|
+
getNodes(): QueryNode[];
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
declare class ConstraintBuilder extends BaseBuilder {
|
|
1491
|
+
private readonly columnNode;
|
|
1492
|
+
private readonly tableName?;
|
|
1493
|
+
private namedConstraints;
|
|
1494
|
+
private context;
|
|
1495
|
+
private sqlType;
|
|
1496
|
+
constructor(sqlType: SqlDataSourceType, nodes: QueryNode[], columnNode: ColumnTypeNode, tableName?: string, namedConstraints?: QueryNode[], context?: CreateTableContext);
|
|
1497
|
+
/**
|
|
1498
|
+
* @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}
|
|
1499
|
+
* @param options is the options for the primary key constraint
|
|
1500
|
+
*/
|
|
1501
|
+
primaryKey(options?: PrimaryKeyOptions): this;
|
|
1502
|
+
/**
|
|
1503
|
+
* @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}
|
|
1504
|
+
* @param references is the table and column name to reference, e.g. "users.id"
|
|
1505
|
+
* @param options is the options for the foreign key constraint
|
|
1506
|
+
*/
|
|
1507
|
+
foreignKey(references: `${string}.${string}`, options?: ForeignKeyOptions): this;
|
|
1508
|
+
/**
|
|
1509
|
+
* @description Sets the column to auto increment
|
|
1510
|
+
*/
|
|
1511
|
+
increment(): this;
|
|
1512
|
+
/**
|
|
1513
|
+
* @description Sets the column to not nullable
|
|
1514
|
+
*/
|
|
1515
|
+
notNullable(): this;
|
|
1516
|
+
/**
|
|
1517
|
+
* @description Sets the column to nullable, by default it already is nullable, this method is only used for alter table
|
|
1518
|
+
*/
|
|
1519
|
+
nullable(): this;
|
|
1231
1520
|
/**
|
|
1232
1521
|
* @description Sets the default value for the column
|
|
1233
1522
|
* @param value is the default value for the column
|
|
1523
|
+
* @oracle not supported must be defined manually in a separate statement
|
|
1234
1524
|
*/
|
|
1235
1525
|
default(value: string | number | boolean | null | RawNode): this;
|
|
1236
1526
|
/**
|
|
@@ -1704,35 +1994,6 @@ declare class Schema {
|
|
|
1704
1994
|
private generateAstInstance;
|
|
1705
1995
|
}
|
|
1706
1996
|
|
|
1707
|
-
declare class FromNode extends QueryNode {
|
|
1708
|
-
table: string | QueryNode | QueryNode[];
|
|
1709
|
-
chainsWith: string;
|
|
1710
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1711
|
-
folder: string;
|
|
1712
|
-
file: string;
|
|
1713
|
-
alias?: string;
|
|
1714
|
-
constructor(table: string | QueryNode | QueryNode[], alias?: string);
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
declare class InterpreterUtils {
|
|
1718
|
-
private readonly model;
|
|
1719
|
-
private readonly modelColumnsMap;
|
|
1720
|
-
constructor(model: typeof Model);
|
|
1721
|
-
formatStringColumn(dbType: SqlDataSourceType, column: string): string;
|
|
1722
|
-
/**
|
|
1723
|
-
* @description Formats the table name for the database type, idempotent for quoting
|
|
1724
|
-
*/
|
|
1725
|
-
formatStringTable(dbType: SqlDataSourceType, table: string): string;
|
|
1726
|
-
prepareColumns(columns: string[], values: any[], mode?: "insert" | "update"): Promise<{
|
|
1727
|
-
columns: string[];
|
|
1728
|
-
values: any[];
|
|
1729
|
-
}>;
|
|
1730
|
-
/**
|
|
1731
|
-
* @description Formats the from node for write operations removing the "from" keyword
|
|
1732
|
-
*/
|
|
1733
|
-
getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
1997
|
type DeleteOptions = {
|
|
1737
1998
|
ignoreBeforeDeleteHook?: boolean;
|
|
1738
1999
|
};
|
|
@@ -2885,223 +3146,82 @@ type UpdateOptions = {
|
|
|
2885
3146
|
ignoreBeforeUpdateHook?: boolean;
|
|
2886
3147
|
};
|
|
2887
3148
|
|
|
2888
|
-
type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
2889
|
-
type StartTransactionOptions = {
|
|
2890
|
-
isolationLevel?: TransactionIsolationLevel;
|
|
2891
|
-
};
|
|
2892
3149
|
/**
|
|
2893
|
-
* @description
|
|
3150
|
+
* @description Due to query limitations some query builder methods may not be available in a RelationQueryBuilder
|
|
2894
3151
|
*/
|
|
2895
|
-
type
|
|
3152
|
+
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">;
|
|
3153
|
+
|
|
3154
|
+
declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends QueryBuilder<T> {
|
|
3155
|
+
relation: Relation;
|
|
3156
|
+
protected sqlModelManagerUtils: SqlModelManagerUtils<T>;
|
|
3157
|
+
protected relationQueryBuilders: ModelQueryBuilder<any>[];
|
|
3158
|
+
protected modelSelectedColumns: string[];
|
|
3159
|
+
private modelColumnsMap;
|
|
3160
|
+
private modelColumnsDatabaseNames;
|
|
3161
|
+
protected limitValue?: number;
|
|
3162
|
+
protected offsetValue?: number;
|
|
3163
|
+
performance: {
|
|
3164
|
+
many: (options?: ManyOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3165
|
+
data: AnnotatedModel<T, A, R>[];
|
|
3166
|
+
time: number;
|
|
3167
|
+
}>;
|
|
3168
|
+
one: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3169
|
+
data: AnnotatedModel<T, A, R> | null;
|
|
3170
|
+
time: number;
|
|
3171
|
+
}>;
|
|
3172
|
+
oneOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3173
|
+
data: AnnotatedModel<T, A, R>;
|
|
3174
|
+
time: number;
|
|
3175
|
+
}>;
|
|
3176
|
+
first: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3177
|
+
data: AnnotatedModel<T, A, R> | null;
|
|
3178
|
+
time: number;
|
|
3179
|
+
}>;
|
|
3180
|
+
firstOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3181
|
+
data: AnnotatedModel<T, A, R>;
|
|
3182
|
+
time: number;
|
|
3183
|
+
}>;
|
|
3184
|
+
paginate: (page: number, perPage: number, options?: {
|
|
3185
|
+
ignoreHooks?: boolean;
|
|
3186
|
+
}, returnType?: "millis" | "seconds") => Promise<{
|
|
3187
|
+
data: PaginatedData<T, A, R>;
|
|
3188
|
+
time: number;
|
|
3189
|
+
}>;
|
|
3190
|
+
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
3191
|
+
data: boolean;
|
|
3192
|
+
time: number;
|
|
3193
|
+
}>;
|
|
3194
|
+
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
3195
|
+
data: [CursorPaginatedData<T, A, R>, Cursor<T, ModelKey<T>>];
|
|
3196
|
+
time: number;
|
|
3197
|
+
}>;
|
|
3198
|
+
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
3199
|
+
data: void;
|
|
3200
|
+
time: number;
|
|
3201
|
+
}>;
|
|
3202
|
+
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
3203
|
+
data: number;
|
|
3204
|
+
time: number;
|
|
3205
|
+
}>;
|
|
3206
|
+
update: (data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3207
|
+
data: number;
|
|
3208
|
+
time: number;
|
|
3209
|
+
}>;
|
|
3210
|
+
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
3211
|
+
data: number;
|
|
3212
|
+
time: number;
|
|
3213
|
+
}>;
|
|
3214
|
+
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
3215
|
+
data: PluckReturnType<T, ModelKey<T>>;
|
|
3216
|
+
time: number;
|
|
3217
|
+
}>;
|
|
3218
|
+
};
|
|
3219
|
+
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
2896
3220
|
/**
|
|
2897
|
-
* @description
|
|
3221
|
+
* @description Returns true if the query builder is a relation query builder, this changes the behavior of the query builder like limit, offset, etc.
|
|
3222
|
+
* @internal
|
|
2898
3223
|
*/
|
|
2899
|
-
|
|
2900
|
-
};
|
|
2901
|
-
type TransactionOptionsOrCallback = StartTransactionOptions | ((trx: Transaction) => Promise<void>);
|
|
2902
|
-
type StartTransactionReturnType<T extends TransactionOptionsOrCallback> = T extends StartTransactionOptions ? Transaction : T extends (trx: Transaction) => Promise<void> ? void : Transaction;
|
|
2903
|
-
|
|
2904
|
-
/**
|
|
2905
|
-
* @description Transaction class, not meant to be used directly, use sql.startTransaction() instead
|
|
2906
|
-
*/
|
|
2907
|
-
declare class Transaction {
|
|
2908
|
-
/**
|
|
2909
|
-
* @description The sql data source instance that the transaction is running on here you can both query or execute raw queries
|
|
2910
|
-
* @example
|
|
2911
|
-
* ```ts
|
|
2912
|
-
* import { sql } from "hysteria-orm";
|
|
2913
|
-
* import { User } from "./models/user";
|
|
2914
|
-
*
|
|
2915
|
-
* // Raw queries
|
|
2916
|
-
* const trx = await sql.startTransaction();
|
|
2917
|
-
* await trx.rawQuery("SELECT * FROM users");
|
|
2918
|
-
*
|
|
2919
|
-
* // Model manager
|
|
2920
|
-
* const modelManager = trx.sql.getModelManager(User);
|
|
2921
|
-
* await modelManager.insert({ name: "John Doe" });
|
|
2922
|
-
*
|
|
2923
|
-
* // Query builder
|
|
2924
|
-
* await trx.query(User.table).insert({ name: "John Doe" });
|
|
2925
|
-
*
|
|
2926
|
-
* await trx.commit();
|
|
2927
|
-
* ```
|
|
2928
|
-
*/
|
|
2929
|
-
sql: SqlDataSourceWithoutTransaction;
|
|
2930
|
-
/**
|
|
2931
|
-
* @description Whether the transaction is active
|
|
2932
|
-
*/
|
|
2933
|
-
isActive: boolean;
|
|
2934
|
-
/**
|
|
2935
|
-
* @description The transaction unique identifier
|
|
2936
|
-
*/
|
|
2937
|
-
transactionId: string;
|
|
2938
|
-
private connectionReleased;
|
|
2939
|
-
private isolationLevel?;
|
|
2940
|
-
private isNested;
|
|
2941
|
-
private nestingDepth;
|
|
2942
|
-
constructor(sql: SqlDataSource, isolationLevel?: TransactionIsolationLevel, isNested?: boolean, nestingDepth?: number);
|
|
2943
|
-
/**
|
|
2944
|
-
* @description Creates a new transaction with the same isolation level and same connection using save points
|
|
2945
|
-
* @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
|
|
2946
|
-
*/
|
|
2947
|
-
nestedTransaction(): Promise<Transaction>;
|
|
2948
|
-
nestedTransaction(cb: (trx: Transaction) => Promise<void>): Promise<void>;
|
|
2949
|
-
/**
|
|
2950
|
-
* @description Starts a transaction, automatically handled from the sql data source instance in the `startTransaction` method
|
|
2951
|
-
*/
|
|
2952
|
-
startTransaction(): Promise<void>;
|
|
2953
|
-
/**
|
|
2954
|
-
* @description Commit the transaction releasing the connection
|
|
2955
|
-
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
2956
|
-
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
2957
|
-
*/
|
|
2958
|
-
commit(options?: TransactionExecutionOptions): Promise<void>;
|
|
2959
|
-
/**
|
|
2960
|
-
* @description Rollback the transaction releasing the connection
|
|
2961
|
-
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
2962
|
-
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
2963
|
-
*/
|
|
2964
|
-
rollback(options?: TransactionExecutionOptions): Promise<void>;
|
|
2965
|
-
/**
|
|
2966
|
-
* @description Release the connection, does nothing if the connection is already released
|
|
2967
|
-
*/
|
|
2968
|
-
private releaseConnection;
|
|
2969
|
-
private getIsolationLevelQuery;
|
|
2970
|
-
private getSavePointName;
|
|
2971
|
-
private getMssqlTransactionLevel;
|
|
2972
|
-
}
|
|
2973
|
-
|
|
2974
|
-
type ModelWithoutRelations<T extends Model> = Pick<T, ExcludeRelations<Omit<T, "*">>>;
|
|
2975
|
-
type NumberModelKey<T extends Model> = {
|
|
2976
|
-
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
2977
|
-
}[keyof T];
|
|
2978
|
-
type BaseModelMethodOptions = {
|
|
2979
|
-
/**
|
|
2980
|
-
* @description The connection to use for the model, by default the main connection will be used
|
|
2981
|
-
* @description The main connection is the one created by the `sql.connect` method
|
|
2982
|
-
* @example
|
|
2983
|
-
* ```ts
|
|
2984
|
-
* import { sql } from "hysteria-orm";
|
|
2985
|
-
* const customConnection = await sql.connectToSecondarySource({
|
|
2986
|
-
* type: "postgres",
|
|
2987
|
-
* host: "localhost",
|
|
2988
|
-
* username: "root",
|
|
2989
|
-
* password: "root",
|
|
2990
|
-
* database: "test",
|
|
2991
|
-
* port: 5432,
|
|
2992
|
-
* });
|
|
2993
|
-
*
|
|
2994
|
-
* const user = await User.query({ connection: customConnection }).first();
|
|
2995
|
-
* ```
|
|
2996
|
-
*/
|
|
2997
|
-
connection?: SqlDataSource | AugmentedSqlDataSource;
|
|
2998
|
-
/**
|
|
2999
|
-
* @description The transaction instance to use for the model
|
|
3000
|
-
*/
|
|
3001
|
-
trx?: Transaction;
|
|
3002
|
-
/**
|
|
3003
|
-
* @description Whether to ignore the hooks for the model
|
|
3004
|
-
*/
|
|
3005
|
-
ignoreHooks?: boolean;
|
|
3006
|
-
};
|
|
3007
|
-
/**
|
|
3008
|
-
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
3009
|
-
*/
|
|
3010
|
-
type RawModelOptions = {
|
|
3011
|
-
/**
|
|
3012
|
-
* Alias for the table
|
|
3013
|
-
*/
|
|
3014
|
-
alias?: string;
|
|
3015
|
-
/**
|
|
3016
|
-
* @description Convert the column casing before making a Database query, by default preserves what is provided
|
|
3017
|
-
*/
|
|
3018
|
-
databaseCaseConvention?: CaseConvention;
|
|
3019
|
-
/**
|
|
3020
|
-
* Column to use for soft deleted, by default is `deleted_at`
|
|
3021
|
-
*/
|
|
3022
|
-
softDeleteColumn?: string;
|
|
3023
|
-
/**
|
|
3024
|
-
* Column to use for soft deleted, by default is date in format: "YYYY-MM-DD HH:mm:ss" in UTC timezone
|
|
3025
|
-
*/
|
|
3026
|
-
softDeleteValue?: string | boolean;
|
|
3027
|
-
};
|
|
3028
|
-
|
|
3029
|
-
/**
|
|
3030
|
-
* @description Due to query limitations some query builder methods may not be available in a RelationQueryBuilder
|
|
3031
|
-
*/
|
|
3032
|
-
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">;
|
|
3033
|
-
|
|
3034
|
-
declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends QueryBuilder<T> {
|
|
3035
|
-
relation: Relation;
|
|
3036
|
-
protected sqlModelManagerUtils: SqlModelManagerUtils<T>;
|
|
3037
|
-
protected relationQueryBuilders: ModelQueryBuilder<any>[];
|
|
3038
|
-
protected modelSelectedColumns: string[];
|
|
3039
|
-
private modelColumnsMap;
|
|
3040
|
-
private modelColumnsDatabaseNames;
|
|
3041
|
-
protected limitValue?: number;
|
|
3042
|
-
protected offsetValue?: number;
|
|
3043
|
-
performance: {
|
|
3044
|
-
many: (options?: ManyOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3045
|
-
data: AnnotatedModel<T, A, R>[];
|
|
3046
|
-
time: number;
|
|
3047
|
-
}>;
|
|
3048
|
-
one: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3049
|
-
data: AnnotatedModel<T, A, R> | null;
|
|
3050
|
-
time: number;
|
|
3051
|
-
}>;
|
|
3052
|
-
oneOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3053
|
-
data: AnnotatedModel<T, A, R>;
|
|
3054
|
-
time: number;
|
|
3055
|
-
}>;
|
|
3056
|
-
first: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3057
|
-
data: AnnotatedModel<T, A, R> | null;
|
|
3058
|
-
time: number;
|
|
3059
|
-
}>;
|
|
3060
|
-
firstOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3061
|
-
data: AnnotatedModel<T, A, R>;
|
|
3062
|
-
time: number;
|
|
3063
|
-
}>;
|
|
3064
|
-
paginate: (page: number, perPage: number, options?: {
|
|
3065
|
-
ignoreHooks?: boolean;
|
|
3066
|
-
}, returnType?: "millis" | "seconds") => Promise<{
|
|
3067
|
-
data: PaginatedData<T, A, R>;
|
|
3068
|
-
time: number;
|
|
3069
|
-
}>;
|
|
3070
|
-
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
3071
|
-
data: boolean;
|
|
3072
|
-
time: number;
|
|
3073
|
-
}>;
|
|
3074
|
-
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
3075
|
-
data: [CursorPaginatedData<T, A, R>, Cursor<T, ModelKey<T>>];
|
|
3076
|
-
time: number;
|
|
3077
|
-
}>;
|
|
3078
|
-
truncate: (returnType?: "millis" | "seconds") => Promise<{
|
|
3079
|
-
data: void;
|
|
3080
|
-
time: number;
|
|
3081
|
-
}>;
|
|
3082
|
-
delete: (returnType?: "millis" | "seconds") => Promise<{
|
|
3083
|
-
data: number;
|
|
3084
|
-
time: number;
|
|
3085
|
-
}>;
|
|
3086
|
-
update: (data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
3087
|
-
data: number;
|
|
3088
|
-
time: number;
|
|
3089
|
-
}>;
|
|
3090
|
-
softDelete: (options?: Omit<SoftDeleteOptions<T>, "ignoreBeforeDeleteHook">, returnType?: "millis" | "seconds") => Promise<{
|
|
3091
|
-
data: number;
|
|
3092
|
-
time: number;
|
|
3093
|
-
}>;
|
|
3094
|
-
pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
|
|
3095
|
-
data: PluckReturnType<T, ModelKey<T>>;
|
|
3096
|
-
time: number;
|
|
3097
|
-
}>;
|
|
3098
|
-
};
|
|
3099
|
-
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3100
|
-
/**
|
|
3101
|
-
* @description Returns true if the query builder is a relation query builder, this changes the behavior of the query builder like limit, offset, etc.
|
|
3102
|
-
* @internal
|
|
3103
|
-
*/
|
|
3104
|
-
protected get isRelationQueryBuilder(): boolean;
|
|
3224
|
+
protected get isRelationQueryBuilder(): boolean;
|
|
3105
3225
|
/**
|
|
3106
3226
|
* @description Creates a new ModelQueryBuilder instance from a model. Will use the main connection to the database by default.
|
|
3107
3227
|
*/
|
|
@@ -3316,10 +3436,15 @@ declare class ModelManager<T extends Model> {
|
|
|
3316
3436
|
protected modelInstance: T;
|
|
3317
3437
|
protected astParser: AstParser;
|
|
3318
3438
|
protected interpreterUtils: InterpreterUtils;
|
|
3439
|
+
protected replicationMode: "master" | "slave" | null;
|
|
3319
3440
|
/**
|
|
3320
3441
|
* @description Constructor for ModelManager class.
|
|
3321
3442
|
*/
|
|
3322
3443
|
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3444
|
+
/**
|
|
3445
|
+
* @description Sets the replication mode for queries created by this model manager
|
|
3446
|
+
*/
|
|
3447
|
+
setReplicationMode(mode: "master" | "slave"): this;
|
|
3323
3448
|
/**
|
|
3324
3449
|
* @description Finds all records that match the input
|
|
3325
3450
|
*/
|
|
@@ -3380,6 +3505,12 @@ declare class ModelManager<T extends Model> {
|
|
|
3380
3505
|
* @description Mysql does not return the inserted model, so we need to get the inserted model from the database
|
|
3381
3506
|
*/
|
|
3382
3507
|
private handleMysqlInsert;
|
|
3508
|
+
/**
|
|
3509
|
+
* @description Oracle with identity columns doesn't support INSERT ALL properly.
|
|
3510
|
+
* This method inserts records one at a time to avoid duplicate ID issues.
|
|
3511
|
+
* After each insert, it queries the row back using unique columns to get the generated ID.
|
|
3512
|
+
*/
|
|
3513
|
+
private handleOracleIdentityInsert;
|
|
3383
3514
|
}
|
|
3384
3515
|
|
|
3385
3516
|
type TableColumnInfo = {
|
|
@@ -3417,163 +3548,203 @@ type TableForeignKeyInfo = {
|
|
|
3417
3548
|
};
|
|
3418
3549
|
|
|
3419
3550
|
/**
|
|
3420
|
-
* @description
|
|
3551
|
+
* @description Maps a SqlDataSourceType to the raw driver response type
|
|
3421
3552
|
*/
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3553
|
+
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;
|
|
3554
|
+
|
|
3555
|
+
type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
3556
|
+
type StartTransactionOptions = {
|
|
3557
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
3558
|
+
};
|
|
3559
|
+
/**
|
|
3560
|
+
* @description Options for the transaction execution
|
|
3561
|
+
*/
|
|
3562
|
+
type TransactionExecutionOptions = {
|
|
3428
3563
|
/**
|
|
3429
|
-
* @description
|
|
3564
|
+
* @description If true, the transaction will throw an error if it is inactive
|
|
3430
3565
|
*/
|
|
3431
|
-
|
|
3566
|
+
throwErrorOnInactiveTransaction?: boolean;
|
|
3567
|
+
};
|
|
3568
|
+
|
|
3569
|
+
/**
|
|
3570
|
+
* @description Transaction class, not meant to be used directly, use sql.startTransaction() instead
|
|
3571
|
+
*/
|
|
3572
|
+
declare class Transaction {
|
|
3432
3573
|
/**
|
|
3433
|
-
* @description
|
|
3434
|
-
* @
|
|
3574
|
+
* @description The sql data source instance that the transaction is running on here you can both query or execute raw queries
|
|
3575
|
+
* @example
|
|
3576
|
+
* ```ts
|
|
3577
|
+
* import { sql } from "hysteria-orm";
|
|
3578
|
+
* import { User } from "./models/user";
|
|
3579
|
+
*
|
|
3580
|
+
* // Raw queries
|
|
3581
|
+
* const trx = await sql.startTransaction();
|
|
3582
|
+
* await trx.rawQuery("SELECT * FROM users");
|
|
3583
|
+
*
|
|
3584
|
+
* // Model manager
|
|
3585
|
+
* const modelManager = trx.sql.getModelManager(User);
|
|
3586
|
+
* await modelManager.insert({ name: "John Doe" });
|
|
3587
|
+
*
|
|
3588
|
+
* // Query builder
|
|
3589
|
+
* await trx.query(User.table).insert({ name: "John Doe" });
|
|
3590
|
+
*
|
|
3591
|
+
* await trx.commit();
|
|
3592
|
+
* ```
|
|
3435
3593
|
*/
|
|
3436
|
-
|
|
3594
|
+
sql: Omit<SqlDataSource, "transaction" | "startGlobalTransaction" | "startTransaction">;
|
|
3437
3595
|
/**
|
|
3438
|
-
* @description
|
|
3596
|
+
* @description Whether the transaction is active
|
|
3439
3597
|
*/
|
|
3440
|
-
|
|
3598
|
+
isActive: boolean;
|
|
3441
3599
|
/**
|
|
3442
|
-
* @description
|
|
3600
|
+
* @description The transaction unique identifier
|
|
3443
3601
|
*/
|
|
3444
|
-
|
|
3602
|
+
transactionId: string;
|
|
3603
|
+
private connectionReleased;
|
|
3604
|
+
private isolationLevel?;
|
|
3605
|
+
private isNested;
|
|
3606
|
+
private nestingDepth;
|
|
3607
|
+
constructor(sql: SqlDataSource, isolationLevel?: TransactionIsolationLevel, isNested?: boolean, nestingDepth?: number);
|
|
3445
3608
|
/**
|
|
3446
|
-
* @description
|
|
3609
|
+
* @description Creates a new transaction with the same isolation level and same connection using save points
|
|
3610
|
+
* @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
|
|
3447
3611
|
*/
|
|
3448
|
-
|
|
3612
|
+
nestedTransaction(): Promise<Transaction>;
|
|
3613
|
+
nestedTransaction(cb: (trx: Transaction) => Promise<void>): Promise<void>;
|
|
3449
3614
|
/**
|
|
3450
|
-
* @description
|
|
3615
|
+
* @description Starts a transaction, automatically handled from the sql data source instance in the `startTransaction` method
|
|
3451
3616
|
*/
|
|
3452
|
-
|
|
3617
|
+
startTransaction(): Promise<void>;
|
|
3453
3618
|
/**
|
|
3454
|
-
* @description
|
|
3619
|
+
* @description Commit the transaction releasing the connection
|
|
3620
|
+
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
3621
|
+
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
3455
3622
|
*/
|
|
3456
|
-
|
|
3623
|
+
commit(options?: TransactionExecutionOptions): Promise<void>;
|
|
3457
3624
|
/**
|
|
3458
|
-
* @description
|
|
3459
|
-
|
|
3460
|
-
|
|
3625
|
+
* @description Rollback the transaction releasing the connection
|
|
3626
|
+
* @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
|
|
3627
|
+
* @logs if the transaction is not active and options.throwErrorOnInactiveTransaction is false
|
|
3628
|
+
*/
|
|
3629
|
+
rollback(options?: TransactionExecutionOptions): Promise<void>;
|
|
3461
3630
|
/**
|
|
3462
|
-
* @description
|
|
3463
|
-
* @description You can continue to use the global sql class exported by hysteria after the connection without having to rely on the return of this function
|
|
3464
|
-
* @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
|
|
3465
|
-
* @example
|
|
3466
|
-
* ```ts
|
|
3467
|
-
* import { sql } from "hysteria-orm";
|
|
3468
|
-
* const connection = await sql.connect();
|
|
3469
|
-
* // You can use both connection and sql from now own, since `sql` will use the default connection after being connected
|
|
3470
|
-
* connection.query();
|
|
3471
|
-
* sql.query();
|
|
3472
|
-
*
|
|
3473
|
-
* // Models will use the default connection after being connected
|
|
3474
|
-
* User.query(); // Will use the default connection
|
|
3475
|
-
* ```
|
|
3631
|
+
* @description Release the connection, does nothing if the connection is already released
|
|
3476
3632
|
*/
|
|
3477
|
-
|
|
3478
|
-
|
|
3633
|
+
private releaseConnection;
|
|
3634
|
+
private getIsolationLevelQuery;
|
|
3635
|
+
private getSavePointName;
|
|
3636
|
+
private getMssqlTransactionLevel;
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3639
|
+
/**
|
|
3640
|
+
* @description The SqlDataSource class is the main class for interacting with the database, it's used to create connections, execute queries, and manage transactions
|
|
3641
|
+
* @example
|
|
3642
|
+
* ```ts
|
|
3643
|
+
* // Create and connect to a database
|
|
3644
|
+
* const sql = new SqlDataSource({
|
|
3645
|
+
* type: "mysql",
|
|
3646
|
+
* host: "localhost",
|
|
3647
|
+
* username: "root",
|
|
3648
|
+
* password: "password",
|
|
3649
|
+
* database: "mydb",
|
|
3650
|
+
* models: { User, Post }
|
|
3651
|
+
* });
|
|
3652
|
+
* await sql.connect();
|
|
3653
|
+
*
|
|
3654
|
+
* // Now you can use the connection
|
|
3655
|
+
* const users = await sql.query("users").many();
|
|
3656
|
+
* ```
|
|
3657
|
+
*/
|
|
3658
|
+
declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> extends DataSource {
|
|
3659
|
+
#private;
|
|
3660
|
+
private globalTransaction;
|
|
3661
|
+
private sqlType;
|
|
3662
|
+
private _models;
|
|
3663
|
+
private ownsPool;
|
|
3479
3664
|
/**
|
|
3480
|
-
* @description
|
|
3481
|
-
* @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
|
|
3482
|
-
* @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
|
|
3483
|
-
* @example
|
|
3484
|
-
* ```ts
|
|
3485
|
-
* const anotherSql = await Sql.connectToSecondarySource({
|
|
3486
|
-
* ...connectionData
|
|
3487
|
-
* });
|
|
3488
|
-
*
|
|
3489
|
-
* const user = await User.query({ connection: anotherSql }).many();
|
|
3490
|
-
* ```
|
|
3665
|
+
* @description The slaves data sources to use for the sql data source, slaves are automatically used for read operations unless specified otherwise
|
|
3491
3666
|
*/
|
|
3492
|
-
|
|
3493
|
-
static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
|
|
3667
|
+
slaves: SqlDataSource<D, T, C>[];
|
|
3494
3668
|
/**
|
|
3495
|
-
* @description
|
|
3496
|
-
* @
|
|
3497
|
-
* @
|
|
3498
|
-
* @example
|
|
3499
|
-
* ```ts
|
|
3500
|
-
* await Sql.useConnection({
|
|
3501
|
-
* ...connectionData
|
|
3502
|
-
* }, (sql) => {
|
|
3503
|
-
* const user = await User.query({ connection: sql }).many();
|
|
3504
|
-
* });
|
|
3505
|
-
* ```
|
|
3669
|
+
* @description The algorithm to use for selecting the slave for read operations
|
|
3670
|
+
* @default "roundRobin" - Distributes requests evenly across all slaves in sequence
|
|
3671
|
+
* @option "random" - Randomly selects a slave for each request
|
|
3506
3672
|
*/
|
|
3507
|
-
|
|
3673
|
+
slaveAlgorithm: SlaveAlgorithm;
|
|
3508
3674
|
/**
|
|
3509
|
-
* @description
|
|
3510
|
-
* @
|
|
3675
|
+
* @description The current index for round-robin slave selection
|
|
3676
|
+
* @private
|
|
3511
3677
|
*/
|
|
3512
|
-
|
|
3678
|
+
private roundRobinIndex;
|
|
3513
3679
|
/**
|
|
3514
|
-
* @description
|
|
3515
|
-
* @description Query builder from the SqlDataSource instance returns raw data from the database, the data is not parsed or serialized in any way
|
|
3516
|
-
* @description Optimal for performance-critical operations
|
|
3517
|
-
* @description Use Models to have type safety and serialization
|
|
3518
|
-
* @description Default soft delete column is "deleted_at" with stringed date value
|
|
3519
|
-
* @param table The table name to query from, must be in valid sql format `table` or `table as alias`
|
|
3680
|
+
* @description The pool of connections for the database
|
|
3520
3681
|
*/
|
|
3521
|
-
|
|
3682
|
+
sqlPool: SqlPoolType | null;
|
|
3522
3683
|
/**
|
|
3523
|
-
* @description
|
|
3524
|
-
* @
|
|
3525
|
-
* @returns The dry query builder instance
|
|
3684
|
+
* @description Only used in transaction context to specify the connection, not meant to be used directly
|
|
3685
|
+
* @private
|
|
3526
3686
|
*/
|
|
3527
|
-
|
|
3687
|
+
sqlConnection: GetConnectionReturnType<D> | null;
|
|
3528
3688
|
/**
|
|
3529
|
-
* @description
|
|
3689
|
+
* @description Options provided in the sql data source initialization
|
|
3530
3690
|
*/
|
|
3531
|
-
|
|
3691
|
+
inputDetails: SqlDataSourceInput<D, T, C>;
|
|
3532
3692
|
/**
|
|
3533
|
-
* @description
|
|
3693
|
+
* @description Adapter for `useCache`, uses an in memory strategy by default
|
|
3534
3694
|
*/
|
|
3535
|
-
|
|
3695
|
+
cacheAdapter: CacheAdapter;
|
|
3536
3696
|
/**
|
|
3537
|
-
* @description
|
|
3697
|
+
* @description Maps global keys to specific handlers for cache handling
|
|
3538
3698
|
*/
|
|
3539
|
-
|
|
3699
|
+
cacheKeys: C;
|
|
3540
3700
|
/**
|
|
3541
|
-
* @description
|
|
3542
|
-
* @throws {HysteriaError} If the global transaction is not started
|
|
3701
|
+
* @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
|
|
3543
3702
|
*/
|
|
3544
|
-
|
|
3703
|
+
migrationsPath: string;
|
|
3545
3704
|
/**
|
|
3546
|
-
* @description
|
|
3547
|
-
* @throws {HysteriaError} If the global transaction is not started
|
|
3705
|
+
* @description AdminJS configuration options
|
|
3548
3706
|
*/
|
|
3549
|
-
|
|
3707
|
+
private adminJsOptions?;
|
|
3550
3708
|
/**
|
|
3551
|
-
* @description
|
|
3552
|
-
* @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
|
|
3553
|
-
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3554
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3555
|
-
* @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)
|
|
3556
|
-
* @sqlite ignores the isolation level
|
|
3709
|
+
* @description Cached AdminJS instance
|
|
3557
3710
|
*/
|
|
3558
|
-
|
|
3559
|
-
static startTransaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3711
|
+
private adminJsInstance?;
|
|
3560
3712
|
/**
|
|
3561
|
-
* @
|
|
3562
|
-
*
|
|
3563
|
-
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3564
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3565
|
-
* @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)
|
|
3566
|
-
* @sqlite ignores the isolation level
|
|
3713
|
+
* @description Returns the primary instance of the SqlDataSource (set via connect with setPrimary: true)
|
|
3714
|
+
* All models by default will use this instance to execute queries unless you pass a different connection/transaction in the query options
|
|
3567
3715
|
*/
|
|
3568
|
-
static
|
|
3569
|
-
static transaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3570
|
-
static transaction(optionsOrCb?: StartTransactionOptions | ((trx: Transaction) => Promise<void>), maybeOptions?: StartTransactionOptions): Promise<StartTransactionReturnType<TransactionOptionsOrCallback>>;
|
|
3716
|
+
static get instance(): SqlDataSource;
|
|
3571
3717
|
/**
|
|
3572
|
-
* @description
|
|
3718
|
+
* @description Creates a secondary database connection that won't be set as the primary instance
|
|
3719
|
+
* @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
|
|
3720
|
+
* @example
|
|
3721
|
+
* ```ts
|
|
3722
|
+
* const secondaryDb = await SqlDataSource.connectToSecondarySource({
|
|
3723
|
+
* type: "postgres",
|
|
3724
|
+
* host: "replica.db.com",
|
|
3725
|
+
* ...
|
|
3726
|
+
* });
|
|
3727
|
+
*
|
|
3728
|
+
* const user = await User.query({ connection: secondaryDb }).many();
|
|
3729
|
+
* ```
|
|
3573
3730
|
*/
|
|
3574
|
-
static
|
|
3731
|
+
static connectToSecondarySource<U extends SqlDataSourceType, M extends Record<string, SqlDataSourceModel> = {}, K extends CacheKeys = {}>(input: Omit<SqlDataSourceInput<U, M, K>, "slaves">, cb?: (sqlDataSource: SqlDataSource<U, M, K>) => Promise<void> | void): Promise<SqlDataSource<U, M, K>>;
|
|
3575
3732
|
/**
|
|
3576
|
-
* @description
|
|
3733
|
+
* @description Creates a temporary connection that is automatically closed after the callback is executed
|
|
3734
|
+
* @example
|
|
3735
|
+
* ```ts
|
|
3736
|
+
* await SqlDataSource.useConnection({
|
|
3737
|
+
* type: "mysql",
|
|
3738
|
+
* ...connectionData
|
|
3739
|
+
* }, async (sql) => {
|
|
3740
|
+
* const user = await User.query({ connection: sql }).many();
|
|
3741
|
+
* });
|
|
3742
|
+
* // Connection is automatically closed here
|
|
3743
|
+
* ```
|
|
3744
|
+
*/
|
|
3745
|
+
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>;
|
|
3746
|
+
/**
|
|
3747
|
+
* @description Closes the primary connection (singleton instance)
|
|
3577
3748
|
*/
|
|
3578
3749
|
static closeConnection(): Promise<void>;
|
|
3579
3750
|
/**
|
|
@@ -3581,69 +3752,93 @@ declare class SqlDataSource extends DataSource {
|
|
|
3581
3752
|
*/
|
|
3582
3753
|
static disconnect(): Promise<void>;
|
|
3583
3754
|
/**
|
|
3584
|
-
* @description
|
|
3755
|
+
* @description Starts a global transaction on the primary database connection
|
|
3756
|
+
* @description Intended for testing purposes - wraps all operations in a transaction that can be rolled back
|
|
3585
3757
|
*/
|
|
3586
|
-
static
|
|
3758
|
+
static startGlobalTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3587
3759
|
/**
|
|
3588
|
-
* @description
|
|
3760
|
+
* @description Commits a global transaction on the primary database connection
|
|
3761
|
+
* @throws {HysteriaError} If the global transaction is not started
|
|
3762
|
+
*/
|
|
3763
|
+
static commitGlobalTransaction(): Promise<void>;
|
|
3764
|
+
/**
|
|
3765
|
+
* @description Rolls back a global transaction on the primary database connection
|
|
3766
|
+
* @throws {HysteriaError} If the global transaction is not started
|
|
3767
|
+
*/
|
|
3768
|
+
static rollbackGlobalTransaction(): Promise<void>;
|
|
3769
|
+
/**
|
|
3770
|
+
* @description Returns true if the primary instance is in a global transaction
|
|
3771
|
+
*/
|
|
3772
|
+
static get isInGlobalTransaction(): boolean;
|
|
3773
|
+
/**
|
|
3774
|
+
* @description Creates a new SqlDataSource instance. Call `.connect()` to establish the connection.
|
|
3775
|
+
* @param input Configuration options for the database connection. If not provided, uses env variables.
|
|
3589
3776
|
* @example
|
|
3590
3777
|
* ```ts
|
|
3591
|
-
*
|
|
3778
|
+
* // With explicit config
|
|
3779
|
+
* const sql = new SqlDataSource({
|
|
3780
|
+
* type: "mysql",
|
|
3781
|
+
* host: "localhost",
|
|
3782
|
+
* username: "root",
|
|
3783
|
+
* password: "password",
|
|
3784
|
+
* database: "mydb",
|
|
3785
|
+
* models: { User, Post }
|
|
3786
|
+
* });
|
|
3787
|
+
* await sql.connect();
|
|
3592
3788
|
*
|
|
3593
|
-
*
|
|
3789
|
+
* // Using env variables
|
|
3790
|
+
* const sql = new SqlDataSource();
|
|
3791
|
+
* await sql.connect();
|
|
3594
3792
|
* ```
|
|
3595
3793
|
*/
|
|
3596
|
-
|
|
3794
|
+
constructor(input?: SqlDataSourceInput<D, T, C>);
|
|
3597
3795
|
/**
|
|
3598
|
-
* @description
|
|
3599
|
-
* @
|
|
3600
|
-
* @
|
|
3601
|
-
*
|
|
3602
|
-
*
|
|
3796
|
+
* @description Establishes the database connection and sets this instance as the primary connection, it also connects to the slaves if any are configured
|
|
3797
|
+
* @throws {HysteriaError} If the connection is already established, use `SqlDataSource.useConnection` or `SqlDataSource.connectToSecondarySource` for auxiliary connections
|
|
3798
|
+
* @example
|
|
3799
|
+
* ```ts
|
|
3800
|
+
* const sql = new SqlDataSource({ type: "mysql", ... });
|
|
3801
|
+
* await sql.connect();
|
|
3802
|
+
* ```
|
|
3603
3803
|
*/
|
|
3604
|
-
|
|
3804
|
+
connect(): Promise<void>;
|
|
3605
3805
|
/**
|
|
3606
|
-
* @description
|
|
3607
|
-
* @description All AdminJS dependencies are loaded at runtime via dynamic import() to keep the plugin optional
|
|
3608
|
-
* @description To use AdminJS with Express, install: npm install adminjs @adminjs/express express express-formidable --save-dev
|
|
3609
|
-
* @throws {HysteriaError} If AdminJS is not enabled or connection not established
|
|
3610
|
-
* @returns The AdminJS instance with Express router
|
|
3806
|
+
* @description Returns true if the connection is established
|
|
3611
3807
|
*/
|
|
3612
|
-
|
|
3808
|
+
get isConnected(): boolean;
|
|
3613
3809
|
/**
|
|
3614
|
-
* @description Returns
|
|
3615
|
-
* @returns The AdminJS instance or undefined if not initialized
|
|
3810
|
+
* @description Returns true if this instance is in a global transaction
|
|
3616
3811
|
*/
|
|
3617
|
-
|
|
3812
|
+
get isInGlobalTransaction(): boolean;
|
|
3618
3813
|
/**
|
|
3619
|
-
* @description
|
|
3620
|
-
* @returns True if AdminJS is enabled
|
|
3814
|
+
* @description Returns the models configured on this SqlDataSource instance
|
|
3621
3815
|
*/
|
|
3622
|
-
|
|
3623
|
-
|
|
3816
|
+
get models(): T;
|
|
3817
|
+
/**
|
|
3818
|
+
* @description Selects a slave from the pool using the configured algorithm
|
|
3819
|
+
* @returns A slave SqlDataSource instance or null if no slaves are available
|
|
3820
|
+
*/
|
|
3821
|
+
getSlave(): SqlDataSource<D, T, C> | null;
|
|
3624
3822
|
/**
|
|
3625
3823
|
* @description Uses the cache adapter to get a value from the cache
|
|
3626
3824
|
* @param key The key to get the value from
|
|
3627
3825
|
* @param args The arguments to pass to the key handler
|
|
3628
3826
|
*/
|
|
3629
|
-
useCache<
|
|
3827
|
+
useCache<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3630
3828
|
/**
|
|
3631
3829
|
* @description Uses the cache adapter to get a value from the cache
|
|
3632
3830
|
* @param key The key to get the value from
|
|
3633
3831
|
* @param ttl The time to live for the value in milliseconds
|
|
3634
3832
|
* @param args The arguments to pass to the key handler
|
|
3635
3833
|
*/
|
|
3636
|
-
useCache<
|
|
3834
|
+
useCache<K extends keyof C>(key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3637
3835
|
/**
|
|
3638
3836
|
* @description Invalidates a value from the cache
|
|
3639
3837
|
* @param key The key to invalidate the value from
|
|
3640
|
-
* @param args The arguments to pass to the key handler
|
|
3641
|
-
*/
|
|
3642
|
-
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>;
|
|
3643
|
-
/**
|
|
3644
|
-
* @description Returns true if the connection is established
|
|
3838
|
+
* @param args The arguments to pass to the key handler (required if the handler expects arguments)
|
|
3645
3839
|
*/
|
|
3646
|
-
|
|
3840
|
+
invalidCache<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<void>;
|
|
3841
|
+
invalidCache<K extends keyof C>(key: K): Promise<void>;
|
|
3647
3842
|
/**
|
|
3648
3843
|
* @description Clones the SqlDataSource instance
|
|
3649
3844
|
* @param options.shouldRecreatePool Whether to recreate the pool of connections for the given driver, by default it's false
|
|
@@ -3654,20 +3849,15 @@ declare class SqlDataSource extends DataSource {
|
|
|
3654
3849
|
/**
|
|
3655
3850
|
* @description Returns the type of the database
|
|
3656
3851
|
*/
|
|
3657
|
-
getDbType():
|
|
3852
|
+
getDbType(): D;
|
|
3658
3853
|
/**
|
|
3659
|
-
* @description Returns a QueryBuilder instance
|
|
3660
|
-
* @description Query builder from the SqlDataSource instance
|
|
3661
|
-
* @
|
|
3662
|
-
* @description Use Models to have type safety and serialization
|
|
3663
|
-
* @description Default soft delete column is "deleted_at" with stringed date value
|
|
3664
|
-
* @param table The table name to query from, must be in valid sql format `table` or `table as alias`
|
|
3854
|
+
* @description Returns a QueryBuilder instance for raw queries
|
|
3855
|
+
* @description Query builder from the SqlDataSource instance returns raw data from the database
|
|
3856
|
+
* @param table The table name to query from
|
|
3665
3857
|
*/
|
|
3666
3858
|
query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
|
|
3667
3859
|
/**
|
|
3668
|
-
* @description Returns a DryQueryBuilder instance
|
|
3669
|
-
* @description The dry query builder instance will not execute the query, it will return the query statement
|
|
3670
|
-
* @returns The dry query builder instance
|
|
3860
|
+
* @description Returns a DryQueryBuilder instance that returns the query statement without executing
|
|
3671
3861
|
*/
|
|
3672
3862
|
dryQuery<S extends string>(table: TableFormat<S>, options?: RawModelOptions): DryQueryBuilderWithoutReadOperations;
|
|
3673
3863
|
/**
|
|
@@ -3679,94 +3869,78 @@ declare class SqlDataSource extends DataSource {
|
|
|
3679
3869
|
*/
|
|
3680
3870
|
createTable(...args: Parameters<Schema["createTable"]>): string;
|
|
3681
3871
|
/**
|
|
3682
|
-
* @description Starts a global transaction on the database
|
|
3872
|
+
* @description Starts a global transaction on the database
|
|
3873
|
+
* @description Intended for testing purposes - wraps all operations in a transaction that can be rolled back
|
|
3683
3874
|
*/
|
|
3684
3875
|
startGlobalTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3685
3876
|
/**
|
|
3686
|
-
* @description Commits a global transaction on the database
|
|
3877
|
+
* @description Commits a global transaction on the database
|
|
3687
3878
|
* @throws {HysteriaError} If the global transaction is not started
|
|
3688
3879
|
*/
|
|
3689
3880
|
commitGlobalTransaction(options?: TransactionExecutionOptions): Promise<void>;
|
|
3690
3881
|
/**
|
|
3691
|
-
* @description Rolls back a global transaction on the database
|
|
3692
|
-
* @throws {HysteriaError} If the global transaction is not started and options.throwErrorOnInactiveTransaction is true
|
|
3882
|
+
* @description Rolls back a global transaction on the database
|
|
3693
3883
|
*/
|
|
3694
3884
|
rollbackGlobalTransaction(options?: TransactionExecutionOptions): Promise<void>;
|
|
3695
3885
|
/**
|
|
3696
|
-
* @description
|
|
3886
|
+
* @description Starts a transaction on a dedicated connection from the pool
|
|
3697
3887
|
* @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
|
|
3698
3888
|
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3699
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3700
|
-
* @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)
|
|
3701
3889
|
* @sqlite ignores the isolation level
|
|
3702
3890
|
*/
|
|
3703
3891
|
startTransaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3704
3892
|
startTransaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3705
3893
|
/**
|
|
3706
3894
|
* @alias startTransaction
|
|
3707
|
-
* @description Get's a connection from the pool and starts a transaction on the database and returns an already started transaction instance
|
|
3708
|
-
* @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
|
|
3709
|
-
* @param options.isolationLevel The isolation level to use for the transaction
|
|
3710
|
-
* @param options.throwErrorOnInactiveTransaction Whether to throw an error if the transaction is not active
|
|
3711
|
-
* @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)
|
|
3712
|
-
* @sqlite ignores the isolation level
|
|
3713
3895
|
*/
|
|
3714
3896
|
transaction(options?: StartTransactionOptions): Promise<Transaction>;
|
|
3715
3897
|
transaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
|
|
3716
3898
|
/**
|
|
3717
|
-
* @description Returns a ModelManager instance for the given model
|
|
3718
|
-
* @description This is intended to use only if you do not want to use active record pattern
|
|
3899
|
+
* @description Returns a ModelManager instance for the given model
|
|
3719
3900
|
*/
|
|
3720
|
-
getModelManager<
|
|
3721
|
-
new ():
|
|
3722
|
-
} | typeof Model): ModelManager<
|
|
3901
|
+
getModelManager<M extends Model>(model: {
|
|
3902
|
+
new (): M;
|
|
3903
|
+
} | typeof Model): ModelManager<M>;
|
|
3723
3904
|
/**
|
|
3724
|
-
* @description Returns the current raw driver Pool
|
|
3905
|
+
* @description Returns the current raw driver Pool
|
|
3725
3906
|
* @throws {HysteriaError} If the connection pool is not established
|
|
3726
|
-
* @example
|
|
3727
|
-
* const mysqlConnection = sql.getPool("mysql"); // mysql2 Pool
|
|
3728
|
-
* const pgConnection = sql.getPool("postgres"); // pg Pool
|
|
3729
|
-
* const sqliteConnection = sql.getPool("sqlite"); // sqlite3 Database
|
|
3730
3907
|
*/
|
|
3731
|
-
getPool
|
|
3908
|
+
getPool(): getPoolReturnType<D>;
|
|
3732
3909
|
/**
|
|
3733
|
-
* @description Returns a connection from the pool
|
|
3910
|
+
* @description Returns a connection from the pool
|
|
3734
3911
|
* @throws {HysteriaError} If the connection is not established
|
|
3735
|
-
* @example
|
|
3736
|
-
* const mysqlConnection = sql.getConnection("mysql"); // mysql2 PoolConnection
|
|
3737
|
-
* const pgConnection = sql.getConnection("postgres"); // pg PoolClient
|
|
3738
|
-
* const sqliteConnection = sql.getConnection("sqlite"); // sqlite3 Database
|
|
3739
3912
|
*/
|
|
3740
|
-
getConnection
|
|
3913
|
+
getConnection(): Promise<GetConnectionReturnType<D>>;
|
|
3741
3914
|
/**
|
|
3742
3915
|
* @description Closes the current connection
|
|
3743
3916
|
* @description If there is an active global transaction, it will be rolled back
|
|
3917
|
+
* @description Also disconnects all slave connections if any are configured
|
|
3744
3918
|
*/
|
|
3745
3919
|
closeConnection(): Promise<void>;
|
|
3746
|
-
|
|
3920
|
+
/**
|
|
3921
|
+
* @description Returns the connection details
|
|
3922
|
+
*/
|
|
3923
|
+
getConnectionDetails(): SqlDataSourceInput<D, T, C>;
|
|
3747
3924
|
/**
|
|
3748
3925
|
* @alias closeConnection
|
|
3749
3926
|
*/
|
|
3750
3927
|
disconnect(): Promise<void>;
|
|
3751
3928
|
/**
|
|
3752
3929
|
* @description Syncs the schema of the database with the models metadata
|
|
3753
|
-
* @warning This will drop and recreate all the indexes and constraints, use with caution
|
|
3754
|
-
* @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
|
|
3930
|
+
* @warning This will drop and recreate all the indexes and constraints, use with caution
|
|
3755
3931
|
* @sqlite Not supported but won't throw an error
|
|
3756
3932
|
*/
|
|
3757
3933
|
syncSchema(options?: {
|
|
3758
3934
|
transactional: boolean;
|
|
3759
3935
|
}): Promise<void>;
|
|
3760
3936
|
/**
|
|
3761
|
-
* @description Executes a raw query on the database
|
|
3937
|
+
* @description Executes a raw query on the database and returns the raw driver result
|
|
3762
3938
|
*/
|
|
3763
|
-
rawQuery<
|
|
3939
|
+
rawQuery<R = RawQueryResponseType<D>>(query: string, params?: any[], options?: RawQueryOptions): Promise<R>;
|
|
3764
3940
|
/**
|
|
3765
|
-
* @description Adds a raw statement to an operation like where or update
|
|
3941
|
+
* @description Adds a raw statement to an operation like where or update
|
|
3766
3942
|
* @example
|
|
3767
3943
|
* ```ts
|
|
3768
|
-
* import { sql } from "hysteria-orm";
|
|
3769
|
-
*
|
|
3770
3944
|
* await User.query().where("name", sql.rawStatement("LOWER(name)"));
|
|
3771
3945
|
* ```
|
|
3772
3946
|
*/
|
|
@@ -3785,33 +3959,24 @@ declare class SqlDataSource extends DataSource {
|
|
|
3785
3959
|
})[];
|
|
3786
3960
|
/**
|
|
3787
3961
|
* @description Initializes AdminJS with the configured options
|
|
3788
|
-
* @description All AdminJS dependencies are loaded at runtime via dynamic import() to keep the plugin optional
|
|
3789
|
-
* @description To use AdminJS, install: npm install adminjs
|
|
3790
3962
|
* @throws {HysteriaError} If AdminJS is not enabled in the configuration
|
|
3791
|
-
* @returns The AdminJS instance
|
|
3792
3963
|
*/
|
|
3793
3964
|
initializeAdminJs(): Promise<AdminJsAdminInstance>;
|
|
3794
3965
|
/**
|
|
3795
3966
|
* @description Initializes AdminJS with Express router
|
|
3796
|
-
* @description All AdminJS dependencies are loaded at runtime via dynamic import() to keep the plugin optional
|
|
3797
|
-
* @description To use AdminJS with Express, install: npm install adminjs @adminjs/express express express-formidable --save-dev
|
|
3798
3967
|
* @throws {HysteriaError} If AdminJS is not enabled in the configuration
|
|
3799
|
-
* @returns The AdminJS instance with Express router
|
|
3800
3968
|
*/
|
|
3801
|
-
initializeAdminJsExpress(): Promise<AdminJsInstance
|
|
3969
|
+
initializeAdminJsExpress(): Promise<Required<AdminJsInstance>>;
|
|
3802
3970
|
/**
|
|
3803
3971
|
* @description Returns the AdminJS instance if initialized
|
|
3804
|
-
* @returns The AdminJS instance or undefined if not initialized
|
|
3805
3972
|
*/
|
|
3806
3973
|
getAdminJs(): AdminJsInstance | undefined;
|
|
3807
3974
|
/**
|
|
3808
3975
|
* @description Returns the AdminJS configuration options
|
|
3809
|
-
* @returns The AdminJS configuration options or undefined if not configured
|
|
3810
3976
|
*/
|
|
3811
3977
|
getAdminJsOptions(): AdminJsOptions | undefined;
|
|
3812
3978
|
/**
|
|
3813
3979
|
* @description Checks if AdminJS is enabled
|
|
3814
|
-
* @returns True if AdminJS is enabled
|
|
3815
3980
|
*/
|
|
3816
3981
|
isAdminJsEnabled(): boolean;
|
|
3817
3982
|
/**
|
|
@@ -3819,217 +3984,86 @@ declare class SqlDataSource extends DataSource {
|
|
|
3819
3984
|
*/
|
|
3820
3985
|
getTableInfo(table: string): Promise<TableColumnInfo[]>;
|
|
3821
3986
|
/**
|
|
3822
|
-
* @description Introspects table indexes metadata
|
|
3987
|
+
* @description Introspects table indexes metadata
|
|
3823
3988
|
*/
|
|
3824
3989
|
getIndexInfo(table: string): Promise<TableIndexInfo[]>;
|
|
3990
|
+
/**
|
|
3991
|
+
* @description Introspects table foreign keys metadata
|
|
3992
|
+
*/
|
|
3825
3993
|
getForeignKeyInfo(table: string): Promise<TableForeignKeyInfo[]>;
|
|
3826
3994
|
/**
|
|
3827
3995
|
* @description Introspects table primary key from the database
|
|
3828
3996
|
*/
|
|
3829
3997
|
getPrimaryKeyInfo(table: string): Promise<TablePrimaryKeyInfo | undefined>;
|
|
3830
|
-
private testConnectionQuery;
|
|
3831
|
-
private sanitizeModelKeys;
|
|
3832
|
-
static get isInGlobalTransaction(): boolean;
|
|
3833
|
-
get isInGlobalTransaction(): boolean;
|
|
3834
3998
|
/**
|
|
3835
|
-
* @description
|
|
3999
|
+
* @description Internal method to establish connection without setting as primary instance
|
|
4000
|
+
* @description Used by connectToSecondarySource and useConnection
|
|
3836
4001
|
*/
|
|
3837
|
-
|
|
4002
|
+
private connectWithoutSettingPrimary;
|
|
3838
4003
|
}
|
|
3839
4004
|
|
|
3840
|
-
type
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
type
|
|
3845
|
-
type PgPoolClientInstance = InstanceType<PgImport["Pool"]>;
|
|
3846
|
-
type SqliteConnectionInstance = InstanceType<Sqlite3Import["Database"]>;
|
|
3847
|
-
type MssqlPoolInstance = InstanceType<MssqlImport["ConnectionPool"]>;
|
|
3848
|
-
type MssqlConnectionInstance = Awaited<ReturnType<MssqlPoolInstance["connect"]>>;
|
|
3849
|
-
type SqlPoolType = MysqlConnectionInstance | PgPoolClientInstance | SqliteConnectionInstance | MssqlPoolInstance;
|
|
3850
|
-
/**
|
|
3851
|
-
* @description The connection policies for the sql data source
|
|
3852
|
-
* @default By default, the connection policies are not set, so no query will be retried
|
|
3853
|
-
*/
|
|
3854
|
-
type ConnectionPolicies = {
|
|
3855
|
-
/**
|
|
3856
|
-
* @description The retry policy for the sql data source, it allows to retry a query if it fails
|
|
3857
|
-
*/
|
|
3858
|
-
retry?: {
|
|
3859
|
-
maxRetries?: number;
|
|
3860
|
-
delay?: number;
|
|
3861
|
-
};
|
|
3862
|
-
};
|
|
3863
|
-
type SqlDataSourceModel = typeof Model;
|
|
3864
|
-
/**
|
|
3865
|
-
* @description The input type for the SqlDataSource constructor
|
|
3866
|
-
* @description The connectionPolicies object is used to configure the connection policies for the sql data source
|
|
3867
|
-
*/
|
|
3868
|
-
type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
|
|
3869
|
-
readonly type?: D;
|
|
3870
|
-
/**
|
|
3871
|
-
* @description Whether to log the sql queries and other debug information
|
|
3872
|
-
*/
|
|
3873
|
-
readonly logs?: boolean;
|
|
3874
|
-
/**
|
|
3875
|
-
* @description The connection policies to use for the sql data source that are not configured in the driverOptions
|
|
3876
|
-
*/
|
|
3877
|
-
connectionPolicies?: ConnectionPolicies;
|
|
4005
|
+
type ModelWithoutRelations<T extends Model> = Pick<T, ExcludeRelations<Omit<T, "*">>>;
|
|
4006
|
+
type NumberModelKey<T extends Model> = {
|
|
4007
|
+
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
4008
|
+
}[keyof T];
|
|
4009
|
+
type BaseModelMethodOptions = {
|
|
3878
4010
|
/**
|
|
3879
|
-
* @description The
|
|
4011
|
+
* @description The connection to use for the model, by default the main connection will be used
|
|
4012
|
+
* @description The main connection is the one created via `new SqlDataSource().connect()`
|
|
4013
|
+
* @example
|
|
4014
|
+
* ```ts
|
|
4015
|
+
* import { SqlDataSource } from "hysteria-orm";
|
|
4016
|
+
* const customConnection = await SqlDataSource.connectToSecondarySource({
|
|
4017
|
+
* type: "postgres",
|
|
4018
|
+
* host: "localhost",
|
|
4019
|
+
* username: "root",
|
|
4020
|
+
* password: "root",
|
|
4021
|
+
* database: "test",
|
|
4022
|
+
* port: 5432,
|
|
4023
|
+
* });
|
|
4024
|
+
*
|
|
4025
|
+
* const user = await User.query({ connection: customConnection }).first();
|
|
4026
|
+
* ```
|
|
3880
4027
|
*/
|
|
3881
|
-
|
|
4028
|
+
connection?: SqlDataSource;
|
|
3882
4029
|
/**
|
|
3883
|
-
* @description The
|
|
3884
|
-
* @description Models can still be used as standalone entities, but they won't be available for the sql data source instance
|
|
4030
|
+
* @description The transaction instance to use for the model
|
|
3885
4031
|
*/
|
|
3886
|
-
|
|
4032
|
+
trx?: Transaction;
|
|
3887
4033
|
/**
|
|
3888
|
-
* @description
|
|
3889
|
-
* @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`
|
|
4034
|
+
* @description Whether to ignore the hooks for the model
|
|
3890
4035
|
*/
|
|
3891
|
-
|
|
4036
|
+
ignoreHooks?: boolean;
|
|
3892
4037
|
/**
|
|
3893
|
-
* @description The
|
|
3894
|
-
* @
|
|
4038
|
+
* @description The replication mode to use for the model
|
|
4039
|
+
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
4040
|
+
* @description If set to "master", all operations will use master
|
|
4041
|
+
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
3895
4042
|
*/
|
|
3896
|
-
|
|
4043
|
+
replicationMode?: ReplicationType;
|
|
4044
|
+
};
|
|
4045
|
+
/**
|
|
4046
|
+
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
4047
|
+
*/
|
|
4048
|
+
type RawModelOptions = {
|
|
3897
4049
|
/**
|
|
3898
|
-
*
|
|
4050
|
+
* Alias for the table
|
|
3899
4051
|
*/
|
|
3900
|
-
|
|
3901
|
-
cacheAdapter?: CacheAdapter;
|
|
3902
|
-
keys: C;
|
|
3903
|
-
};
|
|
4052
|
+
alias?: string;
|
|
3904
4053
|
/**
|
|
3905
|
-
* @description
|
|
3906
|
-
* @description To use AdminJS, install: `npm install adminjs`
|
|
4054
|
+
* @description Convert the column casing before making a Database query, by default preserves what is provided
|
|
3907
4055
|
*/
|
|
3908
|
-
|
|
3909
|
-
} & (MysqlSqlDataSourceInput | MssqlDataSourceInput | PostgresSqlDataSourceInput | SqliteDataSourceInput);
|
|
3910
|
-
type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
|
|
3911
|
-
readonly type: Exclude<DataSourceType, "mongo">;
|
|
3912
|
-
readonly logs?: boolean;
|
|
3913
|
-
readonly models?: T;
|
|
3914
|
-
readonly driverOptions?: SqlDriverSpecificOptions<D>;
|
|
3915
|
-
connectionPolicies?: ConnectionPolicies;
|
|
3916
|
-
queryFormatOptions?: FormatOptionsWithLanguage;
|
|
3917
|
-
cacheStrategy?: {
|
|
3918
|
-
cacheAdapter: CacheAdapter;
|
|
3919
|
-
keys: C;
|
|
3920
|
-
};
|
|
4056
|
+
databaseCaseConvention?: CaseConvention;
|
|
3921
4057
|
/**
|
|
3922
|
-
*
|
|
3923
|
-
* @description AdminJS is completely optional - dependencies are loaded at runtime via dynamic import()
|
|
4058
|
+
* Column to use for soft deleted, by default is `deleted_at`
|
|
3924
4059
|
*/
|
|
3925
|
-
|
|
3926
|
-
} & (NotNullableMysqlSqlDataSourceInput | NotNullablePostgresSqlDataSourceInput | NotNullableSqliteDataSourceInput);
|
|
3927
|
-
type SqlDataSourceType = Exclude<DataSourceType, "mongo">;
|
|
3928
|
-
type SqlCloneOptions = {
|
|
4060
|
+
softDeleteColumn?: string;
|
|
3929
4061
|
/**
|
|
3930
|
-
*
|
|
3931
|
-
* @warning If false, the pool of connections will be reused from the caller instance
|
|
4062
|
+
* Column to use for soft deleted, by default is date in format: "YYYY-MM-DD HH:mm:ss" in UTC timezone
|
|
3932
4063
|
*/
|
|
3933
|
-
|
|
3934
|
-
};
|
|
3935
|
-
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 : never;
|
|
3936
|
-
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 : never;
|
|
3937
|
-
type UseCacheOverloads<C extends CacheKeys> = {
|
|
3938
|
-
<K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3939
|
-
<K extends keyof C>(key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
|
|
3940
|
-
};
|
|
3941
|
-
type UseCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["useCache"] : UseCacheOverloads<C>;
|
|
3942
|
-
type InvalidCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["invalidCache"] : <K extends keyof C>(key: K) => Promise<void>;
|
|
3943
|
-
type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = Omit<SqlDataSource, "useCache" | "invalidCache" | "clone"> & {
|
|
3944
|
-
useCache: UseCacheType<C>;
|
|
3945
|
-
invalidCache: InvalidCacheType<C>;
|
|
3946
|
-
clone(options?: SqlCloneOptions): Promise<AugmentedSqlDataSource<T, C>>;
|
|
3947
|
-
} & {
|
|
3948
|
-
[key in keyof T]: T[key];
|
|
3949
|
-
};
|
|
3950
|
-
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"> & {
|
|
3951
|
-
[key in keyof T]: T[key];
|
|
3952
|
-
};
|
|
3953
|
-
/** Only accepts formats `string` e `string as string` */
|
|
3954
|
-
type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
|
|
3955
|
-
type TableFormat<S extends string> = NoSpace<S> | (S extends `${infer L} as ${infer R}` ? `${NoSpace<L>} as ${NoSpace<R>}` : never);
|
|
3956
|
-
|
|
3957
|
-
type AstParserType = {
|
|
3958
|
-
sql: string;
|
|
3959
|
-
bindings: any[];
|
|
4064
|
+
softDeleteValue?: string | boolean;
|
|
3960
4065
|
};
|
|
3961
4066
|
|
|
3962
|
-
declare class AstParser {
|
|
3963
|
-
private readonly dbType;
|
|
3964
|
-
private readonly model;
|
|
3965
|
-
constructor(model: typeof Model, dbType: SqlDataSourceType);
|
|
3966
|
-
parse(nodes: (QueryNode | null)[], startBindingIndex?: number, isNestedCondition?: boolean): AstParserType;
|
|
3967
|
-
/**
|
|
3968
|
-
* Map the database type to a common type if shares the same driver (e.g. mysql and mariadb)
|
|
3969
|
-
*/
|
|
3970
|
-
private mapCommonDbType;
|
|
3971
|
-
/**
|
|
3972
|
-
* @description Generates MSSQL table hints from lock node
|
|
3973
|
-
* MSSQL uses WITH (UPDLOCK), WITH (HOLDLOCK), etc. as table hints
|
|
3974
|
-
* READPAST is the MSSQL equivalent of SKIP LOCKED
|
|
3975
|
-
*/
|
|
3976
|
-
private getMssqlTableHints;
|
|
3977
|
-
}
|
|
3978
|
-
|
|
3979
|
-
declare class DeleteNode extends QueryNode {
|
|
3980
|
-
fromNode: FromNode;
|
|
3981
|
-
chainsWith: string;
|
|
3982
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
3983
|
-
folder: string;
|
|
3984
|
-
file: string;
|
|
3985
|
-
constructor(fromNode: FromNode, isRawValue?: boolean);
|
|
3986
|
-
}
|
|
3987
|
-
|
|
3988
|
-
declare class InsertNode extends QueryNode {
|
|
3989
|
-
fromNode: FromNode;
|
|
3990
|
-
records: Record<string, any>[];
|
|
3991
|
-
returning?: string[];
|
|
3992
|
-
disableReturning: boolean;
|
|
3993
|
-
chainsWith: string;
|
|
3994
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
3995
|
-
folder: string;
|
|
3996
|
-
file: string;
|
|
3997
|
-
constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
|
|
3998
|
-
}
|
|
3999
|
-
|
|
4000
|
-
declare class OnDuplicateNode extends QueryNode {
|
|
4001
|
-
table: string;
|
|
4002
|
-
conflictColumns: string[];
|
|
4003
|
-
columnsToUpdate: string[];
|
|
4004
|
-
returning?: string[];
|
|
4005
|
-
mode: "update" | "ignore";
|
|
4006
|
-
chainsWith: string;
|
|
4007
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
4008
|
-
folder: string;
|
|
4009
|
-
file: string;
|
|
4010
|
-
constructor(table: string, conflictColumns: string[], columnsToUpdate: string[], mode?: "update" | "ignore", returning?: string[], isRawValue?: boolean);
|
|
4011
|
-
}
|
|
4012
|
-
|
|
4013
|
-
declare class TruncateNode extends QueryNode {
|
|
4014
|
-
fromNode: FromNode | string;
|
|
4015
|
-
chainsWith: string;
|
|
4016
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
4017
|
-
folder: string;
|
|
4018
|
-
file: string;
|
|
4019
|
-
constructor(fromNode: FromNode | string, isRawValue?: boolean);
|
|
4020
|
-
}
|
|
4021
|
-
|
|
4022
|
-
declare class UpdateNode extends QueryNode {
|
|
4023
|
-
fromNode: FromNode;
|
|
4024
|
-
columns: string[];
|
|
4025
|
-
values: (any | RawNode)[];
|
|
4026
|
-
chainsWith: string;
|
|
4027
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
4028
|
-
folder: string;
|
|
4029
|
-
file: string;
|
|
4030
|
-
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
4031
|
-
}
|
|
4032
|
-
|
|
4033
4067
|
declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
4034
4068
|
model: typeof Model;
|
|
4035
4069
|
protected astParser: AstParser;
|
|
@@ -4044,6 +4078,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4044
4078
|
protected updateNode: UpdateNode | null;
|
|
4045
4079
|
protected deleteNode: DeleteNode | null;
|
|
4046
4080
|
protected truncateNode: TruncateNode | null;
|
|
4081
|
+
protected replicationMode: ReplicationType | null;
|
|
4047
4082
|
/**
|
|
4048
4083
|
* @description Performance methods that return the time that took to execute the query with the result
|
|
4049
4084
|
*/
|
|
@@ -4110,6 +4145,14 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4110
4145
|
}>;
|
|
4111
4146
|
};
|
|
4112
4147
|
constructor(model: typeof Model, sqlDataSource?: SqlDataSource);
|
|
4148
|
+
/**
|
|
4149
|
+
* @description Sets the replication mode for the query builder
|
|
4150
|
+
* @param replicationMode - The replication mode to use for the query builder
|
|
4151
|
+
* @description If not specified, read operations will use slave (if available) else master, and write operations will always use master
|
|
4152
|
+
* @description If set to "master", all operations will use master
|
|
4153
|
+
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
4154
|
+
*/
|
|
4155
|
+
setReplicationMode(replicationMode: ReplicationType): this;
|
|
4113
4156
|
/**
|
|
4114
4157
|
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
4115
4158
|
*/
|
|
@@ -4294,6 +4337,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4294
4337
|
* @description Insert multiple records into a table
|
|
4295
4338
|
* @param returning - The columns to return from the query, only supported by postgres and cockroachdb - default is "*"
|
|
4296
4339
|
* @returns raw driver response
|
|
4340
|
+
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
4297
4341
|
*/
|
|
4298
4342
|
insertMany(data: Record<string, any>[], returning?: string[]): Promise<T[]>;
|
|
4299
4343
|
/**
|
|
@@ -4411,6 +4455,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4411
4455
|
* @description Executes pagination queries, serializing them for MSSQL transactions
|
|
4412
4456
|
*/
|
|
4413
4457
|
protected executePaginateQueries<M, C>(modelsQuery: () => Promise<M>, countQuery: () => Promise<C>): Promise<[M, C]>;
|
|
4458
|
+
protected getSqlDataSource(mode: "read" | "write"): Promise<SqlDataSource>;
|
|
4414
4459
|
}
|
|
4415
4460
|
|
|
4416
4461
|
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
@@ -4591,6 +4636,7 @@ declare abstract class Model extends Entity {
|
|
|
4591
4636
|
* @mysql If no Primary Key is present in the model definition, the model will be returned
|
|
4592
4637
|
* @sqlite If no Primary Key is present in the model definition, the model will be returned
|
|
4593
4638
|
* @sqlite Returning Not supported and won't have effect
|
|
4639
|
+
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
4594
4640
|
*/
|
|
4595
4641
|
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>): Promise<AnnotatedModel<T, {}>[]>;
|
|
4596
4642
|
/**
|
|
@@ -5810,7 +5856,7 @@ declare abstract class Migration {
|
|
|
5810
5856
|
/**
|
|
5811
5857
|
* @description This method is called after the migration has been run
|
|
5812
5858
|
*/
|
|
5813
|
-
afterMigration?(sqlDataSource: SqlDataSource
|
|
5859
|
+
afterMigration?(sqlDataSource: SqlDataSource): Promise<void>;
|
|
5814
5860
|
}
|
|
5815
5861
|
|
|
5816
5862
|
/**
|
|
@@ -5863,7 +5909,7 @@ type WithPerformanceResult<R = any> = [string, R];
|
|
|
5863
5909
|
*/
|
|
5864
5910
|
declare const withPerformance: <A extends any[], R>(fn: (...args: A) => Promise<R>, returnType?: "millis" | "seconds", fix?: number) => (...args: A) => Promise<WithPerformanceResult<R>>;
|
|
5865
5911
|
|
|
5866
|
-
type HysteriaErrorCode = `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";
|
|
5912
|
+
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";
|
|
5867
5913
|
|
|
5868
5914
|
declare class HysteriaError extends Error {
|
|
5869
5915
|
code: HysteriaErrorCode;
|
|
@@ -5888,4 +5934,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
5888
5934
|
$id?: string;
|
|
5889
5935
|
}>;
|
|
5890
5936
|
|
|
5891
|
-
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,
|
|
5937
|
+
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, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type ReplicationType, type SlaveAlgorithm, 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 };
|