hysteria-orm 10.3.0 → 10.3.2
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 +12 -12
- package/lib/cli.cjs.map +1 -1
- package/lib/cli.js +12 -12
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +10 -10
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +75 -7
- package/lib/index.d.ts +75 -7
- package/lib/index.js +10 -10
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ import { Collection as Collection$1 } from 'mongodb';
|
|
|
6
6
|
import * as sqlite3 from 'sqlite3';
|
|
7
7
|
import { RunResult } from 'sqlite3';
|
|
8
8
|
import * as pg from 'pg';
|
|
9
|
-
import {
|
|
9
|
+
import { PoolConfig, PoolClient, QueryResult as QueryResult$1 } from 'pg';
|
|
10
10
|
import * as mysql2_promise from 'mysql2/promise';
|
|
11
11
|
import { PoolOptions, PoolConnection, QueryResult } from 'mysql2/promise';
|
|
12
12
|
import { RedisOptions, Redis } from 'ioredis';
|
|
@@ -131,12 +131,12 @@ type MongoClientImport = typeof mongodb;
|
|
|
131
131
|
type MssqlImport = typeof mssql;
|
|
132
132
|
type OracleDBCreateConnectionOptions = PoolAttributes;
|
|
133
133
|
type MysqlCreateConnectionOptions = PoolOptions;
|
|
134
|
-
type
|
|
134
|
+
type PgPoolOptions = PoolConfig;
|
|
135
135
|
type MssqlConnectionOptions = Omit<config, "options"> & {
|
|
136
136
|
options?: Omit<NonNullable<config["options"]>, "abortTransactionOnError" | "enableImplicitTransactions">;
|
|
137
137
|
};
|
|
138
138
|
type MongoConnectionOptions = NonNullable<ConstructorParameters<MongoClientImport["MongoClient"]>[1]>;
|
|
139
|
-
type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ?
|
|
139
|
+
type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ? PgPoolOptions : T extends "redis" ? RedisOptions : T extends "mysql" | "mariadb" ? MysqlCreateConnectionOptions : T extends "mssql" ? MssqlConnectionOptions : T extends "oracledb" ? OracleDBCreateConnectionOptions : never;
|
|
140
140
|
|
|
141
141
|
type MongoCollectionKey<T> = T extends Collection ? T : never;
|
|
142
142
|
type BaseModelMethodOptions$1 = {
|
|
@@ -1164,6 +1164,21 @@ type SqlDataSourceInput<D extends SqlDataSourceType = SqlDataSourceType, T exten
|
|
|
1164
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
1165
|
*/
|
|
1166
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
|
+
};
|
|
1167
1182
|
} & Omit<MapSqlDataSourceTypeToInput<D>, "type">;
|
|
1168
1183
|
/**
|
|
1169
1184
|
* @description Maps a SqlDataSourceType to its corresponding non-nullable input interface
|
|
@@ -1202,6 +1217,16 @@ type GetConnectionReturnType<T = SqlDataSourceType> = T extends "mysql" ? PoolCo
|
|
|
1202
1217
|
/** Only accepts formats `string` e `string as string` */
|
|
1203
1218
|
type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
|
|
1204
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
|
+
};
|
|
1205
1230
|
|
|
1206
1231
|
type AstParserType = {
|
|
1207
1232
|
sql: string;
|
|
@@ -3411,10 +3436,15 @@ declare class ModelManager<T extends Model> {
|
|
|
3411
3436
|
protected modelInstance: T;
|
|
3412
3437
|
protected astParser: AstParser;
|
|
3413
3438
|
protected interpreterUtils: InterpreterUtils;
|
|
3439
|
+
protected replicationMode: "master" | "slave" | null;
|
|
3414
3440
|
/**
|
|
3415
3441
|
* @description Constructor for ModelManager class.
|
|
3416
3442
|
*/
|
|
3417
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;
|
|
3418
3448
|
/**
|
|
3419
3449
|
* @description Finds all records that match the input
|
|
3420
3450
|
*/
|
|
@@ -3631,6 +3661,21 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3631
3661
|
private sqlType;
|
|
3632
3662
|
private _models;
|
|
3633
3663
|
private ownsPool;
|
|
3664
|
+
/**
|
|
3665
|
+
* @description The slaves data sources to use for the sql data source, slaves are automatically used for read operations unless specified otherwise
|
|
3666
|
+
*/
|
|
3667
|
+
slaves: SqlDataSource<D, T, C>[];
|
|
3668
|
+
/**
|
|
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
|
|
3672
|
+
*/
|
|
3673
|
+
slaveAlgorithm: SlaveAlgorithm;
|
|
3674
|
+
/**
|
|
3675
|
+
* @description The current index for round-robin slave selection
|
|
3676
|
+
* @private
|
|
3677
|
+
*/
|
|
3678
|
+
private roundRobinIndex;
|
|
3634
3679
|
/**
|
|
3635
3680
|
* @description The pool of connections for the database
|
|
3636
3681
|
*/
|
|
@@ -3683,7 +3728,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3683
3728
|
* const user = await User.query({ connection: secondaryDb }).many();
|
|
3684
3729
|
* ```
|
|
3685
3730
|
*/
|
|
3686
|
-
static connectToSecondarySource<U extends SqlDataSourceType, M extends Record<string, SqlDataSourceModel> = {}, K extends CacheKeys = {}>(input: SqlDataSourceInput<U, M, K>, cb?: (sqlDataSource: SqlDataSource<U, M, K>) => Promise<void> | void): Promise<SqlDataSource<U, M, K>>;
|
|
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>>;
|
|
3687
3732
|
/**
|
|
3688
3733
|
* @description Creates a temporary connection that is automatically closed after the callback is executed
|
|
3689
3734
|
* @example
|
|
@@ -3748,7 +3793,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3748
3793
|
*/
|
|
3749
3794
|
constructor(input?: SqlDataSourceInput<D, T, C>);
|
|
3750
3795
|
/**
|
|
3751
|
-
* @description Establishes the database connection and sets this instance as the primary connection
|
|
3796
|
+
* @description Establishes the database connection and sets this instance as the primary connection, it also connects to the slaves if any are configured
|
|
3752
3797
|
* @throws {HysteriaError} If the connection is already established, use `SqlDataSource.useConnection` or `SqlDataSource.connectToSecondarySource` for auxiliary connections
|
|
3753
3798
|
* @example
|
|
3754
3799
|
* ```ts
|
|
@@ -3769,6 +3814,11 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3769
3814
|
* @description Returns the models configured on this SqlDataSource instance
|
|
3770
3815
|
*/
|
|
3771
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;
|
|
3772
3822
|
/**
|
|
3773
3823
|
* @description Uses the cache adapter to get a value from the cache
|
|
3774
3824
|
* @param key The key to get the value from
|
|
@@ -3864,6 +3914,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3864
3914
|
/**
|
|
3865
3915
|
* @description Closes the current connection
|
|
3866
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
|
|
3867
3918
|
*/
|
|
3868
3919
|
closeConnection(): Promise<void>;
|
|
3869
3920
|
/**
|
|
@@ -3885,7 +3936,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3885
3936
|
/**
|
|
3886
3937
|
* @description Executes a raw query on the database and returns the raw driver result
|
|
3887
3938
|
*/
|
|
3888
|
-
rawQuery<R = RawQueryResponseType<D>>(query: string, params?: any[]): Promise<R>;
|
|
3939
|
+
rawQuery<R = RawQueryResponseType<D>>(query: string, params?: any[], options?: RawQueryOptions): Promise<R>;
|
|
3889
3940
|
/**
|
|
3890
3941
|
* @description Adds a raw statement to an operation like where or update
|
|
3891
3942
|
* @example
|
|
@@ -3983,6 +4034,13 @@ type BaseModelMethodOptions = {
|
|
|
3983
4034
|
* @description Whether to ignore the hooks for the model
|
|
3984
4035
|
*/
|
|
3985
4036
|
ignoreHooks?: boolean;
|
|
4037
|
+
/**
|
|
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
|
|
4042
|
+
*/
|
|
4043
|
+
replicationMode?: ReplicationType;
|
|
3986
4044
|
};
|
|
3987
4045
|
/**
|
|
3988
4046
|
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
@@ -4020,6 +4078,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4020
4078
|
protected updateNode: UpdateNode | null;
|
|
4021
4079
|
protected deleteNode: DeleteNode | null;
|
|
4022
4080
|
protected truncateNode: TruncateNode | null;
|
|
4081
|
+
protected replicationMode: ReplicationType | null;
|
|
4023
4082
|
/**
|
|
4024
4083
|
* @description Performance methods that return the time that took to execute the query with the result
|
|
4025
4084
|
*/
|
|
@@ -4086,6 +4145,14 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4086
4145
|
}>;
|
|
4087
4146
|
};
|
|
4088
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;
|
|
4089
4156
|
/**
|
|
4090
4157
|
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
4091
4158
|
*/
|
|
@@ -4388,6 +4455,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4388
4455
|
* @description Executes pagination queries, serializing them for MSSQL transactions
|
|
4389
4456
|
*/
|
|
4390
4457
|
protected executePaginateQueries<M, C>(modelsQuery: () => Promise<M>, countQuery: () => Promise<C>): Promise<[M, C]>;
|
|
4458
|
+
protected getSqlDataSource(mode: "read" | "write"): Promise<SqlDataSource>;
|
|
4391
4459
|
}
|
|
4392
4460
|
|
|
4393
4461
|
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
@@ -5866,4 +5934,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
5866
5934
|
$id?: string;
|
|
5867
5935
|
}>;
|
|
5868
5936
|
|
|
5869
|
-
export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnnotatedModel, type AsymmetricEncryptionOptions, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, unique, view, withPerformance };
|
|
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 };
|
package/lib/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Collection as Collection$1 } from 'mongodb';
|
|
|
6
6
|
import * as sqlite3 from 'sqlite3';
|
|
7
7
|
import { RunResult } from 'sqlite3';
|
|
8
8
|
import * as pg from 'pg';
|
|
9
|
-
import {
|
|
9
|
+
import { PoolConfig, PoolClient, QueryResult as QueryResult$1 } from 'pg';
|
|
10
10
|
import * as mysql2_promise from 'mysql2/promise';
|
|
11
11
|
import { PoolOptions, PoolConnection, QueryResult } from 'mysql2/promise';
|
|
12
12
|
import { RedisOptions, Redis } from 'ioredis';
|
|
@@ -131,12 +131,12 @@ type MongoClientImport = typeof mongodb;
|
|
|
131
131
|
type MssqlImport = typeof mssql;
|
|
132
132
|
type OracleDBCreateConnectionOptions = PoolAttributes;
|
|
133
133
|
type MysqlCreateConnectionOptions = PoolOptions;
|
|
134
|
-
type
|
|
134
|
+
type PgPoolOptions = PoolConfig;
|
|
135
135
|
type MssqlConnectionOptions = Omit<config, "options"> & {
|
|
136
136
|
options?: Omit<NonNullable<config["options"]>, "abortTransactionOnError" | "enableImplicitTransactions">;
|
|
137
137
|
};
|
|
138
138
|
type MongoConnectionOptions = NonNullable<ConstructorParameters<MongoClientImport["MongoClient"]>[1]>;
|
|
139
|
-
type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ?
|
|
139
|
+
type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ? PgPoolOptions : T extends "redis" ? RedisOptions : T extends "mysql" | "mariadb" ? MysqlCreateConnectionOptions : T extends "mssql" ? MssqlConnectionOptions : T extends "oracledb" ? OracleDBCreateConnectionOptions : never;
|
|
140
140
|
|
|
141
141
|
type MongoCollectionKey<T> = T extends Collection ? T : never;
|
|
142
142
|
type BaseModelMethodOptions$1 = {
|
|
@@ -1164,6 +1164,21 @@ type SqlDataSourceInput<D extends SqlDataSourceType = SqlDataSourceType, T exten
|
|
|
1164
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
1165
|
*/
|
|
1166
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
|
+
};
|
|
1167
1182
|
} & Omit<MapSqlDataSourceTypeToInput<D>, "type">;
|
|
1168
1183
|
/**
|
|
1169
1184
|
* @description Maps a SqlDataSourceType to its corresponding non-nullable input interface
|
|
@@ -1202,6 +1217,16 @@ type GetConnectionReturnType<T = SqlDataSourceType> = T extends "mysql" ? PoolCo
|
|
|
1202
1217
|
/** Only accepts formats `string` e `string as string` */
|
|
1203
1218
|
type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
|
|
1204
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
|
+
};
|
|
1205
1230
|
|
|
1206
1231
|
type AstParserType = {
|
|
1207
1232
|
sql: string;
|
|
@@ -3411,10 +3436,15 @@ declare class ModelManager<T extends Model> {
|
|
|
3411
3436
|
protected modelInstance: T;
|
|
3412
3437
|
protected astParser: AstParser;
|
|
3413
3438
|
protected interpreterUtils: InterpreterUtils;
|
|
3439
|
+
protected replicationMode: "master" | "slave" | null;
|
|
3414
3440
|
/**
|
|
3415
3441
|
* @description Constructor for ModelManager class.
|
|
3416
3442
|
*/
|
|
3417
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;
|
|
3418
3448
|
/**
|
|
3419
3449
|
* @description Finds all records that match the input
|
|
3420
3450
|
*/
|
|
@@ -3631,6 +3661,21 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3631
3661
|
private sqlType;
|
|
3632
3662
|
private _models;
|
|
3633
3663
|
private ownsPool;
|
|
3664
|
+
/**
|
|
3665
|
+
* @description The slaves data sources to use for the sql data source, slaves are automatically used for read operations unless specified otherwise
|
|
3666
|
+
*/
|
|
3667
|
+
slaves: SqlDataSource<D, T, C>[];
|
|
3668
|
+
/**
|
|
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
|
|
3672
|
+
*/
|
|
3673
|
+
slaveAlgorithm: SlaveAlgorithm;
|
|
3674
|
+
/**
|
|
3675
|
+
* @description The current index for round-robin slave selection
|
|
3676
|
+
* @private
|
|
3677
|
+
*/
|
|
3678
|
+
private roundRobinIndex;
|
|
3634
3679
|
/**
|
|
3635
3680
|
* @description The pool of connections for the database
|
|
3636
3681
|
*/
|
|
@@ -3683,7 +3728,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3683
3728
|
* const user = await User.query({ connection: secondaryDb }).many();
|
|
3684
3729
|
* ```
|
|
3685
3730
|
*/
|
|
3686
|
-
static connectToSecondarySource<U extends SqlDataSourceType, M extends Record<string, SqlDataSourceModel> = {}, K extends CacheKeys = {}>(input: SqlDataSourceInput<U, M, K>, cb?: (sqlDataSource: SqlDataSource<U, M, K>) => Promise<void> | void): Promise<SqlDataSource<U, M, K>>;
|
|
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>>;
|
|
3687
3732
|
/**
|
|
3688
3733
|
* @description Creates a temporary connection that is automatically closed after the callback is executed
|
|
3689
3734
|
* @example
|
|
@@ -3748,7 +3793,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3748
3793
|
*/
|
|
3749
3794
|
constructor(input?: SqlDataSourceInput<D, T, C>);
|
|
3750
3795
|
/**
|
|
3751
|
-
* @description Establishes the database connection and sets this instance as the primary connection
|
|
3796
|
+
* @description Establishes the database connection and sets this instance as the primary connection, it also connects to the slaves if any are configured
|
|
3752
3797
|
* @throws {HysteriaError} If the connection is already established, use `SqlDataSource.useConnection` or `SqlDataSource.connectToSecondarySource` for auxiliary connections
|
|
3753
3798
|
* @example
|
|
3754
3799
|
* ```ts
|
|
@@ -3769,6 +3814,11 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3769
3814
|
* @description Returns the models configured on this SqlDataSource instance
|
|
3770
3815
|
*/
|
|
3771
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;
|
|
3772
3822
|
/**
|
|
3773
3823
|
* @description Uses the cache adapter to get a value from the cache
|
|
3774
3824
|
* @param key The key to get the value from
|
|
@@ -3864,6 +3914,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3864
3914
|
/**
|
|
3865
3915
|
* @description Closes the current connection
|
|
3866
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
|
|
3867
3918
|
*/
|
|
3868
3919
|
closeConnection(): Promise<void>;
|
|
3869
3920
|
/**
|
|
@@ -3885,7 +3936,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
3885
3936
|
/**
|
|
3886
3937
|
* @description Executes a raw query on the database and returns the raw driver result
|
|
3887
3938
|
*/
|
|
3888
|
-
rawQuery<R = RawQueryResponseType<D>>(query: string, params?: any[]): Promise<R>;
|
|
3939
|
+
rawQuery<R = RawQueryResponseType<D>>(query: string, params?: any[], options?: RawQueryOptions): Promise<R>;
|
|
3889
3940
|
/**
|
|
3890
3941
|
* @description Adds a raw statement to an operation like where or update
|
|
3891
3942
|
* @example
|
|
@@ -3983,6 +4034,13 @@ type BaseModelMethodOptions = {
|
|
|
3983
4034
|
* @description Whether to ignore the hooks for the model
|
|
3984
4035
|
*/
|
|
3985
4036
|
ignoreHooks?: boolean;
|
|
4037
|
+
/**
|
|
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
|
|
4042
|
+
*/
|
|
4043
|
+
replicationMode?: ReplicationType;
|
|
3986
4044
|
};
|
|
3987
4045
|
/**
|
|
3988
4046
|
* @description Options that can be provided to a raw sql operation (like the raw QueryBuilder)
|
|
@@ -4020,6 +4078,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4020
4078
|
protected updateNode: UpdateNode | null;
|
|
4021
4079
|
protected deleteNode: DeleteNode | null;
|
|
4022
4080
|
protected truncateNode: TruncateNode | null;
|
|
4081
|
+
protected replicationMode: ReplicationType | null;
|
|
4023
4082
|
/**
|
|
4024
4083
|
* @description Performance methods that return the time that took to execute the query with the result
|
|
4025
4084
|
*/
|
|
@@ -4086,6 +4145,14 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4086
4145
|
}>;
|
|
4087
4146
|
};
|
|
4088
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;
|
|
4089
4156
|
/**
|
|
4090
4157
|
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
4091
4158
|
*/
|
|
@@ -4388,6 +4455,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
4388
4455
|
* @description Executes pagination queries, serializing them for MSSQL transactions
|
|
4389
4456
|
*/
|
|
4390
4457
|
protected executePaginateQueries<M, C>(modelsQuery: () => Promise<M>, countQuery: () => Promise<C>): Promise<[M, C]>;
|
|
4458
|
+
protected getSqlDataSource(mode: "read" | "write"): Promise<SqlDataSource>;
|
|
4391
4459
|
}
|
|
4392
4460
|
|
|
4393
4461
|
type UnionCallBack<T extends Model> = (queryBuilder: QueryBuilder<T>) => QueryBuilder<T>;
|
|
@@ -5866,4 +5934,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
5866
5934
|
$id?: string;
|
|
5867
5935
|
}>;
|
|
5868
5936
|
|
|
5869
|
-
export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnnotatedModel, type AsymmetricEncryptionOptions, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, unique, view, withPerformance };
|
|
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 };
|