forge-sql-orm 1.0.31 → 2.0.0
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 +216 -695
- package/dist/ForgeSQLORM.js +526 -564
- package/dist/ForgeSQLORM.js.map +1 -1
- package/dist/ForgeSQLORM.mjs +527 -554
- package/dist/ForgeSQLORM.mjs.map +1 -1
- package/dist/core/ForgeSQLCrudOperations.d.ts +101 -130
- package/dist/core/ForgeSQLCrudOperations.d.ts.map +1 -1
- package/dist/core/ForgeSQLORM.d.ts +11 -10
- package/dist/core/ForgeSQLORM.d.ts.map +1 -1
- package/dist/core/ForgeSQLQueryBuilder.d.ts +275 -111
- package/dist/core/ForgeSQLQueryBuilder.d.ts.map +1 -1
- package/dist/core/ForgeSQLSelectOperations.d.ts +65 -22
- package/dist/core/ForgeSQLSelectOperations.d.ts.map +1 -1
- package/dist/core/SystemTables.d.ts +59 -0
- package/dist/core/SystemTables.d.ts.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/utils/sqlUtils.d.ts +53 -6
- package/dist/utils/sqlUtils.d.ts.map +1 -1
- package/dist-cli/cli.js +461 -397
- package/dist-cli/cli.js.map +1 -1
- package/dist-cli/cli.mjs +461 -397
- package/dist-cli/cli.mjs.map +1 -1
- package/package.json +21 -27
- package/src/core/ForgeSQLCrudOperations.ts +360 -473
- package/src/core/ForgeSQLORM.ts +38 -79
- package/src/core/ForgeSQLQueryBuilder.ts +255 -132
- package/src/core/ForgeSQLSelectOperations.ts +185 -72
- package/src/core/SystemTables.ts +7 -0
- package/src/index.ts +1 -2
- package/src/utils/sqlUtils.ts +164 -22
- package/dist/core/ComplexQuerySchemaBuilder.d.ts +0 -38
- package/dist/core/ComplexQuerySchemaBuilder.d.ts.map +0 -1
- package/dist/knex/index.d.ts +0 -4
- package/dist/knex/index.d.ts.map +0 -1
- package/src/core/ComplexQuerySchemaBuilder.ts +0 -63
- package/src/knex/index.ts +0 -4
|
@@ -1,164 +1,328 @@
|
|
|
1
1
|
import { UpdateQueryResponse } from "@forge/sql";
|
|
2
|
-
import type { EntityName, LoggingOptions, QBFilterQuery } from "..";
|
|
3
|
-
import type { EntitySchema } from "@mikro-orm/core/metadata/EntitySchema";
|
|
4
|
-
import type { QueryBuilder } from "@mikro-orm/knex/query";
|
|
5
|
-
import type { Knex } from "knex";
|
|
6
|
-
import { EntityKey, EntityProperty } from "@mikro-orm/core";
|
|
7
2
|
import { SqlParameters } from "@forge/sql/out/sql-statement";
|
|
8
|
-
import {
|
|
3
|
+
import { MySql2Database } from "drizzle-orm/mysql2/driver";
|
|
4
|
+
import { AnyMySqlSelectQueryBuilder, AnyMySqlTable } from "drizzle-orm/mysql-core";
|
|
5
|
+
import { MySqlSelectDynamic } from "drizzle-orm/mysql-core/query-builders/select.types";
|
|
6
|
+
import { InferInsertModel, SQL } from "drizzle-orm";
|
|
9
7
|
/**
|
|
10
8
|
* Interface representing the main ForgeSQL operations.
|
|
9
|
+
* Provides access to CRUD operations and schema-level SQL operations.
|
|
11
10
|
*/
|
|
12
11
|
export interface ForgeSqlOperation extends QueryBuilderForgeSql {
|
|
13
12
|
/**
|
|
14
|
-
* Provides CRUD operations.
|
|
13
|
+
* Provides CRUD (Create, Read, Update, Delete) operations.
|
|
14
|
+
* @returns {CRUDForgeSQL} Interface for performing CRUD operations
|
|
15
15
|
*/
|
|
16
16
|
crud(): CRUDForgeSQL;
|
|
17
17
|
/**
|
|
18
18
|
* Provides schema-level SQL fetch operations.
|
|
19
|
+
* @returns {SchemaSqlForgeSql} Interface for executing schema-bound SQL queries
|
|
19
20
|
*/
|
|
20
21
|
fetch(): SchemaSqlForgeSql;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
+
* Interface for Query Builder operations.
|
|
25
|
+
* Provides access to the underlying Drizzle ORM query builder.
|
|
24
26
|
*/
|
|
25
|
-
export interface
|
|
26
|
-
/**
|
|
27
|
-
* Enables logging of raw SQL queries in the Atlassian Forge Developer Console.
|
|
28
|
-
*/
|
|
29
|
-
logRawSqlQuery?: boolean;
|
|
27
|
+
export interface QueryBuilderForgeSql {
|
|
30
28
|
/**
|
|
31
|
-
*
|
|
29
|
+
* Creates a new query builder for the given entity.
|
|
30
|
+
* @returns {MySql2Database<Record<string, unknown>>} The Drizzle database instance for building queries
|
|
32
31
|
*/
|
|
33
|
-
|
|
32
|
+
getDrizzleQueryBuilder(): MySql2Database<Record<string, unknown>>;
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
|
-
* Interface for
|
|
35
|
+
* Interface for CRUD (Create, Read, Update, Delete) operations.
|
|
36
|
+
* Provides methods for basic database operations with support for optimistic locking.
|
|
37
37
|
*/
|
|
38
|
-
export interface
|
|
39
|
-
/**
|
|
40
|
-
* Executes a schema-bound SQL query and maps the result to the specified entity schema.
|
|
41
|
-
* @param query - The SQL query to execute.
|
|
42
|
-
* @param schema - The entity schema.
|
|
43
|
-
* @returns A list of mapped entity objects.
|
|
44
|
-
*/
|
|
45
|
-
executeSchemaSQL<T extends object>(query: string, schema: EntitySchema<T>): Promise<T[]>;
|
|
38
|
+
export interface CRUDForgeSQL {
|
|
46
39
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
49
|
-
* @param schema - The entity schema
|
|
50
|
-
* @
|
|
40
|
+
* Inserts multiple records into the database.
|
|
41
|
+
* @template T - The type of the table schema
|
|
42
|
+
* @param {T} schema - The entity schema
|
|
43
|
+
* @param {Partial<InferInsertModel<T>>[]} models - The list of entities to insert
|
|
44
|
+
* @param {boolean} [updateIfExists] - Whether to update the row if it already exists (default: false)
|
|
45
|
+
* @returns {Promise<number>} The number of inserted rows
|
|
46
|
+
* @throws {Error} If the insert operation fails
|
|
51
47
|
*/
|
|
52
|
-
|
|
48
|
+
insert<T extends AnyMySqlTable>(schema: T, models: Partial<InferInsertModel<T>>[], updateIfExists?: boolean): Promise<number>;
|
|
53
49
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
* @
|
|
50
|
+
* Deletes a record by its ID.
|
|
51
|
+
* @template T - The type of the table schema
|
|
52
|
+
* @param {unknown} id - The ID of the record to delete
|
|
53
|
+
* @param {T} schema - The entity schema
|
|
54
|
+
* @returns {Promise<number>} The number of rows affected
|
|
55
|
+
* @throws {Error} If the delete operation fails
|
|
57
56
|
*/
|
|
58
|
-
|
|
57
|
+
deleteById<T extends AnyMySqlTable>(id: unknown, schema: T): Promise<number>;
|
|
59
58
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
59
|
+
* Updates a record by its ID with optimistic locking support.
|
|
60
|
+
* If a version field is defined in the schema, versioning is applied:
|
|
61
|
+
* - the current record version is retrieved
|
|
62
|
+
* - checked for concurrent modifications
|
|
63
|
+
* - and then incremented
|
|
64
|
+
*
|
|
65
|
+
* @template T - The type of the table schema
|
|
66
|
+
* @param {Partial<InferInsertModel<T>>} entity - The entity with updated values
|
|
67
|
+
* @param {T} schema - The entity schema
|
|
68
|
+
* @returns {Promise<number>} The number of rows affected
|
|
69
|
+
* @throws {Error} If the primary key is not included in the update fields
|
|
70
|
+
* @throws {Error} If optimistic locking check fails
|
|
64
71
|
*/
|
|
65
|
-
|
|
72
|
+
updateById<T extends AnyMySqlTable>(entity: Partial<InferInsertModel<T>>, schema: T): Promise<number>;
|
|
66
73
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
74
|
+
* Updates specified fields of records based on provided conditions.
|
|
75
|
+
* If the "where" parameter is not provided, the WHERE clause is built from the entity fields
|
|
76
|
+
* that are not included in the list of fields to update.
|
|
77
|
+
*
|
|
78
|
+
* @template T - The type of the table schema
|
|
79
|
+
* @param {Partial<InferInsertModel<T>>} updateData - The object containing values to update
|
|
80
|
+
* @param {T} schema - The entity schema
|
|
81
|
+
* @param {SQL<unknown>} [where] - Optional filtering conditions for the WHERE clause
|
|
82
|
+
* @returns {Promise<number>} The number of affected rows
|
|
83
|
+
* @throws {Error} If no filtering criteria are provided
|
|
84
|
+
* @throws {Error} If the update operation fails
|
|
71
85
|
*/
|
|
72
|
-
|
|
86
|
+
updateFields<T extends AnyMySqlTable>(updateData: Partial<InferInsertModel<T>>, schema: T, where?: SQL<unknown>): Promise<number>;
|
|
73
87
|
}
|
|
74
88
|
/**
|
|
75
|
-
* Interface for
|
|
89
|
+
* Interface for schema-level SQL operations.
|
|
90
|
+
* Provides methods for executing SQL queries with schema binding and type safety.
|
|
76
91
|
*/
|
|
77
|
-
export interface
|
|
92
|
+
export interface SchemaSqlForgeSql {
|
|
78
93
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
81
|
-
* @param
|
|
82
|
-
* @
|
|
83
|
-
* @
|
|
94
|
+
* Executes a Drizzle query and returns the result.
|
|
95
|
+
* @template T - The type of the query builder
|
|
96
|
+
* @param {T} query - The Drizzle query to execute
|
|
97
|
+
* @returns {Promise<Awaited<T>>} The query result
|
|
98
|
+
* @throws {Error} If the query execution fails
|
|
84
99
|
*/
|
|
85
|
-
|
|
100
|
+
executeQuery<T extends MySqlSelectDynamic<AnyMySqlSelectQueryBuilder>>(query: T): Promise<Awaited<T>>;
|
|
86
101
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
89
|
-
* @param
|
|
90
|
-
* @returns
|
|
102
|
+
* Executes a Drizzle query and returns a single result.
|
|
103
|
+
* @template T - The type of the query builder
|
|
104
|
+
* @param {T} query - The Drizzle query to execute
|
|
105
|
+
* @returns {Promise<Awaited<T> extends Array<any> ? Awaited<T>[number] | undefined : Awaited<T> | undefined>} A single result object or undefined
|
|
106
|
+
* @throws {Error} If more than one record is returned
|
|
107
|
+
* @throws {Error} If the query execution fails
|
|
91
108
|
*/
|
|
92
|
-
|
|
109
|
+
executeQueryOnlyOne<T extends MySqlSelectDynamic<AnyMySqlSelectQueryBuilder>>(query: T): Promise<Awaited<T> extends Array<any> ? Awaited<T>[number] | undefined : Awaited<T> | undefined>;
|
|
93
110
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* * @param schema - The entity schema.
|
|
101
|
-
* * @throws If the primary key is not included in the update fields.
|
|
102
|
-
* */
|
|
103
|
-
updateById<T extends object>(entity: Partial<T>, schema: EntitySchema<T>): Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* Updates specified fields of records based on provided conditions.
|
|
106
|
-
* If the "where" parameter is not provided, the WHERE clause is built from the entity fields
|
|
107
|
-
* that are not included in the list of fields to update.
|
|
108
|
-
*
|
|
109
|
-
* @param entity - The object containing values to update and potential criteria for filtering.
|
|
110
|
-
* @param fields - Array of field names to update.
|
|
111
|
-
* @param schema - The entity schema.
|
|
112
|
-
* @param where - Optional filtering conditions for the WHERE clause.
|
|
113
|
-
* @returns The number of affected rows.
|
|
114
|
-
* @throws If no filtering criteria are provided (either via "where" or from the remaining entity fields).
|
|
111
|
+
* Executes a raw SQL query and returns the results.
|
|
112
|
+
* @template T - The type of the result objects
|
|
113
|
+
* @param {string} query - The raw SQL query
|
|
114
|
+
* @param {SqlParameters[]} [params] - Optional SQL parameters
|
|
115
|
+
* @returns {Promise<T[]>} A list of results as objects
|
|
116
|
+
* @throws {Error} If the query execution fails
|
|
115
117
|
*/
|
|
116
|
-
|
|
118
|
+
executeRawSQL<T extends object | unknown>(query: string, params?: SqlParameters[]): Promise<T[]>;
|
|
117
119
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @param entity - The entity with updated values.
|
|
125
|
-
* @param fields - The list of field names to update.
|
|
126
|
-
* @param schema - The entity schema.
|
|
127
|
-
* @throws If the primary key is not included in the update fields.
|
|
120
|
+
* Executes a raw SQL update query.
|
|
121
|
+
* @param {string} query - The raw SQL update query
|
|
122
|
+
* @param {SqlParameters[]} [params] - Optional SQL parameters
|
|
123
|
+
* @returns {Promise<UpdateQueryResponse>} The update response containing affected rows
|
|
124
|
+
* @throws {Error} If the update operation fails
|
|
128
125
|
*/
|
|
129
|
-
|
|
126
|
+
executeRawUpdateSQL(query: string, params?: unknown[]): Promise<UpdateQueryResponse>;
|
|
130
127
|
}
|
|
131
128
|
/**
|
|
132
|
-
* Interface for
|
|
129
|
+
* Interface for version field metadata.
|
|
130
|
+
* Defines the configuration for optimistic locking version fields.
|
|
133
131
|
*/
|
|
134
|
-
export interface
|
|
132
|
+
export interface VersionFieldMetadata {
|
|
133
|
+
/** Name of the version field */
|
|
134
|
+
fieldName: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Interface for table metadata.
|
|
138
|
+
* Defines the configuration for a specific table.
|
|
139
|
+
*/
|
|
140
|
+
export interface TableMetadata {
|
|
141
|
+
/** Name of the table */
|
|
142
|
+
tableName: string;
|
|
143
|
+
/** Version field configuration for optimistic locking */
|
|
144
|
+
versionField: VersionFieldMetadata;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Type for additional metadata configuration.
|
|
148
|
+
* Maps table names to their metadata configuration.
|
|
149
|
+
*/
|
|
150
|
+
export type AdditionalMetadata = Record<string, TableMetadata>;
|
|
151
|
+
/**
|
|
152
|
+
* Options for configuring ForgeSQL ORM behavior.
|
|
153
|
+
*/
|
|
154
|
+
export interface ForgeSqlOrmOptions {
|
|
135
155
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @
|
|
139
|
-
* @param loggerContext - Logging options.
|
|
140
|
-
* @returns The query builder instance.
|
|
156
|
+
* Enables logging of raw SQL queries in the Atlassian Forge Developer Console.
|
|
157
|
+
* Useful for debugging and monitoring SQL operations.
|
|
158
|
+
* @default false
|
|
141
159
|
*/
|
|
142
|
-
|
|
160
|
+
logRawSqlQuery?: boolean;
|
|
143
161
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @
|
|
162
|
+
* Enables logging of raw SQL queries in the Atlassian Forge Developer Console.
|
|
163
|
+
* Useful for debugging and monitoring SQL operations.
|
|
164
|
+
* @default false
|
|
147
165
|
*/
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
export interface ComplexQuerySchemaBuilder<T> {
|
|
166
|
+
logRawSqlQueryParams?: boolean;
|
|
151
167
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* @
|
|
155
|
-
* @returns The updated instance of the builder.
|
|
168
|
+
* Disables optimistic locking for all operations.
|
|
169
|
+
* When enabled, version checks are skipped during updates.
|
|
170
|
+
* @default false
|
|
156
171
|
*/
|
|
157
|
-
|
|
172
|
+
disableOptimisticLocking?: boolean;
|
|
158
173
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
174
|
+
* Additional metadata for table configuration.
|
|
175
|
+
* Allows specifying table-specific settings and behaviors.
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* {
|
|
179
|
+
* users: {
|
|
180
|
+
* tableName: "users",
|
|
181
|
+
* versionField: {
|
|
182
|
+
* fieldName: "updatedAt",
|
|
183
|
+
* type: "datetime",
|
|
184
|
+
* nullable: false
|
|
185
|
+
* }
|
|
186
|
+
* }
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
161
189
|
*/
|
|
162
|
-
|
|
190
|
+
additionalMetadata?: AdditionalMetadata;
|
|
163
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Custom type for MySQL datetime fields.
|
|
194
|
+
* Handles conversion between JavaScript Date objects and MySQL datetime strings.
|
|
195
|
+
*/
|
|
196
|
+
export declare const mySqlDateTimeString: {
|
|
197
|
+
(): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
198
|
+
name: "";
|
|
199
|
+
dataType: "custom";
|
|
200
|
+
columnType: "MySqlCustomColumn";
|
|
201
|
+
data: Date;
|
|
202
|
+
driverParam: unknown;
|
|
203
|
+
enumValues: undefined;
|
|
204
|
+
}>;
|
|
205
|
+
<TConfig extends Record<string, any> & {
|
|
206
|
+
format?: string;
|
|
207
|
+
}>(fieldConfig?: TConfig | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
208
|
+
name: "";
|
|
209
|
+
dataType: "custom";
|
|
210
|
+
columnType: "MySqlCustomColumn";
|
|
211
|
+
data: Date;
|
|
212
|
+
driverParam: unknown;
|
|
213
|
+
enumValues: undefined;
|
|
214
|
+
}>;
|
|
215
|
+
<TName extends string>(dbName: TName, fieldConfig?: {
|
|
216
|
+
format?: string;
|
|
217
|
+
} | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
218
|
+
name: TName;
|
|
219
|
+
dataType: "custom";
|
|
220
|
+
columnType: "MySqlCustomColumn";
|
|
221
|
+
data: Date;
|
|
222
|
+
driverParam: unknown;
|
|
223
|
+
enumValues: undefined;
|
|
224
|
+
}>;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Custom type for MySQL timestamp fields.
|
|
228
|
+
* Handles conversion between JavaScript Date objects and MySQL timestamp strings.
|
|
229
|
+
*/
|
|
230
|
+
export declare const mySqlTimestampString: {
|
|
231
|
+
(): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
232
|
+
name: "";
|
|
233
|
+
dataType: "custom";
|
|
234
|
+
columnType: "MySqlCustomColumn";
|
|
235
|
+
data: Date;
|
|
236
|
+
driverParam: unknown;
|
|
237
|
+
enumValues: undefined;
|
|
238
|
+
}>;
|
|
239
|
+
<TConfig extends Record<string, any> & {
|
|
240
|
+
format?: string;
|
|
241
|
+
}>(fieldConfig?: TConfig | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
242
|
+
name: "";
|
|
243
|
+
dataType: "custom";
|
|
244
|
+
columnType: "MySqlCustomColumn";
|
|
245
|
+
data: Date;
|
|
246
|
+
driverParam: unknown;
|
|
247
|
+
enumValues: undefined;
|
|
248
|
+
}>;
|
|
249
|
+
<TName extends string>(dbName: TName, fieldConfig?: {
|
|
250
|
+
format?: string;
|
|
251
|
+
} | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
252
|
+
name: TName;
|
|
253
|
+
dataType: "custom";
|
|
254
|
+
columnType: "MySqlCustomColumn";
|
|
255
|
+
data: Date;
|
|
256
|
+
driverParam: unknown;
|
|
257
|
+
enumValues: undefined;
|
|
258
|
+
}>;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Custom type for MySQL date fields.
|
|
262
|
+
* Handles conversion between JavaScript Date objects and MySQL date strings.
|
|
263
|
+
*/
|
|
264
|
+
export declare const mySqlDateString: {
|
|
265
|
+
(): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
266
|
+
name: "";
|
|
267
|
+
dataType: "custom";
|
|
268
|
+
columnType: "MySqlCustomColumn";
|
|
269
|
+
data: Date;
|
|
270
|
+
driverParam: unknown;
|
|
271
|
+
enumValues: undefined;
|
|
272
|
+
}>;
|
|
273
|
+
<TConfig extends Record<string, any> & {
|
|
274
|
+
format?: string;
|
|
275
|
+
}>(fieldConfig?: TConfig | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
276
|
+
name: "";
|
|
277
|
+
dataType: "custom";
|
|
278
|
+
columnType: "MySqlCustomColumn";
|
|
279
|
+
data: Date;
|
|
280
|
+
driverParam: unknown;
|
|
281
|
+
enumValues: undefined;
|
|
282
|
+
}>;
|
|
283
|
+
<TName extends string>(dbName: TName, fieldConfig?: {
|
|
284
|
+
format?: string;
|
|
285
|
+
} | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
286
|
+
name: TName;
|
|
287
|
+
dataType: "custom";
|
|
288
|
+
columnType: "MySqlCustomColumn";
|
|
289
|
+
data: Date;
|
|
290
|
+
driverParam: unknown;
|
|
291
|
+
enumValues: undefined;
|
|
292
|
+
}>;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Custom type for MySQL time fields.
|
|
296
|
+
* Handles conversion between JavaScript Date objects and MySQL time strings.
|
|
297
|
+
*/
|
|
298
|
+
export declare const mySqlTimeString: {
|
|
299
|
+
(): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
300
|
+
name: "";
|
|
301
|
+
dataType: "custom";
|
|
302
|
+
columnType: "MySqlCustomColumn";
|
|
303
|
+
data: Date;
|
|
304
|
+
driverParam: unknown;
|
|
305
|
+
enumValues: undefined;
|
|
306
|
+
}>;
|
|
307
|
+
<TConfig extends Record<string, any> & {
|
|
308
|
+
format?: string;
|
|
309
|
+
}>(fieldConfig?: TConfig | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
310
|
+
name: "";
|
|
311
|
+
dataType: "custom";
|
|
312
|
+
columnType: "MySqlCustomColumn";
|
|
313
|
+
data: Date;
|
|
314
|
+
driverParam: unknown;
|
|
315
|
+
enumValues: undefined;
|
|
316
|
+
}>;
|
|
317
|
+
<TName extends string>(dbName: TName, fieldConfig?: {
|
|
318
|
+
format?: string;
|
|
319
|
+
} | undefined): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
320
|
+
name: TName;
|
|
321
|
+
dataType: "custom";
|
|
322
|
+
columnType: "MySqlCustomColumn";
|
|
323
|
+
data: Date;
|
|
324
|
+
driverParam: unknown;
|
|
325
|
+
enumValues: undefined;
|
|
326
|
+
}>;
|
|
327
|
+
};
|
|
164
328
|
//# sourceMappingURL=ForgeSQLQueryBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForgeSQLQueryBuilder.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLQueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"ForgeSQLQueryBuilder.d.ts","source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yD;IACzD,YAAY,EAAE,oBAAoB,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;;;;;;;;;;;;;;OAgBG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAID;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;iBAGX,MAAM;;;;;;;;;;iBAAN,MAAM;;;;;;;;;CAYzB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;iBAGZ,MAAM;;;;;;;;;;iBAAN,MAAM;;;;;;;;;CAYzB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;iBAGP,MAAM;;;;;;;;;;iBAAN,MAAM;;;;;;;;;CAYzB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;iBAGP,MAAM;;;;;;;;;;iBAAN,MAAM;;;;;;;;;CAWzB,CAAC"}
|
|
@@ -1,38 +1,81 @@
|
|
|
1
1
|
import { UpdateQueryResponse } from "@forge/sql";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { ForgeSqlOrmOptions, SchemaSqlForgeSql } from "./ForgeSQLQueryBuilder";
|
|
3
|
+
import { AnyMySqlSelectQueryBuilder, MySqlSelectDynamic } from "drizzle-orm/mysql-core/query-builders/select.types";
|
|
4
|
+
/**
|
|
5
|
+
* Class implementing SQL select operations for ForgeSQL ORM.
|
|
6
|
+
* Provides methods for executing queries and mapping results to entity types.
|
|
7
|
+
*/
|
|
6
8
|
export declare class ForgeSQLSelectOperations implements SchemaSqlForgeSql {
|
|
7
9
|
private readonly options;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new instance of ForgeSQLSelectOperations.
|
|
12
|
+
* @param {ForgeSqlOrmOptions} options - Configuration options for the ORM
|
|
13
|
+
*/
|
|
8
14
|
constructor(options: ForgeSqlOrmOptions);
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
16
|
+
* Executes a Drizzle query and returns the results.
|
|
17
|
+
* Maps the raw database results to the appropriate entity types.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the query builder
|
|
20
|
+
* @param {T} query - The Drizzle query to execute
|
|
21
|
+
* @returns {Promise<Awaited<T>>} The query results mapped to entity types
|
|
22
|
+
*/
|
|
23
|
+
executeQuery<T extends MySqlSelectDynamic<AnyMySqlSelectQueryBuilder>>(query: T): Promise<Awaited<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Extracts column information and alias name from a column definition.
|
|
26
|
+
* @param {any} column - The column definition from Drizzle
|
|
27
|
+
* @returns {Object} Object containing the real column and its alias name
|
|
28
|
+
*/
|
|
29
|
+
private extractColumnInfo;
|
|
30
|
+
/**
|
|
31
|
+
* Finds the alias chunk in SQL query chunks.
|
|
32
|
+
* @param {SQL} realColumnSql - The SQL query chunks
|
|
33
|
+
* @returns {StringChunk | undefined} The string chunk containing the alias or undefined
|
|
34
|
+
*/
|
|
35
|
+
private findAliasChunk;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves the alias name from the string chunk or column.
|
|
38
|
+
* @param {StringChunk | undefined} stringChunk - The string chunk containing the alias
|
|
39
|
+
* @param {Column | undefined} realColumn - The real column definition
|
|
40
|
+
* @param {boolean} withoutAlias - Whether the column has no alias
|
|
41
|
+
* @returns {string} The resolved alias name
|
|
42
|
+
*/
|
|
43
|
+
private resolveAliasName;
|
|
44
|
+
/**
|
|
45
|
+
* Parses a column value based on its SQL type.
|
|
46
|
+
* Handles datetime, date, and time types with appropriate formatting.
|
|
47
|
+
*
|
|
48
|
+
* @param {Column} column - The column definition
|
|
49
|
+
* @param {unknown} value - The raw value to parse
|
|
50
|
+
* @returns {unknown} The parsed value
|
|
14
51
|
*/
|
|
15
|
-
|
|
16
|
-
executeSchemaSQLOnlyOne<T extends object>(query: string, schema: EntitySchema<T>): Promise<T | undefined>;
|
|
52
|
+
private parseColumnValue;
|
|
17
53
|
/**
|
|
18
|
-
* Executes a
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
54
|
+
* Executes a Drizzle query and returns a single result.
|
|
55
|
+
* Throws an error if more than one record is returned.
|
|
56
|
+
*
|
|
57
|
+
* @template T - The type of the query builder
|
|
58
|
+
* @param {T} query - The Drizzle query to execute
|
|
59
|
+
* @returns {Promise<Awaited<T> extends Array<any> ? Awaited<T>[number] | undefined : Awaited<T> | undefined>} A single result object or undefined
|
|
60
|
+
* @throws {Error} If more than one record is returned
|
|
22
61
|
*/
|
|
23
|
-
|
|
62
|
+
executeQueryOnlyOne<T extends MySqlSelectDynamic<AnyMySqlSelectQueryBuilder>>(query: T): Promise<Awaited<T> extends Array<any> ? Awaited<T>[number] | undefined : Awaited<T> | undefined>;
|
|
24
63
|
/**
|
|
25
64
|
* Executes a raw SQL query and returns the results.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
65
|
+
* Logs the query if logging is enabled.
|
|
66
|
+
*
|
|
67
|
+
* @template T - The type of the result objects
|
|
68
|
+
* @param {string} query - The raw SQL query to execute
|
|
69
|
+
* @param {SqlParameters[]} [params] - Optional SQL parameters
|
|
70
|
+
* @returns {Promise<T[]>} A list of results as objects
|
|
28
71
|
*/
|
|
29
|
-
executeRawSQL<T extends object | unknown>(query: string): Promise<T[]>;
|
|
72
|
+
executeRawSQL<T extends object | unknown>(query: string, params?: unknown[]): Promise<T[]>;
|
|
30
73
|
/**
|
|
31
74
|
* Executes a raw SQL update query.
|
|
32
|
-
* @param query - The raw SQL update query
|
|
33
|
-
* @param params -
|
|
34
|
-
* @returns The update response containing affected rows
|
|
75
|
+
* @param {string} query - The raw SQL update query
|
|
76
|
+
* @param {SqlParameters[]} [params] - Optional SQL parameters
|
|
77
|
+
* @returns {Promise<UpdateQueryResponse>} The update response containing affected rows
|
|
35
78
|
*/
|
|
36
|
-
executeRawUpdateSQL(query: string, params?:
|
|
79
|
+
executeRawUpdateSQL(query: string, params?: unknown[]): Promise<UpdateQueryResponse>;
|
|
37
80
|
}
|
|
38
81
|
//# sourceMappingURL=ForgeSQLSelectOperations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForgeSQLSelectOperations.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLSelectOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,mBAAmB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ForgeSQLSelectOperations.d.ts","sourceRoot":"","sources":["../../src/core/ForgeSQLSelectOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,oDAAoD,CAAC;AAG5D;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,iBAAiB;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C;;;OAGG;gBACS,OAAO,EAAE,kBAAkB;IAIvC;;;;;;;OAOG;IACG,YAAY,CAAC,CAAC,SAAS,kBAAkB,CAAC,0BAA0B,CAAC,EACzE,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IA8BtB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAyBzB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAQtB;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;;;;;;OAQG;IACG,mBAAmB,CAAC,CAAC,SAAS,kBAAkB,CAAC,0BAA0B,CAAC,EAChF,KAAK,EAAE,CAAC,GACP,OAAO,CACR,OAAO,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CACxF;IAaD;;;;;;;;OAQG;IACG,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAehG;;;;;OAKG;IACG,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAQ3F"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const migrations: import("drizzle-orm/mysql-core/table").MySqlTableWithColumns<{
|
|
2
|
+
name: "__migrations";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
id: import("drizzle-orm/mysql-core/index").MySqlColumn<{
|
|
6
|
+
name: "id";
|
|
7
|
+
tableName: "__migrations";
|
|
8
|
+
dataType: "number";
|
|
9
|
+
columnType: "MySqlInt";
|
|
10
|
+
data: number;
|
|
11
|
+
driverParam: string | number;
|
|
12
|
+
notNull: true;
|
|
13
|
+
hasDefault: true;
|
|
14
|
+
isPrimaryKey: true;
|
|
15
|
+
isAutoincrement: true;
|
|
16
|
+
hasRuntimeDefault: false;
|
|
17
|
+
enumValues: undefined;
|
|
18
|
+
baseColumn: never;
|
|
19
|
+
identity: undefined;
|
|
20
|
+
generated: undefined;
|
|
21
|
+
}, {}, {}>;
|
|
22
|
+
name: import("drizzle-orm/mysql-core/index").MySqlColumn<{
|
|
23
|
+
name: "name";
|
|
24
|
+
tableName: "__migrations";
|
|
25
|
+
dataType: "string";
|
|
26
|
+
columnType: "MySqlVarChar";
|
|
27
|
+
data: string;
|
|
28
|
+
driverParam: string | number;
|
|
29
|
+
notNull: true;
|
|
30
|
+
hasDefault: false;
|
|
31
|
+
isPrimaryKey: false;
|
|
32
|
+
isAutoincrement: false;
|
|
33
|
+
hasRuntimeDefault: false;
|
|
34
|
+
enumValues: [string, ...string[]];
|
|
35
|
+
baseColumn: never;
|
|
36
|
+
identity: undefined;
|
|
37
|
+
generated: undefined;
|
|
38
|
+
}, {}, {}>;
|
|
39
|
+
created_at: import("drizzle-orm/mysql-core/index").MySqlColumn<{
|
|
40
|
+
name: "created_at";
|
|
41
|
+
tableName: "__migrations";
|
|
42
|
+
dataType: "date";
|
|
43
|
+
columnType: "MySqlTimestamp";
|
|
44
|
+
data: Date;
|
|
45
|
+
driverParam: string | number;
|
|
46
|
+
notNull: true;
|
|
47
|
+
hasDefault: true;
|
|
48
|
+
isPrimaryKey: false;
|
|
49
|
+
isAutoincrement: false;
|
|
50
|
+
hasRuntimeDefault: false;
|
|
51
|
+
enumValues: undefined;
|
|
52
|
+
baseColumn: never;
|
|
53
|
+
identity: undefined;
|
|
54
|
+
generated: undefined;
|
|
55
|
+
}, {}, {}>;
|
|
56
|
+
};
|
|
57
|
+
dialect: "mysql";
|
|
58
|
+
}>;
|
|
59
|
+
//# sourceMappingURL=SystemTables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemTables.d.ts","sourceRoot":"","sources":["../../src/core/SystemTables.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIrB,CAAC"}
|