hysteria-orm 10.0.4 → 10.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.cts CHANGED
@@ -1,12 +1,13 @@
1
1
  import * as mongodb from 'mongodb';
2
+ import { Collection as Collection$1 } from 'mongodb';
2
3
  import * as sqlite3 from 'sqlite3';
3
4
  import * as pg from 'pg';
4
5
  import { PoolClient } from 'pg';
5
6
  import * as mysql2_promise from 'mysql2/promise';
6
7
  import { PoolConnection } from 'mysql2/promise';
8
+ import { RedisOptions, Redis } from 'ioredis';
7
9
  import { PassThrough } from 'node:stream';
8
10
  import { FormatOptionsWithLanguage } from 'sql-formatter';
9
- import { Redis, RedisOptions } from 'ioredis';
10
11
 
11
12
  type CaseConvention = "camel" | "snake" | "preserve" | RegExp | ((column: string) => string);
12
13
 
@@ -28,6 +29,68 @@ declare abstract class Entity {
28
29
  static databaseCaseConvention: CaseConvention;
29
30
  }
30
31
 
32
+ /**
33
+ * @description Creates a datasource for the selected database type with the provided credentials
34
+ */
35
+ type DataSourceType = "cockroachdb" | "mysql" | "postgres" | "mariadb" | "sqlite" | "mongo";
36
+ interface CommonDataSourceInput {
37
+ readonly type?: DataSourceType;
38
+ readonly logs?: boolean;
39
+ }
40
+ interface MongoDataSourceInput extends CommonDataSourceInput {
41
+ readonly type: "mongo";
42
+ readonly mongoOptions?: MongoConnectionOptions;
43
+ readonly url?: string;
44
+ }
45
+ interface PostgresSqlDataSourceInput extends CommonDataSourceInput {
46
+ readonly type?: "postgres" | "cockroachdb";
47
+ readonly host?: string;
48
+ readonly port?: number;
49
+ readonly username?: string;
50
+ readonly password?: string;
51
+ readonly database?: string;
52
+ readonly driverOptions?: PgClientOptions;
53
+ }
54
+ interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInput {
55
+ readonly type?: "postgres" | "cockroachdb";
56
+ readonly host: string;
57
+ readonly username: string;
58
+ readonly password: string;
59
+ readonly database: string;
60
+ readonly port?: number;
61
+ readonly driverOptions?: PgClientOptions;
62
+ }
63
+ interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
64
+ readonly type?: "mysql" | "mariadb";
65
+ readonly host?: string;
66
+ readonly port?: number;
67
+ readonly username?: string;
68
+ readonly password?: string;
69
+ readonly database?: string;
70
+ readonly driverOptions?: MysqlCreateConnectionOptions;
71
+ }
72
+ interface NotNullableMysqlSqlDataSourceInput extends MysqlSqlDataSourceInput {
73
+ readonly type?: "mysql" | "mariadb";
74
+ readonly host: string;
75
+ readonly username: string;
76
+ readonly password: string;
77
+ readonly database: string;
78
+ readonly port?: number;
79
+ readonly driverOptions?: MysqlCreateConnectionOptions;
80
+ }
81
+ interface SqliteDataSourceInput extends CommonDataSourceInput {
82
+ readonly type?: "sqlite";
83
+ readonly database?: string;
84
+ }
85
+ interface NotNullableSqliteDataSourceInput extends SqliteDataSourceInput {
86
+ readonly type?: "sqlite";
87
+ readonly database: string;
88
+ }
89
+ /**
90
+ * @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
91
+ */
92
+ type DataSourceInput = MysqlSqlDataSourceInput | SqliteDataSourceInput | PostgresSqlDataSourceInput | MongoDataSourceInput;
93
+
31
94
  type Mysql2Import = typeof mysql2_promise;
32
95
  type PgImport = typeof pg;
33
96
  type Sqlite3Import = typeof sqlite3;
@@ -36,11 +99,7 @@ type ExcludeStringFromOptions<T> = T extends string ? never : T;
36
99
  type MysqlCreateConnectionOptions = Parameters<Mysql2Import["createPool"]>[0];
37
100
  type PgClientOptions = ExcludeStringFromOptions<ConstructorParameters<PgImport["Pool"]>[0]>;
38
101
  type MongoConnectionOptions = NonNullable<ConstructorParameters<MongoClientImport["MongoClient"]>[1]>;
39
- type DriverSpecificOptions = {
40
- mysqlOptions?: MysqlCreateConnectionOptions;
41
- pgOptions?: PgClientOptions;
42
- mongoOptions?: MongoConnectionOptions;
43
- };
102
+ type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" ? PgClientOptions : T extends "redis" ? RedisOptions : T extends "postgres" ? PgClientOptions : T extends "mongo" ? MongoConnectionOptions : T extends "mariadb" ? MysqlCreateConnectionOptions : T extends "mysql" ? MysqlCreateConnectionOptions : never;
44
103
 
45
104
  type MongoCollectionKey<T> = T extends Collection ? T : never;
