hysteria-orm 10.0.4 → 10.0.6

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
  */
@@ -2440,20 +2401,67 @@ type PaginateWithCursorOptions<T extends Model, K extends ModelKey<T>> = {
2440
2401
  operator?: "<" | ">";
2441
2402
  orderBy?: "asc" | "desc";
2442
2403
  };
2443
-
2444
- type UpdateOptions = {
2445
- ignoreBeforeUpdateHook?: boolean;
2404
+ type UpsertOptionsRawBuilder = {
2405
+ updateOnConflict?: boolean;
2406
+ returning?: string[];
2446
2407
  };
2447
2408
 
2448
- type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
2449
- type StartTransactionOptions = {
2450
- isolationLevel?: TransactionIsolationLevel;
2451
- };
2452
- /**
2453
- * @description Options for the transaction execution
2454
- */
2455
- type TransactionExecutionOptions = {
2456
- /**
2409
+ declare class SqlModelManagerUtils<T extends Model> {
2410
+ protected dbType: SqlDataSourceType;
2411
+ protected sqlDataSource: SqlDataSource;
2412
+ protected modelRelations: Relation[];
2413
+ protected modelRelationsMap: Map<string, Relation>;
2414
+ constructor(typeofModel: typeof Model, dbType: SqlDataSourceType, sqlDataSource: SqlDataSource);
2415
+ getRelationFromModel(relation: ModelRelation<T>): Relation;
2416
+ }
2417
+
2418
+ type PaginationMetadata = {
2419
+ perPage: number;
2420
+ currentPage: number;
2421
+ firstPage: number;
2422
+ isEmpty: boolean;
2423
+ total: number;
2424
+ lastPage: number;
2425
+ hasMorePages: boolean;
2426
+ hasPages: boolean;
2427
+ };
2428
+ type CursorPaginationMetadata = {
2429
+ perPage: number;
2430
+ firstPage: number;
2431
+ isEmpty: boolean;
2432
+ total: number;
2433
+ };
2434
+ type PaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
2435
+ paginationMetadata: PaginationMetadata;
2436
+ data: AnnotatedModel<T, A, R>[];
2437
+ };
2438
+ type CursorPaginatedData<T extends Model, A extends object = {}, R extends object = {}> = {
2439
+ paginationMetadata: CursorPaginationMetadata;
2440
+ data: AnnotatedModel<T, A, R>[];
2441
+ };
2442
+
2443
+ type DeleteOptions = {
2444
+ ignoreBeforeDeleteHook?: boolean;
2445
+ };
2446
+ type SoftDeleteOptions<T> = {
2447
+ column?: MongoCollectionKey<T>;
2448
+ value?: string | number | boolean;
2449
+ ignoreBeforeDeleteHook?: boolean;
2450
+ };
2451
+
2452
+ type UpdateOptions = {
2453
+ ignoreBeforeUpdateHook?: boolean;
2454
+ };
2455
+
2456
+ type TransactionIsolationLevel = "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
2457
+ type StartTransactionOptions = {
2458
+ isolationLevel?: TransactionIsolationLevel;
2459
+ };
2460
+ /**
2461
+ * @description Options for the transaction execution
2462
+ */
2463
+ type TransactionExecutionOptions = {
2464
+ /**
2457
2465
  * @description If true, the transaction will throw an error if it is inactive
2458
2466
  */
2459
2467
  throwErrorOnInactiveTransaction?: boolean;
@@ -2642,14 +2650,6 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2642
2650
  data: number;
2643
2651
  time: number;
2644
2652
  }>;
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
2653
  update: (data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions, returnType?: "millis" | "seconds") => Promise<{
2654
2654
  data: number;
2655
2655
  time: number;
@@ -2658,6 +2658,10 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2658
2658
  data: number;
2659
2659
  time: number;
2660
2660
  }>;
2661
+ pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
2662
+ data: PluckReturnType<T, ModelKey<T>>;
2663
+ time: number;
2664
+ }>;
2661
2665
  };
2662
2666
  constructor(model: typeof Model, sqlDataSource: SqlDataSource);
2663
2667
  /**
@@ -2683,8 +2687,16 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2683
2687
  }): Promise<AnnotatedModel<T, A, R>>;
2684
2688
  many(options?: ManyOptions): Promise<AnnotatedModel<T, A, R>[]>;
2685
2689
  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>>>;
2690
+ stream(options?: ManyOptions & StreamOptions): Promise<PassThrough & AsyncGenerator<AnnotatedModel<T, A, R>>>;
2687
2691
  paginateWithCursor<K extends ModelKey<T>>(page: number, options?: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[CursorPaginatedData<T, A, R>, Cursor<T, K>]>;
2692
+ /**
2693
+ * @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.
2694
+ */
2695
+ insert(...args: Parameters<typeof this$1.model.insert>): ReturnType<typeof this$1.model.insert>;
2696
+ /**
2697
+ * @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.
2698
+ */
2699
+ insertMany(...args: Parameters<typeof this$1.model.insertMany>): ReturnType<typeof this$1.model.insertMany>;
2688
2700
  update(data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions): Promise<number>;
2689
2701
  softDelete(options?: SoftDeleteOptions<T>): Promise<number>;
2690
2702
  delete(options?: DeleteOptions): Promise<number>;
@@ -2754,37 +2766,37 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2754
2766
  * @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
2767
  */
2756
2768
  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;
2769
+ havingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2758
2770
  /**
2759
2771
  * @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
2772
  * @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
2773
  */
2762
2774
  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;
2775
+ andHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2764
2776
  /**
2765
2777
  * @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
2778
  * @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
2779
  */
2768
2780
  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;
2781
+ orHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2770
2782
  /**
2771
2783
  * @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
2784
  * @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
2785
  */
2774
2786
  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;
2787
+ notHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2776
2788
  /**
2777
2789
  * @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
2790
  * @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
2791
  */
2780
2792
  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;
2793
+ andNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2782
2794
  /**
2783
2795
  * @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
2796
  * @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
2797
  */
2786
2798
  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;
2799
+ orNotHavingRelated<RelationKey extends ModelRelation<T>>(relation: RelationKey, operatorOrValue?: BinaryOperatorType | BaseValues, maybeValue?: BaseValues): this;
2788
2800
  /**
2789
2801
  * @description Returns a copy of the query builder instance.
2790
2802
  */
@@ -2797,7 +2809,7 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2797
2809
  protected getRelatedModelsForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): Promise<ModelWithoutRelations<T>[]>;
2798
2810
  protected getRelatedModelsQueryForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): ModelQueryBuilder<T>;
2799
2811
  protected getFilterValuesFromModelsForRelation(relation: Relation, models: T[]): any[];
