ts-prorm-orm 1.2.2 → 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.
Files changed (129) hide show
  1. package/CHANGELOG.md +209 -0
  2. package/README.md +32 -24
  3. package/dist/compliance/index.d.ts +2 -0
  4. package/dist/compliance/index.js +13 -1
  5. package/dist/connection-manager.js +13 -1
  6. package/dist/core/expressions.d.ts +58 -0
  7. package/dist/core/expressions.js +83 -0
  8. package/dist/core/hooks-manager.d.ts +179 -0
  9. package/dist/core/hooks-manager.js +291 -0
  10. package/dist/core/types.d.ts +235 -0
  11. package/dist/core/types.js +9 -0
  12. package/dist/decorators/index.d.ts +2 -0
  13. package/dist/decorators/index.js +11 -1
  14. package/dist/diagrams/chen-diagram.d.ts +15 -12
  15. package/dist/diagrams/chen-diagram.js +76 -85
  16. package/dist/diagrams/class-diagram.d.ts +9 -8
  17. package/dist/diagrams/class-diagram.js +60 -82
  18. package/dist/diagrams/core/index.d.ts +13 -0
  19. package/dist/diagrams/core/index.js +33 -0
  20. package/dist/diagrams/core/layout.d.ts +104 -0
  21. package/dist/diagrams/core/layout.js +223 -0
  22. package/dist/diagrams/{svg-dom.d.ts → core/svg.d.ts} +8 -20
  23. package/dist/diagrams/{svg-dom.js → core/svg.js} +21 -29
  24. package/dist/diagrams/core/theme.d.ts +84 -0
  25. package/dist/diagrams/core/theme.js +62 -0
  26. package/dist/diagrams/dependency-diagram.d.ts +15 -14
  27. package/dist/diagrams/dependency-diagram.js +71 -105
  28. package/dist/diagrams/er-diagram.d.ts +13 -26
  29. package/dist/diagrams/er-diagram.js +180 -259
  30. package/dist/diagrams/flow-diagram.d.ts +16 -11
  31. package/dist/diagrams/flow-diagram.js +96 -91
  32. package/dist/diagrams/gantt-diagram.d.ts +10 -5
  33. package/dist/diagrams/gantt-diagram.js +77 -103
  34. package/dist/diagrams/index-diagram.d.ts +10 -10
  35. package/dist/diagrams/index-diagram.js +106 -116
  36. package/dist/diagrams/index.d.ts +6 -9
  37. package/dist/diagrams/index.js +9 -24
  38. package/dist/diagrams/migration-diagram.d.ts +8 -4
  39. package/dist/diagrams/migration-diagram.js +189 -161
  40. package/dist/diagrams/model-diagram.d.ts +34 -34
  41. package/dist/diagrams/model-diagram.js +106 -485
  42. package/dist/diagrams/package-diagram.d.ts +9 -6
  43. package/dist/diagrams/package-diagram.js +64 -101
  44. package/dist/diagrams/relational-diagram.d.ts +12 -10
  45. package/dist/diagrams/relational-diagram.js +87 -114
  46. package/dist/diagrams/schemadoc-diagram.d.ts +8 -8
  47. package/dist/diagrams/schemadoc-diagram.js +71 -93
  48. package/dist/diagrams/sequence-diagram.d.ts +10 -10
  49. package/dist/diagrams/sequence-diagram.js +64 -89
  50. package/dist/diagrams/state-diagram.d.ts +10 -9
  51. package/dist/diagrams/state-diagram.js +69 -92
  52. package/dist/diagrams/tree-diagram.d.ts +11 -5
  53. package/dist/diagrams/tree-diagram.js +41 -65
  54. package/dist/dialects/clickhouse/index.js +15 -0
  55. package/dist/dialects/cockroachdb/index.d.ts +1 -1
  56. package/dist/dialects/cockroachdb/index.js +32 -63
  57. package/dist/dialects/db2/index.js +23 -8
  58. package/dist/dialects/dialect.d.ts +29 -5
  59. package/dist/dialects/duckdb/index.js +9 -2
  60. package/dist/dialects/hana/index.js +22 -5
  61. package/dist/dialects/lock-clause-helper.d.ts +167 -0
  62. package/dist/dialects/lock-clause-helper.js +316 -0
  63. package/dist/dialects/mariadb/index.d.ts +7 -4
  64. package/dist/dialects/mariadb/index.js +36 -60
  65. package/dist/dialects/mssql/index.js +34 -3
  66. package/dist/dialects/mysql/index.d.ts +1 -1
  67. package/dist/dialects/mysql/index.js +17 -45
  68. package/dist/dialects/oracle/index.d.ts +14 -3
  69. package/dist/dialects/oracle/index.js +66 -36
  70. package/dist/dialects/order-expression-helper.d.ts +72 -0
  71. package/dist/dialects/order-expression-helper.js +154 -0
  72. package/dist/dialects/partial-index.d.ts +52 -0
  73. package/dist/dialects/partial-index.js +251 -0
  74. package/dist/dialects/postgres/index.d.ts +1 -1
  75. package/dist/dialects/postgres/index.js +43 -68
  76. package/dist/dialects/redshift/index.js +9 -2
  77. package/dist/dialects/snowflake/index.js +17 -0
  78. package/dist/dialects/spanner/index.js +7 -2
  79. package/dist/dialects/sqlite/driver.d.ts +55 -0
  80. package/dist/dialects/sqlite/driver.js +102 -0
  81. package/dist/dialects/sqlite/index.d.ts +1 -1
  82. package/dist/dialects/sqlite/index.js +49 -27
  83. package/dist/graph/base-graph-dialect.d.ts +24 -3
  84. package/dist/graph/base-graph-dialect.js +43 -2
  85. package/dist/graph/dgraph/index.js +6 -0
  86. package/dist/graph/gremlin/index.d.ts +6 -0
  87. package/dist/graph/gremlin/index.js +12 -1
  88. package/dist/graph/index.d.ts +1 -1
  89. package/dist/graph/neo4j/index.d.ts +2 -0
  90. package/dist/graph/neo4j/index.js +6 -1
  91. package/dist/graph/types.d.ts +12 -1
  92. package/dist/index.d.ts +13 -4
  93. package/dist/index.js +54 -7
  94. package/dist/logging/index.d.ts +10 -0
  95. package/dist/logging/index.js +23 -0
  96. package/dist/logging/query-logging.d.ts +82 -0
  97. package/dist/logging/query-logging.js +102 -0
  98. package/dist/models/decorators.d.ts +39 -3
  99. package/dist/models/decorators.js +74 -0
  100. package/dist/models/eager-load.d.ts +99 -0
  101. package/dist/models/eager-load.js +348 -5
  102. package/dist/models/indexes.d.ts +3 -2
  103. package/dist/models/indexes.js +7 -1
  104. package/dist/models/model.js +69 -43
  105. package/dist/prorm.d.ts +175 -409
  106. package/dist/prorm.js +1142 -557
  107. package/dist/query-builders/order-limit-builder.js +12 -10
  108. package/dist/query-builders/sql-compiler.d.ts +10 -3
  109. package/dist/query-builders/sql-compiler.js +14 -43
  110. package/dist/query-interface.d.ts +2 -1
  111. package/dist/sql-constants.d.ts +44 -0
  112. package/dist/sql-constants.js +138 -1
  113. package/dist/types/index.d.ts +53 -17
  114. package/dist/types/index.js +10 -15
  115. package/dist/types/query-types.d.ts +26 -0
  116. package/dist/types/query-types.js +30 -0
  117. package/package.json +32 -5
  118. package/dist/decorators/belongs-to-many.js +0 -115
  119. package/dist/decorators/belongs-to.js +0 -115
  120. package/dist/decorators/has-many.js +0 -127
  121. package/dist/decorators/has-one.js +0 -116
  122. package/dist/diagrams/palette.d.ts +0 -138
  123. package/dist/diagrams/palette.js +0 -194
  124. package/dist/hooks/hooks-manager.d.ts +0 -189
  125. package/dist/hooks/hooks-manager.js +0 -350
  126. package/dist/hooks/index.d.ts +0 -8
  127. package/dist/hooks/index.js +0 -37
  128. /package/dist/{logging.d.ts → logging/logger.d.ts} +0 -0
  129. /package/dist/{logging.js → logging/logger.js} +0 -0