46
105
  type BaseModelMethodOptions$1 = {
@@ -83,7 +142,7 @@ declare class MongoQueryBuilder<T extends Collection> {
83
142
  protected limitNumber?: number;
84
143
  protected offsetNumber?: number;
85
144
  protected mongoDataSource: MongoDataSource;
86
- protected collection: MongoClientImport["Collection"]["prototype"];
145
+ protected collection: Collection$1<T>;
87
146
  protected model: typeof Collection;
88
147
  protected logs: boolean;
89
148
  protected session?: ReturnType<MongoDataSource["startSession"]>;
@@ -367,68 +426,6 @@ declare class MongoQueryBuilder<T extends Collection> {
367
426
  offset(offset: number): this;
368
427
  }
369
428
 
370
- /**
371
- * @description Creates a datasource for the selected database type with the provided credentials
372
- */
373
- type DataSourceType = "cockroachdb" | "mysql" | "postgres" | "mariadb" | "sqlite" | "mongo";
374
- interface CommonDataSourceInput {
375
- readonly type?: DataSourceType;
376
- readonly logs?: boolean;
377
- }
378
- interface MongoDataSourceInput extends CommonDataSourceInput {
379
- readonly type: "mongo";
380
- readonly mongoOptions?: MongoConnectionOptions;
381
- readonly url?: string;
382
- }
383
- interface PostgresSqlDataSourceInput extends CommonDataSourceInput {
384
- readonly type?: "postgres" | "cockroachdb";
385
- readonly host?: string;
386
- readonly port?: number;
387
- readonly username?: string;
388
- readonly password?: string;
389
- readonly database?: string;
390
- readonly driverOptions?: PgClientOptions;
391
- }
392
- interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInput {
393
- readonly type?: "postgres" | "cockroachdb";
394
- readonly host: string;
395
- readonly username: string;
396
- readonly password: string;
397
- readonly database: string;
398
- readonly port?: number;
399
- readonly driverOptions?: PgClientOptions;
400
- }
401
- interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
402
- readonly type?: "mysql" | "mariadb";
403
- readonly host?: string;
404
- readonly port?: number;
405
- readonly username?: string;
406
- readonly password?: string;
407
- readonly database?: string;
408
- readonly driverOptions?: MysqlCreateConnectionOptions;
409
- }
410
- interface NotNullableMysqlSqlDataSourceInput extends MysqlSqlDataSourceInput {
411
- readonly type?: "mysql" | "mariadb";
412
- readonly host: string;
413
- readonly username: string;
414
- readonly password: string;
415
- readonly database: string;
416
- readonly port?: number;
417
- readonly driverOptions?: MysqlCreateConnectionOptions;
418
- }
419
- interface SqliteDataSourceInput extends CommonDataSourceInput {
420
- readonly type?: "sqlite";
421
- readonly database?: string;
422
- }
423
- interface NotNullableSqliteDataSourceInput extends SqliteDataSourceInput {
424
- readonly type?: "sqlite";
425
- readonly database: string;
426
- }
427
- /**
428
- * @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
429
- */
430
- type DataSourceInput = MysqlSqlDataSourceInput | SqliteDataSourceInput | PostgresSqlDataSourceInput | MongoDataSourceInput;
431
-
432
429
  declare abstract class DataSource {
433
430
  type: DataSourceType;
434
431
  host: string;
@@ -592,6 +589,12 @@ declare class Collection extends Entity {
592
589
  * @returns {MongoQueryBuilder<T>}
593
590
  */
594
591
  static query<T extends Collection>(this: new () => T | typeof Collection, options?: BaseModelMethodOptions$1): MongoQueryBuilder<T>;
592
+ /**
593
+ * @description Gets the raw collection from the mongoInstance using the underlying mongodb driver
594
+ * @param this
595
+ * @returns {DriverCollection<T>}
596
+ */
597
+ static rawCollection<T extends typeof Collection>(this: T): Collection$1<Omit<InstanceType<T>, "$annotations" | "id">>;
595
598
  /**
596
599
  * @description Finds records in the collection, to use for simple queries
597
600
  * @param this
@@ -1389,9 +1392,9 @@ declare class InterpreterUtils {
1389
1392
  getFromForWriteOperations(dbType: SqlDataSourceType, fromNode: FromNode): string;
1390
1393
  }
1391
1394
 
1392
- type BaseValues$1 = string | number | boolean | undefined | null | RawNode;
1393
- type BinaryOperatorType$1 = "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "is" | "is not" | "like" | "not like" | "is null" | "is not null" | "ilike" | "in" | "not in" | "between" | "not between" | "regexp" | "not regexp" | "not ilike";
1394
- declare class WhereNode extends QueryNode {
1395
+ type BaseValues$1 = string | number | boolean | null;
1396
+ type BinaryOperatorType$1 = "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "like" | "ilike" | "in";
1397
+ declare class HavingNode extends QueryNode {
1395
1398
  column: string;
1396
1399
  isNegated: boolean;
1397
1400
  operator: BinaryOperatorType$1;
@@ -1403,6 +1406,20 @@ declare class WhereNode extends QueryNode {
1403
1406
  constructor(column: string, chainsWith: "and" | "or", isNegated: boolean | undefined, operator: BinaryOperatorType$1, value: BaseValues$1 | BaseValues$1[], isRawValue?: boolean);
1404
1407
  }
1405
1408
 
1409
+ type BaseValues = string | number | boolean | undefined | null | RawNode;
1410
+ type BinaryOperatorType = "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "is" | "is not" | "like" | "not like" | "is null" | "is not null" | "ilike" | "in" | "not in" | "between" | "not between" | "regexp" | "not regexp" | "not ilike";
1411
+ declare class WhereNode extends QueryNode {
1412
+ column: string;
1413
+ isNegated: boolean;
1414
+ operator: BinaryOperatorType;
1415
+ value: BaseValues | BaseValues[];
1416
+ chainsWith: "and" | "or";
1417
+ canKeywordBeSeenMultipleTimes: boolean;
1418
+ folder: string;
1419
+ file: string;
1420
+ constructor(column: string, chainsWith: "and" | "or", isNegated: boolean | undefined, operator: BinaryOperatorType, value: BaseValues | BaseValues[], isRawValue?: boolean);
1421
+ }
1422
+
1406
1423
  type SubqueryOperatorType = "in" | "not in" | "exists" | "not exists" | "between" | "not between" | ">" | "<" | ">=" | "<=";
1407
1424
  declare class WhereSubqueryNode extends QueryNode {
1408
1425
  column: string;
@@ -1424,86 +1441,6 @@ declare class WhereGroupNode extends QueryNode {
1424
1441
  constructor(nodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[], chainsWith?: "and" | "or");
1425
1442
  }
1426
1443
 
1427
- /**
1428
- * @description Options for the relation
1429
- * @property {string} softDeleteColumn - The column name for the soft delete column, if set, the relation will only return rows that have not been soft deleted
1430
- * @property {string} softDeleteType - The type of the soft delete column
1431
- */
1432
- declare enum RelationEnum {
1433
- hasOne = "hasOne",// One to One without foreign key
1434
- belongsTo = "belongsTo",// One to One with foreign key
1435
- hasMany = "hasMany",
1436
- manyToMany = "manyToMany"
1437
- }
1438
- /**
1439
- * Main Relation Class
1440
- */
1441
- declare abstract class Relation {
1442
- abstract type: RelationEnum;
1443
- model: typeof Model;
1444
- columnName: string;
1445
- foreignKey?: string;
1446
- relatedModel: string;
1447
- protected constructor(model: typeof Model, columnName: string);
1448
- }
1449
-
1450
- declare class SqlModelManagerUtils<T extends Model> {
1451
- protected dbType: SqlDataSourceType;
1452
- protected sqlDataSource: SqlDataSource;
1453
- protected modelRelations: Relation[];
1454
- protected modelRelationsMap: Map<string, Relation>;
1455
- constructor(typeofModel: typeof Model, dbType: SqlDataSourceType, sqlDataSource: SqlDataSource);
1456
- getRelationFromModel(relation: ModelRelation<T>): Relation;
1457
- }
1458
-
1459
- type PaginationMetadata = {
1460
- perPage: number;
1461
- currentPage: number;
1462
- firstPage: number;
1463
- isEmpty: boolean;
1464
- total: number;
1465
- lastPage: number;
1466
- hasMorePages: boolean;
1467
- hasPages: boolean;
1468
- };
1469
- type CursorPaginationMetadata = {
1470
- perPage: number;
1471
- firstPage: number;
1472
- isEmpty: boolean;
1473
- total: number;
1474
- };
1475
- type PaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
1476
- paginationMetadata: PaginationMetadata;
1477
- data: AnnotatedModel<T, A, R>[];
1478
- };
1479
- type CursorPaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
1480
- paginationMetadata: CursorPaginationMetadata;
1481
- data: AnnotatedModel<T, A, R>[];
1482
- };
1483
-
1484
- type DeleteOptions = {
1485
- ignoreBeforeDeleteHook?: boolean;
1486
- };
1487
- type SoftDeleteOptions<T> = {
1488
- column?: MongoCollectionKey<T>;
1489
- value?: string | number | boolean;
1490
- ignoreBeforeDeleteHook?: boolean;
1491
- };
1492
-
1493
- type BaseValues = string | number | boolean | null;
1494
- type BinaryOperatorType = "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "like" | "ilike" | "in";
1495
- declare class HavingNode extends QueryNode {
1496
- column: string;
1497
- isNegated: boolean;
1498
- operator: BinaryOperatorType;
1499
- value: BaseValues | BaseValues[];
1500
- chainsWith: "and" | "or";
1501
- canKeywordBeSeenMultipleTimes: boolean;
1502
- folder: string;
1503
- file: string;
1504
- constructor(column: string, chainsWith: "and" | "or", isNegated: boolean | undefined, operator: BinaryOperatorType, value: BaseValues | BaseValues[], isRawValue?: boolean);
1505
- }
1506
-
1507
1444
  declare class DistinctNode extends QueryNode {
1508
1445
  chainsWith: string;
1509
1446
  canKeywordBeSeenMultipleTimes: boolean;
@@ -1593,6 +1530,29 @@ declare class OrderByNode extends QueryNode {
1593
1530
  type DateFormat = "ISO" | "TIMESTAMP" | "DATE_ONLY" | "TIME_ONLY";
1594
1531
  type Timezone = "UTC" | "LOCAL";
1595
1532
 
1533
+ /**
1534
+ * @description Options for the relation
1535
+ * @property {string} softDeleteColumn - The column name for the soft delete column, if set, the relation will only return rows that have not been soft deleted
1536
+ * @property {string} softDeleteType - The type of the soft delete column
1537
+ */
1538
+ declare enum RelationEnum {
1539
+ hasOne = "hasOne",// One to One without foreign key
1540
+ belongsTo = "belongsTo",// One to One with foreign key
1541
+ hasMany = "hasMany",
1542
+ manyToMany = "manyToMany"
1543
+ }
1544
+ /**
1545
+ * Main Relation Class
1546
+ */
1547
+ declare abstract class Relation {
1548
+ abstract type: RelationEnum;
1549
+ model: typeof Model;
1550
+ columnName: string;
1551
+ foreignKey?: string;
1552
+ relatedModel: string;
1553
+ protected constructor(model: typeof Model, columnName: string);
1554
+ }
1555
+
1596
1556
  type ColumnDataType = Exclude<keyof CreateTableBuilder, "enum" | "rawColumn" | "custom"> | readonly string[];
1597
1557
  type ColumnDataTypeOptionWithLength = {
1598
1558
  type?: "char" | "varchar" | "string" | "uuid" | "ulid" | "varbinary" | "integer" | "tinyint" | "smallint" | "mediumint" | "bigint";
@@ -1885,10 +1845,10 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
1885
1845
  * @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
1886
1846
  * @param operator - The comparison operator to use in the ON clause (default: "=")
1887
1847
  */
1888
- innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType$1): this;
1889
- innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType$1): this;
1890
- innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType$1): this;
1891
- innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType$1): this;
1848
+ innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
1849
+ innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
1850
+ innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
1851
+ innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
1892
1852
  /**
1893
1853
  * @description Join a table with the current model
1894
1854
  * @param relationTable - The table to join
@@ -1896,10 +1856,10 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
1896
1856
  * @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
1897
1857
  * @param operator - The comparison operator to use in the ON clause (default: "=")
1898
1858
  */
1899
- join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType$1): this;
1900
- join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType$1): this;
1901
- join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType$1): this;
1902
- join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType$1): this;
1859
+ join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
1860
+ join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
1861
+ join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
1862
+ join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
1903
1863
  /**
1904
1864
  * @description Join a table with the current model
1905
1865
  * @param relationTable - The table to join
@@ -1907,10 +1867,10 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
1907
1867
  * @param primaryColumn - The primary column of the current model, default is caller model primary key if using a Model, if using a Raw Query Builder you must provide the key for the primary table, must be in the format of `table.column`
1908
1868
  * @param operator - The comparison operator to use in the ON clause (default: "=")
1909
1869
  */
1910
- leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType$1): this;
1911
- leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType$1): this;
1912
- leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType$1): this;
1913
- leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType$1): this;
1870
+ leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
1871
+ leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
1872
+ leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
1873
+ leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
1914
1874
  /**
1915
1875
  * @description Join a table with the current model
1916
1876
  * @param relationTable - The table to join
@@ -1918,8 +1878,8 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
1918
1878
  * @param primaryColumn - The primary column of the current model, default is caller model primary key if using A Model, if using a Raw Query Builder you must provide the key for the primary table
1919
1879
  * @param operator - The comparison operator to use in the ON clause (default: "=")
1920
1880
  */
1921
- rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType$1): this;
1922
- rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType$1): this;
1881
+ rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
1882
+ rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
1923
1883
  /**
1924
1884
  * @description Perform a FULL OUTER JOIN with another table
1925
1885
  * @param relationTable - The table to join
@@ -1927,8 +1887,8 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
1927
1887
  * @param primaryColumn - The primary column of the current model
1928
1888
  * @param operator - The comparison operator to use in the ON clause (default: "=")
1929
1889
  */
1930
- fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType$1): this;
1931
- fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType$1): this;
1890
+ fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
1891
+ fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
1932
1892
  }
1933
1893
 
1934
1894
  declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
@@ -1990,8 +1950,9 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
1990
1950
  /**
1991
1951
  * @description Sets the table to select from, by default is the table defined in the Model
1992
1952
  * @description Can be used on non select queries too, it will only specify the table name (es. INSERT INTO $table)
1953
+ * @param table The table name to query from, must be in valid sql format `table` or `table as alias`
1993
1954
  */
1994
- from(table: string): this;
1955
+ from<S extends string>(table: TableFormat<S>): this;
1995
1956
  /**
1996
1957
  * @description Sets the table to select from, by default is the table defined in the Model
1997
1958
  * @description Better naming convention for non select queries
@@ -2031,84 +1992,84 @@ declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBui
2031
1992
  /**
2032
1993
  * @description Adds a WHERE condition to the query.
2033
1994
  */