2800
- protected applyHavingRelatedFilter(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, operator?: BinaryOperatorType$1, value?: BaseValues$1): void;
2812
+ protected applyHavingRelatedFilter(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, operator?: BinaryOperatorType, value?: BaseValues): void;
2801
2813
  protected addAdditionalColumnsToModel(row: any, typeofModel: typeof Model): Record<string, any>;
2802
2814
  private manyWithPerformance;
2803
2815
  private oneWithPerformance;
@@ -2810,8 +2822,6 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
2810
2822
  private pluckWithPerformance;
2811
2823
  private softDeleteWithPerformance;
2812
2824
  private updateWithPerformance;
2813
- private insertWithPerformance;
2814
- private insertManyWithPerformance;
2815
2825
  private deleteWithPerformance;
2816
2826
  private truncateWithPerformance;
2817
2827
  }
@@ -2936,7 +2946,7 @@ declare class SqlDataSource extends DataSource {
2936
2946
  /**
2937
2947
  * @description Options provided in the sql data source initialization
2938
2948
  */
2939
- inputDetails: SqlDataSourceInput;
2949
+ inputDetails: SqlDataSourceInput<SqlDataSourceType>;
2940
2950
  /**
2941
2951
  * @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
2952
  * @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 +2963,7 @@ declare class SqlDataSource extends DataSource {
2953
2963
  * User.query(); // Will use the default connection
2954
2964
  * ```
2955
2965
  */
2956
- static connect<T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
2966
+ 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
2967
  static connect<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
2958
2968
  /**
2959
2969
  * @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 +2978,7 @@ declare class SqlDataSource extends DataSource {
2968
2978
  * const user = await User.query({ connection: anotherSql }).many();
2969
2979
  * ```
2970
2980
  */
2971
- static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
2981
+ 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
2982
  static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
2973
2983
  /**
2974
2984
  * @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 +2993,7 @@ declare class SqlDataSource extends DataSource {
2983
2993
  * });
2984
2994
  * ```
2985
2995
  */
2986
- static useConnection<T extends Record<string, SqlDataSourceModel> = {}>(connectionDetails: UseConnectionInput<T>, cb: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void>): Promise<void>;
2996
+ static useConnection<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(connectionDetails: UseConnectionInput<U, T>, cb: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void>): Promise<void>;
2987
2997
  /**
2988
2998
  * @description Returns the instance of the SqlDataSource
2989
2999
  * @throws {HysteriaError} If the connection is not established
@@ -2994,8 +3004,10 @@ declare class SqlDataSource extends DataSource {
2994
3004
  * @description Query builder from the SqlDataSource instance returns raw data from the database, the data is not parsed or serialized in any way
2995
3005
  * @description Optimal for performance-critical operations
2996
3006
  * @description Use Models to have type safety and serialization
3007
+ * @description Default soft delete column is "deleted_at" with stringed date value
3008
+ * @param table The table name to query from, must be in valid sql format `table` or `table as alias`
2997
3009
  */
2998
- static query(table: string, options?: RawModelOptions): QueryBuilder;
3010
+ static query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
2999
3011
  /**
3000
3012
  * @description Creates a table on the database, return the query to be executed to create the table
3001
3013
  */
@@ -3087,8 +3099,9 @@ declare class SqlDataSource extends DataSource {
3087
3099
  * @description Optimal for performance-critical operations
3088
3100
  * @description Use Models to have type safety and serialization
3089
3101
  * @description Default soft delete column is "deleted_at" with stringed date value
3102
+ * @param table The table name to query from, must be in valid sql format `table` or `table as alias`
3090
3103
  */
3091
- query(table: string, options?: RawModelOptions): QueryBuilder;
3104
+ query<S extends string>(table: TableFormat<S>, options?: RawModelOptions): QueryBuilder;
3092
3105
  /**
3093
3106
  * @description Return the query to alter the given table schema
3094
3107
  */
@@ -3162,7 +3175,7 @@ declare class SqlDataSource extends DataSource {
3162
3175
  * @description If there is an active global transaction, it will be rolled back
3163
3176
  */
3164
3177
  closeConnection(): Promise<void>;
3165
- getConnectionDetails(): SqlDataSourceInput;
3178
+ getConnectionDetails(): SqlDataSourceInput<SqlDataSourceType>;
3166
3179
  /**
3167
3180
  * @alias closeConnection
3168
3181
  */
@@ -3224,7 +3237,7 @@ declare class SqlDataSource extends DataSource {
3224
3237
  get registeredModels(): Record<string, typeof Model>;
3225
3238
  }
3226
3239
 
3227
- type SqlDriverSpecificOptions = Omit<DriverSpecificOptions, "mongoOptions" | "redisOptions">;
3240
+ type SqlDriverSpecificOptions<T extends DataSourceType> = Omit<DriverSpecificOptions<T>, "mongoOptions" | "redisOptions">;
3228
3241
  type MysqlConnectionInstance = Awaited<ReturnType<Mysql2Import["createPool"]>>;
3229
3242
  type PgPoolClientInstance = InstanceType<PgImport["Pool"]>;
3230
3243
  type SqliteConnectionInstance = InstanceType<Sqlite3Import["Database"]>;
@@ -3247,7 +3260,7 @@ type SqlDataSourceModel = typeof Model;
3247
3260
  * @description The input type for the SqlDataSource constructor
3248
3261
  * @description The connectionPolicies object is used to configure the connection policies for the sql data source
3249
3262
  */
3250
- type SqlDataSourceInput<T extends Record<string, SqlDataSourceModel> = {}> = {
3263
+ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3251
3264
  readonly type?: Exclude<DataSourceType, "mongo">;
3252
3265
  /**
3253
3266
  * @description Whether to log the sql queries and other debug information
@@ -3269,13 +3282,13 @@ type SqlDataSourceInput<T extends Record<string, SqlDataSourceModel> = {}> = {
3269
3282
  /**
3270
3283
  * @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
3284
  */
3272
- driverOptions?: SqlDriverSpecificOptions;
3285
+ driverOptions?: SqlDriverSpecificOptions<D>;
3273
3286
  } & (MysqlSqlDataSourceInput | PostgresSqlDataSourceInput | SqliteDataSourceInput);
3274
- type UseConnectionInput<T extends Record<string, SqlDataSourceModel> = {}> = {
3287
+ type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3275
3288
  readonly type: Exclude<DataSourceType, "mongo">;
3276
3289
  readonly logs?: boolean;
3277
3290
  readonly models?: T;
3278
- readonly driverOptions?: SqlDriverSpecificOptions;
3291
+ readonly driverOptions?: SqlDriverSpecificOptions<D>;
3279
3292
  connectionPolicies?: ConnectionPolicies;
3280
3293
  queryFormatOptions?: FormatOptionsWithLanguage;
3281
3294
  } & (NotNullableMysqlSqlDataSourceInput | NotNullablePostgresSqlDataSourceInput | NotNullableSqliteDataSourceInput);
@@ -3295,6 +3308,9 @@ type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}> =
3295
3308
  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
3309
  [key in keyof T]: T[key];
3297
3310
  };
3311
+ /** Only accepts formats `string` e `string as string` */
3312
+ type NoSpace<S extends string> = S extends `${infer _} ${infer _}` ? never : S;
3313
+ type TableFormat<S extends string> = NoSpace<S> | (S extends `${infer L} as ${infer R}` ? `${NoSpace<L>} as ${NoSpace<R>}` : never);
3298
3314
 
3299
3315
  type AstParserType = {
3300
3316
  sql: string;
@@ -3312,6 +3328,47 @@ declare class AstParser {
3312
3328
  private mapCommonDbType;
3313
3329
  }
3314
3330
 
3331
+ declare class DeleteNode extends QueryNode {
3332
+ fromNode: FromNode;
3333
+ chainsWith: string;
3334
+ canKeywordBeSeenMultipleTimes: boolean;
3335
+ folder: string;
3336
+ file: string;
3337
+ constructor(fromNode: FromNode, isRawValue?: boolean);
3338
+ }
3339
+
3340
+ declare class InsertNode extends QueryNode {
3341
+ fromNode: FromNode;
3342
+ records: Record<string, any>[];
3343
+ returning?: string[];
3344
+ disableReturning: boolean;
3345
+ chainsWith: string;
3346
+ canKeywordBeSeenMultipleTimes: boolean;
3347
+ folder: string;
3348
+ file: string;
3349
+ constructor(fromNode: FromNode, records?: Record<string, any>[], returning?: string[], disableReturning?: boolean, isRawValue?: boolean);
3350
+ }
3351
+
3352
+ declare class TruncateNode extends QueryNode {
3353
+ fromNode: FromNode | string;
3354
+ chainsWith: string;
3355
+ canKeywordBeSeenMultipleTimes: boolean;
3356
+ folder: string;
3357
+ file: string;
3358
+ constructor(fromNode: FromNode | string, isRawValue?: boolean);
3359
+ }
3360
+
3361
+ declare class UpdateNode extends QueryNode {
3362
+ fromNode: FromNode;
3363
+ columns: string[];
3364
+ values: (any | RawNode)[];
3365
+ chainsWith: string;
3366
+ canKeywordBeSeenMultipleTimes: boolean;
3367
+ folder: string;
3368
+ file: string;
3369
+ constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
3370
+ }
3371
+
3315
3372
  declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3316
3373
  model: typeof Model;
3317
3374
  protected astParser: AstParser;
@@ -3321,6 +3378,10 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3321
3378
  protected isNestedCondition: boolean;
3322
3379
  protected mustRemoveAnnotations: boolean;
3323
3380
  protected interpreterUtils: InterpreterUtils;
3381
+ protected insertNode: InsertNode | null;
3382
+ protected updateNode: UpdateNode | null;
3383
+ protected deleteNode: DeleteNode | null;
3384
+ protected truncateNode: TruncateNode | null;
3324
3385
  /**
3325
3386
  * @description Performance methods that return the time that took to execute the query with the result
3326
3387
  */
@@ -3381,6 +3442,10 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3381
3442
  data: number;
3382
3443
  time: number;
3383
3444
  }>;
3445
+ pluck: (key: ModelKey<T>, returnType?: "millis" | "seconds") => Promise<{
3446
+ data: PluckReturnType<T, ModelKey<T>>;
3447
+ time: number;
3448
+ }>;
3384
3449
  };