package/dist/prorm.d.ts CHANGED
@@ -6,347 +6,34 @@ import { Dialect, ColumnDefinition, TableOptions, CreateExtensionOptions, DropEx
6
6
  import { ForeignDataManager, ForeignServerOptions, UserMappingOptions, ForeignTableOptions, ImportForeignSchemaOptions, ServerInfo } from './foreign-data';
7
7
  import { UserManager } from './user-management';
8
8
  import { DatabaseConnectionPool } from './connection-pool';
9
- import { PrormOptions, ModelStatic, ModelOptions as ModelOptionsType, AttributeOptions, DestroyOptions, ReloadOptions, Transaction, TransactionOptions, DataType } from './types';
9
+ import { PrormOptions, ModelStatic, ModelOptions as ModelOptionsType, AttributeOptions, Transaction, TransactionOptions, DataType } from './types';
10
10
  import { ExternalStoreRegistry } from './external-fields';
11
11
  import type { RegisterStoreOptions } from './external-fields';
12
12
  import { Logger } from './logging';
13
13
  import { ValidationError } from './errors';
14
14
  import { type IsolationLevelValue } from './sql-constants';
15
15
  type AnyModel = any;
16
- /**
17
- * Hook types for the ORM
18
- */
19
- export type HookCallback = (...args: any[]) => void | Promise<void>;
20
- /**
21
- * Connection type for hook callbacks
22
- */
23
- export interface Connection {
24
- id: string;
25
- createdAt: number;
26
- [key: string]: any;
27
- }
28
- /**
29
- * Hook manager for Prorm instance
30
- */
31
- export declare class HooksManager {
32
- private beforeDefineHooks;
33
- private afterDefineHooks;
34
- private beforeSyncHooks;
35
- private afterSyncHooks;
36
- private beforeConnectHooks;
37
- private afterConnectHooks;
38
- private beforeDisconnectHooks;
39
- private afterDisconnectHooks;
40
- private beforeDestroyHooks;
41
- private afterDestroyHooks;
42
- private beforeUpsertHooks;
43
- private afterUpsertHooks;
44
- private beforeReloadHooks;
45
- /**
46
- * Register a beforeDefine hook
47
- */
48
- beforeDefine(callback: HookCallback): void;
49
- /**
50
- * Register an afterDefine hook
51
- */
52
- afterDefine(callback: HookCallback): void;
53
- /**
54
- * Register a beforeSync hook
55
- */
56
- beforeSync(callback: HookCallback): void;
57
- /**
58
- * Register an afterSync hook
59
- */
60
- afterSync(callback: HookCallback): void;
61
- /**
62
- * Register a beforeConnect hook
63
- */
64
- beforeConnect(callback: HookCallback): void;
65
- /**
66
- * Register an afterConnect hook
67
- */
68
- afterConnect(callback: HookCallback): void;
69
- /**
70
- * Register a beforeDisconnect hook
71
- */
72
- beforeDisconnect(callback: HookCallback): void;
73
- /**
74
- * Register an afterDisconnect hook
75
- */
76
- afterDisconnect(callback: HookCallback): void;
77
- /**
78
- * Register a beforeDestroy hook
79
- */
80
- beforeDestroy(callback: HookCallback): void;
81
- /**
82
- * Register an afterDestroy hook
83
- */
84
- afterDestroy(callback: HookCallback): void;
85
- /**
86
- * Register a beforeUpsert hook
87
- */
88
- beforeUpsert(callback: HookCallback): void;
89
- /**
90
- * Register an afterUpsert hook
91
- */
92
- afterUpsert(callback: HookCallback): void;
93
- /**
94
- * Register a beforeReload hook
95
- */
96
- beforeReload(callback: HookCallback): void;
97
- /**
98
- * Execute all beforeDefine hooks
99
- */
100
- runBeforeDefine(modelName: string, attributes: Record<string, AttributeOptions>, options: ModelOptionsType): Promise<void>;
101
- /**
102
- * Execute all afterDefine hooks
103
- */
104
- runAfterDefine(model: ModelStatic<AnyModel>): Promise<void>;
105
- /**
106
- * Execute all beforeSync hooks
107
- */
108
- runBeforeSync(options: SyncOptions): Promise<void>;
109
- /**
110
- * Execute all afterSync hooks
111
- */
112
- runAfterSync(options: SyncOptions): Promise<void>;
113
- /**
114
- * Execute all beforeConnect hooks
115
- */
116
- runBeforeConnect(): Promise<void>;
117
- /**
118
- * Execute all afterConnect hooks
119
- * @param connection - The connection object to pass to hooks
120
- */
121
- runAfterConnect(connection: Connection): Promise<void>;
122
- /**
123
- * Execute all beforeDisconnect hooks
124
- * @param connection - The connection object to pass to hooks
125
- */
126
- runBeforeDisconnect(connection: Connection): Promise<void>;
127
- /**
128
- * Execute all afterDisconnect hooks
129
- * @param connection - The connection object to pass to hooks
130
- */
131
- runAfterDisconnect(connection: Connection): Promise<void>;
132
- /**
133
- * Execute all beforeDestroy hooks
134
- * @param options - The destroy options
135
- */
136
- runBeforeDestroy(options: DestroyOptions): Promise<void>;
137
- /**
138
- * Execute all afterDestroy hooks
139
- * @param options - The destroy options
140
- */
141
- runAfterDestroy(options: DestroyOptions): Promise<void>;
142
- /**
143
- * Execute all beforeUpsert hooks
144
- * @param options - The upsert options
145
- */
146
- runBeforeUpsert(options: any): Promise<void>;
147
- /**
148
- * Execute all afterUpsert hooks
149
- * @param options - The upsert options
150
- */
151
- runAfterUpsert(options: any): Promise<void>;
152
- /**
153
- * Execute all beforeReload hooks
154
- * @param options - The reload options
155
- */
156
- runBeforeReload(options: ReloadOptions): Promise<void>;
157
- /**
158
- * Add a hook by name
159
- * @param hookName - The name of the hook (e.g., 'beforeDefine', 'afterSync')
160
- * @param callback - The hook callback function
161
- */
162
- addHook(hookName: string, callback: HookCallback): void;
163
- /**
164
- * Clear all hooks
165
- */
166
- clearHooks(): void;
167
- }
168
- /**
169
- * Options for sync method
170
- */
171
- export interface SyncOptions {
172
- /**
173
- * If true, drops all tables and recreates them.
174
- * WARNING: This will destroy all data in the tables!
175
- * @default false
176
- */
177
- force?: boolean;
178
- /**
179
- * If true, alter tables to match model definitions.
180
- * This will add new columns, remove extra columns, and change column types as needed.
181
- * Preserves existing data in the table.
182
- * Can be an object with { drop: false } to prevent dropping columns
183
- * @default false
184
- */
185
- alter?: boolean | {
186
- drop?: boolean;
187
- };
188
- /**
189
- * Regular expression to match the database name.
190
- * Sync will only proceed if the database name matches this pattern.
191
- * Useful for development vs production environments.
192
- * Example: /test/ - only syncs if database name contains "test"
193
- */
194
- match?: RegExp;
195
- /**
196
- * Custom logging function
197
- */
198
- logging?: boolean | ((sql: string, timing?: number) => void);
199
- /**
200
- * If true, run sync hooks (beforeSync, afterSync, etc.)
201
- * @default true
202
- */
203
- hooks?: boolean;
204
- /**
205
- * If true, also sync indexes
206
- * @default true
207
- */
208
- indexes?: boolean;
209
- /**
210
- * If true, also sync foreign key constraints
211
- * @default true
212
- */
213
- constraints?: boolean;
214
- }
215
- /**
216
- * Represents a raw SQL literal value
217
- * Used for inserting raw SQL expressions into queries
218
- *
219
- * @example
220
- * // Use in default values
221
- * createdAt: { type: DATE, defaultValue: prorm.literal('NOW()') }
222
- *
223
- * @example
224
- * // Use in updates
225
- * User.update({ count: prorm.literal('count + 1') }, {...})
226
- *
227
- * @example
228
- * // Use in select with calculations
229
- * User.findAll({ attributes: [[prorm.literal('1 + 1'), 'two']] })
230
- */
231
- export declare class Literal {
232
- readonly val: string;
233
- constructor(sql: string);
234
- /**
235
- * Get the raw SQL string
236
- */
237
- toString(): string;
238
- }
239
- /**
240
- * Class representing a column reference for use with Prorm functions
241
- * Used to create properly quoted column identifiers
242
- *
243
- * @example
244
- * // Single column: col('name') -> "name"
245
- * // Table and column: col('User', 'name') -> "User"."name"
246
- * // Dot notation: col('table.column') -> "table"."column"
247
- */
248
- export declare class Col {
249
- private readonly col;
250
- /**
251
- * Create a column reference
252
- * @param tableOrColumn - Table name (if second param provided) or column name
253
- * @param column - Column name (if first param is table name)
254
- */
255
- constructor(tableOrColumn: string, column?: string);
256
- /**
257
- * Get the SQL representation of the column
258
- */
259
- toSql(): string;
260
- /**
261
- * Get the column as a string
262
- */
263
- toString(): string;
264
- }
16
+ import { HooksManager } from './core/hooks-manager';
17
+ import { Literal, Col } from './core/expressions';
18
+ import type { HookCallback, HookName, ModelHookMap, Connection, SyncOptions, RawQueryResult, QueryOptions, Fn, Cast, WhereObject, AndOrObject, JsonObject } from './core/types';
19
+ export { HooksManager, Literal, Col };
20
+ export type { HookCallback, HookName, ModelHookMap, Connection, SyncOptions, RawQueryResult, QueryOptions, Fn, Cast, WhereObject, AndOrObject, JsonObject, };
265
21
  /**
266
22
  * Query types for raw SQL queries
267
23
  */
268
- export declare enum QueryTypes {
269
- SELECT = "SELECT",
270
- INSERT = "INSERT",
271
- UPDATE = "UPDATE",
272
- DELETE = "DELETE",
273
- BULKDELETE = "BULKDELETE",
274
- BULKINSERT = "BULKINSERT",
275
- UPSERT = "UPSERT",
276
- VERSION = "VERSION",
277
- SHOWTABLES = "SHOWTABLES",
278
- DESCRIBE = "DESCRIBE",
279
- RAW = "RAW"
280
- }
24
+ import { QueryTypes } from './types/query-types';
25
+ export { QueryTypes };
281
26
  /**
282
- * Options for raw query execution
27
+ * The part of `ConnectionManager` a `Prorm` instance needs in order to resolve
28
+ * `FindOptions.using` - i.e. to look up a sibling connection by name.
29
+ *
30
+ * Declared structurally so prorm.ts doesn't have to import
31
+ * connection-manager.ts (which already imports Prorm, so a real import would
32
+ * close a cycle). `ConnectionManager` satisfies it as-is.
283
33
  */
284
- export interface RawQueryResult {
285
- rows: unknown[];
286
- count: number;
287
- isSelect: boolean;
288
- }
289
- export interface QueryOptions {
290
- /**
291
- * Query type - determines how results are processed
292
- * Forces the query type for result handling
293
- * - SELECT: Returns array of rows
294
- * - INSERT: Returns [rows, created]
295
- * - UPDATE: Returns affected count
296
- * - DELETE: Returns affected count
297
- * - BULKDELETE: Returns affected count
298
- * - UPSERT: Returns [rows, created]
299
- */
300
- type?: QueryTypes | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'BULKDELETE' | 'UPSERT' | 'BULKINSERT' | 'VERSION' | 'SHOWTABLES' | 'DESCRIBE' | 'RAW';
301
- /**
302
- * Replacements for named (:param) or positional (?) placeholders
303
- * For named: { username: 'john' } replaces :username in SQL
304
- * For positional: ['john', 'smith'] replaces ? in order
305
- */
306
- replacements?: Record<string, unknown> | unknown[];
307
- /**
308
- * Return raw results without model instantiation
309
- */
310
- raw?: boolean;
311
- /**
312
- * Whether to log the query
313
- */
314
- logging?: boolean | ((sql: string, timing?: number) => void);
315
- /**
316
- * When true, logs query execution time
317
- */
318
- benchmark?: boolean;
319
- /**
320
- * Transaction to use for the query
321
- */
322
- transaction?: Transaction;
323
- /**
324
- * Retry configuration for query execution
325
- * On connection failure or retryable errors, retry up to max times
326
- * @param max - Maximum number of retry attempts
327
- * @param match - Array of error message patterns that trigger retry
328
- *
329
- * @example
330
- * // Retry on connection refused or timeout errors
331
- * await prorm.query('SELECT * FROM users', {
332
- * retry: { max: 3, match: ['Connection refused', 'Timeout', 'ECONNREFUSED'] }
333
- * });
334
- */
335
- retry?: {
336
- max: number;
337
- match?: string[];
338
- };
339
- /**
340
- * Map raw query results to a model instance
341
- * When true, maps the result rows to ModelInstance objects using the provided model
342
- * @default false
343
- */
344
- mapToModel?: boolean;
345
- /**
346
- * Model to use for mapping raw results to model instances
347
- * Used together with mapToModel to create ModelInstance objects from raw query results
348
- */
349
- model?: ModelStatic<any>;
34
+ export interface ConnectionRegistry {
35
+ getConnection(name: string): Prorm | undefined;
36
+ getConnectionNames(): string[];
350
37
  }
351
38
  /**
352
39
  * Main Prorm class with error handling and logging
@@ -356,6 +43,17 @@ export declare class Prorm extends EventEmitter {
356
43
  private _fdwManager;
357
44
  private _userManager;
358
45
  private _models;
46
+ /**
47
+ * The registry this instance was created by, if any.
48
+ *
49
+ * `ConnectionManager.addConnection()` sets this on the instance it builds,
50
+ * which is what makes `FindOptions.using` work: a query can name a sibling
51
+ * connection and be routed to that connection's copy of the model. Nothing
52
+ * else assigned it before, so `using` threw "Available: none" on every call.
53
+ * Typed structurally (rather than as `ConnectionManager`) to keep prorm.ts
54
+ * free of an import cycle with connection-manager.ts.
55
+ */
56
+ connectionManager: ConnectionRegistry | null;
359
57
  /**
360
58
  * Get all models as an object for backward compatibility
361
59
  * Allows accessing models via prorm.models.ModelName
@@ -694,11 +392,25 @@ export declare class Prorm extends EventEmitter {
694
392
  }): Promise<void>;
695
393
  /**
696
394
  * Disable foreign key checks for the current session
395
+ *
396
+ * On PostgreSQL this issues `SET session_replication_role = 'replica'`, which
397
+ * needs superuser or a role granted `SET ON PARAMETER
398
+ * session_replication_role` (PostgreSQL 15+).
399
+ *
400
+ * @throws {UnsupportedForeignKeyChecksError} on dialects with no
401
+ * session-level switch (SQL Server, Oracle and Db2 are per-table; Redshift,
402
+ * Snowflake and ClickHouse never enforce foreign keys).
697
403
  * @returns Promise that resolves when foreign key checks are disabled
698
404
  */
699
405
  disableForeignKeyChecks(): Promise<void>;
700
406
  /**
701
407
  * Enable foreign key checks for the current session
408
+ *
409
+ * The inverse of {@link disableForeignKeyChecks}, with the same dialect
410
+ * support and the same PostgreSQL privilege requirement.
411
+ *
412
+ * @throws {UnsupportedForeignKeyChecksError} on dialects with no
413
+ * session-level switch
702
414
  * @returns Promise that resolves when foreign key checks are enabled
703
415
  */
704
416
  enableForeignKeyChecks(): Promise<void>;
@@ -710,11 +422,24 @@ export declare class Prorm extends EventEmitter {
710
422
  setIsolationLevel(level: IsolationLevelValue): Promise<void>;
711
423
  /**
712
424
  * Get SQL for disabling foreign key checks for the current dialect
425
+ *
426
+ * Routing lives in `sql-constants.getForeignKeyChecksSQL` so that the three
427
+ * mutually incompatible statements (SQLite's PRAGMA, MySQL's session
428
+ * variable, PostgreSQL's `session_replication_role`) are chosen from one
429
+ * table. This used to fall through to MySQL syntax for every dialect it did
430
+ * not name - PostgreSQL included - so `disableForeignKeyChecks()` threw a
431
+ * syntax error at the server on most of the supported databases.
432
+ *
433
+ * @throws {UnsupportedForeignKeyChecksError} when the dialect has no
434
+ * session-level equivalent
713
435
  * @returns SQL string for disabling foreign key checks
714
436
  */
715
437
  getDisableForeignKeyChecksSQL(): string;
716
438
  /**
717
439
  * Get SQL for enabling foreign key checks for the current dialect
440
+ *
441
+ * @throws {UnsupportedForeignKeyChecksError} when the dialect has no
442
+ * session-level equivalent
718
443
  * @returns SQL string for enabling foreign key checks
719
444
  */
720
445
  getEnableForeignKeyChecksSQL(): string;
@@ -726,11 +451,27 @@ export declare class Prorm extends EventEmitter {
726
451
  getSetIsolationLevelSQL(level: IsolationLevelValue): string;
727
452
  /**
728
453
  * Disable unique key checks for the current session (MySQL/MariaDB only)
454
+ *
455
+ * The no-op on other dialects is deliberate, and is not the same situation as
456
+ * the foreign key switch above. `SET UNIQUE_CHECKS` is a MySQL/MariaDB
457
+ * *optimisation* hint: it defers uniqueness verification on InnoDB secondary
458
+ * indexes during bulk loads. No other supported database has a session
459
+ * setting that suspends unique constraint checking - PostgreSQL's
460
+ * `session_replication_role = 'replica'` suppresses triggers and foreign
461
+ * keys but still enforces unique indexes - so there is nothing to translate
462
+ * it to. Skipping the statement leaves the database in exactly the state the
463
+ * caller already had (uniqueness enforced), which is safe; throwing would
464
+ * break the common `disableUniqueKeyChecks(); bulkCreate(); enable...()`
465
+ * bulk-load pattern on every non-MySQL dialect for no benefit.
466
+ *
729
467
  * @returns Promise that resolves when unique key checks are disabled
730
468
  */
731
469
  disableUniqueKeyChecks(): Promise<void>;
732
470
  /**
733
471
  * Enable unique key checks for the current session (MySQL/MariaDB only)
472
+ *
473
+ * A no-op elsewhere, for the reason given on {@link disableUniqueKeyChecks}.
474
+ *
734
475
  * @returns Promise that resolves when unique key checks are enabled
735
476
  */
736
477
  enableUniqueKeyChecks(): Promise<void>;
@@ -1662,6 +1403,54 @@ export declare class Prorm extends EventEmitter {
1662
1403
  * registered, so callers can report them rather than silently skipping.
1663
1404
  */
1664
1405
  private _unresolvedAssociationTargets;
1406
+ /**
1407
+ * Run a `findAll` against the connection named by `FindOptions.using`.
1408
+ *
1409
+ * `using` lets one query hop to a sibling database registered on the same
1410
+ * `ConnectionManager` (`User.findAll({ using: 'analytics' })`). The target
1411
+ * connection has its own models, so this re-dispatches to *that*
1412
+ * connection's copy of the model by name and drops `using` from the options
1413
+ * so the delegate runs the query normally instead of bouncing forever.
1414
+ *
1415
+ * Both failure modes report what is actually available, since a typo in a
1416
+ * connection name and a model that was never defined on the target
1417
+ * connection are otherwise indistinguishable from "the query returned
1418
+ * nothing".
1419
+ */
1420
+ private _findAllUsingConnection;
1421
+ /**
1422
+ * Resolve an `include` list into concrete, per-association entries.
1423
+ *
1424
+ * Every pass that reads an include - the cross-table `$assoc.col$` rewrite,
1425
+ * the parent-filtering (`required`) pass, and the eager loader itself - is
1426
+ * written against an entry that carries a `model`. `{ all: true }` carries
1427
+ * none, so each of those passes has to see the *expanded* list or it silently
1428
+ * does nothing for `all`: that is how `include: [{ all: true, required: true }]`
1429
+ * came to load the associations without narrowing the parents, while the
1430
+ * equivalent explicit include filtered correctly.
1431
+ *
1432
+ * Expansion is idempotent - a list with no `all` entry comes back as the same
1433
+ * entries - so running it here as well as inside `loadIncludes()` is safe.
1434
+ */
1435
+ private _expandIncludes;
1436
+ /**
1437
+ * Narrow a WHERE clause by the query's filtering (`required`) includes.
1438
+ *
1439
+ * Shared by `findAll`, `_countRows` and `_aggregate` so that a filtering
1440
+ * include restricts the rows, the count and an aggregate to the same set.
1441
+ * Returns `null` when some include can match no parent at all - the whole
1442
+ * query is then empty, and each caller spells "empty" its own way (no rows,
1443
+ * a count of 0, a null aggregate).
1444
+ *
1445
+ * Several includes can constrain the *same* parent column, and since
1446
+ * `{ all: true, required: true }` expands to one include per association that
1447
+ * is now the common case rather than a corner. Their key sets are intersected
1448
+ * here. They must not be emitted as two conditions on one key: a
1449
+ * `{ id: { $and: [{ $in: [...] }, { $in: [...] }] } }` shape is not something
1450
+ * the where-builders recognize, and it collapsed to a single `"id" = ?` -
1451
+ * which is why two `required` includes used to return the wrong rows.
1452
+ */
1453
+ private _applyRequiredIncludeFilters;
1665
1454
  /**
1666
1455
  * Issue a real `SELECT COUNT(...)` for a model.
1667
1456
  *
@@ -1670,6 +1459,9 @@ export declare class Prorm extends EventEmitter {
1670
1459
  * - `col` picks the counted expression (`COUNT("col")`)
1671
1460
  * - `distinct: true` counts distinct values of `col`, or of the primary key
1672
1461
  * - `group` returns the number of groups
1462
+ *
1463
+ * A query carrying `union` branches is counted over the combined query rather
1464
+ * than this model's table alone - see the derived-table note below.
1673
1465
  */
1674
1466
  private _countRows;
1675
1467
  /**
@@ -1683,6 +1475,31 @@ export declare class Prorm extends EventEmitter {
1683
1475
  * include soft-deleted rows that `findAll` excluded.
1684
1476
  */
1685
1477
  private _aggregate;
1478
+ /**
1479
+ * Log one executed query, and emit the events that hang off it.
1480
+ *
1481
+ * Every statement the ORM issues should route through here. Query logging was
1482
+ * previously inlined at four call sites and only some ran it, so `count`,
1483
+ * `bulkCreate`, `increment` and the aggregates emitted nothing - turning
1484
+ * logging on showed an incomplete picture of what the ORM was doing.
1485
+ */
1486
+ private _logQuery;
1487
+ /**
1488
+ * Apply `+/- delta` to numeric columns in a single UPDATE.
1489
+ *
1490
+ * Backs `Model.increment` / `Model.decrement`. The arithmetic happens in the
1491
+ * database, so two concurrent callers both land - a read-modify-write in
1492
+ * application code silently drops one of them.
1493
+ */
1494
+ private _applyDelta;
1495
+ /**
1496
+ * Update many rows to different values in one statement.
1497
+ *
1498
+ * Backs `Model.bulkUpdate`. Compiles one UPDATE with a CASE expression per
1499
+ * column - portable across every supported dialect - instead of N round
1500
+ * trips.
1501
+ */
1502
+ private _bulkUpdate;
1686
1503
  /**
1687
1504
  * The view of this instance that the shared eager-loader needs.
1688
1505
  */
@@ -1714,8 +1531,36 @@ export declare class Prorm extends EventEmitter {
1714
1531
  * Alter sync mode - modifies tables to match models (preserves data)
1715
1532
  */
1716
1533
  private syncAlter;
1534
+ /**
1535
+ * Make sure the model's declared composite unique keys are enforced on an
1536
+ * existing table, as a unique index.
1537
+ *
1538
+ * `alterTable` reconciles columns only, and on SQLite reconciling a column
1539
+ * means rebuilding the table - which drops the table-level UNIQUE constraint
1540
+ * that `createTableFromModel` put in the CREATE TABLE text. Without this step
1541
+ * a single `sync({ alter: true })` would silently un-enforce a unique key the
1542
+ * model still declares, which is the same silent-data-integrity failure the
1543
+ * unique key support was added to fix.
1544
+ *
1545
+ * A unique index enforces exactly the same rule as a unique constraint and,
1546
+ * unlike `ADD CONSTRAINT`, every dialect here can create one. Existing
1547
+ * indexes are listed first so re-syncing is idempotent on dialects whose
1548
+ * `addIndex` has no IF NOT EXISTS.
1549
+ *
1550
+ * This deliberately does not remove unique keys the model no longer declares
1551
+ * (dropping a constraint is not a change to make implicitly), and it will
1552
+ * fail loudly if the table already holds rows that violate a newly declared
1553
+ * key - which is the honest outcome, not something to swallow.
1554
+ */
1555
+ private reconcileUniqueKeys;
1717
1556
  /**
1718
1557
  * Alter a table to match model definition
1558
+ *
1559
+ * Scope note: this reconciles *columns* only - it adds, changes and (with
1560
+ * `drop`) removes them. Table-level constraints are not diffed against the
1561
+ * database. The composite unique keys collected by `collectUniqueKeys` are
1562
+ * the exception, and they are handled just after this runs, by
1563
+ * `reconcileUniqueKeys`, because a column rebuild would otherwise drop them.
1719
1564
  */
1720
1565
  private alterTable;
1721
1566
  /**
@@ -1997,85 +1842,6 @@ export declare class Prorm extends EventEmitter {
1997
1842
  model?: ModelStatic<AnyModel>;
1998
1843
  }): Promise<ValidationError | null>;
1999
1844
  }
2000
- /**
2001
- * Represents a SQL function expression
2002
- * Used with prorm.fn() to create SQL functions like COUNT, UPPER, YEAR, etc.
2003
- */
2004
- export interface Fn {
2005
- /**
2006
- * The SQL function name (e.g., 'COUNT', 'UPPER', 'YEAR')
2007
- */
2008
- fn: string;
2009
- /**
2010
- * The arguments to the function (can be column references, literals, or other functions)
2011
- */
2012
- args: (string | Col | Fn | Literal)[];
2013
- }
2014
- /**
2015
- * Represents a SQL CAST expression
2016
- * Used to cast a value to a specific data type
2017
- */
2018
- export interface Cast {
2019
- /**
2020
- * Type identifier for CAST
2021
- */
2022
- $type: 'cast';
2023
- /**
2024
- * The value to cast (column reference, literal, or function)
2025
- */
2026
- value: string | Col | Fn | Literal;
2027
- /**
2028
- * The target data type (e.g., 'VARCHAR', 'INTEGER', 'DATE', 'BOOLEAN')
2029
- */
2030
- type: string;
2031
- }
2032
- /**
2033
- * Represents a WHERE condition for complex queries
2034
- */
2035
- export interface WhereObject {
2036
- /**
2037
- * Type identifier for WHERE
2038
- */
2039
- $type: 'where';
2040
- /**
2041
- * The column or expression to compare
2042
- */
2043
- col: Col | Fn | Literal;
2044
- /**
2045
- * The value or condition to compare against
2046
- */
2047
- value: unknown;
2048
- }
2049
- /**
2050
- * Represents an AND or OR combination of conditions
2051
- */
2052
- export interface AndOrObject {
2053
- /**
2054
- * Type identifier - 'and' or 'or'
2055
- */
2056
- $type: 'and' | 'or';
2057
- /**
2058
- * The conditions to combine
2059
- */
2060
- conditions: unknown[];
2061
- }
2062
- /**
2063
- * Represents a JSON path query for JSON columns
2064
- */
2065
- export interface JsonObject {
2066
- /**
2067
- * Type identifier for JSON
2068
- */
2069
- $type: 'json';
2070
- /**
2071
- * The JSON path to query (dot notation or array notation)
2072
- */
2073
- path: string;
2074
- /**
2075
- * Optional value to compare against
2076
- */
2077
- value?: unknown;
2078
- }
2079
1845
  /**
2080
1846
  * DataTypes for model definitions
2081
1847
  */