2034
- where(column: ModelKey<T>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2035
- where<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
1995
+ where(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
1996
+ where<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
2036
1997
  where(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
2037
1998
  where(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2038
1999
  where(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2039
- where(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues$1): this;
2000
+ where(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
2040
2001
  /**
2041
2002
  * @description Adds an AND WHERE condition to the query.
2042
2003
  */
2043
- andWhere(column: ModelKey<T>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2044
- andWhere(column: SelectableColumn<string>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2045
- andWhere(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues$1): this;
2004
+ andWhere(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
2005
+ andWhere(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
2006
+ andWhere(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
2046
2007
  andWhere(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
2047
2008
  andWhere(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2048
2009
  andWhere(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2049
2010
  /**
2050
2011
  * @description Adds an OR WHERE condition to the query.
2051
2012
  */
2052
- orWhere(column: ModelKey<T>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2053
- orWhere<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2054
- orWhere<S extends string>(column: ModelKey<T> | SelectableColumn<S>, value: BaseValues$1): this;
2013
+ orWhere(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
2014
+ orWhere<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
2015
+ orWhere<S extends string>(column: ModelKey<T> | SelectableColumn<S>, value: BaseValues): this;
2055
2016
  orWhere(cb: (queryBuilder: WhereOnlyQueryBuilder<T>) => void): this;
2056
2017
  orWhere(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2057
2018
  orWhere(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2058
2019
  /**
2059
2020
  * @description Adds a negated WHERE condition to the query.
2060
2021
  */
2061
- whereNot(column: ModelKey<T>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2062
- whereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2063
- whereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues$1): this;
2022
+ whereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
2023
+ whereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
2024
+ whereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
2064
2025
  whereNot(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2065
2026
  whereNot(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2066
2027
  /**
2067
2028
  * @description Adds a negated AND WHERE condition to the query.
2068
2029
  */
2069
- andWhereNot(column: ModelKey<T>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2070
- andWhereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2071
- andWhereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues$1): this;
2030
+ andWhereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
2031
+ andWhereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
2032
+ andWhereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
2072
2033
  andWhereNot(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2073
2034
  andWhereNot(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2074
2035
  /**
2075
2036
  * @description Adds a negated OR WHERE condition to the query.
2076
2037
  */
2077
- orWhereNot(column: ModelKey<T>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2078
- orWhereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType$1, value: BaseValues$1): this;
2079
- orWhereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues$1): this;
2038
+ orWhereNot(column: ModelKey<T>, operator: BinaryOperatorType, value: BaseValues): this;
2039
+ orWhereNot<S extends string>(column: SelectableColumn<S>, operator: BinaryOperatorType, value: BaseValues): this;
2040
+ orWhereNot(column: ModelKey<T> | SelectableColumn<string>, value: BaseValues): this;
2080
2041
  orWhereNot(column: ModelKey<T> | SelectableColumn<string>, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2081
2042
  orWhereNot(column: ModelKey<T> | SelectableColumn<string>, operator: SubqueryOperatorType, subQuery: QueryBuilder<T> | ((subQuery: QueryBuilder<T>) => void)): this;
2082
2043
  /**
2083
2044
  * @description Adds a WHERE BETWEEN condition to the query.
2084
2045
  */
2085
- whereBetween(column: ModelKey<T>, min: BaseValues$1, max: BaseValues$1): this;
2086
- whereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues$1, max: BaseValues$1): this;
2046
+ whereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
2047
+ whereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
2087
2048
  /**
2088
2049
  * @description Adds an AND WHERE BETWEEN condition to the query.
2089
2050
  */
2090
- andWhereBetween(column: ModelKey<T>, min: BaseValues$1, max: BaseValues$1): this;
2091
- andWhereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues$1, max: BaseValues$1): this;
2051
+ andWhereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
2052
+ andWhereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
2092
2053
  /**
2093
2054
  * @description Adds an OR WHERE BETWEEN condition to the query.
2094
2055
  */
2095
- orWhereBetween(column: ModelKey<T>, min: BaseValues$1, max: BaseValues$1): this;
2096
- orWhereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues$1, max: BaseValues$1): this;
2056
+ orWhereBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
2057
+ orWhereBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
2097
2058
  /**
2098
2059
  * @description Adds a WHERE NOT BETWEEN condition to the query.
2099
2060
  */
2100
- whereNotBetween(column: ModelKey<T>, min: BaseValues$1, max: BaseValues$1): this;
2101
- whereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues$1, max: BaseValues$1): this;
2061
+ whereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
2062
+ whereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
2102
2063
  /**
2103
2064
  * @description Adds an AND WHERE NOT BETWEEN condition to the query.
2104
2065
  */
2105
- andWhereNotBetween(column: ModelKey<T>, min: BaseValues$1, max: BaseValues$1): this;
2106
- andWhereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues$1, max: BaseValues$1): this;
2066
+ andWhereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
2067
+ andWhereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
2107
2068
  /**
2108
2069
  * @description Adds an OR WHERE NOT BETWEEN condition to the query.
2109
2070
  */
2110
- orWhereNotBetween(column: ModelKey<T>, min: BaseValues$1, max: BaseValues$1): this;
2111
- orWhereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues$1, max: BaseValues$1): this;
2071
+ orWhereNotBetween(column: ModelKey<T>, min: BaseValues, max: BaseValues): this;
2072
+ orWhereNotBetween<S extends string>(column: SelectableColumn<S>, min: BaseValues, max: BaseValues): this;
2112
2073
  /**
2113
2074
  * @description Adds a WHERE LIKE condition to the query.
2114
2075
  */
@@ -2173,38 +2134,38 @@ declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBui
2173
2134
  * @description Adds a WHERE IN condition to the query.
2174
2135
  * @warning If the array is empty, it will add an impossible condition.
2175
2136
  */
2176
- whereIn(column: ModelKey<T>, values: BaseValues$1[]): this;
2177
- whereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues$1[]): this;
2137
+ whereIn(column: ModelKey<T>, values: BaseValues[]): this;
2138
+ whereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
2178
2139
  /**
2179
2140
  * @description Adds an AND WHERE IN condition to the query.
2180
2141
  * @warning If the array is empty, it will add an impossible condition.
2181
2142
  */
2182
- andWhereIn(column: ModelKey<T>, values: BaseValues$1[]): this;
2183
- andWhereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues$1[]): this;
2143
+ andWhereIn(column: ModelKey<T>, values: BaseValues[]): this;
2144
+ andWhereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
2184
2145
  /**
2185
2146
  * @description Adds an OR WHERE IN condition to the query.
2186
2147
  * @warning If the array is empty, it will add an impossible condition.
2187
2148
  */
2188
- orWhereIn(column: ModelKey<T>, values: BaseValues$1[]): this;
2189
- orWhereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues$1[]): this;
2149
+ orWhereIn(column: ModelKey<T>, values: BaseValues[]): this;
2150
+ orWhereIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
2190
2151
  /**
2191
2152
  * @description Adds a WHERE NOT IN condition to the query.
2192
2153
  * @warning If the array is empty, it will add an obvious condition to make it true.
2193
2154
  */
2194
- whereNotIn(column: ModelKey<T>, values: BaseValues$1[]): this;
2195
- whereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues$1[]): this;
2155
+ whereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
2156
+ whereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
2196
2157
  /**
2197
2158
  * @description Adds an OR WHERE NOT IN condition to the query.
2198
2159
  * @warning If the array is empty, it will add an obvious condition to make it true.
2199
2160
  */
2200
- andWhereNotIn(column: ModelKey<T>, values: BaseValues$1[]): this;
2201
- andWhereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues$1[]): this;
2161
+ andWhereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
2162
+ andWhereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
2202
2163
  /**
2203
2164
  * @description Adds an OR WHERE NOT IN condition to the query.
2204
2165
  * @warning If the array is empty, it will add an obvious condition to make it true.
2205
2166
  */
2206
- orWhereNotIn(column: ModelKey<T>, values: BaseValues$1[]): this;
2207
- orWhereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues$1[]): this;
2167
+ orWhereNotIn(column: ModelKey<T>, values: BaseValues[]): this;
2168
+ orWhereNotIn<S extends string>(column: SelectableColumn<S>, values: BaseValues[]): this;
2208
2169
  /**
2209
2170
  * @description Adds a WHERE NULL condition to the query.
2210
2171
  */
@@ -2296,17 +2257,17 @@ declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBui
2296
2257
  * @description Adds a HAVING condition to the query.
2297
2258
  */
2298
2259
  having<S extends string>(column: SelectableColumn<S>, value: any): this;
2299
- having(column: ModelKey<T>, operator: BinaryOperatorType$1, value: any): this;
2260
+ having(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
2300
2261
  /**
2301
2262
  * @description Adds an AND HAVING condition to the query.
2302
2263
  */
2303
2264
  andHaving<S extends string>(column: SelectableColumn<S>, value: any): this;
2304
- andHaving(column: ModelKey<T>, operator: BinaryOperatorType$1, value: any): this;
2265
+ andHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
2305
2266
  /**
2306
2267
  * @description Adds an OR HAVING condition to the query.
2307
2268
  */
2308
2269
  orHaving<S extends string>(column: SelectableColumn<S>, value: any): this;
2309
- orHaving(column: ModelKey<T>, operator: BinaryOperatorType$1, value: any): this;
2270
+ orHaving(column: ModelKey<T>, operator: BinaryOperatorType, value: any): this;
2310
2271
  /**
2311
2272
  * @description Adds a raw HAVING condition to the query.
2312
2273
  */
@@ -2441,6 +2402,49 @@ type PaginateWithCursorOptions<T extends Model, K extends ModelKey<T>> = {
2441
2402
  orderBy?: "asc" | "desc";
2442
2403
  };
2443
2404
 
2405
+ declare class SqlModelManagerUtils<T extends Model> {
2406
+ protected dbType: SqlDataSourceType;
2407
+ protected sqlDataSource: SqlDataSource;
2408
+ protected modelRelations: Relation[];
2409
+ protected modelRelationsMap: Map<string, Relation>;
2410
+ constructor(typeofModel: typeof Model, dbType: SqlDataSourceType, sqlDataSource: SqlDataSource);
2411
+ getRelationFromModel(relation: ModelRelation<T>): Relation;
2412
+ }
2413
+
2414
+ type PaginationMetadata = {
2415
+ perPage: number;
2416
+ currentPage: number;
2417
+ firstPage: number;
2418
+ isEmpty: boolean;
2419
+ total: number;
2420
+ lastPage: number;
2421
+ hasMorePages: boolean;
2422
+ hasPages: boolean;
2423
+ };
2424
+ type CursorPaginationMetadata = {
2425
+ perPage: number;
2426
+ firstPage: number;
2427
+ isEmpty: boolean;
2428
+ total: number;
2429
+ };
2430
+ type PaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
2431
+ paginationMetadata: PaginationMetadata;
2432
+ data: AnnotatedModel<T, A, R>[];
2433
+ };
2434
+ type CursorPaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
2435
+ paginationMetadata: CursorPaginationMetadata;
2436
+ data: AnnotatedModel<T, A, R>[];
2437
+ };
2438
+
2439
+ type DeleteOptions = {
2440
+ ignoreBeforeDeleteHook?: boolean;
2441
+ };
2442
+ type SoftDeleteOptions<T> = {
2443
+ column?: MongoCollectionKey<T>;
2444
+ value?: string | number | boolean;
2445
+ ignoreBeforeDeleteHook?: boolean;
2446
+ };
2447
+
2444
2448
  type UpdateOptions = {
2445
2449
  ignoreBeforeUpdateHook?: boolean;
2446
2450
  };
@@ -2642,14 +2646,6 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2642
2646
  data: number;
2643
2647
  time: number;
2644
2648
  }>;
2645
- insert: (data: Partial<ModelWithoutRelations<T>>, returnType?: "millis" | "seconds") => Promise<{
2646
- data: T;
2647
- time: number;
2648
- }>;
2649
- insertMany: (data: Partial<ModelWithoutRelations<T>>[], returnType?: "millis" | "seconds") => Promise<{
2650
- data: T[];
2651
- time: number;
2652
- }>;
2653
2649
  update: (data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions, returnType?: "millis" | "seconds") => Promise<{
2654
2650
  data: number;
2655
2651
  time: number;
@@ -2658,6 +2654,10 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2658
2654
  data: number;
2659
2655
  time: number;
2660
2656
  }>;
2657
+ pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
2658
+ data: PluckReturnType<T, ModelKey<T>>;
2659
+ time: number;
2660
+ }>;
2661
2661
  };
2662
2662
  constructor(model: typeof Model, sqlDataSource: SqlDataSource);
2663
2663
  /**
@@ -2683,8 +2683,16 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2683
2683
  }): Promise<AnnotatedModel<T, A, R>>;
2684
2684
  many(options?: ManyOptions): Promise<AnnotatedModel<T, A, R>[]>;
2685
2685
  chunk(chunkSize: number, options?: ManyOptions): AsyncGenerator<AnnotatedModel<T, A, R>[]>;
2686
- stream(options?: ManyOptions & StreamOptions, cb?: (stream: PassThrough & AsyncGenerator<AnnotatedModel<T, A, R>>) => void | Promise<void>): Promise<PassThrough & AsyncGenerator<AnnotatedModel<T, A, R>>>;
2686
+ stream(options?: ManyOptions & StreamOptions): Promise<PassThrough & AsyncGenerator<AnnotatedModel<T, A, R>>>;
2687
2687
  paginateWithCursor<K extends ModelKey<T>>(page: number, options?: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[CursorPaginatedData<T, A, R>, Cursor<T, K>]>;
2688
+ /**
2689
+ * @description Inserts a new record into the database, it is not advised to use this method directly from the query builder if using a ModelQueryBuilder (`Model.query()`), use the `Model.insert` method instead.
2690
+ */
2691
+ insert(...args: Parameters<typeof this$1.model.insert>): ReturnType<typeof this$1.model.insert>;
2692
+ /**
2693
+ * @description Inserts multiple records into the database, it is not advised to use this method directly from the query builder if using a ModelQueryBuilder (`Model.query()`), use the `Model.insertMany` method instead.
2694
+ */
2695
+ insertMany(...args: Parameters<typeof this$1.model.insertMany>): ReturnType<typeof this$1.model.insertMany>;
2688
2696
  update(data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions): Promise<number>;
2689
2697
  softDelete(options?: SoftDeleteOptions<T>): Promise<number>;
2690
2698
  delete(options?: DeleteOptions): Promise<number>;
@@ -2754,37 +2762,37 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2754
2762
  * @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
2755
2763
  */
2756
2764
  havingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
2757
- havingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType$1 | BaseValues$1, maybeValue?: BaseValues$1): this;
2765
+ havingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2758
2766
  /**
2759
2767
  * @description Checks if the relation exists in the models and has the given filters, if no callback is provided, it only check if there is at least one record for the relation
2760
2768
  * @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
2761
2769
  */
2762
2770
  andHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
2763
- andHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType$1 | BaseValues$1, maybeValue?: BaseValues$1): this;
2771
+ andHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2764
2772
  /**
2765
2773
  * @description Checks if the relation exists in the models and has the given filters, if no callback is provided, it only check if there is at least one record for the relation,
2766
2774
  * @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
2767
2775
  */
2768
2776
  orHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
2769
- orHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType$1 | BaseValues$1, maybeValue?: BaseValues$1): this;
2777
+ orHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2770
2778
  /**
2771
2779
  * @description Checks if the relation does not exist in the models and has the given filters, if no callback is provided, it only check if there is no record for the Relation
2772
2780
  * @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
2773
2781
  */
2774
2782
  notHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
2775
- notHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType$1 | BaseValues$1, maybeValue?: BaseValues$1): this;
2783
+ notHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2776
2784
  /**
2777
2785
  * @description Checks if the relation does not exist in the models and has the given filters, if no callback is provided, it only check if there is no record for the relation
2778
2786
  * @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
2779
2787
  */
2780
2788
  andNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
2781
- andNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType$1 | BaseValues$1, maybeValue?: BaseValues$1): this;
2789
+ andNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2782
2790
  /**
2783
2791
  * @description Checks if the relation does not exist in the models and has the given filters, if no callback is provided, it only check if there is no record for the Relation
2784
2792
  * @warning All select statements are ignored, since we're only checking if the relation exists, a "select 1" will be added to the Query
2785
2793
  */
2786
2794
  orNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, cb?: (queryBuilder: ModelQueryBuilder<RelatedInstance<T, RelationKey>>) => void): this;