3385
3450
  constructor(model: typeof Model, sqlDataSource?: SqlDataSource);
3386
3451
  /**
@@ -3540,7 +3605,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3540
3605
  /**
3541
3606
  * @description Overrides the from clause in the query.
3542
3607
  */
3543
- from(table: string, alias?: string): this;
3608
+ from<S extends string>(table: TableFormat<S>, alias?: string): this;
3544
3609
  from(cb: (qb: QueryBuilder<T>) => void, alias: string): this;
3545
3610
  /**
3546
3611
  * @description Adds a CTE to the query using a callback to build the subquery.
@@ -3568,6 +3633,22 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3568
3633
  * @returns raw driver response
3569
3634
  */
3570
3635
  insertMany(data: Record<string, any>[], returning?: string[]): Promise<T[]>;
3636
+ /**
3637
+ * @description Updates or creates a new record using upsert functionality
3638
+ * @param data The data to insert or update
3639
+ * @param searchCriteria The criteria to search for existing records
3640
+ * @param options Upsert options including updateOnConflict and returning columns
3641
+ * @returns The upserted record
3642
+ */
3643
+ upsert<O extends Record<string, any>>(data: O, searchCriteria: Partial<O>, options?: UpsertOptionsRawBuilder): Promise<T[]>;
3644
+ /**
3645
+ * @description Updates or creates multiple records using upsert functionality
3646
+ * @param conflictColumns The columns to check for conflicts
3647
+ * @param columnsToUpdate The columns to update on conflict
3648
+ * @param data Array of data objects to insert or update
3649
+ * @param options Upsert options including updateOnConflict and returning columns
3650
+ */
3651
+ upsertMany<O extends Record<string, any>>(conflictColumns: string[], columnsToUpdate: string[], data: O[], options?: UpsertOptionsRawBuilder): Promise<T[]>;
3571
3652
  /**
3572
3653
  * @description Updates records from a table
3573
3654
  * @returns the number of affected rows
@@ -3575,6 +3656,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
3575
3656
  update(data: Record<string, any>): Promise<number>;
3576
3657
  /**
3577
3658
  * @description Deletes all records from a table
3659
+ * @warning This operation does not trigger any hook
3578
3660
  */
3579
3661
  truncate(): Promise<void>;
3580
3662
  /**
@@ -3957,12 +4039,12 @@ declare abstract class Model extends Entity {
3957
4039
  */
3958
4040
  static combineProps<T extends Model>(sqlInstance: Partial<T>, data: Partial<T>): void;
3959
4041
  /**
3960
- * @description Adds a beforeFetch clause to the model, adding the ability to modify the query before fetching the data
4042
+ * @description Adds a beforeFetch clause to the model, adding the ability to modify the querybuilder before fetching the data
3961
4043
  */
3962
4044
  static beforeFetch?(queryBuilder: ModelQueryBuilder<any>): Promise<void> | void;
