forge-sql-orm 2.0.30 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1410 -81
- package/dist/ForgeSQLORM.js +1456 -60
- package/dist/ForgeSQLORM.js.map +1 -1
- package/dist/ForgeSQLORM.mjs +1440 -61
- package/dist/ForgeSQLORM.mjs.map +1 -1
- package/dist/core/ForgeSQLAnalyseOperations.d.ts +1 -1
- package/dist/core/ForgeSQLAnalyseOperations.d.ts.map +1 -1
- package/dist/core/ForgeSQLCacheOperations.d.ts +119 -0
- package/dist/core/ForgeSQLCacheOperations.d.ts.map +1 -0
- package/dist/core/ForgeSQLCrudOperations.d.ts +38 -22
- package/dist/core/ForgeSQLCrudOperations.d.ts.map +1 -1
- package/dist/core/ForgeSQLORM.d.ts +248 -13
- package/dist/core/ForgeSQLORM.d.ts.map +1 -1
- package/dist/core/ForgeSQLQueryBuilder.d.ts +394 -19
- package/dist/core/ForgeSQLQueryBuilder.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/drizzle/extensions/additionalActions.d.ts +90 -0
- package/dist/lib/drizzle/extensions/additionalActions.d.ts.map +1 -0
- package/dist/utils/cacheContextUtils.d.ts +123 -0
- package/dist/utils/cacheContextUtils.d.ts.map +1 -0
- package/dist/utils/cacheUtils.d.ts +56 -0
- package/dist/utils/cacheUtils.d.ts.map +1 -0
- package/dist/utils/sqlUtils.d.ts +8 -0
- package/dist/utils/sqlUtils.d.ts.map +1 -1
- package/dist/webtriggers/clearCacheSchedulerTrigger.d.ts +46 -0
- package/dist/webtriggers/clearCacheSchedulerTrigger.d.ts.map +1 -0
- package/dist/webtriggers/index.d.ts +1 -0
- package/dist/webtriggers/index.d.ts.map +1 -1
- package/package.json +15 -12
- package/src/core/ForgeSQLAnalyseOperations.ts +1 -1
- package/src/core/ForgeSQLCacheOperations.ts +195 -0
- package/src/core/ForgeSQLCrudOperations.ts +49 -40
- package/src/core/ForgeSQLORM.ts +743 -34
- package/src/core/ForgeSQLQueryBuilder.ts +456 -20
- package/src/index.ts +1 -1
- package/src/lib/drizzle/extensions/additionalActions.ts +852 -0
- package/src/lib/drizzle/extensions/types.d.ts +99 -10
- package/src/utils/cacheContextUtils.ts +212 -0
- package/src/utils/cacheUtils.ts +403 -0
- package/src/utils/sqlUtils.ts +42 -0
- package/src/webtriggers/clearCacheSchedulerTrigger.ts +79 -0
- package/src/webtriggers/index.ts +1 -0
- package/dist/lib/drizzle/extensions/selectAliased.d.ts +0 -9
- package/dist/lib/drizzle/extensions/selectAliased.d.ts.map +0 -1
- package/src/lib/drizzle/extensions/selectAliased.ts +0 -72
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ForgeSqlOperation, SchemaAnalyzeForgeSql } from "./ForgeSQLQueryBuilder";
|
|
2
2
|
import { Query } from "drizzle-orm";
|
|
3
3
|
import { ClusterStatementRowCamelCase, ExplainAnalyzeRow, SlowQueryNormalized } from "./SystemTables";
|
|
4
|
-
import { AnyMySqlTable } from "drizzle-orm/mysql-core
|
|
4
|
+
import { AnyMySqlTable } from "drizzle-orm/mysql-core";
|
|
5
5
|
/**
|
|
6
6
|
* Interface representing a raw slow query row from the database
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForgeSQLAnalyseOperations.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLAnalyseOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ForgeSQLAnalyseOperations.d.ts","sourceRoot":"","sources":["../../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AAC,4BAA4B,EAAE,CAAC;IAS1C;;;;;;OAMG;IACG,qBAAqB,CACzB,MAAM,EAAE,aAAa,EAAE,EACvB,QAAQ,CAAC,EAAE,IAAI,EACf,MAAM,CAAC,EAAE,IAAI,GACZ,OAAO,CAAC,4BAA4B,EAAE,CAAC;CAI3C"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { MySqlSelectDynamic } from "drizzle-orm/mysql-core/query-builders/select.types";
|
|
2
|
+
import { AnyMySqlSelectQueryBuilder, AnyMySqlTable } from "drizzle-orm/mysql-core";
|
|
3
|
+
import { CacheForgeSQL, ForgeSqlOperation, ForgeSqlOrmOptions } from "./ForgeSQLQueryBuilder";
|
|
4
|
+
import { InferInsertModel, SQL } from "drizzle-orm";
|
|
5
|
+
/**
|
|
6
|
+
* Implementation of cache operations for ForgeSQL ORM.
|
|
7
|
+
* Provides methods for cacheable database operations with automatic cache management.
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ **IMPORTANT**: All modification methods in this class use optimistic locking/versioning
|
|
10
|
+
* through `modifyWithVersioning()` internally. This ensures data consistency and prevents
|
|
11
|
+
* concurrent modification conflicts.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ForgeSQLCacheOperations implements CacheForgeSQL {
|
|
14
|
+
private readonly options;
|
|
15
|
+
private readonly forgeOperations;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new instance of ForgeSQLCacheOperations.
|
|
18
|
+
*
|
|
19
|
+
* @param options - Configuration options for the ORM
|
|
20
|
+
* @param forgeOperations - The ForgeSQL operations instance
|
|
21
|
+
*/
|
|
22
|
+
constructor(options: ForgeSqlOrmOptions, forgeOperations: ForgeSqlOperation);
|
|
23
|
+
/**
|
|
24
|
+
* Evicts cache for multiple tables using Drizzle table objects.
|
|
25
|
+
*
|
|
26
|
+
* @param tables - Array of Drizzle table objects to clear cache for
|
|
27
|
+
* @returns Promise that resolves when cache eviction is complete
|
|
28
|
+
* @throws Error if cacheEntityName is not configured
|
|
29
|
+
*/
|
|
30
|
+
evictCacheEntities(tables: AnyMySqlTable[]): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Evicts cache for multiple tables by their names.
|
|
33
|
+
*
|
|
34
|
+
* @param tables - Array of table names to clear cache for
|
|
35
|
+
* @returns Promise that resolves when cache eviction is complete
|
|
36
|
+
* @throws Error if cacheEntityName is not configured
|
|
37
|
+
*/
|
|
38
|
+
evictCache(tables: string[]): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Inserts records with optimistic locking/versioning and automatically evicts cache.
|
|
41
|
+
*
|
|
42
|
+
* This method uses `modifyWithVersioning().insert()` internally, providing:
|
|
43
|
+
* - Automatic version field initialization
|
|
44
|
+
* - Optimistic locking support
|
|
45
|
+
* - Cache eviction after successful operation
|
|
46
|
+
*
|
|
47
|
+
* @param schema - The table schema
|
|
48
|
+
* @param models - Array of entities to insert
|
|
49
|
+
* @param updateIfExists - Whether to update existing records
|
|
50
|
+
* @returns Promise that resolves to the number of inserted rows
|
|
51
|
+
* @throws Error if cacheEntityName is not configured
|
|
52
|
+
* @throws Error if optimistic locking check fails
|
|
53
|
+
*/
|
|
54
|
+
insert<T extends AnyMySqlTable>(schema: T, models: InferInsertModel<T>[], updateIfExists?: boolean): Promise<number>;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes a record by ID with optimistic locking/versioning and automatically evicts cache.
|
|
57
|
+
*
|
|
58
|
+
* This method uses `modifyWithVersioning().deleteById()` internally, providing:
|
|
59
|
+
* - Optimistic locking checks before deletion
|
|
60
|
+
* - Version field validation
|
|
61
|
+
* - Cache eviction after successful operation
|
|
62
|
+
*
|
|
63
|
+
* @param id - The ID of the record to delete
|
|
64
|
+
* @param schema - The table schema
|
|
65
|
+
* @returns Promise that resolves to the number of affected rows
|
|
66
|
+
* @throws Error if cacheEntityName is not configured
|
|
67
|
+
* @throws Error if optimistic locking check fails
|
|
68
|
+
*/
|
|
69
|
+
deleteById<T extends AnyMySqlTable>(id: unknown, schema: T): Promise<number>;
|
|
70
|
+
/**
|
|
71
|
+
* Updates a record by ID with optimistic locking/versioning and automatically evicts cache.
|
|
72
|
+
*
|
|
73
|
+
* This method uses `modifyWithVersioning().updateById()` internally, providing:
|
|
74
|
+
* - Optimistic locking checks before update
|
|
75
|
+
* - Version field incrementation
|
|
76
|
+
* - Cache eviction after successful operation
|
|
77
|
+
*
|
|
78
|
+
* @param entity - The entity with updated values (must include primary key)
|
|
79
|
+
* @param schema - The table schema
|
|
80
|
+
* @returns Promise that resolves to the number of affected rows
|
|
81
|
+
* @throws Error if cacheEntityName is not configured
|
|
82
|
+
* @throws Error if optimistic locking check fails
|
|
83
|
+
*/
|
|
84
|
+
updateById<T extends AnyMySqlTable>(entity: Partial<InferInsertModel<T>>, schema: T): Promise<number>;
|
|
85
|
+
/**
|
|
86
|
+
* Updates fields based on conditions with optimistic locking/versioning and automatically evicts cache.
|
|
87
|
+
*
|
|
88
|
+
* This method uses `modifyWithVersioning().updateFields()` internally, providing:
|
|
89
|
+
* - Optimistic locking support (if version field is configured)
|
|
90
|
+
* - Version field validation and incrementation
|
|
91
|
+
* - Cache eviction after successful operation
|
|
92
|
+
*
|
|
93
|
+
* @param updateData - The data to update
|
|
94
|
+
* @param schema - The table schema
|
|
95
|
+
* @param where - Optional WHERE conditions
|
|
96
|
+
* @returns Promise that resolves to the number of affected rows
|
|
97
|
+
* @throws Error if cacheEntityName is not configured
|
|
98
|
+
* @throws Error if optimistic locking check fails
|
|
99
|
+
*/
|
|
100
|
+
updateFields<T extends AnyMySqlTable>(updateData: Partial<InferInsertModel<T>>, schema: T, where?: SQL<unknown>): Promise<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Executes a query with caching support.
|
|
103
|
+
* First checks cache, if not found executes query and stores result in cache.
|
|
104
|
+
*
|
|
105
|
+
* @param query - The Drizzle query to execute
|
|
106
|
+
* @param cacheTtl - Optional cache TTL override
|
|
107
|
+
* @returns Promise that resolves to the query results
|
|
108
|
+
* @throws Error if cacheEntityName is not configured
|
|
109
|
+
*/
|
|
110
|
+
executeQuery<T extends MySqlSelectDynamic<AnyMySqlSelectQueryBuilder>>(query: T, cacheTtl?: number): Promise<Awaited<T>>;
|
|
111
|
+
/**
|
|
112
|
+
* Validates that cache configuration is properly set up.
|
|
113
|
+
*
|
|
114
|
+
* @throws Error if cacheEntityName is not configured
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
private validateCacheConfiguration;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=ForgeSQLCacheOperations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ForgeSQLCacheOperations.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLCacheOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AACxF,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAS,GAAG,EAAE,MAAM,aAAa,CAAC;AAI3D;;;;;;;GAOG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoB;IAEpD;;;;;OAKG;gBACS,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,iBAAiB;IAK3E;;;;;;OAMG;IACG,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOhE;;;;;;OAMG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD;;;;;;;;;;;;;;OAcG;IACG,MAAM,CAAC,CAAC,SAAS,aAAa,EAClC,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAC7B,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC,MAAM,CAAC;IASlB;;;;;;;;;;;;;OAaG;IACG,UAAU,CAAC,CAAC,SAAS,aAAa,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAOlF;;;;;;;;;;;;;OAaG;IACG,UAAU,CAAC,CAAC,SAAS,aAAa,EACtC,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EACpC,MAAM,EAAE,CAAC,GACR,OAAO,CAAC,MAAM,CAAC;IAOlB;;;;;;;;;;;;;;OAcG;IACG,YAAY,CAAC,CAAC,SAAS,aAAa,EACxC,UAAU,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EACxC,MAAM,EAAE,CAAC,EACT,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,GACnB,OAAO,CAAC,MAAM,CAAC;IASlB;;;;;;;;OAQG;IACG,YAAY,CAAC,CAAC,SAAS,kBAAkB,CAAC,0BAA0B,CAAC,EACzE,KAAK,EAAE,CAAC,EACR,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAYtB;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;CAKnC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ForgeSqlOrmOptions } from "..";
|
|
2
|
-
import {
|
|
3
|
-
import { AnyMySqlTable } from "drizzle-orm/mysql-core
|
|
4
|
-
import { InferInsertModel } from "drizzle-orm";
|
|
5
|
-
import { SQL } from "drizzle-orm";
|
|
2
|
+
import { VerioningModificationForgeSQL, ForgeSqlOperation } from "./ForgeSQLQueryBuilder";
|
|
3
|
+
import { AnyMySqlTable } from "drizzle-orm/mysql-core";
|
|
4
|
+
import { InferInsertModel, SQL } from "drizzle-orm";
|
|
6
5
|
/**
|
|
7
|
-
* Class implementing
|
|
6
|
+
* Class implementing Modification operations for ForgeSQL ORM.
|
|
8
7
|
* Provides methods for inserting, updating, and deleting records with support for optimistic locking.
|
|
9
8
|
*/
|
|
10
|
-
export declare class ForgeSQLCrudOperations implements
|
|
9
|
+
export declare class ForgeSQLCrudOperations implements VerioningModificationForgeSQL {
|
|
11
10
|
private readonly forgeOperations;
|
|
12
11
|
private readonly options;
|
|
13
12
|
/**
|
|
@@ -20,24 +19,35 @@ export declare class ForgeSQLCrudOperations implements CRUDForgeSQL {
|
|
|
20
19
|
* Inserts records into the database with optional versioning support.
|
|
21
20
|
* If a version field exists in the schema, versioning is applied.
|
|
22
21
|
*
|
|
22
|
+
* This method automatically handles:
|
|
23
|
+
* - Version field initialization for optimistic locking
|
|
24
|
+
* - Batch insertion for multiple records
|
|
25
|
+
* - Duplicate key handling with optional updates
|
|
26
|
+
*
|
|
23
27
|
* @template T - The type of the table schema
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @returns
|
|
28
|
-
* @throws
|
|
28
|
+
* @param schema - The entity schema
|
|
29
|
+
* @param models - Array of entities to insert
|
|
30
|
+
* @param updateIfExists - Whether to update existing records (default: false)
|
|
31
|
+
* @returns Promise that resolves to the number of inserted rows
|
|
32
|
+
* @throws Error if the insert operation fails
|
|
29
33
|
*/
|
|
30
34
|
insert<T extends AnyMySqlTable>(schema: T, models: InferInsertModel<T>[], updateIfExists?: boolean): Promise<number>;
|
|
31
35
|
/**
|
|
32
36
|
* Deletes a record by its primary key with optional version check.
|
|
33
37
|
* If versioning is enabled, ensures the record hasn't been modified since last read.
|
|
34
38
|
*
|
|
39
|
+
* This method automatically handles:
|
|
40
|
+
* - Single primary key validation
|
|
41
|
+
* - Optimistic locking checks if versioning is enabled
|
|
42
|
+
* - Version field validation before deletion
|
|
43
|
+
*
|
|
35
44
|
* @template T - The type of the table schema
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @returns
|
|
39
|
-
* @throws
|
|
40
|
-
* @throws
|
|
45
|
+
* @param id - The ID of the record to delete
|
|
46
|
+
* @param schema - The entity schema
|
|
47
|
+
* @returns Promise that resolves to the number of affected rows
|
|
48
|
+
* @throws Error if the delete operation fails
|
|
49
|
+
* @throws Error if multiple primary keys are found
|
|
50
|
+
* @throws Error if optimistic locking check fails
|
|
41
51
|
*/
|
|
42
52
|
deleteById<T extends AnyMySqlTable>(id: unknown, schema: T): Promise<number>;
|
|
43
53
|
/**
|
|
@@ -47,13 +57,19 @@ export declare class ForgeSQLCrudOperations implements CRUDForgeSQL {
|
|
|
47
57
|
* - Checks for concurrent modifications
|
|
48
58
|
* - Increments the version on successful update
|
|
49
59
|
*
|
|
60
|
+
* This method automatically handles:
|
|
61
|
+
* - Primary key validation
|
|
62
|
+
* - Version field retrieval and validation
|
|
63
|
+
* - Optimistic locking conflict detection
|
|
64
|
+
* - Version field incrementation
|
|
65
|
+
*
|
|
50
66
|
* @template T - The type of the table schema
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @returns
|
|
54
|
-
* @throws
|
|
55
|
-
* @throws
|
|
56
|
-
* @throws
|
|
67
|
+
* @param entity - The entity with updated values (must include primary key)
|
|
68
|
+
* @param schema - The entity schema
|
|
69
|
+
* @returns Promise that resolves to the number of affected rows
|
|
70
|
+
* @throws Error if the primary key is not provided
|
|
71
|
+
* @throws Error if optimistic locking check fails
|
|
72
|
+
* @throws Error if multiple primary keys are found
|
|
57
73
|
*/
|
|
58
74
|
updateById<T extends AnyMySqlTable>(entity: Partial<InferInsertModel<T>>, schema: T): Promise<number>;
|
|
59
75
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForgeSQLCrudOperations.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLCrudOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EA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,EACT,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,GACnB,OAAO,CAAC,MAAM,CAAC;IAclB;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAStB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAoD5B;;;;;;;;;OASG;YACW,iBAAiB;IAyB/B;;;;;;;OAOG;IACH,OAAO,CAAC,uBAAuB;IA0B/B;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;;;;;;;OAQG;YACW,WAAW;CA2B1B"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MySqlRemoteDatabase, MySqlRemotePreparedQueryHKT } from "drizzle-orm/mysql-proxy";
|
|
1
|
+
import { VerioningModificationForgeSQL, ForgeSqlOperation, ForgeSqlOrmOptions, SchemaAnalyzeForgeSql, SchemaSqlForgeSql } from "./ForgeSQLQueryBuilder";
|
|
2
|
+
import { MySqlRemoteDatabase, MySqlRemotePreparedQueryHKT, MySqlRemoteQueryResultHKT } from "drizzle-orm/mysql-proxy";
|
|
3
3
|
import type { SelectedFields } from "drizzle-orm/mysql-core/query-builders/select.types";
|
|
4
4
|
import { MySqlSelectBuilder } from "drizzle-orm/mysql-core";
|
|
5
|
+
import { DeleteAndEvictCacheType, InsertAndEvictCacheType, SelectAliasedCacheableType, SelectAliasedDistinctCacheableType, SelectAliasedDistinctType, SelectAliasedType, UpdateAndEvictCacheType } from "../lib/drizzle/extensions/additionalActions";
|
|
6
|
+
import { ForgeSQLCacheOperations } from "./ForgeSQLCacheOperations";
|
|
7
|
+
import type { MySqlTable } from "drizzle-orm/mysql-core/table";
|
|
8
|
+
import { MySqlDeleteBase, MySqlInsertBuilder, MySqlUpdateBuilder } from "drizzle-orm/mysql-core/query-builders";
|
|
9
|
+
import { SQLWrapper } from "drizzle-orm/sql/sql";
|
|
10
|
+
import { WithSubquery } from "drizzle-orm/subquery";
|
|
5
11
|
/**
|
|
6
12
|
* Public class that acts as a wrapper around the private ForgeSQLORMImpl.
|
|
7
13
|
* Provides a clean interface for working with Forge SQL and Drizzle ORM.
|
|
@@ -9,6 +15,140 @@ import { MySqlSelectBuilder } from "drizzle-orm/mysql-core";
|
|
|
9
15
|
declare class ForgeSQLORM implements ForgeSqlOperation {
|
|
10
16
|
private readonly ormInstance;
|
|
11
17
|
constructor(options?: ForgeSqlOrmOptions);
|
|
18
|
+
selectCacheable<TSelection extends SelectedFields>(fields: TSelection, cacheTTL?: number): MySqlSelectBuilder<TSelection, MySqlRemotePreparedQueryHKT>;
|
|
19
|
+
selectDistinctCacheable<TSelection extends SelectedFields>(fields: TSelection, cacheTTL?: number): MySqlSelectBuilder<TSelection, MySqlRemotePreparedQueryHKT>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a select query builder for all columns from a table with field aliasing support.
|
|
22
|
+
* This is a convenience method that automatically selects all columns from the specified table.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of the table
|
|
25
|
+
* @param table - The table to select from
|
|
26
|
+
* @returns Select query builder with all table columns and field aliasing support
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const users = await forgeSQL.selectFrom(userTable).where(eq(userTable.id, 1));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
selectFrom<T extends MySqlTable>(table: T): import("drizzle-orm/mysql-core").MySqlSelectBase<import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], T["_"]["columns"] extends undefined ? "single" : "partial", MySqlRemotePreparedQueryHKT, import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}, false, never, any, import("drizzle-orm/query-builders/select.types").BuildSubquerySelection<T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}>>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a select distinct query builder for all columns from a table with field aliasing support.
|
|
35
|
+
* This is a convenience method that automatically selects all distinct columns from the specified table.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The type of the table
|
|
38
|
+
* @param table - The table to select from
|
|
39
|
+
* @returns Select distinct query builder with all table columns and field aliasing support
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const uniqueUsers = await forgeSQL.selectDistinctFrom(userTable).where(eq(userTable.status, 'active'));
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
selectDistinctFrom<T extends MySqlTable>(table: T): import("drizzle-orm/mysql-core").MySqlSelectBase<import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], T["_"]["columns"] extends undefined ? "single" : "partial", MySqlRemotePreparedQueryHKT, import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}, false, never, any, import("drizzle-orm/query-builders/select.types").BuildSubquerySelection<T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}>>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a cacheable select query builder for all columns from a table with field aliasing and caching support.
|
|
48
|
+
* This is a convenience method that automatically selects all columns from the specified table with caching enabled.
|
|
49
|
+
*
|
|
50
|
+
* @template T - The type of the table
|
|
51
|
+
* @param table - The table to select from
|
|
52
|
+
* @param cacheTTL - Optional cache TTL override (defaults to global cache TTL)
|
|
53
|
+
* @returns Select query builder with all table columns, field aliasing, and caching support
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const users = await forgeSQL.selectCacheableFrom(userTable, 300).where(eq(userTable.id, 1));
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
selectCacheableFrom<T extends MySqlTable>(table: T, cacheTTL?: number): import("drizzle-orm/mysql-core").MySqlSelectBase<import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], T["_"]["columns"] extends undefined ? "single" : "partial", MySqlRemotePreparedQueryHKT, import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}, false, never, any, import("drizzle-orm/query-builders/select.types").BuildSubquerySelection<T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}>>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a cacheable select distinct query builder for all columns from a table with field aliasing and caching support.
|
|
62
|
+
* This is a convenience method that automatically selects all distinct columns from the specified table with caching enabled.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The type of the table
|
|
65
|
+
* @param table - The table to select from
|
|
66
|
+
* @param cacheTTL - Optional cache TTL override (defaults to global cache TTL)
|
|
67
|
+
* @returns Select distinct query builder with all table columns, field aliasing, and caching support
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const uniqueUsers = await forgeSQL.selectDistinctCacheableFrom(userTable, 300).where(eq(userTable.status, 'active'));
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
selectDistinctCacheableFrom<T extends MySqlTable>(table: T, cacheTTL?: number): import("drizzle-orm/mysql-core").MySqlSelectBase<import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], T["_"]["columns"] extends undefined ? "single" : "partial", MySqlRemotePreparedQueryHKT, import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}, false, never, any, import("drizzle-orm/query-builders/select.types").BuildSubquerySelection<T["_"]["columns"] extends undefined ? import("drizzle-orm/query-builders/select.types").GetSelectTableSelection<T> : T["_"]["columns"], import("drizzle-orm/query-builders/select.types").GetSelectTableName<T> extends string ? Record<string & import("drizzle-orm/query-builders/select.types").GetSelectTableName<T>, "not-null"> : {}>>;
|
|
74
|
+
executeWithCacheContext(cacheContext: () => Promise<void>): Promise<void>;
|
|
75
|
+
executeWithCacheContextAndReturnValue<T>(cacheContext: () => Promise<T>): Promise<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Executes operations within a local cache context.
|
|
78
|
+
* This provides in-memory caching for select queries within a single request scope.
|
|
79
|
+
*
|
|
80
|
+
* @param cacheContext - Function containing operations that will benefit from local caching
|
|
81
|
+
* @returns Promise that resolves when all operations are complete
|
|
82
|
+
*/
|
|
83
|
+
executeWithLocalContext(cacheContext: () => Promise<void>): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Executes operations within a local cache context and returns a value.
|
|
86
|
+
* This provides in-memory caching for select queries within a single request scope.
|
|
87
|
+
*
|
|
88
|
+
* @param cacheContext - Function containing operations that will benefit from local caching
|
|
89
|
+
* @returns Promise that resolves to the return value of the cacheContext function
|
|
90
|
+
*/
|
|
91
|
+
executeWithLocalCacheContextAndReturnValue<T>(cacheContext: () => Promise<T>): Promise<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Creates an insert query builder.
|
|
94
|
+
*
|
|
95
|
+
* ⚠️ **IMPORTANT**: This method does NOT support optimistic locking/versioning.
|
|
96
|
+
* For versioned inserts, use `modifyWithVersioning().insert()` or `modifyWithVersioningAndEvictCache().insert()` instead.
|
|
97
|
+
*
|
|
98
|
+
* @param table - The table to insert into
|
|
99
|
+
* @returns Insert query builder (no versioning, no cache management)
|
|
100
|
+
*/
|
|
101
|
+
insert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates an insert query builder that automatically evicts cache after execution.
|
|
104
|
+
*
|
|
105
|
+
* ⚠️ **IMPORTANT**: This method does NOT support optimistic locking/versioning.
|
|
106
|
+
* For versioned inserts, use `modifyWithVersioning().insert()` or `modifyWithVersioningAndEvictCache().insert()` instead.
|
|
107
|
+
*
|
|
108
|
+
* @param table - The table to insert into
|
|
109
|
+
* @returns Insert query builder with automatic cache eviction (no versioning)
|
|
110
|
+
*/
|
|
111
|
+
insertAndEvictCache<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates an update query builder.
|
|
114
|
+
*
|
|
115
|
+
* ⚠️ **IMPORTANT**: This method does NOT support optimistic locking/versioning.
|
|
116
|
+
* For versioned updates, use `modifyWithVersioning().updateById()` or `modifyWithVersioningAndEvictCache().updateById()` instead.
|
|
117
|
+
*
|
|
118
|
+
* @param table - The table to update
|
|
119
|
+
* @returns Update query builder (no versioning, no cache management)
|
|
120
|
+
*/
|
|
121
|
+
update<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT>;
|
|
122
|
+
/**
|
|
123
|
+
* Creates an update query builder that automatically evicts cache after execution.
|
|
124
|
+
*
|
|
125
|
+
* ⚠️ **IMPORTANT**: This method does NOT support optimistic locking/versioning.
|
|
126
|
+
* For versioned updates, use `modifyWithVersioning().updateById()` or `modifyWithVersioningAndEvictCache().updateById()` instead.
|
|
127
|
+
*
|
|
128
|
+
* @param table - The table to update
|
|
129
|
+
* @returns Update query builder with automatic cache eviction (no versioning)
|
|
130
|
+
*/
|
|
131
|
+
updateAndEvictCache<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT>;
|
|
132
|
+
/**
|
|
133
|
+
* Creates a delete query builder.
|
|
134
|
+
*
|
|
135
|
+
* ⚠️ **IMPORTANT**: This method does NOT support optimistic locking/versioning.
|
|
136
|
+
* For versioned deletes, use `modifyWithVersioning().deleteById()` or `modifyWithVersioningAndEvictCache().deleteById()` instead.
|
|
137
|
+
*
|
|
138
|
+
* @param table - The table to delete from
|
|
139
|
+
* @returns Delete query builder (no versioning, no cache management)
|
|
140
|
+
*/
|
|
141
|
+
delete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT>;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a delete query builder that automatically evicts cache after execution.
|
|
144
|
+
*
|
|
145
|
+
* ⚠️ **IMPORTANT**: This method does NOT support optimistic locking/versioning.
|
|
146
|
+
* For versioned deletes, use `modifyWithVersioning().deleteById()` or `modifyWithVersioningAndEvictCache().deleteById()` instead.
|
|
147
|
+
*
|
|
148
|
+
* @param table - The table to delete from
|
|
149
|
+
* @returns Delete query builder with automatic cache eviction (no versioning)
|
|
150
|
+
*/
|
|
151
|
+
deleteAndEvictCache<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT>;
|
|
12
152
|
/**
|
|
13
153
|
* Creates a select query with unique field aliases to prevent field name collisions in joins.
|
|
14
154
|
* This is particularly useful when working with Atlassian Forge SQL, which collapses fields with the same name in joined tables.
|
|
@@ -43,16 +183,11 @@ declare class ForgeSQLORM implements ForgeSqlOperation {
|
|
|
43
183
|
* ```
|
|
44
184
|
*/
|
|
45
185
|
selectDistinct<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, MySqlRemotePreparedQueryHKT>;
|
|
46
|
-
/**
|
|
47
|
-
* Proxies the `crud` method from `ForgeSQLORMImpl`.
|
|
48
|
-
* @returns CRUD operations.
|
|
49
|
-
*/
|
|
50
|
-
crud(): CRUDForgeSQL;
|
|
51
186
|
/**
|
|
52
187
|
* Proxies the `modify` method from `ForgeSQLORMImpl`.
|
|
53
188
|
* @returns Modify operations.
|
|
54
189
|
*/
|
|
55
|
-
|
|
190
|
+
modifyWithVersioning(): VerioningModificationForgeSQL;
|
|
56
191
|
/**
|
|
57
192
|
* Proxies the `fetch` method from `ForgeSQLORMImpl`.
|
|
58
193
|
* @returns Fetch operations.
|
|
@@ -63,16 +198,116 @@ declare class ForgeSQLORM implements ForgeSqlOperation {
|
|
|
63
198
|
* @returns {SchemaAnalyzeForgeSql} Interface for analyzing query performance
|
|
64
199
|
*/
|
|
65
200
|
analyze(): SchemaAnalyzeForgeSql;
|
|
201
|
+
/**
|
|
202
|
+
* Provides schema-level SQL cacheable operations with type safety.
|
|
203
|
+
* @returns {ForgeSQLCacheOperations} Interface for executing schema-bound SQL queries
|
|
204
|
+
*/
|
|
205
|
+
modifyWithVersioningAndEvictCache(): ForgeSQLCacheOperations;
|
|
66
206
|
/**
|
|
67
207
|
* Returns a Drizzle query builder instance.
|
|
68
208
|
*
|
|
69
|
-
* ⚠️ IMPORTANT: This method should be used ONLY for query building purposes.
|
|
70
|
-
* The returned instance should NOT be used for direct database connections or query execution.
|
|
71
|
-
* All database operations should be performed through Forge SQL's executeRawSQL or executeRawUpdateSQL methods.
|
|
72
|
-
*
|
|
73
209
|
* @returns A Drizzle query builder instance for query construction only.
|
|
74
210
|
*/
|
|
75
|
-
getDrizzleQueryBuilder(): MySqlRemoteDatabase<Record<string, unknown
|
|
211
|
+
getDrizzleQueryBuilder(): MySqlRemoteDatabase<Record<string, unknown>> & {
|
|
212
|
+
selectAliased: SelectAliasedType;
|
|
213
|
+
selectAliasedDistinct: SelectAliasedDistinctType;
|
|
214
|
+
executeQuery: import("../lib/drizzle/extensions/additionalActions").ExecuteQuery;
|
|
215
|
+
selectAliasedCacheable: SelectAliasedCacheableType;
|
|
216
|
+
selectAliasedDistinctCacheable: SelectAliasedDistinctCacheableType;
|
|
217
|
+
executeQueryCacheable: import("../lib/drizzle/extensions/additionalActions").ExecuteQueryCacheable;
|
|
218
|
+
insertWithCacheContext: InsertAndEvictCacheType;
|
|
219
|
+
insertAndEvictCache: InsertAndEvictCacheType;
|
|
220
|
+
updateAndEvictCache: UpdateAndEvictCacheType;
|
|
221
|
+
updateWithCacheContext: UpdateAndEvictCacheType;
|
|
222
|
+
deleteAndEvictCache: DeleteAndEvictCacheType;
|
|
223
|
+
deleteWithCacheContext: DeleteAndEvictCacheType;
|
|
224
|
+
selectFrom: import("../lib/drizzle/extensions/additionalActions").SelectAllFromAliasedType;
|
|
225
|
+
selectDistinctFrom: import("../lib/drizzle/extensions/additionalActions").SelectAllDistinctFromAliasedType;
|
|
226
|
+
selectFromCacheable: import("../lib/drizzle/extensions/additionalActions").SelectAllFromCacheableAliasedType;
|
|
227
|
+
selectDistinctFromCacheable: import("../lib/drizzle/extensions/additionalActions").SelectAllDistinctFromCacheableAliasedType;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Executes a raw SQL query with local cache support.
|
|
231
|
+
* This method provides local caching for raw SQL queries within the current invocation context.
|
|
232
|
+
* Results are cached locally and will be returned from cache on subsequent identical queries.
|
|
233
|
+
*
|
|
234
|
+
* @param query - The SQL query to execute (SQLWrapper or string)
|
|
235
|
+
* @returns Promise with query results
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* // Using SQLWrapper
|
|
239
|
+
* const result = await forgeSQL.execute(sql`SELECT * FROM users WHERE id = ${userId}`);
|
|
240
|
+
*
|
|
241
|
+
* // Using string
|
|
242
|
+
* const result = await forgeSQL.execute("SELECT * FROM users WHERE status = 'active'");
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
execute(query: SQLWrapper | string): Promise<import("drizzle-orm/mysql-proxy").MySqlRawQueryResult>;
|
|
246
|
+
/**
|
|
247
|
+
* Executes a raw SQL query with both local and global cache support.
|
|
248
|
+
* This method provides comprehensive caching for raw SQL queries:
|
|
249
|
+
* - Local cache: Within the current invocation context
|
|
250
|
+
* - Global cache: Cross-invocation caching using @forge/kvs
|
|
251
|
+
*
|
|
252
|
+
* @param query - The SQL query to execute (SQLWrapper or string)
|
|
253
|
+
* @param cacheTtl - Optional cache TTL override (defaults to global cache TTL)
|
|
254
|
+
* @returns Promise with query results
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* // Using SQLWrapper with custom TTL
|
|
258
|
+
* const result = await forgeSQL.executeCacheable(sql`SELECT * FROM users WHERE id = ${userId}`, 300);
|
|
259
|
+
*
|
|
260
|
+
* // Using string with default TTL
|
|
261
|
+
* const result = await forgeSQL.executeCacheable("SELECT * FROM users WHERE status = 'active'");
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
executeCacheable(query: SQLWrapper | string, cacheTtl?: number): Promise<import("drizzle-orm/mysql-proxy").MySqlRawQueryResult>;
|
|
265
|
+
/**
|
|
266
|
+
* Creates a Common Table Expression (CTE) builder for complex queries.
|
|
267
|
+
* CTEs allow you to define temporary named result sets that exist within the scope of a single query.
|
|
268
|
+
*
|
|
269
|
+
* @returns WithBuilder for creating CTEs
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const withQuery = forgeSQL.$with('userStats').as(
|
|
273
|
+
* forgeSQL.select({ userId: users.id, count: sql<number>`count(*)` })
|
|
274
|
+
* .from(users)
|
|
275
|
+
* .groupBy(users.id)
|
|
276
|
+
* );
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
get $with(): import("drizzle-orm/mysql-core").WithBuilder;
|
|
280
|
+
/**
|
|
281
|
+
* Creates a query builder that uses Common Table Expressions (CTEs).
|
|
282
|
+
* CTEs allow you to define temporary named result sets that exist within the scope of a single query.
|
|
283
|
+
*
|
|
284
|
+
* @param queries - Array of CTE queries created with $with()
|
|
285
|
+
* @returns Query builder with CTE support
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const withQuery = forgeSQL.$with('userStats').as(
|
|
289
|
+
* forgeSQL.select({ userId: users.id, count: sql<number>`count(*)` })
|
|
290
|
+
* .from(users)
|
|
291
|
+
* .groupBy(users.id)
|
|
292
|
+
* );
|
|
293
|
+
*
|
|
294
|
+
* const result = await forgeSQL.with(withQuery)
|
|
295
|
+
* .select({ userId: withQuery.userId, count: withQuery.count })
|
|
296
|
+
* .from(withQuery);
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
with(...queries: WithSubquery[]): {
|
|
300
|
+
select: {
|
|
301
|
+
(): MySqlSelectBuilder<undefined, MySqlRemotePreparedQueryHKT, "db">;
|
|
302
|
+
<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, MySqlRemotePreparedQueryHKT, "db">;
|
|
303
|
+
};
|
|
304
|
+
selectDistinct: {
|
|
305
|
+
(): MySqlSelectBuilder<undefined, MySqlRemotePreparedQueryHKT, "db">;
|
|
306
|
+
<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, MySqlRemotePreparedQueryHKT, "db">;
|
|
307
|
+
};
|
|
308
|
+
update: <TTable extends MySqlTable>(table: TTable) => MySqlUpdateBuilder<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT>;
|
|
309
|
+
delete: <TTable extends MySqlTable>(table: TTable) => MySqlDeleteBase<TTable, MySqlRemoteQueryResultHKT, MySqlRemotePreparedQueryHKT, false, never>;
|
|
310
|
+
};
|
|
76
311
|
}
|
|
77
312
|
export default ForgeSQLORM;
|
|
78
313
|
//# sourceMappingURL=ForgeSQLORM.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForgeSQLORM.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLORM.ts"],"names":[],"mappings":"AACA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"ForgeSQLORM.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLORM.ts"],"names":[],"mappings":"AACA,OAAO,EACL,6BAA6B,EAC7B,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAEL,mBAAmB,EACnB,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EAEvB,0BAA0B,EAC1B,kCAAkC,EAClC,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA4iBpD;;;GAGG;AACH,cAAM,WAAY,YAAW,iBAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;gBAEpC,OAAO,CAAC,EAAE,kBAAkB;IAIxC,eAAe,CAAC,UAAU,SAAS,cAAc,EAC/C,MAAM,EAAE,UAAU,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,kBAAkB,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