2787
- orNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType$1 | BaseValues$1, maybeValue?: BaseValues$1): this;
2795
+ orNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2788
2796
  /**
2789
2797
  * @description Returns a copy of the query builder instance.
2790
2798
  */
@@ -2797,7 +2805,7 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2797
2805
  protected getRelatedModelsForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): Promise<ModelWithoutRelations<T>[]>;
2798
2806
  protected getRelatedModelsQueryForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): ModelQueryBuilder<T>;
2799
2807
  protected getFilterValuesFromModelsForRelation(relation: Relation, models: T[]): any[];
2800
- protected applyHavingRelatedFilter(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, operator?: BinaryOperatorType$1, value?: BaseValues$1): void;
2808
+ protected applyHavingRelatedFilter(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, operator?: BinaryOperatorType, value?: BaseValues): void;
2801
2809
  protected addAdditionalColumnsToModel(row: any, typeofModel: typeof Model): Record<string, any>;
2802
2810
  private manyWithPerformance;
2803
2811
  private oneWithPerformance;
@@ -2810,8 +2818,6 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2810
2818
  private pluckWithPerformance;
2811
2819
  private softDeleteWithPerformance;
2812
2820
  private updateWithPerformance;
2813
- private insertWithPerformance;
2814
- private insertManyWithPerformance;
2815
2821
  private deleteWithPerformance;
2816
2822
  private truncateWithPerformance;
2817
2823
  }