3963
4045
  /**
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
4046
+ * @description Adds a beforeInsert clause to the model modifying the data before inserting the data
4047
+ * @param {Model} data The model to be inserted, in insertMany the hook will be called for each model
3966
4048
  * @example
3967
4049
  * ```typescript
3968
4050
  * static async beforeInsert?(data: User): Promise<void> {
@@ -3971,25 +4053,40 @@ declare abstract class Model extends Entity {
3971
4053
  * ```
3972
4054
  */
3973
4055
  static beforeInsert?(data: any): Promise<void> | void;
4056
+ /**
4057
+ * @description Adds a beforeInsertMany clause to the model modifying the data before inserting the data
4058
+ * @param {Model[]} data The models to be inserted, in insertMany the hook will be called for each model
4059
+ * @example
4060
+ * ```typescript
4061
+ * static async beforeInsertMany?(data: User[]): Promise<void> {
4062
+ * data.forEach((user) => {
4063
+ * user.name = user.name.toUpperCase();
4064
+ * });
4065
+ * }
4066
+ * ```
4067
+ */
4068
+ static beforeInsertMany?(data: any[]): Promise<void> | void;
3974
4069
  /**
3975
4070
  * @description Adds a beforeUpdate clause to the model, adding the ability to modify the query before updating the data
4071
+ * @description Includes soft delete
3976
4072
  */
3977
4073
  static beforeUpdate?(queryBuilder: ModelQueryBuilder<any>): Promise<void> | void;
3978
4074
  /**
3979
4075
  * @description Adds a beforeDelete clause to the model, adding the ability to modify the query before deleting the data
4076
+ * @warning This hook does not include soft delete since it's an update operation
3980
4077
  */
3981
4078
  static beforeDelete?(queryBuilder: ModelQueryBuilder<any>): Promise<void> | void;
3982
4079
  /**
3983
4080
  * @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
4081
+ * @param {Model} data Models fetched from the database, must always provide an implementation for an array of models regardless of the query result
3985
4082
  * @example
3986
4083
  * ```typescript
3987
- * static async afterFetch?(data: User): Promise<User> {
4084
+ * static async afterFetch?(data: User[]): Promise<User[]> {
3988
4085
  * return data;
3989
4086
  * }
3990
4087
  * ```
3991
4088
  */
3992
- static afterFetch?(data: any): Promise<any> | any;
4089
+ static afterFetch?(data: any[]): Promise<any[]> | any[];
3993
4090
  /**
3994
4091
  * @description Returns the columns of the model
3995
4092
  */
@@ -4270,10 +4367,16 @@ type RedisStorable = string | number | boolean | Buffer | Array<any> | Record<st
4270
4367
  * @description The RedisFetchable type is a type that can be fetched from redis
4271
4368
  */
4272
4369
  type RedisFetchable = string | number | boolean | Record<string, any> | Array<any> | null;
4370
+ /**
4371
+ * @description Type for Redis message handler callback
4372
+ */
4373
+ type RedisMessageHandler = (channel: string, message: string) => void;
4273
4374
  /**
4274
4375
  * @description The RedisDataSource class is a wrapper around the ioredis library that provides a simple interface to interact with a redis database
4275
4376
  */
4276
4377
  declare class RedisDataSource {
4378
+ static readonly OK = "OK";
4379
+ readonly OK = "OK";
4277
4380
  static isConnected: boolean;
4278
4381
  protected static redisDataSourceInstance: RedisDataSource;
4279
4382
  isConnected: boolean;
@@ -4382,6 +4485,610 @@ declare class RedisDataSource {
4382
4485
  * @returns {Promise<void>}
4383
4486
  */
4384
4487
  disconnect(forceError?: boolean): Promise<void>;
4488
+ /**
4489
+ * @description Adds one or more values to the beginning of a list
4490
+ * @param {string} key - The key of the list
4491
+ * @param {RedisStorable[]} values - The values to add
4492
+ * @returns {Promise<number>} - The length of the list after the push operation
4493
+ */
4494
+ static lpush(key: string, ...values: RedisStorable[]): Promise<number>;
4495
+ /**
4496
+ * @description Adds one or more values to the end of a list
4497
+ * @param {string} key - The key of the list
4498
+ * @param {RedisStorable[]} values - The values to add
4499
+ * @returns {Promise<number>} - The length of the list after the push operation
4500
+ */
4501
+ static rpush(key: string, ...values: RedisStorable[]): Promise<number>;
4502
+ /**
4503
+ * @description Removes and returns the first element of a list
4504
+ * @param {string} key - The key of the list
4505
+ * @returns {Promise<T | null>} - The popped value
4506
+ */
4507
+ static lpop<T = RedisFetchable>(key: string): Promise<T | null>;
4508
+ /**
4509
+ * @description Removes and returns the last element of a list
4510
+ * @param {string} key - The key of the list
4511
+ * @returns {Promise<T | null>} - The popped value
4512
+ */
4513
+ static rpop<T = RedisFetchable>(key: string): Promise<T | null>;
4514
+ /**
4515
+ * @description Gets a range of elements from a list
4516
+ * @param {string} key - The key of the list
4517
+ * @param {number} start - The starting index
4518
+ * @param {number} stop - The stopping index
4519
+ * @returns {Promise<T[]>} - Array of elements in the specified range
4520
+ */
4521
+ static lrange<T = RedisFetchable>(key: string, start: number, stop: number): Promise<T[]>;
4522
+ /**
4523
+ * @description Gets the length of a list
4524
+ * @param {string} key - The key of the list
4525
+ * @returns {Promise<number>} - The length of the list
4526
+ */
4527
+ static llen(key: string): Promise<number>;
4528
+ /**
4529
+ * @description Adds one or more values to the beginning of a list
4530
+ * @param {string} key - The key of the list
4531
+ * @param {RedisStorable[]} values - The values to add
4532
+ * @returns {Promise<number>} - The length of the list after the push operation
4533
+ */
4534
+ lpush(key: string, ...values: RedisStorable[]): Promise<number>;
4535
+ /**
4536
+ * @description Adds one or more values to the end of a list
4537
+ * @param {string} key - The key of the list
4538
+ * @param {RedisStorable[]} values - The values to add
4539
+ * @returns {Promise<number>} - The length of the list after the push operation
4540
+ */
4541
+ rpush(key: string, ...values: RedisStorable[]): Promise<number>;
4542
+ /**
4543
+ * @description Removes and returns the first element of a list
4544
+ * @param {string} key - The key of the list
4545
+ * @returns {Promise<T | null>} - The popped value
4546
+ */
4547
+ lpop<T = RedisFetchable>(key: string): Promise<T | null>;
4548
+ /**
4549
+ * @description Removes and returns the last element of a list
4550
+ * @param {string} key - The key of the list
4551
+ * @returns {Promise<T | null>} - The popped value
4552
+ */
4553
+ rpop<T = RedisFetchable>(key: string): Promise<T | null>;
4554
+ /**
4555
+ * @description Gets a range of elements from a list
4556
+ * @param {string} key - The key of the list
4557
+ * @param {number} start - The starting index
4558
+ * @param {number} stop - The stopping index
4559
+ * @returns {Promise<T[]>} - Array of elements in the specified range
4560
+ */
4561
+ lrange<T = RedisFetchable>(key: string, start: number, stop: number): Promise<T[]>;
4562
+ /**
4563
+ * @description Gets the length of a list
4564
+ * @param {string} key - The key of the list
4565
+ * @returns {Promise<number>} - The length of the list
4566
+ */
4567
+ llen(key: string): Promise<number>;
4568
+ /**
4569
+ * @description Sets field in the hash stored at key to value
4570
+ * @param {string} key - The key of the hash
4571
+ * @param {string} field - The field to set
4572
+ * @param {RedisStorable} value - The value to set
4573
+ * @returns {Promise<number>} - 1 if field is a new field and value was set, 0 if field already exists and the value was updated
4574
+ */
4575
+ static hset(key: string, field: string, value: RedisStorable): Promise<number>;
4576
+ /**
4577
+ * @description Sets multiple fields in the hash stored at key to their respective values
4578
+ * @param {string} key - The key of the hash
4579
+ * @param {Record<string, RedisStorable>} hash - Object containing field-value pairs
4580
+ * @returns {Promise<string>} - "OK" if successful
4581
+ */
4582
+ static hmset(key: string, hash: Record<string, RedisStorable>): Promise<string>;
4583
+ /**
4584
+ * @description Gets the value of a field in a hash
4585
+ * @param {string} key - The key of the hash
4586
+ * @param {string} field - The field to get
4587
+ * @returns {Promise<T | null>} - The value of the field
4588
+ */
4589
+ static hget<T = RedisFetchable>(key: string, field: string): Promise<T | null>;
4590
+ /**
4591
+ * @description Gets all the fields and values in a hash
4592
+ * @param {string} key - The key of the hash
4593
+ * @returns {Promise<Record<string, T>>} - Object containing field-value pairs
4594
+ */
4595
+ static hgetall<T = RedisFetchable>(key: string): Promise<Record<string, T>>;
4596
+ /**
4597
+ * @description Gets values for multiple fields in a hash
4598
+ * @param {string} key - The key of the hash
4599
+ * @param {string[]} fields - The fields to get
4600
+ * @returns {Promise<Array<T | null>>} - Array of values
4601
+ */
4602
+ static hmget<T = RedisFetchable>(key: string, ...fields: string[]): Promise<Array<T | null>>;
4603
+ /**
4604
+ * @description Deletes one or more fields from a hash
4605
+ * @param {string} key - The key of the hash
4606
+ * @param {string[]} fields - The fields to delete
4607
+ * @returns {Promise<number>} - The number of fields that were removed
4608
+ */
4609
+ static hdel(key: string, ...fields: string[]): Promise<number>;
4610
+ /**
4611
+ * @description Checks if a field exists in a hash
4612
+ * @param {string} key - The key of the hash
4613
+ * @param {string} field - The field to check
4614
+ * @returns {Promise<number>} - 1 if the field exists, 0 if not
4615
+ */
4616
+ static hexists(key: string, field: string): Promise<number>;
4617
+ /**
4618
+ * @description Gets all the fields in a hash
4619
+ * @param {string} key - The key of the hash
4620
+ * @returns {Promise<string[]>} - Array of field names
4621
+ */
4622
+ static hkeys(key: string): Promise<string[]>;
4623
+ /**
4624
+ * @description Gets the number of fields in a hash
4625
+ * @param {string} key - The key of the hash
4626
+ * @returns {Promise<number>} - The number of fields
4627
+ */
4628
+ static hlen(key: string): Promise<number>;
4629
+ /**
4630
+ * @description Sets field in the hash stored at key to value
4631
+ * @param {string} key - The key of the hash
4632
+ * @param {string} field - The field to set
4633
+ * @param {RedisStorable} value - The value to set
4634
+ * @returns {Promise<number>} - 1 if field is a new field and value was set, 0 if field already exists and the value was updated
4635
+ */
4636
+ hset(key: string, field: string, value: RedisStorable): Promise<number>;
4637
+ /**
4638
+ * @description Sets multiple fields in the hash stored at key to their respective values
4639
+ * @param {string} key - The key of the hash
4640
+ * @param {Record<string, RedisStorable>} hash - Object containing field-value pairs
4641
+ * @returns {Promise<string>} - "OK" if successful
4642
+ */
4643
+ hmset(key: string, hash: Record<string, RedisStorable>): Promise<string>;
4644
+ /**
4645
+ * @description Gets the value of a field in a hash
4646
+ * @param {string} key - The key of the hash
4647
+ * @param {string} field - The field to get
4648
+ * @returns {Promise<T | null>} - The value of the field
4649
+ */
4650
+ hget<T = RedisFetchable>(key: string, field: string): Promise<T | null>;
4651
+ /**
4652
+ * @description Gets all the fields and values in a hash
4653
+ * @param {string} key - The key of the hash
4654
+ * @returns {Promise<Record<string, T>>} - Object containing field-value pairs
4655
+ */
4656
+ hgetall<T = RedisFetchable>(key: string): Promise<Record<string, T>>;
4657
+ /**
4658
+ * @description Gets values for multiple fields in a hash
4659
+ * @param {string} key - The key of the hash
4660
+ * @param {string[]} fields - The fields to get
4661
+ * @returns {Promise<Array<T | null>>} - Array of values
4662
+ */
4663
+ hmget<T = RedisFetchable>(key: string, ...fields: string[]): Promise<Array<T | null>>;
4664
+ /**
4665
+ * @description Deletes one or more fields from a hash
4666
+ * @param {string} key - The key of the hash
4667
+ * @param {string[]} fields - The fields to delete
4668
+ * @returns {Promise<number>} - The number of fields that were removed
4669
+ */
4670
+ hdel(key: string, ...fields: string[]): Promise<number>;
4671
+ /**
4672
+ * @description Checks if a field exists in a hash
4673
+ * @param {string} key - The key of the hash
4674
+ * @param {string} field - The field to check
4675
+ * @returns {Promise<number>} - 1 if the field exists, 0 if not
4676
+ */
4677
+ hexists(key: string, field: string): Promise<number>;
4678
+ /**
4679
+ * @description Gets all the fields in a hash
4680
+ * @param {string} key - The key of the hash
4681
+ * @returns {Promise<string[]>} - Array of field names
4682
+ */
4683
+ hkeys(key: string): Promise<string[]>;
4684
+ /**
4685
+ * @description Gets the number of fields in a hash
4686
+ * @param {string} key - The key of the hash
4687
+ * @returns {Promise<number>} - The number of fields
4688
+ */
4689
+ hlen(key: string): Promise<number>;
4690
+ /**
4691
+ * @description Adds one or more members to a set
4692
+ * @param {string} key - The key of the set
4693
+ * @param {RedisStorable[]} members - The members to add
4694
+ * @returns {Promise<number>} - The number of elements added to the set
4695
+ */
4696
+ static sadd(key: string, ...members: RedisStorable[]): Promise<number>;
4697
+ /**
4698
+ * @description Gets all members of a set
4699
+ * @param {string} key - The key of the set
4700
+ * @returns {Promise<T[]>} - Array of set members
4701
+ */
4702
+ static smembers<T = RedisFetchable>(key: string): Promise<T[]>;
4703
+ /**
4704
+ * @description Removes one or more members from a set
4705
+ * @param {string} key - The key of the set
4706
+ * @param {RedisStorable[]} members - The members to remove
4707
+ * @returns {Promise<number>} - The number of members that were removed
4708
+ */
4709
+ static srem(key: string, ...members: RedisStorable[]): Promise<number>;
4710
+ /**
4711
+ * @description Determines whether a member belongs to a set
4712
+ * @param {string} key - The key of the set
4713
+ * @param {RedisStorable} member - The member to check
4714
+ * @returns {Promise<number>} - 1 if the member exists in the set, 0 if not
4715
+ */
4716
+ static sismember(key: string, member: RedisStorable): Promise<number>;
4717
+ /**
4718
+ * @description Gets the number of members in a set
4719
+ * @param {string} key - The key of the set
4720
+ * @returns {Promise<number>} - The number of members in the set
4721
+ */
4722
+ static scard(key: string): Promise<number>;
4723
+ /**
4724
+ * @description Returns the intersection of multiple sets
4725
+ * @param {string[]} keys - The keys of the sets to intersect
4726
+ * @returns {Promise<T[]>} - Array of members in the intersection
4727
+ */
4728
+ static sinter<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4729
+ /**
4730
+ * @description Returns the union of multiple sets
4731
+ * @param {string[]} keys - The keys of the sets to union
4732
+ * @returns {Promise<T[]>} - Array of members in the union
4733
+ */
4734
+ static sunion<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4735
+ /**
4736
+ * @description Returns the difference between the first set and all successive sets
4737
+ * @param {string[]} keys - The keys of the sets to diff
4738
+ * @returns {Promise<T[]>} - Array of members in the difference
4739
+ */
4740
+ static sdiff<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4741
+ /**
4742
+ * @description Adds one or more members to a set
4743
+ * @param {string} key - The key of the set
4744
+ * @param {RedisStorable[]} members - The members to add
4745
+ * @returns {Promise<number>} - The number of elements added to the set
4746
+ */
4747
+ sadd(key: string, ...members: RedisStorable[]): Promise<number>;
4748
+ /**
4749
+ * @description Gets all members of a set
4750
+ * @param {string} key - The key of the set
4751
+ * @returns {Promise<T[]>} - Array of set members
4752
+ */
4753
+ smembers<T = RedisFetchable>(key: string): Promise<T[]>;
4754
+ /**
4755
+ * @description Removes one or more members from a set
4756
+ * @param {string} key - The key of the set
4757
+ * @param {RedisStorable[]} members - The members to remove
4758
+ * @returns {Promise<number>} - The number of members that were removed
4759
+ */
4760
+ srem(key: string, ...members: RedisStorable[]): Promise<number>;
4761
+ /**
4762
+ * @description Determines whether a member belongs to a set
4763
+ * @param {string} key - The key of the set
4764
+ * @param {RedisStorable} member - The member to check
4765
+ * @returns {Promise<number>} - 1 if the member exists in the set, 0 if not
4766
+ */
4767
+ sismember(key: string, member: RedisStorable): Promise<number>;
4768
+ /**
4769
+ * @description Gets the number of members in a set
4770
+ * @param {string} key - The key of the set
4771
+ * @returns {Promise<number>} - The number of members in the set
4772
+ */
4773
+ scard(key: string): Promise<number>;
4774
+ /**
4775
+ * @description Returns the intersection of multiple sets
4776
+ * @param {string[]} keys - The keys of the sets to intersect
4777
+ * @returns {Promise<T[]>} - Array of members in the intersection
4778
+ */
4779
+ sinter<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4780
+ /**
4781
+ * @description Returns the union of multiple sets
4782
+ * @param {string[]} keys - The keys of the sets to union
4783
+ * @returns {Promise<T[]>} - Array of members in the union
4784
+ */
4785
+ sunion<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4786
+ /**
4787
+ * @description Returns the difference between the first set and all successive sets
4788
+ * @param {string[]} keys - The keys of the sets to diff
4789
+ * @returns {Promise<T[]>} - Array of members in the difference
4790
+ */
4791
+ sdiff<T = RedisFetchable>(...keys: string[]): Promise<T[]>;
4792
+ /**
4793
+ * @description Adds a member to a sorted set, or updates the score of an existing member
4794
+ * @param {string} key - The key of the sorted set
4795
+ * @param {number} score - The score associated with the member
4796
+ * @param {RedisStorable} member - The member to add or update
4797
+ * @returns {Promise<number>} - The number of new members added to the sorted set
4798
+ */
4799
+ static zadd(key: string, score: number, member: RedisStorable): Promise<number>;
4800
+ static zadd(key: string, scoreMembers: Array<[number, RedisStorable]>): Promise<number>;
4801
+ /**
4802
+ * @description Gets a range of members from a sorted set, ordered by score
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
+ static zrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4810
+ value: T;
4811
+ score: number;
4812
+ }>>;
4813
+ /**
4814
+ * @description Gets a range of members from a sorted set, ordered by score in descending order
4815
+ * @param {string} key - The key of the sorted set
4816
+ * @param {number} start - The starting index
4817
+ * @param {number} stop - The stopping index
4818
+ * @param {boolean} withScores - Whether to return the scores along with the members
4819
+ * @returns {Promise<T[] | Array<{value: T, score: number}>>} - Array of members or [member, score] pairs
4820
+ */
4821
+ static zrevrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4822
+ value: T;
4823
+ score: number;
4824
+ }>>;
4825
+ /**
4826
+ * @description Removes one or more members from a sorted set
4827
+ * @param {string} key - The key of the sorted set
4828
+ * @param {RedisStorable[]} members - The members to remove
4829
+ * @returns {Promise<number>} - The number of members removed
4830
+ */
4831
+ static zrem(key: string, ...members: RedisStorable[]): Promise<number>;
4832
+ /**
4833
+ * @description Gets the score of a member in a sorted set
4834
+ * @param {string} key - The key of the sorted set
4835
+ * @param {RedisStorable} member - The member to get the score of
4836
+ * @returns {Promise<number | null>} - The score of the member, or null if the member does not exist
4837
+ */
4838
+ static zscore(key: string, member: RedisStorable): Promise<number | null>;
4839
+ /**
4840
+ * @description Gets the number of members in a sorted set
4841
+ * @param {string} key - The key of the sorted set
4842
+ * @returns {Promise<number>} - The number of members in the sorted set
4843
+ */
4844
+ static zcard(key: string): Promise<number>;
4845
+ /**
4846
+ * @description Adds a member to a sorted set, or updates the score of an existing member
4847
+ * @param {string} key - The key of the sorted set
4848
+ * @param {number} score - The score associated with the member
4849
+ * @param {RedisStorable} member - The member to add or update
4850
+ * @returns {Promise<number>} - The number of new members added to the sorted set
4851
+ */
4852
+ zadd(key: string, score: number, member: RedisStorable): Promise<number>;
4853
+ zadd(key: string, scoreMembers: Array<[number, RedisStorable]>): Promise<number>;
4854
+ /**
4855
+ * @description Gets a range of members from a sorted set, ordered by score
4856
+ * @param {string} key - The key of the sorted set
4857
+ * @param {number} start - The starting index
4858
+ * @param {number} stop - The stopping index
4859
+ * @param {boolean} withScores - Whether to return the scores along with the members
4860
+ * @returns {Promise<T[] | Array<{value: T, score: number}>>} - Array of members or [member, score] pairs
4861
+ */
4862
+ zrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4863
+ value: T;
4864
+ score: number;
4865
+ }>>;
4866
+ /**
4867
+ * @description Gets a range of members from a sorted set, ordered by score in descending order
4868
+ * @param {string} key - The key of the sorted set
4869
+ * @param {number} start - The starting index
4870
+ * @param {number} stop - The stopping index
4871
+ * @param {boolean} withScores - Whether to return the scores along with the members
4872
+ * @returns {Promise<T[] | Array<{value: T, score: number}>>} - Array of members or [member, score] pairs
4873
+ */
4874
+ zrevrange<T = RedisFetchable>(key: string, start: number, stop: number, withScores?: boolean): Promise<T[] | Array<{
4875
+ value: T;
4876
+ score: number;
4877
+ }>>;
4878
+ /**
4879
+ * @description Removes one or more members from a sorted set
4880
+ * @param {string} key - The key of the sorted set
4881
+ * @param {RedisStorable[]} members - The members to remove
4882
+ * @returns {Promise<number>} - The number of members removed
4883
+ */
4884
+ zrem(key: string, ...members: RedisStorable[]): Promise<number>;
4885
+ /**
4886
+ * @description Gets the score of a member in a sorted set
4887
+ * @param {string} key - The key of the sorted set
4888
+ * @param {RedisStorable} member - The member to get the score of
4889
+ * @returns {Promise<number | null>} - The score of the member, or null if the member does not exist
4890
+ */
4891
+ zscore(key: string, member: RedisStorable): Promise<number | null>;
4892
+ /**
4893
+ * @description Gets the number of members in a sorted set
4894
+ * @param {string} key - The key of the sorted set
4895
+ * @returns {Promise<number>} - The number of members in the sorted set
4896
+ */
4897
+ zcard(key: string): Promise<number>;
4898
+ /**
4899
+ * @description Subscribes to one or more channels
4900
+ * @param {string[]} channels - The channels to subscribe to
4901
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4902
+ * @returns {Promise<void>}
4903
+ */
4904
+ static subscribe(channels: string[], handler: RedisMessageHandler): Promise<void>;
4905
+ /**
4906
+ * @description Unsubscribes from one or more channels
4907
+ * @param {string[]} channels - The channels to unsubscribe from
4908
+ * @returns {Promise<void>}
4909
+ */
4910
+ static unsubscribe(...channels: string[]): Promise<void>;
4911
+ /**
4912
+ * @description Publishes a message to a channel
4913
+ * @param {string} channel - The channel to publish to
4914
+ * @param {RedisStorable} message - The message to publish
4915
+ * @returns {Promise<number>} - The number of clients that received the message
4916
+ */
4917
+ static publish(channel: string, message: RedisStorable): Promise<number>;
4918
+ /**
4919
+ * @description Pattern subscribe to channels
4920
+ * @param {string[]} patterns - The patterns to subscribe to
4921
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4922
+ * @returns {Promise<void>}
4923
+ */
4924
+ static psubscribe(patterns: string[], handler: RedisMessageHandler): Promise<void>;
4925
+ /**
4926
+ * @description Pattern unsubscribe from channels
4927
+ * @param {string[]} patterns - The patterns to unsubscribe from
4928
+ * @returns {Promise<void>}
4929
+ */
4930
+ static punsubscribe(...patterns: string[]): Promise<void>;
4931
+ /**
4932
+ * @description Subscribes to one or more channels
4933
+ * @param {string[]} channels - The channels to subscribe to
4934
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4935
+ * @returns {Promise<void>}
4936
+ */
4937
+ subscribe(channels: string[], handler: RedisMessageHandler): Promise<void>;
4938
+ /**
4939
+ * @description Unsubscribes from one or more channels
4940
+ * @param {string[]} channels - The channels to unsubscribe from
4941
+ * @returns {Promise<void>}
4942
+ */
4943
+ unsubscribe(...channels: string[]): Promise<void>;
4944
+ /**
4945
+ * @description Publishes a message to a channel
4946
+ * @param {string} channel - The channel to publish to
4947
+ * @param {RedisStorable} message - The message to publish
4948
+ * @returns {Promise<number>} - The number of clients that received the message
4949
+ */
4950
+ publish(channel: string, message: RedisStorable): Promise<number>;
4951
+ /**
4952
+ * @description Pattern subscribe to channels
4953
+ * @param {string[]} patterns - The patterns to subscribe to
4954
+ * @param {RedisMessageHandler} handler - The function to call when a message is received
4955
+ * @returns {Promise<void>}
4956
+ */
4957
+ psubscribe(patterns: string[], handler: RedisMessageHandler): Promise<void>;
4958
+ /**
4959
+ * @description Pattern unsubscribe from channels
4960
+ * @param {string[]} patterns - The patterns to unsubscribe from
4961
+ * @returns {Promise<void>}
4962
+ */
4963
+ punsubscribe(...patterns: string[]): Promise<void>;
4964
+ /**
4965
+ * @description Checks if a key exists
4966
+ * @param {string} key - The key to check
4967
+ * @returns {Promise<number>} - 1 if the key exists, 0 if not
4968
+ */
4969
+ static exists(key: string): Promise<number>;
4970
+ /**
4971
+ * @description Sets the expiration time of a key
4972
+ * @param {string} key - The key to set the expiration for
4973
+ * @param {number} seconds - The expiration time in seconds
4974
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4975
+ */
4976
+ static expire(key: string, seconds: number): Promise<number>;
4977
+ /**
4978
+ * @description Sets the expiration time of a key using a UNIX timestamp
4979
+ * @param {string} key - The key to set the expiration for
4980
+ * @param {number} timestamp - UNIX timestamp in seconds
4981
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4982
+ */
4983
+ static expireat(key: string, timestamp: number): Promise<number>;
4984
+ /**
4985
+ * @description Sets the expiration time of a key in milliseconds
4986
+ * @param {string} key - The key to set the expiration for
4987
+ * @param {number} milliseconds - The expiration time in milliseconds
4988
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
4989
+ */
4990
+ static pexpire(key: string, milliseconds: number): Promise<number>;
4991
+ /**
4992
+ * @description Gets the remaining time to live of a key in seconds
4993
+ * @param {string} key - The key to get the TTL for
4994
+ * @returns {Promise<number>} - TTL in seconds, -1 if no expiry, -2 if key doesn't exist
4995
+ */
4996
+ static ttl(key: string): Promise<number>;
4997
+ /**
4998
+ * @description Gets the remaining time to live of a key in milliseconds
4999
+ * @param {string} key - The key to get the TTL for
5000
+ * @returns {Promise<number>} - TTL in milliseconds, -1 if no expiry, -2 if key doesn't exist
5001
+ */
5002
+ static pttl(key: string): Promise<number>;
5003
+ /**
5004
+ * @description Removes the expiration time from a key
5005
+ * @param {string} key - The key to persist
5006
+ * @returns {Promise<number>} - 1 if the timeout was removed, 0 if not
5007
+ */
5008
+ static persist(key: string): Promise<number>;
5009
+ /**
5010
+ * @description Gets all keys matching a pattern
5011
+ * @param {string} pattern - The pattern to match
5012
+ * @returns {Promise<string[]>} - Array of matching keys
5013
+ */
5014
+ static keys(pattern: string): Promise<string[]>;
5015
+ /**
5016
+ * @description Renames a key
5017
+ * @param {string} key - The key to rename
5018
+ * @param {string} newKey - The new name for the key
5019
+ * @returns {Promise<string>} - "OK" if successful
5020
+ */
5021
+ static rename(key: string, newKey: string): Promise<string>;
5022
+ /**
5023
+ * @description Returns the type of value stored at a key
5024
+ * @param {string} key - The key to check
5025
+ * @returns {Promise<string>} - Type of key (string, list, set, zset, hash, or none if key doesn't exist)
5026
+ */
5027
+ static type(key: string): Promise<string>;
5028
+ /**
5029
+ * @description Checks if a key exists
5030
+ * @param {string} key - The key to check
5031
+ * @returns {Promise<number>} - 1 if the key exists, 0 if not
5032
+ */
5033
+ exists(key: string): Promise<number>;
5034
+ /**
5035
+ * @description Sets the expiration time of a key
5036
+ * @param {string} key - The key to set the expiration for
5037
+ * @param {number} seconds - The expiration time in seconds
5038
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
5039
+ */
5040
+ expire(key: string, seconds: number): Promise<number>;
5041
+ /**
5042
+ * @description Sets the expiration time of a key using a UNIX timestamp
5043
+ * @param {string} key - The key to set the expiration for
5044
+ * @param {number} timestamp - UNIX timestamp in seconds
5045
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
5046
+ */
5047
+ expireat(key: string, timestamp: number): Promise<number>;
5048
+ /**
5049
+ * @description Sets the expiration time of a key in milliseconds
5050
+ * @param {string} key - The key to set the expiration for
5051
+ * @param {number} milliseconds - The expiration time in milliseconds
5052
+ * @returns {Promise<number>} - 1 if the timeout was set, 0 if not
5053
+ */
5054
+ pexpire(key: string, milliseconds: number): Promise<number>;
5055
+ /**
5056
+ * @description Gets the remaining time to live of a key in seconds
5057
+ * @param {string} key - The key to get the TTL for
5058
+ * @returns {Promise<number>} - TTL in seconds, -1 if no expiry, -2 if key doesn't exist
5059
+ */
5060
+ ttl(key: string): Promise<number>;
5061
+ /**
5062
+ * @description Gets the remaining time to live of a key in milliseconds
5063
+ * @param {string} key - The key to get the TTL for
5064
+ * @returns {Promise<number>} - TTL in milliseconds, -1 if no expiry, -2 if key doesn't exist
5065
+ */
5066
+ pttl(key: string): Promise<number>;
5067
+ /**
5068
+ * @description Removes the expiration time from a key
5069
+ * @param {string} key - The key to persist
5070
+ * @returns {Promise<number>} - 1 if the timeout was removed, 0 if not
5071
+ */
5072
+ persist(key: string): Promise<number>;
5073
+ /**
5074
+ * @description Gets all keys matching a pattern
5075
+ * @param {string} pattern - The pattern to match
5076
+ * @returns {Promise<string[]>} - Array of matching keys
5077
+ */
5078
+ keys(pattern: string): Promise<string[]>;
5079
+ /**
5080
+ * @description Renames a key
5081
+ * @param {string} key - The key to rename
5082
+ * @param {string} newKey - The new name for the key
5083
+ * @returns {Promise<string>} - "OK" if successful
5084
+ */
5085
+ rename(key: string, newKey: string): Promise<string>;
5086
+ /**
5087
+ * @description Returns the type of value stored at a key
5088
+ * @param {string} key - The key to check
5089
+ * @returns {Promise<string>} - Type of key (string, list, set, zset, hash, or none if key doesn't exist)
5090
+ */
5091
+ type(key: string): Promise<string>;
4385
5092
  protected static getValue<T = RedisFetchable>(value: string | null): T | null;
4386
5093
  }
4387
5094
 
@@ -4454,7 +5161,7 @@ type WithPerformanceResult<R = any> = [string, R];
4454
5161
  */
4455
5162
  declare const withPerformance: <A extends any[], R>(fn: (...args: A) => Promise<R>, returnType?: "millis" | "seconds", fix?: number) => (...args: A) => Promise<WithPerformanceResult<R>>;
4456
5163
 
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";
5164
+ 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
5165
 
4459
5166
  declare class HysteriaError extends Error {
4460
5167
  code: HysteriaErrorCode;
@@ -4478,4 +5185,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
4478
5185
  modelName: string;
4479
5186
  }>;
4480
5187
 
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 };
5188
+ 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 };