@@ -2936,7 +2942,7 @@ declare class SqlDataSource extends DataSource {
2936
2942
  /**
2937
2943
  * @description Options provided in the sql data source initialization
2938
2944
  */
2939
- inputDetails: SqlDataSourceInput;
2945
+ inputDetails: SqlDataSourceInput<SqlDataSourceType>;
2940
2946
  /**
2941
2947
  * @description Establishes the default singleton connection used by default by all the Models, if not configuration is passed, env variables will be used instead
2942
2948
  * @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
@@ -2953,7 +2959,7 @@ declare class SqlDataSource extends DataSource {
2953
2959
  * User.query(); // Will use the default connection
2954
2960
  * ```
2955
2961
  */
2956
- static connect<T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
2962
+ static connect<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<U, T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
2957
2963
  static connect<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
2958
2964
  /**
2959
2965
  * @description Get's another database connection and return it, this won't be marked as the default connection used by the Models, for that use the static method `connect`
@@ -2968,7 +2974,7 @@ declare class SqlDataSource extends DataSource {
2968
2974
  * const user = await User.query({ connection: anotherSql }).many();
2969
2975
  * ```
2970
2976
  */
2971
- static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
2977
+ static connectToSecondarySource<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<U, T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
2972
2978
  static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
2973
2979
  /**
2974
2980
  * @description Creates a new connection and executes a callback with the new instance, the connection is automatically closed after the callback is executed, so it's lifespan is only inside the callback
@@ -2983,7 +2989,7 @@ declare class SqlDataSource extends DataSource {
2983
2989
  * });
2984
2990
  * ```
2985
2991
  */
2986
- static useConnection<T extends Record<string, SqlDataSourceModel> = {}>(connectionDetails: UseConnectionInput<T>, cb: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void>): Promise<void>;
2992
+ static useConnection<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(connectionDetails: UseConnectionInput<U, T>, cb: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void>): Promise<void>;
2987
2993
  /**
2988
2994
  * @description Returns the instance of the SqlDataSource
2989
2995
  * @throws {HysteriaError} If the connection is not established
@@ -2994,8 +3000,10 @@ declare class SqlDataSource extends DataSource {
2994
3000
  * @description Query builder from the SqlDataSource instance returns raw data from the database, the data is not parsed or serialized in any way
2995
3001
  * @description Optimal for performance-critical operations
2996
3002
  * @description Use Models to have type safety and serialization
3003
+ * @description Default soft delete column is "deleted_at" with stringed date value
3004
+ * @param table The table name to query from, must be in valid sql format `table` or `table as alias`
2997
3005
  */
2998
- static query(table: string, options?: RawModelOptions): QueryBuilder;
3006
+ static query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
2999
3007
  /**
3000
3008
  * @description Creates a table on the database, return the query to be executed to create the table
3001
3009
  */
@@ -3087,8 +3095,9 @@ declare class SqlDataSource extends DataSource {
3087
3095
  * @description Optimal for performance-critical operations
3088
3096
  * @description Use Models to have type safety and serialization
3089
3097
  * @description Default soft delete column is "deleted_at" with stringed date value
3098
+ * @param table The table name to query from, must be in valid sql format `table` or `table as alias`
3090
3099
  */
3091
- query(table: string, options?: RawModelOptions): QueryBuilder;
3100
+ query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
3092
3101
  /**
3093
3102
  * @description Return the query to alter the given table schema
3094
3103
  */
@@ -3162,7 +3171,7 @@ declare class SqlDataSource extends DataSource {
3162
3171
  * @description If there is an active global transaction, it will be rolled back
3163
3172
  */
3164
3173
  closeConnection(): Promise<void>;
3165
- getConnectionDetails(): SqlDataSourceInput;
3174
+ getConnectionDetails(): SqlDataSourceInput<SqlDataSourceType>;
3166
3175
  /**
3167
3176
  * @alias closeConnection
3168
3177
  */
@@ -3224,7 +3233,7 @@ declare class SqlDataSource extends DataSource {
3224
3233
  get registeredModels(): Record<string, typeof Model>;
3225
3234
  }
3226
3235
 
3227
- type SqlDriverSpecificOptions = Omit<DriverSpecificOptions, "mongoOptions" | "redisOptions">;
3236
+ type SqlDriverSpecificOptions<T extends DataSourceType> = Omit<DriverSpecificOptions<T>, "mongoOptions" | "redisOptions">;
3228
3237
  type MysqlConnectionInstance = Awaited<ReturnType<Mysql2Import["createPool"]>>;
3229
3238
  type PgPoolClientInstance = InstanceType<PgImport["Pool"]>;
3230
3239
  type SqliteConnectionInstance = InstanceType<Sqlite3Import["Database"]>;
@@ -3247,7 +3256,7 @@ type SqlDataSourceModel = typeof Model;
3247
3256
  * @description The input type for the SqlDataSource constructor
3248
3257
  * @description The connectionPolicies object is used to configure the connection policies for the sql data source
3249
3258
  */
3250
- type SqlDataSourceInput<T extends Record<string, SqlDataSourceModel> = {}> = {
3259
+ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3251
3260
  readonly type?: Exclude<DataSourceType, "mongo">;
3252
3261
  /**
3253
3262
  * @description Whether to log the sql queries and other debug information
@@ -3269,13 +3278,13 @@ type SqlDataSourceInput<T extends Record<string, SqlDataSourceModel> = {}> = {
3269
3278
  /**
3270
3279
  * @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
3271
3280
  */
3272
- driverOptions?: SqlDriverSpecificOptions;
3281
+ driverOptions?: SqlDriverSpecificOptions<D>;
3273
3282
  } & (MysqlSqlDataSourceInput | PostgresSqlDataSourceInput | SqliteDataSourceInput);
3274
- type UseConnectionInput<T extends Record<string, SqlDataSourceModel> = {}> = {
3283
+ type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3275
3284
  readonly type: Exclude<DataSourceType, "mongo">;
3276
3285
  readonly logs?: boolean;
3277
3286
  readonly models?: T;
3278
- readonly driverOptions?: SqlDriverSpecificOptions;
3287
+ readonly driverOptions?: SqlDriverSpecificOptions<D>;
3279
3288
  connectionPolicies?: ConnectionPolicies;
3280
3289
  queryFormatOptions?: FormatOptionsWithLanguage;
3281
3290
  } & (NotNullableMysqlSqlDataSourceInput | NotNullablePostgresSqlDataSourceInput | NotNullableSqliteDataSourceInput);
@@ -3295,6 +3304,9 @@ type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}> =
3295
3304
  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"> & {
3296
3305
  [key in keyof T]: T[key];
3297
3306
  };
3307
+ /** Only accepts formats `string` e `string as string` */
3308
+ type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
3309
+ type TableFormat<S extends string> = NoSpace<S> | (S extends `${infer L} as ${infer R}` ? `${NoSpace<L>} as ${NoSpace<R>}` : never);
3298
3310
 
3299
3311
  type AstParserType = {
3300
3312
  sql: string;
@@ -3381,6 +3393,10 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3381
3393
  data: number;
3382
3394
  time: number;
3383
3395
  }>;
3396
+ pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
3397
+ data: PluckReturnType<T, ModelKey<T>>;
3398
+ time: number;
3399
+ }>;
3384
3400
  };
3385
3401
  constructor(model: typeof Model, sqlDataSource?: SqlDataSource);
3386
3402
  /**
@@ -3540,7 +3556,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3540
3556
  /**
3541
3557
  * @description Overrides the from clause in the query.
3542
3558
  */
3543
- from(table: string, alias?: string): this;
3559
+ from<S extends string>(table: TableFormat<S>, alias?: string): this;
3544
3560
  from(cb: (qb: QueryBuilder<T>) => void, alias: string): this;
3545
3561
  /**
3546
3562
  * @description Adds a CTE to the query using a callback to build the subquery.
@@ -3575,6 +3591,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3575
3591
  update(data: Record<string, any>): Promise<number>;
3576
3592
  /**
3577
3593
  * @description Deletes all records from a table
3594
+ * @warning This operation does not trigger any hook
3578
3595
  */
3579
3596
  truncate(): Promise<void>;
3580
3597
  /**
@@ -3957,12 +3974,12 @@ declare abstract class Model extends Entity {
3957
3974
  */
3958
3975
  static combineProps<T extends Model>(sqlInstance: Partial<T>, data: Partial<T>): void;
3959
3976
  /**
3960
- * @description Adds a beforeFetch clause to the model, adding the ability to modify the query before fetching the data
3977
+ * @description Adds a beforeFetch clause to the model, adding the ability to modify the querybuilder before fetching the data
3961
3978
  */
3962
3979
  static beforeFetch?(queryBuilder: ModelQueryBuilder<any>): Promise<void> | void;
3963
3980
  /**
3964
- * @description Adds a beforeInsert clause to the model, adding the ability to modify the data before inserting the data
3965
- * @param {Model} data The single model to be inserted, in insertMany the hook will be called for each model
3981
+ * @description Adds a beforeInsert clause to the model modifying the data before inserting the data
3982
+ * @param {Model} data The model to be inserted, in insertMany the hook will be called for each model
3966
3983
  * @example
3967
3984
  * ```typescript
3968
3985
  * static async beforeInsert?(data: User): Promise<void> {
@@ -3971,25 +3988,40 @@ declare abstract class Model extends Entity {
3971
3988
  * ```
3972
3989
  */
3973
3990
  static beforeInsert?(data: any): Promise<void> | void;
3991
+ /**
3992
+ * @description Adds a beforeInsertMany clause to the model modifying the data before inserting the data
3993
+ * @param {Model[]} data The models to be inserted, in insertMany the hook will be called for each model
3994
+ * @example
3995
+ * ```typescript
3996
+ * static async beforeInsertMany?(data: User[]): Promise<void> {
3997
+ * data.forEach((user) => {
3998
+ * user.name = user.name.toUpperCase();
3999
+ * });
4000
+ * }
4001
+ * ```
4002
+ */
4003
+ static beforeInsertMany?(data: any[]): Promise<void> | void;
3974
4004
  /**
3975
4005
  * @description Adds a beforeUpdate clause to the model, adding the ability to modify the query before updating the data
4006
+ * @description Includes soft delete
3976
4007
  */
3977
4008
  static beforeUpdate?(queryBuilder: ModelQueryBuilder<any>): Promise<void> | void;
3978
4009
  /**
3979
4010
  * @description Adds a beforeDelete clause to the model, adding the ability to modify the query before deleting the data
4011
+ * @warning This hook does not include soft delete since it's an update operation
3980
4012
  */
3981
4013
  static beforeDelete?(queryBuilder: ModelQueryBuilder<any>): Promise<void> | void;
3982
4014
  /**
3983
4015
  * @description Adds a afterFetch clause to the model, adding the ability to modify the data after fetching the data
3984
- * @param {Model} data The single model to be fetched, in queries that return multiple models the hook will be called for each model
4016
+ * @param {Model} data Models fetched from the database, must always provide an implementation for an array of models regardless of the query result
3985
4017
  * @example
3986
4018
  * ```typescript
3987
- * static async afterFetch?(data: User): Promise<User> {
4019
+ * static async afterFetch?(data: User[]): Promise<User[]> {
3988
4020
  * return data;
3989
4021
  * }
3990
4022
  * ```
3991
4023
  */
3992
- static afterFetch?(data: any): Promise<any> | any;
4024
+ static afterFetch?(data: any[]): Promise<any[]> | any[];
3993
4025
  /**
3994
4026
  * @description Returns the columns of the model
3995
4027
  */
@@ -4270,10 +4302,16 @@ type RedisStorable = string | number | boolean | Buffer | Array<any> | Record<st
4270
4302
  * @description The RedisFetchable type is a type that can be fetched from redis
4271
4303
  */
4272
4304
  type RedisFetchable = string | number | boolean | Record<string, any> | Array<any> | null;
4305
+ /**
4306
+ * @description Type for Redis message handler callback
4307
+ */
4308
+ type RedisMessageHandler = (channel: string, message: string) => void;
4273
4309
  /**
4274
4310
  * @description The RedisDataSource class is a wrapper around the ioredis library that provides a simple interface to interact with a redis database
4275
4311
  */
4276
4312
  declare class RedisDataSource {
4313
+ static readonly OK = "OK";
4314
+ readonly OK = "OK";
4277
4315
  static isConnected: boolean;
4278
4316
  protected static redisDataSourceInstance: RedisDataSource;
4279
4317
  isConnected: boolean;
@@ -4382,6 +4420,610 @@ declare class RedisDataSource {
4382
4420
  * @returns {Promise<void>}
4383
4421
  */
4384
4422
  disconnect(forceError?: boolean): Promise<void>;
4423
+ /**
4424
+ * @description Adds one or more values to the beginning of a list
4425
+ * @param {string} key - The key of the list
4426
+ * @param {RedisStorable[]} values - The values to add
4427
+ * @returns {Promise<number>} - The length of the list after the push operation
4428
+ */
4429
+ static lpush(key: string, ...values: RedisStorable[]): Promise<number>;
4430
+ /**
4431
+ * @description Adds one or more values to the end of a list
4432
+ * @param {string} key - The key of the list
4433
+ * @param {RedisStorable[]} values - The values to add
4434
+ * @returns {Promise<number>} - The length of the list after the push operation
4435
+ */
4436
+ static rpush(key: string, ...values: RedisStorable[]): Promise<number>;
4437
+ /**
4438
+ * @description Removes and returns the first element of a list
4439
+ * @param {string} key - The key of the list
4440
+ * @returns {Promise<T | null>} - The popped value
4441
+ */
4442
+ static lpop<T = RedisFetchable>(key: string): Promise<T | null>;
4443
+ /**
4444
+ * @description Removes and returns the last element of a list
4445
+ * @param {string} key - The key of the list
4446
+ * @returns {Promise<T | null>} - The popped value
4447
+ */
4448
+ static rpop<T = RedisFetchable>(key: string): Promise<T | null>;
4449
+ /**
4450
+ * @description Gets a range of elements from a list
4451
+ * @param {string} key - The key of the list
4452
+ * @param {number} start - The starting index
4453
+ * @param {number} stop - The stopping index
4454
+ * @returns {Promise<T[]>} - Array of elements in the specified range
4455
+ */
4456
+ static lrange<T = RedisFetchable>(key: string, start: number, stop: number): Promise<T[]>;
4457
+ /**
4458
+ * @description Gets the length of a list
4459
+ * @param {string} key - The key of the list
4460
+ * @returns {Promise<number>} - The length of the list
4461
+ */
4462
+ static llen(key: string): Promise<number>;
4463
+ /**
4464
+ * @description Adds one or more values to the beginning of a list
4465
+ * @param {string} key - The key of the list
4466
+ * @param {RedisStorable[]} values - The values to add
4467
+ * @returns {Promise<number>} - The length of the list after the push operation
4468
+ */
4469
+ lpush(key: string, ...values: RedisStorable[]): Promise<number>;
4470
+ /**
4471
+ * @description Adds one or more values to the end of a list
4472
+ * @param {string} key - The key of the list
4473
+ * @param {RedisStorable[]} values - The values to add
4474
+ * @returns {Promise<number>} - The length of the list after the push operation
4475
+ */
4476
+ rpush(key: string, ...values: RedisStorable[]): Promise<number>;
4477
+ /**
4478
+ * @description Removes and returns the first element of a list
4479
+ * @param {string} key - The key of the list
4480
+ * @returns {Promise<T | null>} - The popped value
4481
+ */
4482
+ lpop<T = RedisFetchable>(key: string): Promise<T | null>;
4483
+ /**
4484
+ * @description Removes and returns the last element of a list
4485
+ * @param {string} key - The key of the list
4486
+ * @returns {Promise<T | null>} - The popped value
4487
+ */
4488
+ rpop<T = RedisFetchable>(key: string): Promise<T | null>;
4489
+ /**
4490
+ * @description Gets a range of elements from a list
4491
+ * @param {string} key - The key of the list
4492
+ * @param {number} start - The starting index
4493
+ * @param {number} stop - The stopping index
4494
+ * @returns {Promise<T[]>} - Array of elements in the specified range
4495
+ */
4496
+ lrange<T = RedisFetchable>(key: string, start: number, stop: number): Promise<T[]>;
4497
+ /**
4498
+ * @description Gets the length of a list
4499
+ * @param {string} key - The key of the list
4500
+ * @returns {Promise<number>} - The length of the list
4501
+ */
4502
+ llen(key: string): Promise<number>;
4503
+ /**
4504
+ * @description Sets field in the hash stored at key to value
4505
+ * @param {string} key - The key of the hash
4506
+ * @param {string} field - The field to set
4507
+ * @param {RedisStorable} value - The value to set
4508
+ * @returns {Promise<number>} - 1 if field is a new field and value was set, 0 if field already exists and the value was updated
4509
+ */
4510
+ static hset(key: string, field: string, value: RedisStorable): Promise<number>;
4511
+ /**
4512
+ * @description Sets multiple fields in the hash stored at key to their respective values
4513
+ * @param {string} key - The key of the hash
4514
+ * @param {Record<string, RedisStorable>} hash - Object containing field-value pairs
4515
+ * @returns {Promise<string>} - "OK" if successful
4516
+ */
4517
+ static hmset(key: string, hash: Record<string, RedisStorable>): Promise<string>;
4518
+ /**
4519
+ * @description Gets the value of a field in a hash
4520
+ * @param {string} key - The key of the hash
4521
+ * @param {string} field - The field to get
4522
+ * @returns {Promise<T | null>} - The value of the field
4523
+ */
4524
+ static hget<T = RedisFetchable>(key: string, field: string): Promise<T | null>;
4525
+ /**
4526
+ * @description Gets all the fields and values in a hash
4527
+ * @param {string} key - The key of the hash
4528
+ * @returns {Promise<Record<string, T>>} - Object containing field-value pairs
4529
+ */
4530
+ static hgetall<T = RedisFetchable>(key: string): Promise<Record<string, T>>;
4531
+ /**
4532
+ * @description Gets values for multiple fields in a hash
4533
+ * @param {string} key - The key of the hash
4534
+ * @param {string[]} fields - The fields to get
4535
+ * @returns {Promise<Array<T | null>>} - Array of values
4536
+ */
4537
+ static hmget<T = RedisFetchable>(key: string, ...fields: string[]): Promise<Array<T | null>>;
4538
+ /**
4539
+ * @description Deletes one or more fields from a hash
4540
+ * @param {string} key - The key of the hash
4541
+ * @param {string[]} fields - The fields to delete
4542
+ * @returns {Promise<number>} - The number of fields that were removed
4543
+ */
4544
+ static hdel(key: string, ...fields: string[]): Promise<number>;
4545
+ /**
4546
+ * @description Checks if a field exists in a hash
4547
+ * @param {string} key - The key of the hash
4548
+ * @param {string} field - The field to check
4549
+ * @returns {Promise<number>} - 1 if the field exists, 0 if not
4550
+ */
4551
+ static hexists(key: string, field: string): Promise<number>;
4552
+ /**
4553
+ * @description Gets all the fields in a hash
4554
+ * @param {string} key - The key of the hash
4555
+ * @returns {Promise<string[]>} - Array of field names
4556
+ */
4557
+ static hkeys(key: string): Promise<string[]>;
4558
+ /**
4559
+ * @description Gets the number of fields in a hash
4560
+ * @param {string} key - The key of the hash
4561
+ * @returns {Promise<number>} - The number of fields
4562
+ */
4563
+ static hlen(key: string): Promise<number>;
4564
+ /**
4565
+ * @description Sets field in the hash stored at key to value
4566
+ * @param {string} key - The key of the hash
4567
+ * @param {string} field - The field to set
4568
+ * @param {RedisStorable} value - The value to set
4569
+ * @returns {Promise<number>} - 1 if field is a new field and value was set, 0 if field already exists and the value was updated
4570
+ */
4571
+ hset(key: string, field: string, value: RedisStorable): Promise<number>;
4572
+ /**
4573
+ * @description Sets multiple fields in the hash stored at key to their respective values
4574
+ * @param {string} key - The key of the hash
4575
+ * @param {Record<string, RedisStorable>} hash - Object containing field-value pairs
4576
+ * @returns {Promise<string>} - "OK" if successful
4577
+ */
4578
+ hmset(key: string, hash: Record<string, RedisStorable>): Promise<string>;
4579
+ /**
4580
+ * @description Gets the value of a field in a hash
4581
+ * @param {string} key - The key of the hash
4582
+ * @param {string} field - The field to get
4583
+ * @returns {Promise<T | null>} - The value of the field
4584
+ */
4585
+ hget<T = RedisFetchable>(key: string, field: string): Promise<T | null>;
4586
+ /**
4587
+ * @description Gets all the fields and values in a hash
4588
+ * @param {string} key - The key of the hash
4589
+ * @returns {Promise<Record<string, T>>} - Object containing field-value pairs
4590
+ */
4591
+ hgetall<T = RedisFetchable>(key: string): Promise<Record<string, T>>;
4592
+ /**
4593
+ * @description Gets values for multiple fields in a hash
4594
+ * @param {string} key - The key of the hash
4595
+ * @param {string[]} fields - The fields to get
4596
+ * @returns {Promise<Array<T | null>>} - Array of values
4597
+ */
4598
+ hmget<T = RedisFetchable>(key: string, ...fields: string[]): Promise<Array<T | null>>;
4599
+ /**
4600
+ * @description Deletes one or more fields from a hash
4601
+ * @param {string} key - The key of the hash
4602
+ * @param {string[]} fields - The fields to delete
4603
+ * @returns {Promise<number>} - The number of fields that were removed
4604
+ */
4605
+ hdel(key: string, ...fields: string[]): Promise<number>;
4606
+ /**
4607
+ * @description Checks if a field exists in a hash
4608
+ * @param {string} key - The key of the hash
4609
+ * @param {string} field - The field to check
4610
+ * @returns {Promise<number>} - 1 if the field exists, 0 if not
4611
+ */
4612
+ hexists(key: string, field: string): Promise<number>;
4613
+ /**
4614
+ * @description Gets all the fields in a hash
4615
+ * @param {string} key - The key of the hash
4616
+ * @returns {Promise<string[]>} - Array of field names
4617
+ */
4618
+ hkeys(key: string): Promise<string[]>;
4619
+ /**
4620
+ * @description Gets the number of fields in a hash
4621
+ * @param {string} key - The key of the hash
4622
+ * @returns {Promise<number>} - The number of fields
4623
+ */
4624
+ hlen(key: string): Promise<number>;
4625
+ /**
4626
+ * @description Adds one or more members to a set
4627
+ * @param {string} key - The key of the set
4628
+ * @param {RedisStorable[]} members - The members to add
4629
+ * @returns {Promise<number>} - The number of elements added to the set
4630
+ */
4631
+ static sadd(key: string, ...members: RedisStorable[]): Promise<number>;
4632
+ /**
4633
+ * @description Gets all members of a set
4634
+ * @param {string} key - The key of the set
4635
+ * @returns {Promise<T[]>} - Array of set members
4636
+ */
4637
+ static smembers<T = RedisFetchable>(key: string): Promise<T[]>;
4638
+ /**
4639
+ * @description Removes one or more members from a set
4640
+ * @param {string} key - The key of the set
4641
+ * @param {RedisStorable[]} members - The members to remove
4642
+ * @returns {Promise<number>} - The number of members that were removed
4643
+ */
4644
+ static srem(key: string, ...members: RedisStorable[]): Promise<number>;
4645
+ /**
4646
+ * @description Determines whether a member belongs to a set
4647
+ * @param {string} key - The key of the set
4648
+ * @param {RedisStorable} member - The member to check
4649
+ * @returns {Promise<number>} - 1 if the member exists in the set, 0 if not
4650
+ */
4651
+ static sismember(key: string, member: RedisStorable): Promise<number>;
4652
+ /**
4653
+ * @description Gets the number of members in a set
4654
+ * @param {string} key - The key of the set
4655
+ * @returns {Promise<number>} - The number of members in the set
4656
+ */
4657
+ static scard(key: string): Promise<number>;
4658
+ /**
4659
+ * @description Returns the intersection of multiple sets
4660
+ * @param {string[]} keys - The keys of the sets to intersect
4661
+ * @returns {Promise<T[]>} - Array of members in the intersection
4662
+ */
4663
+ static sinter<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4664
+ /**
4665
+ * @description Returns the union of multiple sets
4666
+ * @param {string[]} keys - The keys of the sets to union
4667
+ * @returns {Promise<T[]>} - Array of members in the union
4668
+ */
4669
+ static sunion<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4670
+ /**
4671
+ * @description Returns the difference between the first set and all successive sets
4672
+ * @param {string[]} keys - The keys of the sets to diff
4673
+ * @returns {Promise<T[]>} - Array of members in the difference
4674
+ */
4675
+ static sdiff<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4676
+ /**
4677
+ * @description Adds one or more members to a set
4678
+ * @param {string} key - The key of the set
4679
+ * @param {RedisStorable[]} members - The members to add
4680
+ * @returns {Promise<number>} - The number of elements added to the set
4681
+ */
4682
+ sadd(key: string, ...members: RedisStorable[]): Promise<number>;
4683
+ /**
4684
+ * @description Gets all members of a set
4685
+ * @param {string} key - The key of the set
4686
+ * @returns {Promise<T[]>} - Array of set members
4687
+ */
4688
+ smembers<T = RedisFetchable>(key: string): Promise<T[]>;
4689
+ /**
4690
+ * @description Removes one or more members from a set
4691
+ * @param {string} key - The key of the set
4692
+ * @param {RedisStorable[]} members - The members to remove
4693
+ * @returns {Promise<number>} - The number of members that were removed
4694
+ */
4695
+ srem(key: string, ...members: RedisStorable[]): Promise<number>;
4696
+ /**
4697
+ * @description Determines whether a member belongs to a set
4698
+ * @param {string} key - The key of the set
4699
+ * @param {RedisStorable} member - The member to check
4700
+ * @returns {Promise<number>} - 1 if the member exists in the set, 0 if not
4701
+ */
4702
+ sismember(key: string, member: RedisStorable): Promise<number>;
4703
+ /**
4704
+ * @description Gets the number of members in a set
4705
+ * @param {string} key - The key of the set
4706
+ * @returns {Promise<number>} - The number of members in the set
4707
+ */
4708
+ scard(key: string): Promise<number>;
4709
+ /**
4710
+ * @description Returns the intersection of multiple sets
4711
+ * @param {string[]} keys - The keys of the sets to intersect
4712
+ * @returns {Promise<T[]>} - Array of members in the intersection
4713
+ */
4714
+ sinter<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4715
+ /**
4716
+ * @description Returns the union of multiple sets
4717
+ * @param {string[]} keys - The keys of the sets to union
4718
+ * @returns {Promise<T[]>} - Array of members in the union
4719
+ */
4720
+ sunion<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4721
+ /**
4722
+ * @description Returns the difference between the first set and all successive sets
4723
+ * @param {string[]} keys - The keys of the sets to diff
4724
+ * @returns {Promise<T[]>} - Array of members in the difference
4725
+ */
4726
+ sdiff<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4727
+ /**
4728
+ * @description Adds a member to a sorted set, or updates the score of an existing member
4729
+ * @param {string} key - The key of the sorted set
4730
+ * @param {number} score - The score associated with the member
4731
+ * @param {RedisStorable} member - The member to add or update
4732
+ * @returns {Promise<number>} - The number of new members added to the sorted set
4733
+ */
4734
+ static zadd(key: string, score: number, member: RedisStorable): Promise<number>;
4735
+ static zadd(key: string, scoreMembers: Array<[number, RedisStorable]>): Promise<number>;
4736
+ /**
4737
+ * @description Gets a range of members from a sorted set, ordered by score
4738
+ * @param {string} key - The key of the sorted set
4739
+ * @param {number} start - The starting index
4740
+ * @param {number} stop - The stopping index
4741
+ * @param {boolean} withScores - Whether to return the scores along with the members
4742
+ * @returns {Promise<T[] | Array<{value: T, score: number}>>} - Array of members or [member, score] pairs
4743
+ */
4744
+ static zrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4745
+ value: T;
4746
+ score: number;
4747
+ }>>;
4748
+ /**
4749
+ * @description Gets a range of members from a sorted set, ordered by score in descending order
4750
+ * @param {string} key - The key of the sorted set
4751
+ * @param {number} start - The starting index
4752
+ * @param {number} stop - The stopping index
4753
+ * @param {boolean} withScores - Whether to return the scores along with the members
4754
+ * @returns {Promise<T[] | Array<{value: T, score: number}>>} - Array of members or [member, score] pairs
4755
+ */
4756
+ static zrevrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4757
+ value: T;
4758
+ score: number;
4759
+ }>>;
4760
+ /**
4761
+ * @description Removes one or more members from a sorted set
4762
+ * @param {string} key - The key of the sorted set
4763
+ * @param {RedisStorable[]} members - The members to remove
4764
+ * @returns {Promise<number>} - The number of members removed
4765
+ */
4766
+ static zrem(key: string, ...members: RedisStorable[]): Promise<number>;
4767
+ /**
4768
+ * @description Gets the score of a member in a sorted set
4769
+ * @param {string} key - The key of the sorted set
4770
+ * @param {RedisStorable} member - The member to get the score of
4771
+ * @returns {Promise<number | null>} - The score of the member, or null if the member does not exist
4772
+ */
4773
+ static zscore(key: string, member: RedisStorable): Promise<number | null>;
4774
+ /**
4775
+ * @description Gets the number of members in a sorted set
4776
+ * @param {string} key - The key of the sorted set
4777
+ * @returns {Promise<number>} - The number of members in the sorted set
4778
+ */
4779
+ static zcard(key: string): Promise<number>;
4780
+ /**
4781
+ * @description Adds a member to a sorted set, or updates the score of an existing member
4782
+ * @param {string} key - The key of the sorted set
4783
+ * @param {number} score - The score associated with the member
4784
+ * @param {RedisStorable} member - The member to add or update
4785
+ * @returns {Promise<number>} - The number of new members added to the sorted set
4786
+ */
4787
+ zadd(key: string, score: number, member: RedisStorable): Promise<number>;
4788
+ zadd(key: string, scoreMembers: Array<[number, RedisStorable]>): Promise<number>;
4789
+ /**
4790
+ * @description Gets a range of members from a sorted set, ordered by score
4791
+ * @param {string} key - The key of the sorted set
4792
+ * @param {number} start - The starting index
4793
+ * @param {number} stop - The stopping index
4794
+ * @param {boolean} withScores - Whether to return the scores along with the members
4795
+ * @returns {Promise<T[] | Array<{value: T, score: number}>>} - Array of members or [member, score] pairs
4796
+ */
4797
+ zrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4798
+ value: T;
4799
+ score: number;
4800
+ }>>;
4801
+ /**
4802
+ * @description Gets a range of members from a sorted set, ordered by score in descending order
4803
+ * @param {string} key - The key of the sorted set
4804
+ * @param {number} start - The starting index
4805
+ * @param {number} stop - The stopping index
4806
+ * @param {boolean} withScores - Whether to return the scores along with the members
4807
+ * @returns {Promise<T[] | Array<{value: T, score: number}>>} - Array of members or [member, score] pairs
4808
+ */
4809
+ zrevrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4810
+ value: T;
4811
+ score: number;
4812
+ }>>;
4813
+ /**
4814
+ * @description Removes one or more members from a sorted set
4815
+ * @param {string} key - The key of the sorted set
4816
+ * @param {RedisStorable[]} members - The members to remove
4817
+ * @returns {Promise<number>} - The number of members removed
4818
+ */
4819
+ zrem(key: string, ...members: RedisStorable[]): Promise<number>;
4820
+ /**
4821
+ * @description Gets the score of a member in a sorted set
4822
+ * @param {string} key - The key of the sorted set
4823
+ * @param {RedisStorable} member - The member to get the score of
4824
+ * @returns {Promise<number | null>} - The score of the member, or null if the member does not exist
4825
+ */
4826
+ zscore(key: string, member: RedisStorable): Promise<number | null>;
4827
+ /**
4828
+ * @description Gets the number of members in a sorted set
4829
+ * @param {string} key - The key of the sorted set
4830
+ * @returns {Promise<number>} - The number of members in the sorted set
4831
+ */
4832
+ zcard(key: string): Promise<number>;
4833
+ /**
4834
+ * @description Subscribes to one or more channels
4835
+ * @param {string[]} channels - The channels to subscribe to
4836
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4837
+ * @returns {Promise<void>}
4838
+ */
4839
+ static subscribe(channels: string[], handler: RedisMessageHandler): Promise<void>;
4840
+ /**
4841
+ * @description Unsubscribes from one or more channels
4842
+ * @param {string[]} channels - The channels to unsubscribe from
4843
+ * @returns {Promise<void>}
4844
+ */
4845
+ static unsubscribe(...channels: string[]): Promise<void>;
4846
+ /**
4847
+ * @description Publishes a message to a channel
4848
+ * @param {string} channel - The channel to publish to
4849
+ * @param {RedisStorable} message - The message to publish
4850
+ * @returns {Promise<number>} - The number of clients that received the message
4851
+ */
4852
+ static publish(channel: string, message: RedisStorable): Promise<number>;
4853
+ /**
4854
+ * @description Pattern subscribe to channels
4855
+ * @param {string[]} patterns - The patterns to subscribe to
4856
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4857
+ * @returns {Promise<void>}
4858
+ */
4859
+ static psubscribe(patterns: string[], handler: RedisMessageHandler): Promise<void>;
4860
+ /**
4861
+ * @description Pattern unsubscribe from channels
4862
+ * @param {string[]} patterns - The patterns to unsubscribe from
4863
+ * @returns {Promise<void>}
4864
+ */
4865
+ static punsubscribe(...patterns: string[]): Promise<void>;
4866
+ /**
4867
+ * @description Subscribes to one or more channels
4868
+ * @param {string[]} channels - The channels to subscribe to
4869
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4870
+ * @returns {Promise<void>}
4871
+ */
4872
+ subscribe(channels: string[], handler: RedisMessageHandler): Promise<void>;
4873
+ /**
4874
+ * @description Unsubscribes from one or more channels
4875
+ * @param {string[]} channels - The channels to unsubscribe from
4876
+ * @returns {Promise<void>}
4877
+ */
4878
+ unsubscribe(...channels: string[]): Promise<void>;
4879
+ /**
4880
+ * @description Publishes a message to a channel
4881
+ * @param {string} channel - The channel to publish to
4882
+ * @param {RedisStorable} message - The message to publish
4883
+ * @returns {Promise<number>} - The number of clients that received the message
4884
+ */
4885
+ publish(channel: string, message: RedisStorable): Promise<number>;
4886
+ /**
4887
+ * @description Pattern subscribe to channels
4888
+ * @param {string[]} patterns - The patterns to subscribe to
4889
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4890
+ * @returns {Promise<void>}
4891
+ */
4892
+ psubscribe(patterns: string[], handler: RedisMessageHandler): Promise<void>;
4893
+ /**
4894
+ * @description Pattern unsubscribe from channels
4895
+ * @param {string[]} patterns - The patterns to unsubscribe from
4896
+ * @returns {Promise<void>}
4897
+ */
4898
+ punsubscribe(...patterns: string[]): Promise<void>;
4899
+ /**
4900
+ * @description Checks if a key exists
4901
+ * @param {string} key - The key to check
4902
+ * @returns {Promise<number>} - 1 if the key exists, 0 if not
4903
+ */
4904
+ static exists(key: string): Promise<number>;
4905
+ /**
4906
+ * @description Sets the expiration time of a key
4907
+ * @param {string} key - The key to set the expiration for
4908
+ * @param {number} seconds - The expiration time in seconds
4909
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4910
+ */
4911
+ static expire(key: string, seconds: number): Promise<number>;
4912
+ /**
4913
+ * @description Sets the expiration time of a key using a UNIX timestamp
4914
+ * @param {string} key - The key to set the expiration for
4915
+ * @param {number} timestamp - UNIX timestamp in seconds
4916
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4917
+ */
4918
+ static expireat(key: string, timestamp: number): Promise<number>;
4919
+ /**
4920
+ * @description Sets the expiration time of a key in milliseconds
4921
+ * @param {string} key - The key to set the expiration for
4922
+ * @param {number} milliseconds - The expiration time in milliseconds
4923
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4924
+ */
4925
+ static pexpire(key: string, milliseconds: number): Promise<number>;
4926
+ /**
4927
+ * @description Gets the remaining time to live of a key in seconds
4928
+ * @param {string} key - The key to get the TTL for
4929
+ * @returns {Promise<number>} - TTL in seconds, -1 if no expiry, -2 if key doesn't exist
4930
+ */
4931
+ static ttl(key: string): Promise<number>;
4932
+ /**
4933
+ * @description Gets the remaining time to live of a key in milliseconds
4934
+ * @param {string} key - The key to get the TTL for
4935
+ * @returns {Promise<number>} - TTL in milliseconds, -1 if no expiry, -2 if key doesn't exist
4936
+ */
4937
+ static pttl(key: string): Promise<number>;
4938
+ /**
4939
+ * @description Removes the expiration time from a key
4940
+ * @param {string} key - The key to persist
4941
+ * @returns {Promise<number>} - 1 if the timeout was removed, 0 if not
4942
+ */
4943
+ static persist(key: string): Promise<number>;
4944
+ /**
4945
+ * @description Gets all keys matching a pattern
4946
+ * @param {string} pattern - The pattern to match
4947
+ * @returns {Promise<string[]>} - Array of matching keys
4948
+ */
4949
+ static keys(pattern: string): Promise<string[]>;
4950
+ /**
4951
+ * @description Renames a key
4952
+ * @param {string} key - The key to rename
4953
+ * @param {string} newKey - The new name for the key
4954
+ * @returns {Promise<string>} - "OK" if successful
4955
+ */
4956
+ static rename(key: string, newKey: string): Promise<string>;
4957
+ /**
4958
+ * @description Returns the type of value stored at a key
4959
+ * @param {string} key - The key to check
4960
+ * @returns {Promise<string>} - Type of key (string, list, set, zset, hash, or none if key doesn't exist)
4961
+ */
4962
+ static type(key: string): Promise<string>;
4963
+ /**
4964
+ * @description Checks if a key exists
4965
+ * @param {string} key - The key to check
4966
+ * @returns {Promise<number>} - 1 if the key exists, 0 if not
4967
+ */
4968
+ exists(key: string): Promise<number>;
4969
+ /**
4970
+ * @description Sets the expiration time of a key
4971
+ * @param {string} key - The key to set the expiration for
4972
+ * @param {number} seconds - The expiration time in seconds
4973
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4974
+ */
4975
+ expire(key: string, seconds: number): Promise<number>;
4976
+ /**
4977
+ * @description Sets the expiration time of a key using a UNIX timestamp
4978
+ * @param {string} key - The key to set the expiration for
4979
+ * @param {number} timestamp - UNIX timestamp in seconds
4980
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4981
+ */
4982
+ expireat(key: string, timestamp: number): Promise<number>;
4983
+ /**
4984
+ * @description Sets the expiration time of a key in milliseconds
4985
+ * @param {string} key - The key to set the expiration for
4986
+ * @param {number} milliseconds - The expiration time in milliseconds
4987
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4988
+ */
4989
+ pexpire(key: string, milliseconds: number): Promise<number>;
4990
+ /**
4991
+ * @description Gets the remaining time to live of a key in seconds
4992
+ * @param {string} key - The key to get the TTL for
4993
+ * @returns {Promise<number>} - TTL in seconds, -1 if no expiry, -2 if key doesn't exist
4994
+ */
4995
+ ttl(key: string): Promise<number>;
4996
+ /**
4997
+ * @description Gets the remaining time to live of a key in milliseconds
4998
+ * @param {string} key - The key to get the TTL for
4999
+ * @returns {Promise<number>} - TTL in milliseconds, -1 if no expiry, -2 if key doesn't exist
5000
+ */
5001
+ pttl(key: string): Promise<number>;
5002
+ /**
5003
+ * @description Removes the expiration time from a key
5004
+ * @param {string} key - The key to persist
5005
+ * @returns {Promise<number>} - 1 if the timeout was removed, 0 if not
5006
+ */
5007
+ persist(key: string): Promise<number>;
5008
+ /**
5009
+ * @description Gets all keys matching a pattern
5010
+ * @param {string} pattern - The pattern to match
5011
+ * @returns {Promise<string[]>} - Array of matching keys
5012
+ */
5013
+ keys(pattern: string): Promise<string[]>;
5014
+ /**
5015
+ * @description Renames a key
5016
+ * @param {string} key - The key to rename
5017
+ * @param {string} newKey - The new name for the key
5018
+ * @returns {Promise<string>} - "OK" if successful
5019
+ */
5020
+ rename(key: string, newKey: string): Promise<string>;
5021
+ /**
5022
+ * @description Returns the type of value stored at a key
5023
+ * @param {string} key - The key to check
5024
+ * @returns {Promise<string>} - Type of key (string, list, set, zset, hash, or none if key doesn't exist)
5025
+ */
5026
+ type(key: string): Promise<string>;
4385
5027
  protected static getValue<T = RedisFetchable>(value: string | null): T | null;
4386
5028
  }
4387
5029
 
@@ -4454,7 +5096,7 @@ type WithPerformanceResult<R = any> = [string, R];
4454
5096
  */
4455
5097
  declare const withPerformance: <A extends any[], R>(fn: (...args: A) => Promise<R>, returnType?: "millis" | "seconds", fix?: number) => (...args: A) => Promise<WithPerformanceResult<R>>;
4456
5098
 
4457
- type HysteriaErrorCode = "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `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";
5099
+ type HysteriaErrorCode = "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `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";
4458
5100
 
4459
5101
  declare class HysteriaError extends Error {
4460
5102
  code: HysteriaErrorCode;
@@ -4478,4 +5120,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
4478
5120
  modelName: string;
4479
5121
  }>;
4480
5122
 
4481
- export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, 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, type FetchHooks, type GetConnectionReturnType, HysteriaError, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseConnectionInput, User, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };
5123
+ export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, 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, type FetchHooks, type GetConnectionReturnType, HysteriaError, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseConnectionInput, User, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };