viborm 0.1.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 (113) hide show
  1. package/README.md +529 -0
  2. package/dist/adapters.d.mts +2 -0
  3. package/dist/adapters.mjs +1 -0
  4. package/dist/bun-sql.d.mts +3 -0
  5. package/dist/bun-sql.mjs +2 -0
  6. package/dist/bun-sql.mjs.map +1 -0
  7. package/dist/bun-sqlite.d.mts +3 -0
  8. package/dist/bun-sqlite.mjs +2 -0
  9. package/dist/bun-sqlite.mjs.map +1 -0
  10. package/dist/cache/cloudflare-kv.d.mts +3 -0
  11. package/dist/cache/cloudflare-kv.mjs +2 -0
  12. package/dist/cache/cloudflare-kv.mjs.map +1 -0
  13. package/dist/cache/memory.d.mts +3 -0
  14. package/dist/cache/memory.mjs +2 -0
  15. package/dist/cache/memory.mjs.map +1 -0
  16. package/dist/cache.d.mts +4 -0
  17. package/dist/cache.mjs +1 -0
  18. package/dist/cli.d.mts +1 -0
  19. package/dist/cli.mjs +41 -0
  20. package/dist/cli.mjs.map +1 -0
  21. package/dist/client-CgdtiDGV.mjs +2 -0
  22. package/dist/client-CgdtiDGV.mjs.map +1 -0
  23. package/dist/client.d.mts +3 -0
  24. package/dist/client.mjs +1 -0
  25. package/dist/cloudflare-kv-DauXhtnT.d.mts +1110 -0
  26. package/dist/d1-http.d.mts +3 -0
  27. package/dist/d1-http.mjs +2 -0
  28. package/dist/d1-http.mjs.map +1 -0
  29. package/dist/d1.d.mts +3 -0
  30. package/dist/d1.mjs +2 -0
  31. package/dist/d1.mjs.map +1 -0
  32. package/dist/driver-B_vBzQ6A.mjs +2 -0
  33. package/dist/driver-B_vBzQ6A.mjs.map +1 -0
  34. package/dist/driver-Cj1EbciY.mjs +2 -0
  35. package/dist/driver-Cj1EbciY.mjs.map +1 -0
  36. package/dist/driver.d.mts +2 -0
  37. package/dist/driver.mjs +1 -0
  38. package/dist/errors-DvcqIdEo.mjs +2 -0
  39. package/dist/errors-DvcqIdEo.mjs.map +1 -0
  40. package/dist/helper-cDCDjRAD.d.mts +3020 -0
  41. package/dist/helpers-WNr9B-2U.mjs +2 -0
  42. package/dist/helpers-WNr9B-2U.mjs.map +1 -0
  43. package/dist/hydration-CFnwc7j6.mjs +2 -0
  44. package/dist/hydration-CFnwc7j6.mjs.map +1 -0
  45. package/dist/index-3sdVKfeG.d.mts +1447 -0
  46. package/dist/index-BGmpst1h.d.mts +2158 -0
  47. package/dist/index.d.mts +46 -0
  48. package/dist/index.mjs +2 -0
  49. package/dist/index.mjs.map +1 -0
  50. package/dist/instrumentation.d.mts +2 -0
  51. package/dist/instrumentation.mjs +1 -0
  52. package/dist/libsql.d.mts +3 -0
  53. package/dist/libsql.mjs +2 -0
  54. package/dist/libsql.mjs.map +1 -0
  55. package/dist/migrations.d.mts +1588 -0
  56. package/dist/migrations.mjs +11 -0
  57. package/dist/migrations.mjs.map +1 -0
  58. package/dist/mysql-adapter-0catKeCI.mjs +6 -0
  59. package/dist/mysql-adapter-0catKeCI.mjs.map +1 -0
  60. package/dist/mysql-utils-BPw9qhac.mjs +2 -0
  61. package/dist/mysql-utils-BPw9qhac.mjs.map +1 -0
  62. package/dist/mysql2.d.mts +3 -0
  63. package/dist/mysql2.mjs +2 -0
  64. package/dist/mysql2.mjs.map +1 -0
  65. package/dist/native-types-BwICkVjz.mjs +2 -0
  66. package/dist/native-types-BwICkVjz.mjs.map +1 -0
  67. package/dist/neon-http.d.mts +3 -0
  68. package/dist/neon-http.mjs +2 -0
  69. package/dist/neon-http.mjs.map +1 -0
  70. package/dist/pending-operation-CkzYTpi4.mjs +2 -0
  71. package/dist/pending-operation-CkzYTpi4.mjs.map +1 -0
  72. package/dist/pg.d.mts +3 -0
  73. package/dist/pg.mjs +2 -0
  74. package/dist/pg.mjs.map +1 -0
  75. package/dist/pglite.d.mts +3 -0
  76. package/dist/pglite.mjs +2 -0
  77. package/dist/pglite.mjs.map +1 -0
  78. package/dist/planetscale.d.mts +3 -0
  79. package/dist/planetscale.mjs +2 -0
  80. package/dist/planetscale.mjs.map +1 -0
  81. package/dist/postgres-adapter-Blzqj1bl.mjs +6 -0
  82. package/dist/postgres-adapter-Blzqj1bl.mjs.map +1 -0
  83. package/dist/postgres.d.mts +3 -0
  84. package/dist/postgres.mjs +2 -0
  85. package/dist/postgres.mjs.map +1 -0
  86. package/dist/push-qZreXYkb.mjs +252 -0
  87. package/dist/push-qZreXYkb.mjs.map +1 -0
  88. package/dist/result-parsing-FNQbuHvC.mjs +2 -0
  89. package/dist/result-parsing-FNQbuHvC.mjs.map +1 -0
  90. package/dist/schema-DeAJZocc.mjs +2 -0
  91. package/dist/schema-DeAJZocc.mjs.map +1 -0
  92. package/dist/schema.d.mts +293 -0
  93. package/dist/schema.mjs +2 -0
  94. package/dist/schema.mjs.map +1 -0
  95. package/dist/spans-CJt5UgbJ.mjs +2 -0
  96. package/dist/spans-CJt5UgbJ.mjs.map +1 -0
  97. package/dist/sqlite-adapter-5Em_-oGU.mjs +6 -0
  98. package/dist/sqlite-adapter-5Em_-oGU.mjs.map +1 -0
  99. package/dist/sqlite-utils-BW7elKTz.mjs +2 -0
  100. package/dist/sqlite-utils-BW7elKTz.mjs.map +1 -0
  101. package/dist/sqlite3.d.mts +3 -0
  102. package/dist/sqlite3.mjs +2 -0
  103. package/dist/sqlite3.mjs.map +1 -0
  104. package/dist/tracer-CGzIAsj8.mjs +2 -0
  105. package/dist/tracer-CGzIAsj8.mjs.map +1 -0
  106. package/dist/validation-RtU-wu4N.mjs +2 -0
  107. package/dist/validation-RtU-wu4N.mjs.map +1 -0
  108. package/dist/validation.d.mts +2 -0
  109. package/dist/validation.mjs +1 -0
  110. package/dist/validator-DpJsJcd7.mjs +3 -0
  111. package/dist/validator-DpJsJcd7.mjs.map +1 -0
  112. package/package.json +278 -0
  113. package/readme/README.md +69 -0
@@ -0,0 +1,2158 @@
1
+ import { H as RelationType } from "./helper-cDCDjRAD.mjs";
2
+ import * as _opentelemetry_api0 from "@opentelemetry/api";
3
+
4
+ //#region src/errors.d.ts
5
+
6
+ /**
7
+ * Error codes for programmatic error handling
8
+ */
9
+ declare enum VibORMErrorCode {
10
+ CONNECTION_FAILED = "V1001",
11
+ CONNECTION_TIMEOUT = "V1002",
12
+ CONNECTION_CLOSED = "V1003",
13
+ QUERY_FAILED = "V2001",
14
+ QUERY_TIMEOUT = "V2002",
15
+ QUERY_SYNTAX = "V2003",
16
+ UNIQUE_CONSTRAINT = "V3001",
17
+ FOREIGN_KEY_CONSTRAINT = "V3002",
18
+ NOT_NULL_CONSTRAINT = "V3003",
19
+ CHECK_CONSTRAINT = "V3004",
20
+ VALIDATION_FAILED = "V4001",
21
+ INVALID_INPUT = "V4002",
22
+ MISSING_REQUIRED = "V4003",
23
+ TRANSACTION_FAILED = "V5001",
24
+ TRANSACTION_TIMEOUT = "V5002",
25
+ DEADLOCK = "V5003",
26
+ SERIALIZATION_FAILURE = "V5004",
27
+ INVALID_TRANSACTION_INPUT = "V5005",
28
+ RECORD_NOT_FOUND = "V6001",
29
+ MODEL_NOT_FOUND = "V6002",
30
+ RELATION_NOT_FOUND = "V6003",
31
+ NESTED_WRITE_FAILED = "V7001",
32
+ NESTED_CREATE_FAILED = "V7002",
33
+ NESTED_UPDATE_FAILED = "V7003",
34
+ NESTED_DELETE_FAILED = "V7004",
35
+ NESTED_CONNECT_FAILED = "V7005",
36
+ FEATURE_NOT_SUPPORTED = "V8001",
37
+ DRIVER_NOT_SUPPORTED = "V8002",
38
+ CACHE_INVALID_TTL = "V10001",
39
+ CACHE_INVALID_KEY = "V10002",
40
+ CACHE_OPERATION_NOT_CACHEABLE = "V10003",
41
+ MIGRATION_FAILED = "V11001",
42
+ MIGRATION_NOT_FOUND = "V11002",
43
+ MIGRATION_CHECKSUM_MISMATCH = "V11003",
44
+ MIGRATION_DIALECT_MISMATCH = "V11004",
45
+ MIGRATION_LOCK_FAILED = "V11005",
46
+ MIGRATION_ALREADY_APPLIED = "V11006",
47
+ MIGRATION_OUT_OF_ORDER = "V11007",
48
+ MIGRATION_FILE_NOT_FOUND = "V11008",
49
+ MIGRATION_INVALID_STATE = "V11009",
50
+ MIGRATION_DESTRUCTIVE_REJECTED = "V11010",
51
+ MIGRATION_STORAGE_REQUIRED = "V11011",
52
+ OPERATION_ALREADY_EXECUTED = "V12001",
53
+ OPERATION_EXECUTION_CONFLICT = "V12002",
54
+ OPERATION_CLIENT_MISMATCH = "V12003",
55
+ INTERNAL_ERROR = "V9001",
56
+ SCHEMA_ERROR = "V9002",
57
+ }
58
+ /**
59
+ * Error metadata for additional context
60
+ */
61
+ interface VibORMErrorMeta {
62
+ /** Model name if applicable */
63
+ model?: string;
64
+ /** Operation being performed */
65
+ operation?: string;
66
+ /** Relation name if applicable */
67
+ relation?: string;
68
+ /** Table name */
69
+ table?: string;
70
+ /** Column names */
71
+ columns?: string[];
72
+ /** Constraint name */
73
+ constraint?: string;
74
+ /** SQL query (redacted by default) */
75
+ query?: string;
76
+ /** Query parameters */
77
+ params?: unknown[];
78
+ /** Feature name */
79
+ feature?: string;
80
+ /** Method name */
81
+ method?: string;
82
+ /** Additional context */
83
+ [key: string]: unknown;
84
+ }
85
+ /**
86
+ * Base error class for all VibORM errors
87
+ */
88
+ declare class VibORMError extends Error {
89
+ /** Error code for programmatic handling */
90
+ readonly code: VibORMErrorCode;
91
+ /** Original cause if wrapping another error */
92
+ readonly originalCause?: Error | undefined;
93
+ /** Additional metadata */
94
+ readonly meta: VibORMErrorMeta;
95
+ /** Timestamp when error occurred */
96
+ readonly timestamp: Date;
97
+ constructor(message: string, code: VibORMErrorCode, options?: {
98
+ cause?: Error | undefined;
99
+ meta?: VibORMErrorMeta | undefined;
100
+ });
101
+ /**
102
+ * Check if error is retryable (deadlock, serialization failure)
103
+ */
104
+ isRetryable(): boolean;
105
+ /**
106
+ * Convert to JSON for logging/serialization
107
+ */
108
+ toJSON(): Record<string, unknown>;
109
+ }
110
+ /**
111
+ * Connection-related errors
112
+ */
113
+ declare class ConnectionError$1 extends VibORMError {
114
+ constructor(message: string, options?: {
115
+ cause?: Error | undefined;
116
+ meta?: VibORMErrorMeta | undefined;
117
+ code?: VibORMErrorCode | undefined;
118
+ });
119
+ }
120
+ /**
121
+ * Query execution errors
122
+ */
123
+ declare class QueryError$1 extends VibORMError {
124
+ constructor(message: string, options?: {
125
+ cause?: Error | undefined;
126
+ meta?: VibORMErrorMeta | undefined;
127
+ code?: VibORMErrorCode | undefined;
128
+ });
129
+ }
130
+ /**
131
+ * Unique constraint violation
132
+ */
133
+ declare class UniqueConstraintError extends VibORMError {
134
+ constructor(message: string, options?: {
135
+ cause?: Error | undefined;
136
+ meta?: VibORMErrorMeta & {
137
+ constraint?: string;
138
+ table?: string;
139
+ columns?: string[];
140
+ };
141
+ });
142
+ }
143
+ /**
144
+ * Foreign key constraint violation
145
+ */
146
+ declare class ForeignKeyError extends VibORMError {
147
+ constructor(message: string, options?: {
148
+ cause?: Error | undefined;
149
+ meta?: VibORMErrorMeta & {
150
+ constraint?: string;
151
+ };
152
+ });
153
+ }
154
+ /**
155
+ * Validation issue details
156
+ */
157
+ interface ValidationIssue {
158
+ path: string;
159
+ message: string;
160
+ }
161
+ /**
162
+ * Input validation errors
163
+ */
164
+ declare class ValidationError$1 extends VibORMError {
165
+ /** Validation issues */
166
+ readonly issues: ValidationIssue[];
167
+ /** Operation that failed validation */
168
+ readonly operation: Operation;
169
+ constructor(operation: Operation, issues: ValidationIssue[], options?: {
170
+ meta?: VibORMErrorMeta;
171
+ });
172
+ }
173
+ /**
174
+ * Transaction errors
175
+ */
176
+ declare class TransactionError extends VibORMError {
177
+ constructor(message: string, options?: {
178
+ cause?: Error | undefined;
179
+ meta?: VibORMErrorMeta | undefined;
180
+ code?: VibORMErrorCode | undefined;
181
+ });
182
+ }
183
+ /**
184
+ * Record not found (for OrThrow operations)
185
+ */
186
+ declare class NotFoundError extends VibORMError {
187
+ constructor(model: string, operation: string, options?: {
188
+ meta?: VibORMErrorMeta;
189
+ });
190
+ }
191
+ /**
192
+ * Nested write operation errors
193
+ */
194
+ declare class NestedWriteError extends VibORMError {
195
+ constructor(message: string, relation: string, options?: {
196
+ cause?: Error | undefined;
197
+ meta?: VibORMErrorMeta | undefined;
198
+ code?: VibORMErrorCode | undefined;
199
+ });
200
+ }
201
+ /**
202
+ * Feature not supported errors
203
+ */
204
+ declare class FeatureNotSupportedError extends VibORMError {
205
+ constructor(feature: string, method: string, suggestion?: string);
206
+ }
207
+ /**
208
+ * Migration error metadata
209
+ */
210
+ interface MigrationErrorMeta extends VibORMErrorMeta {
211
+ /** Name of the migration */
212
+ migrationName?: string;
213
+ /** Expected checksum (from database) */
214
+ expectedChecksum?: string;
215
+ /** Actual checksum (from file) */
216
+ actualChecksum?: string;
217
+ /** Migration index */
218
+ migrationIndex?: number;
219
+ /** Directory path */
220
+ migrationsDir?: string;
221
+ }
222
+ /**
223
+ * Migration-related errors
224
+ */
225
+ declare class MigrationError extends VibORMError {
226
+ constructor(message: string, code?: VibORMErrorCode, options?: {
227
+ cause?: Error | undefined;
228
+ meta?: MigrationErrorMeta | undefined;
229
+ });
230
+ }
231
+ /**
232
+ * Type guard for migration errors
233
+ */
234
+ declare function isMigrationError(error: unknown): error is MigrationError;
235
+ /**
236
+ * Type guard to check if error is a VibORMError
237
+ */
238
+ declare function isVibORMError(error: unknown): error is VibORMError;
239
+ /**
240
+ * Check if error is retryable
241
+ */
242
+ declare function isRetryableError(error: unknown): boolean;
243
+ /**
244
+ * Wrap unknown error in VibORMError
245
+ */
246
+ declare function wrapError(error: unknown, code?: VibORMErrorCode, meta?: VibORMErrorMeta): VibORMError;
247
+ //#endregion
248
+ //#region src/instrumentation/types.d.ts
249
+ /**
250
+ * Log levels for the logging callback
251
+ */
252
+ type LogLevel = "query" | "cache" | "warning" | "error";
253
+ /**
254
+ * Log event payload passed to the logging callback
255
+ */
256
+ interface LogEvent {
257
+ /** Log level */
258
+ level: LogLevel;
259
+ /** Timestamp of the event */
260
+ timestamp: Date;
261
+ /** Duration in milliseconds (for query events) */
262
+ duration?: number | undefined;
263
+ /** Model name */
264
+ model?: string | undefined;
265
+ /** Operation being performed */
266
+ operation?: Operation | undefined;
267
+ /** Error if applicable */
268
+ error?: VibORMError | Error | undefined;
269
+ /** SQL query (only if includeSql is enabled) */
270
+ sql?: string | undefined;
271
+ /** Query parameters (only if includeSql is enabled) */
272
+ params?: unknown[] | undefined;
273
+ /** Additional metadata */
274
+ meta?: Record<string, unknown> | undefined;
275
+ }
276
+ /**
277
+ * Logging callback function signature
278
+ * @param event - The log event
279
+ * @param log - Call this to invoke the default pretty logger
280
+ */
281
+ type LogCallback = (event: LogEvent, log: () => void) => void;
282
+ /**
283
+ * Tracing configuration options
284
+ */
285
+ interface TracingConfig {
286
+ /**
287
+ * Include SQL query text in spans.
288
+ * @default true
289
+ */
290
+ includeSql?: boolean | undefined;
291
+ /**
292
+ * Include query parameters in spans.
293
+ * WARNING: May expose sensitive data. Use only in development/staging.
294
+ * @default false
295
+ */
296
+ includeParams?: boolean | undefined;
297
+ /**
298
+ * Span names to ignore (string or regex patterns)
299
+ * Similar to Prisma's ignoreSpanTypes
300
+ */
301
+ ignoreSpanTypes?: Array<string | RegExp> | undefined;
302
+ }
303
+ /**
304
+ * Handler for a log level: true for default console output, or a custom callback
305
+ */
306
+ type LogLevelHandler = true | LogCallback;
307
+ /**
308
+ * Logging configuration options
309
+ *
310
+ * Each log level can be:
311
+ * - `true` to use the default pretty console output
312
+ * - A callback function for custom handling (receives event and default logger)
313
+ * - Omitted/undefined to disable that level
314
+ *
315
+ * Use `all` as a catch-all for all log levels.
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * logging: {
320
+ * query: true, // Pretty console output
321
+ * error: (event, log) => {
322
+ * errorTracker.capture(event.error);
323
+ * log(); // Also use default logger
324
+ * },
325
+ * // warning: omitted = disabled
326
+ * }
327
+ * ```
328
+ */
329
+ interface LoggingConfig {
330
+ /**
331
+ * Catch-all handler for all log levels.
332
+ * Applied when a specific level handler is not defined.
333
+ */
334
+ all?: LogLevelHandler | undefined;
335
+ /**
336
+ * Query log handler.
337
+ * Emitted for every database query.
338
+ */
339
+ query?: LogLevelHandler | undefined;
340
+ /**
341
+ * Cache log handler.
342
+ * Emitted for cache operations (hit, miss, revalidate).
343
+ */
344
+ cache?: LogLevelHandler | undefined;
345
+ /**
346
+ * Warning log handler.
347
+ * Emitted for non-fatal issues.
348
+ */
349
+ warning?: LogLevelHandler | undefined;
350
+ /**
351
+ * Error log handler.
352
+ * Emitted when operations fail.
353
+ */
354
+ error?: LogLevelHandler | undefined;
355
+ /**
356
+ * Include SQL query text in log events.
357
+ * @default true
358
+ */
359
+ includeSql?: boolean | undefined;
360
+ /**
361
+ * Include query parameters in log events.
362
+ * WARNING: May expose sensitive data. Use only in development/staging.
363
+ * @default false
364
+ */
365
+ includeParams?: boolean | undefined;
366
+ }
367
+ /**
368
+ * Main instrumentation configuration
369
+ */
370
+ interface InstrumentationConfig {
371
+ /**
372
+ * Enable OpenTelemetry tracing.
373
+ * - `true` enables with defaults (includeSql: true, includeParams: false)
374
+ * - Object for custom configuration
375
+ */
376
+ tracing?: true | TracingConfig | undefined;
377
+ /**
378
+ * Enable structured logging.
379
+ * - `true` enables pretty console output for all levels
380
+ * - Object for custom configuration
381
+ */
382
+ logging?: true | LoggingConfig | undefined;
383
+ }
384
+ //#endregion
385
+ //#region src/instrumentation/logger.d.ts
386
+ /**
387
+ * Logger interface for internal use
388
+ */
389
+ interface Logger {
390
+ /** Log an event with explicit level */
391
+ log(event: LogEvent): void;
392
+ /** Log a query event */
393
+ query(event: Omit<LogEvent, "level">): void;
394
+ /** Log a cache event */
395
+ cache(event: Omit<LogEvent, "level">): void;
396
+ /** Log a warning event */
397
+ warn(event: Omit<LogEvent, "level">): void;
398
+ /** Log an error event */
399
+ error(event: Omit<LogEvent, "level">): void;
400
+ /** Check if a specific level is enabled */
401
+ isLevelEnabled(level: LogLevel): boolean;
402
+ }
403
+ //#endregion
404
+ //#region src/instrumentation/spans.d.ts
405
+ /**
406
+ * Span Names
407
+ *
408
+ * Constants for OpenTelemetry span names following VibORM conventions.
409
+ * Using a prefix pattern similar to Prisma (prisma:*) and Drizzle (drizzle.*).
410
+ */
411
+ /**
412
+ * Span name for high-level client operations
413
+ * Created for each client method call (findMany, create, etc.)
414
+ */
415
+ declare const SPAN_OPERATION = "viborm.operation";
416
+ /**
417
+ * Span name for input validation
418
+ * Created during schema validation of operation arguments
419
+ */
420
+ declare const SPAN_VALIDATE = "viborm.validate";
421
+ /**
422
+ * Span name for SQL building
423
+ * Created during query construction
424
+ */
425
+ declare const SPAN_BUILD = "viborm.build";
426
+ /**
427
+ * Span name for query execution
428
+ * Created for the actual database round-trip
429
+ */
430
+ declare const SPAN_EXECUTE = "viborm.execute";
431
+ /**
432
+ * Span name for result parsing
433
+ * Created during result hydration
434
+ */
435
+ declare const SPAN_PARSE = "viborm.parse";
436
+ /**
437
+ * Span name for transactions
438
+ * Created around transaction boundaries
439
+ */
440
+ declare const SPAN_TRANSACTION = "viborm.transaction";
441
+ /**
442
+ * Span name for connection establishment
443
+ * Created during lazy connection initialization
444
+ */
445
+ declare const SPAN_CONNECT = "viborm.connect";
446
+ /**
447
+ * Span name for connection teardown
448
+ * Created during disconnect
449
+ */
450
+ declare const SPAN_DISCONNECT = "viborm.disconnect";
451
+ /**
452
+ * Type for all valid span names
453
+ */
454
+ type VibORMSpanName = typeof SPAN_OPERATION | typeof SPAN_VALIDATE | typeof SPAN_BUILD | typeof SPAN_EXECUTE | typeof SPAN_PARSE | typeof SPAN_TRANSACTION | typeof SPAN_CONNECT | typeof SPAN_DISCONNECT | typeof SPAN_CACHE_GET | typeof SPAN_CACHE_SET | typeof SPAN_CACHE_DELETE | typeof SPAN_CACHE_CLEAR | typeof SPAN_CACHE_INVALIDATE;
455
+ /**
456
+ * Semantic attribute keys for span attributes
457
+ * Following OTel database semantic conventions where possible
458
+ * @see https://opentelemetry.io/docs/specs/semconv/database/database-spans/
459
+ */
460
+ /** Database system (postgresql, mysql, sqlite) - REQUIRED */
461
+ declare const ATTR_DB_SYSTEM = "db.system.name";
462
+ /** Database name/schema - Conditionally required */
463
+ declare const ATTR_DB_NAMESPACE = "db.namespace";
464
+ /** Table/collection name - Conditionally required */
465
+ declare const ATTR_DB_COLLECTION = "db.collection.name";
466
+ /** Operation name (SELECT, INSERT, findMany, create) - Conditionally required */
467
+ declare const ATTR_DB_OPERATION_NAME = "db.operation.name";
468
+ /** SQL query text - Recommended */
469
+ declare const ATTR_DB_QUERY_TEXT = "db.query.text";
470
+ /** Low cardinality query summary - Recommended */
471
+ declare const ATTR_DB_QUERY_SUMMARY = "db.query.summary";
472
+ /** Batch operation size - Recommended */
473
+ declare const ATTR_DB_BATCH_SIZE = "db.operation.batch.size";
474
+ /** Database server host - Recommended */
475
+ declare const ATTR_SERVER_ADDRESS = "server.address";
476
+ /** Database server port - Conditionally required */
477
+ declare const ATTR_SERVER_PORT = "server.port";
478
+ /** Number of rows returned - Optional */
479
+ declare const ATTR_DB_ROWS_RETURNED = "db.response.returned_rows";
480
+ /** Error type on failure - Conditionally required */
481
+ declare const ATTR_ERROR_TYPE = "error.type";
482
+ /** Driver name (postgres, pg, pglite, mysql2, better-sqlite3) */
483
+ declare const ATTR_DB_DRIVER = "db.system.driver";
484
+ /**
485
+ * Query parameter by key or index
486
+ * Usage: `db.query.parameter.0`, `db.query.parameter.userId`
487
+ */
488
+ declare const ATTR_DB_QUERY_PARAMETER_PREFIX = "db.query.parameter";
489
+ /** Span name for cache get operations */
490
+ declare const SPAN_CACHE_GET = "viborm.cache.get";
491
+ /** Span name for cache set operations */
492
+ declare const SPAN_CACHE_SET = "viborm.cache.set";
493
+ /** Span name for cache delete operations */
494
+ declare const SPAN_CACHE_DELETE = "viborm.cache.delete";
495
+ /** Span name for cache clear operations */
496
+ declare const SPAN_CACHE_CLEAR = "viborm.cache.clear";
497
+ /** Span name for cache invalidation */
498
+ declare const SPAN_CACHE_INVALIDATE = "viborm.cache.invalidate";
499
+ /** Cache driver name (memory, cloudflare-kv, redis, etc.) */
500
+ declare const ATTR_CACHE_DRIVER = "cache.driver";
501
+ /** Cache key */
502
+ declare const ATTR_CACHE_KEY = "cache.key";
503
+ /** Cache operation result (hit, miss, stale) */
504
+ declare const ATTR_CACHE_RESULT = "cache.result";
505
+ /** Cache TTL in milliseconds */
506
+ declare const ATTR_CACHE_TTL = "cache.ttl";
507
+ //#endregion
508
+ //#region src/instrumentation/tracer.d.ts
509
+ type Span = _opentelemetry_api0.Span;
510
+ type SpanKind = _opentelemetry_api0.SpanKind;
511
+ type Attributes = _opentelemetry_api0.Attributes;
512
+ /**
513
+ * Extended span options with VibORM-specific attributes
514
+ */
515
+ interface VibORMSpanOptions {
516
+ /** Span name from the predefined constants */
517
+ name: VibORMSpanName;
518
+ /** Span kind (default: INTERNAL) */
519
+ kind?: SpanKind | undefined;
520
+ /** Additional attributes */
521
+ attributes?: Attributes | undefined;
522
+ /** SQL info (only included if tracer config has includeSql enabled) */
523
+ sql?: {
524
+ query: string;
525
+ params?: unknown[];
526
+ } | undefined;
527
+ /** Start a new root span (not child of current context) */
528
+ root?: boolean | undefined;
529
+ }
530
+ /**
531
+ * Tracer wrapper interface
532
+ *
533
+ * All methods are safe to call regardless of whether OTel is loaded.
534
+ * When OTel is not available, methods execute callbacks directly without tracing.
535
+ */
536
+ interface TracerWrapper {
537
+ /**
538
+ * Start an active span and execute callback within it.
539
+ * When OTel unavailable, executes callback directly.
540
+ */
541
+ startActiveSpan<T>(options: VibORMSpanOptions, fn: (span?: Span) => T | Promise<T>): Promise<T>;
542
+ /**
543
+ * Synchronous version for non-async operations.
544
+ * When OTel unavailable, executes callback directly.
545
+ */
546
+ startActiveSpanSync<T>(options: VibORMSpanOptions, fn: (span?: Span) => T): T;
547
+ /**
548
+ * Check if tracing is enabled (OTel loaded and configured)
549
+ */
550
+ isEnabled(): boolean;
551
+ }
552
+ //#endregion
553
+ //#region src/instrumentation/context.d.ts
554
+ /**
555
+ * Combined instrumentation context
556
+ *
557
+ * Note: `tracer` is always defined - it's either a real tracer or a no-op tracer.
558
+ * This allows code to unconditionally call tracer methods without null checks.
559
+ */
560
+ interface InstrumentationContext {
561
+ /** Original configuration */
562
+ config: InstrumentationConfig;
563
+ /** Tracer wrapper - always present (no-op if tracing not configured) */
564
+ tracer: TracerWrapper;
565
+ /** Logger (if logging enabled) */
566
+ logger?: Logger | undefined;
567
+ }
568
+ //#endregion
569
+ //#region src/sql/sql.d.ts
570
+ /**
571
+ * Values supported by SQL engine.
572
+ */
573
+ type Value = unknown;
574
+ /**
575
+ * Supported value or SQL instance.
576
+ */
577
+ type RawValue = Value | Sql;
578
+ /**
579
+ * A SQL instance can be nested within each other to build SQL strings.
580
+ */
581
+ declare class Sql {
582
+ readonly values: Value[];
583
+ readonly strings: string[];
584
+ private _stmt$n;
585
+ private _stmt$;
586
+ private _stmtQ;
587
+ constructor(rawStrings: readonly string[], rawValues: readonly RawValue[]);
588
+ /**
589
+ * Build the final SQL statement string with placeholders.
590
+ * Results are cached per placeholder type for reuse.
591
+ */
592
+ toStatement(placeholder?: "$n" | ":n" | "?"): string;
593
+ }
594
+ //#endregion
595
+ //#region src/drivers/types.d.ts
596
+ /**
597
+ * Driver Types
598
+ *
599
+ * Core types for database drivers.
600
+ */
601
+ /**
602
+ * Supported database dialects
603
+ */
604
+ type Dialect = "postgresql" | "mysql" | "sqlite";
605
+ /**
606
+ * Query result from database execution
607
+ */
608
+ interface QueryResult<T = Record<string, unknown>> {
609
+ /** Returned rows */
610
+ rows: T[];
611
+ /** Number of affected rows (INSERT/UPDATE/DELETE) */
612
+ rowCount: number;
613
+ }
614
+ /**
615
+ * Transaction isolation levels
616
+ */
617
+ type IsolationLevel = "read_uncommitted" | "read_committed" | "repeatable_read" | "serializable";
618
+ /**
619
+ * Transaction options
620
+ */
621
+ interface TransactionOptions {
622
+ isolationLevel?: IsolationLevel;
623
+ timeout?: number;
624
+ }
625
+ /**
626
+ * Log function signature
627
+ */
628
+ type LogFunction = (query: string, params: unknown[], duration: number) => void;
629
+ /**
630
+ * A single query in a batch operation
631
+ */
632
+ interface BatchQuery {
633
+ /** SQL string */
634
+ sql: string;
635
+ /** Query parameters */
636
+ params?: unknown[];
637
+ }
638
+ //#endregion
639
+ //#region src/drivers/driver.d.ts
640
+ /**
641
+ * Driver-level result parsing middleware.
642
+ */
643
+ interface DriverResultParser {
644
+ parseResult?: (raw: unknown, operation: Operation, next: (raw: unknown, operation: Operation) => unknown) => unknown;
645
+ parseRelation?: (value: unknown, type: RelationType, next: (value: unknown, type: RelationType) => unknown) => unknown;
646
+ parseField?: (value: unknown, fieldType: string, next: (value: unknown, fieldType: string) => unknown) => unknown;
647
+ }
648
+ /**
649
+ * Context for the current query execution
650
+ */
651
+ interface QueryExecutionContext {
652
+ model?: string;
653
+ operation?: Operation;
654
+ }
655
+ /**
656
+ * Abstract base class for drivers with lazy client initialization.
657
+ *
658
+ * Subclasses must implement:
659
+ * - `initClient()`: Creates the database client
660
+ * - `closeClient()`: Closes the database client
661
+ * - `execute()`: Executes a query (receives client, sql string, params)
662
+ * - `executeRaw()`: Executes raw SQL (receives client, sql string, params)
663
+ * - `runTransaction()`: Runs a transaction with the client
664
+ */
665
+ declare abstract class Driver<TClient, TTransaction> {
666
+ connect?(): Promise<void>;
667
+ /**
668
+ * Whether this driver supports transactions (BEGIN/COMMIT/ROLLBACK).
669
+ * Default: true for most drivers, false for HTTP-based drivers like D1, Neon-HTTP.
670
+ */
671
+ readonly supportsTransactions: boolean;
672
+ /**
673
+ * Whether this driver supports native batch execution.
674
+ * Batch execution allows multiple independent queries to be executed atomically.
675
+ * Default: false. Override in drivers that have native batch support (D1, D1-HTTP, Neon-HTTP).
676
+ */
677
+ readonly supportsBatch: boolean;
678
+ readonly dialect: Dialect;
679
+ readonly driverName: string;
680
+ abstract readonly adapter: DatabaseAdapter;
681
+ readonly result?: DriverResultParser;
682
+ protected client: TClient | TTransaction | null;
683
+ protected inTransaction: boolean;
684
+ private initPromise;
685
+ private isDisconnecting;
686
+ protected instrumentation?: InstrumentationContext;
687
+ protected currentContext: QueryExecutionContext;
688
+ protected abstract initClient(): Promise<TClient>;
689
+ protected abstract closeClient(client: TClient | TTransaction): Promise<void>;
690
+ /**
691
+ * Execute a query. Receives client, SQL string, and params.
692
+ */
693
+ protected abstract execute<T>(client: TClient | TTransaction, sql: string, params: unknown[]): Promise<QueryResult<T>>;
694
+ /**
695
+ * Execute raw SQL. Receives client, SQL string, and optional params.
696
+ */
697
+ protected abstract executeRaw<T>(client: TClient | TTransaction, sql: string, params?: unknown[]): Promise<QueryResult<T>>;
698
+ /**
699
+ * Run a transaction with the client.
700
+ */
701
+ protected abstract transaction<T>(client: TClient | TTransaction, fn: (tx: TTransaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
702
+ constructor(dialect: Dialect, driverName: string);
703
+ /**
704
+ * Set instrumentation context
705
+ */
706
+ setInstrumentation(ctx: InstrumentationContext | undefined): void;
707
+ /**
708
+ * Set context before execution (called by query engine)
709
+ */
710
+ setContext(ctx: QueryExecutionContext): void;
711
+ /**
712
+ * Clear context after execution
713
+ */
714
+ clearContext(): void;
715
+ /**
716
+ * Get base OTel attributes for this driver.
717
+ * Can be used by other parts of the code to include standard database attributes.
718
+ */
719
+ getBaseAttributes(): Record<string, string>;
720
+ /**
721
+ * Get OTel attributes including current context (model, operation).
722
+ */
723
+ getContextAttributes(): Record<string, string | undefined>;
724
+ /**
725
+ * Build dialect-specific SQL statement.
726
+ * Uses Sql.toStatement() which caches results per placeholder type.
727
+ */
728
+ protected buildStatement(query: Sql): string;
729
+ /**
730
+ * Log a query execution (success)
731
+ */
732
+ protected logQuery(sql: string, params: unknown[], duration: number, model?: string, operation?: Operation, error?: unknown): void;
733
+ /**
734
+ * Get or initialize the client.
735
+ */
736
+ protected getClient(): Promise<TClient | TTransaction>;
737
+ /**
738
+ * Wrap query execution with logging and tracing.
739
+ */
740
+ private withInstrumentation;
741
+ /**
742
+ * Execute a query with instrumentation (tracing + logging).
743
+ * Converts Sql to string/params ONCE, then calls run().
744
+ */
745
+ _execute<T = Record<string, unknown>>(query: Sql): Promise<QueryResult<T>>;
746
+ /**
747
+ * Execute raw SQL with instrumentation.
748
+ */
749
+ _executeRaw<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<QueryResult<T>>;
750
+ /**
751
+ * Execute a function within a transaction.
752
+ *
753
+ * The callback receives the raw transaction object. Use `TransactionBoundDriver`
754
+ * to create a driver that executes all operations within this transaction.
755
+ *
756
+ * @param fn - Callback that receives the transaction object
757
+ * @param options - Transaction options (isolation level, etc.)
758
+ */
759
+ _transaction<T>(fn: (tx: TTransaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
760
+ /**
761
+ * Execute a function with a transaction-bound driver.
762
+ *
763
+ * This is a convenience method that wraps `_transaction` and provides
764
+ * a `TransactionBoundDriver` to the callback, so all operations
765
+ * automatically execute within the transaction.
766
+ *
767
+ * If the driver doesn't support transactions, the callback is executed
768
+ * directly with the current driver (no transaction wrapping).
769
+ *
770
+ * @param fn - Callback that receives a transaction-bound driver
771
+ * @param options - Transaction options (isolation level, etc.)
772
+ *
773
+ * @example
774
+ * ```typescript
775
+ * await driver.withTransaction(async (txDriver) => {
776
+ * await txDriver._execute(query1);
777
+ * await txDriver._execute(query2);
778
+ * // Both queries run in the same transaction
779
+ * });
780
+ * ```
781
+ */
782
+ withTransaction<T>(fn: (txDriver: Driver<TClient, TTransaction>) => Promise<T>, options?: TransactionOptions): Promise<T>;
783
+ /**
784
+ * Execute multiple queries in a batch.
785
+ * Default implementation: sequential execution.
786
+ * Override in drivers with native batch support (D1, D1-HTTP, Neon-HTTP).
787
+ */
788
+ protected executeBatch<T>(client: TClient | TTransaction, queries: BatchQuery[]): Promise<QueryResult<T>[]>;
789
+ /**
790
+ * Public API for batch execution with instrumentation.
791
+ * Uses native batch if supported, otherwise falls back to:
792
+ * 1. Transaction-wrapped sequential execution (if transactions supported)
793
+ * 2. Sequential execution with warning (no atomicity)
794
+ */
795
+ _executeBatch<T>(queries: BatchQuery[]): Promise<QueryResult<T>[]>;
796
+ /**
797
+ * Connect to the database with instrumentation.
798
+ */
799
+ _connect(): Promise<void>;
800
+ /**
801
+ * Disconnect from the database with instrumentation.
802
+ */
803
+ _disconnect(): Promise<void>;
804
+ disconnect(): Promise<void>;
805
+ }
806
+ /**
807
+ * Type alias for any driver (used when concrete types are not needed)
808
+ */
809
+ type AnyDriver = Driver<unknown, unknown>;
810
+ /**
811
+ * A driver wrapper that binds all operations to a specific transaction.
812
+ *
813
+ * This provides proper transaction isolation without prototype cloning.
814
+ * Each TransactionBoundDriver has its own instrumentation context for
815
+ * correct span parenting.
816
+ *
817
+ * @example
818
+ * ```typescript
819
+ * await driver._transaction(async (tx) => {
820
+ * const txDriver = new TransactionBoundDriver(driver, tx);
821
+ * await txDriver._execute(sql); // Executes within the transaction
822
+ * });
823
+ * ```
824
+ */
825
+ declare class TransactionBoundDriver<TClient, TTransaction> extends Driver<TClient, TTransaction> {
826
+ private readonly baseDriver;
827
+ private readonly tx;
828
+ private readonly savepointQueue;
829
+ readonly adapter: DatabaseAdapter;
830
+ readonly result?: DriverResultParser;
831
+ inTransaction: boolean;
832
+ readonly supportsTransactions: boolean;
833
+ readonly supportsBatch: boolean;
834
+ constructor(baseDriver: Driver<TClient, TTransaction>, tx: TTransaction);
835
+ protected getClient(): Promise<TClient | TTransaction>;
836
+ protected initClient(): Promise<TClient>;
837
+ protected closeClient(): Promise<void>;
838
+ protected execute<T>(client: TClient | TTransaction, sql: string, params: unknown[]): Promise<QueryResult<T>>;
839
+ protected executeRaw<T>(client: TClient | TTransaction, sql: string, params?: unknown[]): Promise<QueryResult<T>>;
840
+ protected transaction<T>(_client: TClient | TTransaction, fn: (tx: TTransaction) => Promise<T>, _options?: TransactionOptions): Promise<T>;
841
+ disconnect(): Promise<void>;
842
+ }
843
+ //#endregion
844
+ //#region src/query-engine/types.d.ts
845
+ /**
846
+ * Raw result from database execution
847
+ * - For regular queries: array of rows
848
+ * - For batch operations (createMany, etc.): object with rowCount
849
+ */
850
+ type RawQueryResult = unknown[] | {
851
+ rowCount: number;
852
+ };
853
+ /**
854
+ * Result parser function type
855
+ * Transforms raw database result into typed application objects
856
+ */
857
+ type ResultParser<T> = (raw: RawQueryResult) => T;
858
+ /**
859
+ * Prepared query ready for batch execution
860
+ */
861
+ interface PreparedQuery {
862
+ /** SQL string */
863
+ sql: string;
864
+ /** Query parameters */
865
+ params: unknown[];
866
+ }
867
+ /**
868
+ * Query metadata for lazy execution
869
+ *
870
+ * Validation and SQL building are deferred to execution time.
871
+ * This enables proper span ordering and prepares for future prepared statement support.
872
+ */
873
+ interface QueryMetadata<T> {
874
+ /** Unique identifier for the client that created this operation */
875
+ clientId: symbol;
876
+ /** Raw arguments (not yet validated) */
877
+ args: Record<string, unknown>;
878
+ /** The operation type */
879
+ operation: Operation;
880
+ /** Model name */
881
+ model: string;
882
+ /** Function to execute the operation (validates, builds SQL, executes, parses) */
883
+ execute: (driverOverride?: AnyDriver) => Promise<T>;
884
+ /**
885
+ * Function to prepare the query (validate, build SQL) without executing.
886
+ * Returns the SQL string and parameters for batch execution.
887
+ * Only available for operations that can be batched (no nested writes).
888
+ */
889
+ prepare?: (driverOverride?: AnyDriver) => PreparedQuery;
890
+ /**
891
+ * Function to parse raw query result into typed result.
892
+ * Used after batch execution to transform the raw result.
893
+ */
894
+ parseResult?: (raw: {
895
+ rows: unknown[];
896
+ rowCount: number;
897
+ }) => T;
898
+ /** Whether this is a batch operation (returns rowCount instead of rows) */
899
+ isBatchOperation: boolean;
900
+ /** Whether this operation has nested writes (can't be batched) */
901
+ hasNestedWrites: boolean;
902
+ }
903
+ /**
904
+ * All supported operations
905
+ */
906
+ type Operation = "findFirst" | "findMany" | "findUnique" | "create" | "createMany" | "update" | "updateMany" | "delete" | "deleteMany" | "upsert" | "count" | "aggregate" | "groupBy" | "exist";
907
+ //#endregion
908
+ //#region src/adapters/database-adapter.d.ts
909
+ /**
910
+ * Logical cast types that adapters map to dialect-specific SQL types.
911
+ *
912
+ * Instead of hardcoding SQL type names like "TEXT" or "VARCHAR",
913
+ * use these logical types and let each adapter map to the correct syntax.
914
+ */
915
+ type CastType = "text" | "integer" | "boolean" | "numeric";
916
+ /**
917
+ * DatabaseAdapter Interface
918
+ *
919
+ * A monadic, composable interface for database-specific SQL generation.
920
+ * Each method is a pure function that transforms Sql fragments or primitives
921
+ * into new Sql fragments, enabling clean composition without side effects.
922
+ *
923
+ * DESIGN PRINCIPLES:
924
+ * - Pure functions: Same inputs always produce same outputs
925
+ * - Composable: Outputs can be inputs to other methods
926
+ * - Database-agnostic inputs: Query engine speaks neutral language
927
+ * - Database-specific outputs: Adapter handles syntax differences
928
+ *
929
+ * USAGE:
930
+ * The query engine calls adapter methods to build SQL fragments,
931
+ * then composes them into complete queries. The adapter never
932
+ * needs to understand query semantics - just SQL syntax.
933
+ */
934
+ interface DatabaseAdapter {
935
+ /**
936
+ * RAW
937
+ * Escape hatch for raw SQL strings (use sparingly)
938
+ */
939
+ raw: (sqlString: string) => Sql;
940
+ /**
941
+ * IDENTIFIERS
942
+ * Database-specific identifier escaping (table names, column names, aliases)
943
+ */
944
+ identifiers: {
945
+ /** Escape a single identifier: "name" or `name` */
946
+ escape: (name: string) => Sql;
947
+ /** Create qualified column reference: "alias"."field" */
948
+ column: (alias: string, field: string) => Sql;
949
+ /** Create table with alias: "table" AS "alias" */
950
+ table: (tableName: string, alias: string) => Sql;
951
+ /** Create aliased expression: expr AS "alias" */
952
+ aliased: (expression: Sql, alias: string) => Sql;
953
+ };
954
+ /**
955
+ * LITERALS
956
+ * Value wrapping with proper parameterization
957
+ */
958
+ literals: {
959
+ /** Wrap a value as parameterized SQL */
960
+ value: (v: unknown) => Sql;
961
+ /** NULL keyword */
962
+ null: () => Sql;
963
+ /** TRUE literal (database-specific: TRUE vs 1) */
964
+ true: () => Sql;
965
+ /** FALSE literal (database-specific: FALSE vs 0) */
966
+ false: () => Sql;
967
+ /** Create a value list: ($1, $2, $3) */
968
+ list: (values: Sql[]) => Sql;
969
+ /** JSON value (PG: native, MySQL/SQLite: JSON.stringify) */
970
+ json: (v: unknown) => Sql;
971
+ };
972
+ /**
973
+ * OPERATORS
974
+ * Comparison and logical operators (pure Sql -> Sql)
975
+ */
976
+ operators: {
977
+ eq: (left: Sql, right: Sql) => Sql;
978
+ neq: (left: Sql, right: Sql) => Sql;
979
+ lt: (left: Sql, right: Sql) => Sql;
980
+ lte: (left: Sql, right: Sql) => Sql;
981
+ gt: (left: Sql, right: Sql) => Sql;
982
+ gte: (left: Sql, right: Sql) => Sql;
983
+ like: (column: Sql, pattern: Sql) => Sql;
984
+ notLike: (column: Sql, pattern: Sql) => Sql;
985
+ /** Case-insensitive LIKE (PG: ILIKE, MySQL: LIKE, SQLite: LIKE COLLATE NOCASE) */
986
+ ilike: (column: Sql, pattern: Sql) => Sql;
987
+ notIlike: (column: Sql, pattern: Sql) => Sql;
988
+ in: (column: Sql, values: Sql) => Sql;
989
+ notIn: (column: Sql, values: Sql) => Sql;
990
+ isNull: (expr: Sql) => Sql;
991
+ isNotNull: (expr: Sql) => Sql;
992
+ between: (column: Sql, min: Sql, max: Sql) => Sql;
993
+ notBetween: (column: Sql, min: Sql, max: Sql) => Sql;
994
+ and: (...conditions: Sql[]) => Sql;
995
+ or: (...conditions: Sql[]) => Sql;
996
+ not: (condition: Sql) => Sql;
997
+ exists: (subquery: Sql) => Sql;
998
+ notExists: (subquery: Sql) => Sql;
999
+ };
1000
+ /**
1001
+ * EXPRESSIONS
1002
+ * Computed values and functions
1003
+ */
1004
+ expressions: {
1005
+ add: (left: Sql, right: Sql) => Sql;
1006
+ subtract: (left: Sql, right: Sql) => Sql;
1007
+ multiply: (left: Sql, right: Sql) => Sql;
1008
+ divide: (left: Sql, right: Sql) => Sql;
1009
+ concat: (...parts: Sql[]) => Sql;
1010
+ upper: (expr: Sql) => Sql;
1011
+ lower: (expr: Sql) => Sql;
1012
+ coalesce: (...exprs: Sql[]) => Sql;
1013
+ greatest: (...exprs: Sql[]) => Sql;
1014
+ least: (...exprs: Sql[]) => Sql;
1015
+ cast: (expr: Sql, type: CastType) => Sql;
1016
+ };
1017
+ /**
1018
+ * AGGREGATES
1019
+ * Aggregate functions
1020
+ */
1021
+ aggregates: {
1022
+ count: (expr?: Sql) => Sql;
1023
+ countDistinct: (expr: Sql) => Sql;
1024
+ sum: (expr: Sql) => Sql;
1025
+ avg: (expr: Sql) => Sql;
1026
+ min: (expr: Sql) => Sql;
1027
+ max: (expr: Sql) => Sql;
1028
+ };
1029
+ /**
1030
+ * JSON
1031
+ * Database-specific JSON building and extraction
1032
+ */
1033
+ json: {
1034
+ /** Build JSON object from key-value pairs */
1035
+ object: (pairs: [string, Sql][]) => Sql;
1036
+ /** Build JSON array from items */
1037
+ array: (items: Sql[]) => Sql;
1038
+ /** Empty JSON array literal: '[]'::json (PG), JSON_ARRAY() (MySQL), '[]' (SQLite) */
1039
+ emptyArray: () => Sql;
1040
+ /** Aggregate rows into JSON array */
1041
+ agg: (expr: Sql) => Sql;
1042
+ /** Convert row to JSON object (PG only - use objectFromColumns for MySQL/SQLite) */
1043
+ rowToJson: (alias: string) => Sql;
1044
+ /** Build JSON object from explicit column list (works on all databases) */
1045
+ objectFromColumns: (columns: [string, Sql][]) => Sql;
1046
+ /** Extract value from JSON by path */
1047
+ extract: (column: Sql, path: string[]) => Sql;
1048
+ /** Extract value as text */
1049
+ extractText: (column: Sql, path: string[]) => Sql;
1050
+ };
1051
+ /**
1052
+ * ARRAYS
1053
+ * Array operations (PG: native arrays, MySQL/SQLite: JSON-based)
1054
+ */
1055
+ arrays: {
1056
+ /** Create array literal */
1057
+ literal: (items: Sql[]) => Sql;
1058
+ /** Check if array contains value */
1059
+ has: (column: Sql, value: Sql) => Sql;
1060
+ /** Check if array contains all values */
1061
+ hasEvery: (column: Sql, values: Sql) => Sql;
1062
+ /** Check if array contains any value */
1063
+ hasSome: (column: Sql, values: Sql) => Sql;
1064
+ /** Check if array is empty */
1065
+ isEmpty: (column: Sql) => Sql;
1066
+ /** Get array length */
1067
+ length: (column: Sql) => Sql;
1068
+ /** Get element at index */
1069
+ get: (column: Sql, index: Sql) => Sql;
1070
+ /** Append value to array */
1071
+ push: (column: Sql, value: Sql) => Sql;
1072
+ /** Set value at index */
1073
+ set: (column: Sql, index: Sql, value: Sql) => Sql;
1074
+ };
1075
+ /**
1076
+ * ORDER BY
1077
+ * Ordering helpers
1078
+ */
1079
+ orderBy: {
1080
+ asc: (column: Sql) => Sql;
1081
+ desc: (column: Sql) => Sql;
1082
+ /** NULLS FIRST (PG only, no-op for MySQL/SQLite) */
1083
+ nullsFirst: (expr: Sql) => Sql;
1084
+ /** NULLS LAST (PG only, no-op for MySQL/SQLite) */
1085
+ nullsLast: (expr: Sql) => Sql;
1086
+ };
1087
+ /**
1088
+ * CLAUSES
1089
+ * SQL clause keywords
1090
+ */
1091
+ clauses: {
1092
+ select: (columns: Sql) => Sql;
1093
+ selectDistinct: (columns: Sql) => Sql;
1094
+ from: (table: Sql) => Sql;
1095
+ where: (condition: Sql) => Sql;
1096
+ orderBy: (orders: Sql) => Sql;
1097
+ limit: (count: Sql) => Sql;
1098
+ offset: (count: Sql) => Sql;
1099
+ groupBy: (columns: Sql) => Sql;
1100
+ having: (condition: Sql) => Sql;
1101
+ };
1102
+ /**
1103
+ * SET
1104
+ * UPDATE SET operations
1105
+ */
1106
+ set: {
1107
+ /** Simple assignment: "col" = value */
1108
+ assign: (column: Sql, value: Sql) => Sql;
1109
+ /** Increment: "col" = "col" + value */
1110
+ increment: (column: Sql, by: Sql) => Sql;
1111
+ /** Decrement: "col" = "col" - value */
1112
+ decrement: (column: Sql, by: Sql) => Sql;
1113
+ /** Multiply: "col" = "col" * value */
1114
+ multiply: (column: Sql, by: Sql) => Sql;
1115
+ /** Divide: "col" = "col" / value */
1116
+ divide: (column: Sql, by: Sql) => Sql;
1117
+ /** Array push (database-specific): append to array */
1118
+ push: (column: Sql, value: Sql) => Sql;
1119
+ /** Array unshift (database-specific): prepend to array */
1120
+ unshift: (column: Sql, value: Sql) => Sql;
1121
+ };
1122
+ /**
1123
+ * FILTERS
1124
+ * Relation filter wrappers for subqueries
1125
+ */
1126
+ filters: {
1127
+ /** EXISTS wrapper for "some" relation filter (to-many) */
1128
+ some: (subquery: Sql) => Sql;
1129
+ /** NOT EXISTS wrapper for "every" - negated condition (to-many) */
1130
+ every: (subquery: Sql) => Sql;
1131
+ /** NOT EXISTS wrapper for "none" (to-many) */
1132
+ none: (subquery: Sql) => Sql;
1133
+ /** EXISTS wrapper for "is" relation filter (to-one) */
1134
+ is: (subquery: Sql) => Sql;
1135
+ /** NOT EXISTS wrapper for "isNot" relation filter (to-one) */
1136
+ isNot: (subquery: Sql) => Sql;
1137
+ };
1138
+ /**
1139
+ * SUBQUERIES
1140
+ * Subquery wrappers
1141
+ */
1142
+ subqueries: {
1143
+ /** Scalar subquery: (SELECT ...) */
1144
+ scalar: (query: Sql) => Sql;
1145
+ /** Correlated subquery with alias */
1146
+ correlate: (query: Sql, alias: string) => Sql;
1147
+ /** Build EXISTS-style subquery: SELECT 1 FROM table WHERE condition */
1148
+ existsCheck: (from: Sql, where: Sql) => Sql;
1149
+ };
1150
+ /**
1151
+ * ASSEMBLE
1152
+ * Build complete SQL statements from parts
1153
+ */
1154
+ assemble: {
1155
+ /** Assemble a complete SELECT query from parts */
1156
+ select: (parts: QueryParts) => Sql;
1157
+ };
1158
+ /**
1159
+ * CTE
1160
+ * Common Table Expressions
1161
+ */
1162
+ cte: {
1163
+ /** Build WITH clause: WITH name AS (query), ... */
1164
+ with: (definitions: {
1165
+ name: string;
1166
+ query: Sql;
1167
+ }[]) => Sql;
1168
+ /** Build recursive CTE: WITH RECURSIVE name AS (anchor UNION ALL recursive) */
1169
+ recursive: (name: string, anchor: Sql, recursive: Sql, union?: "all" | "distinct") => Sql;
1170
+ };
1171
+ /**
1172
+ * MUTATIONS
1173
+ * Insert, Update, Delete operations
1174
+ */
1175
+ mutations: {
1176
+ /** INSERT INTO table (cols) VALUES (...), with optional prefix (e.g., IGNORE for MySQL) */
1177
+ insert: (table: Sql, columns: string[], values: Sql[][], prefix?: Sql) => Sql;
1178
+ /** UPDATE table SET ... WHERE ... */
1179
+ update: (table: Sql, sets: Sql, where?: Sql) => Sql;
1180
+ /** DELETE FROM table WHERE ... */
1181
+ delete: (table: Sql, where?: Sql) => Sql;
1182
+ /** RETURNING clause (PG/SQLite) or empty (MySQL) */
1183
+ returning: (columns: Sql) => Sql;
1184
+ /**
1185
+ * ON CONFLICT / ON DUPLICATE KEY
1186
+ * @param target - Conflict target columns (e.g., "id")
1187
+ * @param action - Action to take (e.g., UPDATE SET ...)
1188
+ * @param targetWhere - Optional WHERE for partial unique index matching
1189
+ * PostgreSQL: ON CONFLICT (id) WHERE <targetWhere> DO UPDATE ...
1190
+ */
1191
+ onConflict: (target: Sql | null, action: Sql, targetWhere?: Sql) => Sql;
1192
+ /**
1193
+ * Build update action for ON CONFLICT (PG/SQLite: UPDATE SET ..., MySQL: just the SET part)
1194
+ * @param sets - SET clause assignments
1195
+ * @param setWhere - Optional WHERE for conditional updates
1196
+ * PostgreSQL: ... DO UPDATE SET x = y WHERE <setWhere>
1197
+ */
1198
+ onConflictUpdate: (sets: Sql, setWhere?: Sql) => Sql;
1199
+ /**
1200
+ * Skip duplicate key errors (for createMany with skipDuplicates: true)
1201
+ * PostgreSQL/SQLite: ON CONFLICT DO NOTHING (suffix)
1202
+ * MySQL: INSERT IGNORE (prefix)
1203
+ */
1204
+ skipDuplicates: () => {
1205
+ prefix: Sql;
1206
+ suffix: Sql;
1207
+ };
1208
+ };
1209
+ /**
1210
+ * CAPABILITIES
1211
+ * Database feature flags for conditional query building
1212
+ */
1213
+ capabilities: {
1214
+ /** Whether database supports RETURNING clause (PG, SQLite 3.35+) */
1215
+ supportsReturning: boolean;
1216
+ /** Whether database supports CTEs with data-modifying statements (PG, SQLite) */
1217
+ supportsCteWithMutations: boolean;
1218
+ /** Whether database supports FULL OUTER JOIN */
1219
+ supportsFullOuterJoin: boolean;
1220
+ /**
1221
+ * Whether database supports LATERAL joins (PG 9.3+, MySQL 8.0.14+)
1222
+ * When true, include builder uses lateral joins for better performance
1223
+ * When false, falls back to correlated subqueries
1224
+ */
1225
+ supportsLateralJoins: boolean;
1226
+ /**
1227
+ * Whether database supports WHERE clauses in upsert/ON CONFLICT:
1228
+ * - targetWhere: ON CONFLICT (id) WHERE <targetWhere> DO UPDATE ... (partial unique index)
1229
+ * - setWhere: ON CONFLICT ... DO UPDATE SET x = y WHERE <setWhere> (conditional update)
1230
+ *
1231
+ * PostgreSQL/SQLite: true - native support
1232
+ * MySQL: false - ON DUPLICATE KEY UPDATE doesn't support WHERE clauses
1233
+ *
1234
+ * When false, the query engine falls back to a transaction-based approach
1235
+ * using SELECT FOR UPDATE + conditional INSERT/UPDATE.
1236
+ */
1237
+ supportsUpsertWhere: boolean;
1238
+ };
1239
+ /**
1240
+ * LAST INSERT ID
1241
+ * Returns SQL for getting the last auto-generated ID.
1242
+ * Used in multi-statement nested creates to reference parent's ID in child inserts.
1243
+ *
1244
+ * PostgreSQL: lastval() - returns last value from any sequence in session
1245
+ * SQLite: last_insert_rowid() - returns last ROWID inserted
1246
+ * MySQL: LAST_INSERT_ID() - returns last AUTO_INCREMENT value
1247
+ */
1248
+ lastInsertId: () => Sql;
1249
+ /**
1250
+ * JOINS
1251
+ * Join operations
1252
+ */
1253
+ joins: {
1254
+ inner: (table: Sql, condition: Sql) => Sql;
1255
+ left: (table: Sql, condition: Sql) => Sql;
1256
+ right: (table: Sql, condition: Sql) => Sql;
1257
+ full: (table: Sql, condition: Sql) => Sql;
1258
+ cross: (table: Sql) => Sql;
1259
+ /**
1260
+ * LATERAL subquery join (PostgreSQL 9.3+, MySQL 8.0.14+)
1261
+ * Allows referencing columns from preceding tables in the subquery.
1262
+ * Used for efficient nested includes.
1263
+ *
1264
+ * @param subquery - The lateral subquery (must be a complete SELECT)
1265
+ * @param alias - Alias for the lateral result
1266
+ * @returns JOIN LATERAL (subquery) AS alias ON true
1267
+ */
1268
+ lateral: (subquery: Sql, alias: string) => Sql;
1269
+ /**
1270
+ * LEFT JOIN LATERAL - same as lateral but with LEFT JOIN semantics
1271
+ * Returns NULL for the joined columns when subquery returns no rows.
1272
+ *
1273
+ * @param subquery - The lateral subquery (must be a complete SELECT)
1274
+ * @param alias - Alias for the lateral result
1275
+ * @returns LEFT JOIN LATERAL (subquery) AS alias ON true
1276
+ */
1277
+ lateralLeft: (subquery: Sql, alias: string) => Sql;
1278
+ };
1279
+ /**
1280
+ * SET OPERATIONS
1281
+ * UNION, INTERSECT, EXCEPT operations
1282
+ */
1283
+ setOperations: {
1284
+ /** UNION (removes duplicates) */
1285
+ union: (...queries: Sql[]) => Sql;
1286
+ /** UNION ALL (keeps duplicates) */
1287
+ unionAll: (...queries: Sql[]) => Sql;
1288
+ /** INTERSECT */
1289
+ intersect: (...queries: Sql[]) => Sql;
1290
+ /** EXCEPT / MINUS */
1291
+ except: (left: Sql, right: Sql) => Sql;
1292
+ };
1293
+ /**
1294
+ * VECTOR
1295
+ * Vector operations for similarity search (pgvector)
1296
+ *
1297
+ * Matches filter schema: { l2, cosine }
1298
+ * Drivers that don't support vector operations can override
1299
+ * this property with an object that throws FeatureNotSupportedError.
1300
+ */
1301
+ vector: {
1302
+ /** Create a vector literal from number array: '[1,2,3]'::vector */
1303
+ literal: (values: number[]) => Sql;
1304
+ /** L2 (Euclidean) distance operator for ORDER BY: column <-> vector */
1305
+ l2: (column: Sql, vector: Sql) => Sql;
1306
+ /** Cosine distance operator for ORDER BY: column <=> vector */
1307
+ cosine: (column: Sql, vector: Sql) => Sql;
1308
+ };
1309
+ /**
1310
+ * GEOSPATIAL
1311
+ * Geospatial operations (PostGIS)
1312
+ *
1313
+ * Matches filter schema: { equals, intersects, contains, within, crosses, overlaps, touches, covers, dWithin }
1314
+ * Drivers that don't support geospatial operations can override
1315
+ * this property with an object that throws FeatureNotSupportedError.
1316
+ */
1317
+ geospatial: {
1318
+ /** Create a point from longitude/latitude: ST_SetSRID(ST_MakePoint(lng, lat), 4326) */
1319
+ point: (lng: Sql, lat: Sql) => Sql;
1320
+ /** ST_Equals: geometries are spatially equal */
1321
+ equals: (geom1: Sql, geom2: Sql) => Sql;
1322
+ /** ST_Intersects: geometries share any space */
1323
+ intersects: (geom1: Sql, geom2: Sql) => Sql;
1324
+ /** ST_Contains: geom1 completely contains geom2 */
1325
+ contains: (geom1: Sql, geom2: Sql) => Sql;
1326
+ /** ST_Within: geom1 is completely within geom2 */
1327
+ within: (geom1: Sql, geom2: Sql) => Sql;
1328
+ /** ST_Crosses: geometries cross each other */
1329
+ crosses: (geom1: Sql, geom2: Sql) => Sql;
1330
+ /** ST_Overlaps: geometries overlap */
1331
+ overlaps: (geom1: Sql, geom2: Sql) => Sql;
1332
+ /** ST_Touches: geometries touch at boundary */
1333
+ touches: (geom1: Sql, geom2: Sql) => Sql;
1334
+ /** ST_Covers: geom1 covers geom2 (no points of geom2 outside geom1) */
1335
+ covers: (geom1: Sql, geom2: Sql) => Sql;
1336
+ /** ST_DWithin: geometries are within specified distance (meters for geography) */
1337
+ dWithin: (geom1: Sql, geom2: Sql, distance: Sql) => Sql;
1338
+ };
1339
+ /**
1340
+ * RESULT PARSING
1341
+ * Database-specific result parsing middleware.
1342
+ * Each method receives a `next` function that calls the default parsing logic.
1343
+ *
1344
+ * ## Usage Pattern
1345
+ *
1346
+ * - `next()` - Continue with original value (passthrough)
1347
+ * - `next(transformed)` - Continue with transformed value
1348
+ * - `return value` - Short-circuit, skip default parsing
1349
+ *
1350
+ * ## Database Behaviors
1351
+ *
1352
+ * - **PostgreSQL**: Mostly passthrough (native JSON, native booleans)
1353
+ * - **MySQL/SQLite**: Parse JSON strings, convert 0/1 to booleans
1354
+ */
1355
+ result: {
1356
+ /**
1357
+ * Parse operation result (count, aggregate, etc.)
1358
+ *
1359
+ * @param raw - Raw database result
1360
+ * @param operation - Query operation type
1361
+ * @param next - Call to continue with default parsing
1362
+ * - `next()` uses original raw value
1363
+ * - `next(transformed)` uses the transformed value
1364
+ *
1365
+ * @returns Parsed result or result of `next()`
1366
+ *
1367
+ * @example
1368
+ * // Normalize COUNT(*) column name
1369
+ * parseResult: (raw, op, next) => {
1370
+ * if (op === 'count') {
1371
+ * const normalized = normalizeCountResult(raw);
1372
+ * if (normalized) return next(normalized);
1373
+ * }
1374
+ * return next();
1375
+ * }
1376
+ */
1377
+ parseResult: (raw: unknown, operation: Operation, next: (value?: unknown) => unknown) => unknown;
1378
+ /**
1379
+ * Parse relation value (nested JSON from includes)
1380
+ *
1381
+ * @param value - Raw relation value from database
1382
+ * @param type - Relation type (oneToMany, manyToOne, etc.)
1383
+ * @param next - Call to continue with default parsing
1384
+ * - `next()` uses original value
1385
+ * - `next(parsed)` uses the parsed value
1386
+ *
1387
+ * @returns Parsed relation or result of `next()`
1388
+ *
1389
+ * @example
1390
+ * // Parse JSON strings (MySQL/SQLite)
1391
+ * parseRelation: (value, type, next) => {
1392
+ * const parsed = tryParseJsonString(value);
1393
+ * return parsed !== undefined ? next(parsed) : next();
1394
+ * }
1395
+ */
1396
+ parseRelation: (value: unknown, type: RelationType, next: (value?: unknown) => unknown) => unknown;
1397
+ /**
1398
+ * Parse field value by type
1399
+ *
1400
+ * @param value - Raw field value from database
1401
+ * @param fieldType - Field type (boolean, datetime, bigint, etc.)
1402
+ * @param next - Call to continue with default parsing
1403
+ * - `next()` uses original value
1404
+ * - `next(converted)` uses the converted value
1405
+ *
1406
+ * @returns Parsed value, or result of `next()`, or short-circuit return
1407
+ *
1408
+ * @example
1409
+ * // Convert 0/1 to boolean (SQLite/MySQL)
1410
+ * parseField: (value, fieldType, next) => {
1411
+ * if (fieldType === 'boolean') {
1412
+ * const bool = parseIntegerBoolean(value);
1413
+ * if (bool !== undefined) return bool; // Short-circuit
1414
+ * }
1415
+ * return next();
1416
+ * }
1417
+ */
1418
+ parseField: (value: unknown, fieldType: string, next: (value?: unknown) => unknown) => unknown;
1419
+ };
1420
+ }
1421
+ /**
1422
+ * Type for query parts assembly
1423
+ */
1424
+ interface QueryParts {
1425
+ columns: Sql;
1426
+ from: Sql;
1427
+ joins?: Sql[];
1428
+ where?: Sql;
1429
+ groupBy?: Sql;
1430
+ having?: Sql;
1431
+ orderBy?: Sql;
1432
+ limit?: Sql;
1433
+ offset?: Sql;
1434
+ /** DISTINCT ON columns (PostgreSQL), or simulated via ROW_NUMBER() (MySQL/SQLite) */
1435
+ distinct?: Sql;
1436
+ /** Column alias names for outer SELECT when using DISTINCT simulation (MySQL/SQLite) */
1437
+ distinctColumnAliases?: string[];
1438
+ /**
1439
+ * Add FOR UPDATE clause for row locking.
1440
+ * Used in transaction-based upserts to prevent race conditions.
1441
+ * PostgreSQL/MySQL: FOR UPDATE
1442
+ * SQLite: No-op (SQLite uses database-level locking)
1443
+ */
1444
+ forUpdate?: boolean;
1445
+ }
1446
+ /**
1447
+ * Type for insert parts assembly
1448
+ */
1449
+ interface InsertParts {
1450
+ table: Sql;
1451
+ columns: string[];
1452
+ values: Sql[][];
1453
+ onConflict?: Sql;
1454
+ returning?: Sql;
1455
+ }
1456
+ /**
1457
+ * Type for update parts assembly
1458
+ */
1459
+ interface UpdateParts {
1460
+ table: Sql;
1461
+ set: Sql;
1462
+ where?: Sql;
1463
+ returning?: Sql;
1464
+ }
1465
+ /**
1466
+ * Type for delete parts assembly
1467
+ */
1468
+ interface DeleteParts {
1469
+ table: Sql;
1470
+ where?: Sql;
1471
+ returning?: Sql;
1472
+ }
1473
+ //#endregion
1474
+ //#region src/adapters/databases/mysql/mysql-adapter.d.ts
1475
+ /**
1476
+ * MySQL Database Adapter
1477
+ *
1478
+ * Implements the DatabaseAdapter interface for MySQL-specific SQL generation.
1479
+ *
1480
+ * Key MySQL features:
1481
+ * - Backtick identifier escaping: `table`.`column`
1482
+ * - No native ARRAY type - uses JSON for arrays
1483
+ * - LIKE is case-insensitive by default (with collation)
1484
+ * - JSON_OBJECT(), JSON_ARRAYAGG() for JSON operations
1485
+ * - No RETURNING clause (use LAST_INSERT_ID())
1486
+ * - No NULLS FIRST/LAST ordering
1487
+ * - ON DUPLICATE KEY UPDATE for upserts
1488
+ */
1489
+ declare class MySQLAdapter implements DatabaseAdapter {
1490
+ raw: (sqlString: string) => Sql;
1491
+ identifiers: {
1492
+ escape: (name: string) => Sql;
1493
+ column: (alias: string, field: string) => Sql;
1494
+ table: (tableName: string, alias: string) => Sql;
1495
+ aliased: (expression: Sql, alias: string) => Sql;
1496
+ };
1497
+ literals: {
1498
+ value: (v: unknown) => Sql;
1499
+ null: () => Sql;
1500
+ true: () => Sql;
1501
+ false: () => Sql;
1502
+ list: (values: Sql[]) => Sql;
1503
+ json: (v: unknown) => Sql;
1504
+ };
1505
+ operators: {
1506
+ eq: (left: Sql, right: Sql) => Sql;
1507
+ neq: (left: Sql, right: Sql) => Sql;
1508
+ lt: (left: Sql, right: Sql) => Sql;
1509
+ lte: (left: Sql, right: Sql) => Sql;
1510
+ gt: (left: Sql, right: Sql) => Sql;
1511
+ gte: (left: Sql, right: Sql) => Sql;
1512
+ like: (column: Sql, pattern: Sql) => Sql;
1513
+ notLike: (column: Sql, pattern: Sql) => Sql;
1514
+ ilike: (column: Sql, pattern: Sql) => Sql;
1515
+ notIlike: (column: Sql, pattern: Sql) => Sql;
1516
+ in: (column: Sql, values: Sql) => Sql;
1517
+ notIn: (column: Sql, values: Sql) => Sql;
1518
+ isNull: (expr: Sql) => Sql;
1519
+ isNotNull: (expr: Sql) => Sql;
1520
+ between: (column: Sql, min: Sql, max: Sql) => Sql;
1521
+ notBetween: (column: Sql, min: Sql, max: Sql) => Sql;
1522
+ and: (...conditions: Sql[]) => Sql;
1523
+ or: (...conditions: Sql[]) => Sql;
1524
+ not: (condition: Sql) => Sql;
1525
+ exists: (subquery: Sql) => Sql;
1526
+ notExists: (subquery: Sql) => Sql;
1527
+ };
1528
+ expressions: {
1529
+ add: (left: Sql, right: Sql) => Sql;
1530
+ subtract: (left: Sql, right: Sql) => Sql;
1531
+ multiply: (left: Sql, right: Sql) => Sql;
1532
+ divide: (left: Sql, right: Sql) => Sql;
1533
+ concat: (...parts: Sql[]) => Sql;
1534
+ upper: (expr: Sql) => Sql;
1535
+ lower: (expr: Sql) => Sql;
1536
+ coalesce: (...exprs: Sql[]) => Sql;
1537
+ greatest: (...exprs: Sql[]) => Sql;
1538
+ least: (...exprs: Sql[]) => Sql;
1539
+ cast: (expr: Sql, type: CastType) => Sql;
1540
+ };
1541
+ aggregates: {
1542
+ count: (expr?: Sql) => Sql;
1543
+ countDistinct: (expr: Sql) => Sql;
1544
+ sum: (expr: Sql) => Sql;
1545
+ avg: (expr: Sql) => Sql;
1546
+ min: (expr: Sql) => Sql;
1547
+ max: (expr: Sql) => Sql;
1548
+ };
1549
+ json: {
1550
+ object: (pairs: [string, Sql][]) => Sql;
1551
+ array: (items: Sql[]) => Sql;
1552
+ emptyArray: () => Sql;
1553
+ agg: (expr: Sql) => Sql;
1554
+ rowToJson: (alias: string) => Sql;
1555
+ objectFromColumns: (columns: [string, Sql][]) => Sql;
1556
+ extract: (column: Sql, path: string[]) => Sql;
1557
+ extractText: (column: Sql, path: string[]) => Sql;
1558
+ };
1559
+ arrays: {
1560
+ literal: (items: Sql[]) => Sql;
1561
+ has: (column: Sql, value: Sql) => Sql;
1562
+ hasEvery: (column: Sql, values: Sql) => Sql;
1563
+ hasSome: (column: Sql, values: Sql) => Sql;
1564
+ isEmpty: (column: Sql) => Sql;
1565
+ length: (column: Sql) => Sql;
1566
+ get: (column: Sql, index: Sql) => Sql;
1567
+ push: (column: Sql, value: Sql) => Sql;
1568
+ set: (column: Sql, index: Sql, value: Sql) => Sql;
1569
+ };
1570
+ orderBy: {
1571
+ asc: (column: Sql) => Sql;
1572
+ desc: (column: Sql) => Sql;
1573
+ nullsFirst: (expr: Sql) => Sql;
1574
+ nullsLast: (expr: Sql) => Sql;
1575
+ };
1576
+ clauses: {
1577
+ select: (columns: Sql) => Sql;
1578
+ selectDistinct: (columns: Sql) => Sql;
1579
+ from: (table: Sql) => Sql;
1580
+ where: (condition: Sql) => Sql;
1581
+ orderBy: (orders: Sql) => Sql;
1582
+ limit: (count: Sql) => Sql;
1583
+ offset: (count: Sql) => Sql;
1584
+ groupBy: (columns: Sql) => Sql;
1585
+ having: (condition: Sql) => Sql;
1586
+ };
1587
+ set: {
1588
+ assign: (column: Sql, value: Sql) => Sql;
1589
+ increment: (column: Sql, by: Sql) => Sql;
1590
+ decrement: (column: Sql, by: Sql) => Sql;
1591
+ multiply: (column: Sql, by: Sql) => Sql;
1592
+ divide: (column: Sql, by: Sql) => Sql;
1593
+ push: (column: Sql, value: Sql) => Sql;
1594
+ unshift: (column: Sql, value: Sql) => Sql;
1595
+ };
1596
+ filters: {
1597
+ some: (subquery: Sql) => Sql;
1598
+ every: (subquery: Sql) => Sql;
1599
+ none: (subquery: Sql) => Sql;
1600
+ is: (subquery: Sql) => Sql;
1601
+ isNot: (subquery: Sql) => Sql;
1602
+ };
1603
+ subqueries: {
1604
+ scalar: (query: Sql) => Sql;
1605
+ correlate: (query: Sql, alias: string) => Sql;
1606
+ existsCheck: (from: Sql, where: Sql) => Sql;
1607
+ };
1608
+ assemble: {
1609
+ select: (parts: QueryParts) => Sql;
1610
+ };
1611
+ /**
1612
+ * Simulate DISTINCT ON using ROW_NUMBER() window function.
1613
+ *
1614
+ * Generates:
1615
+ * SELECT col1, col2, ... FROM (
1616
+ * SELECT columns, ROW_NUMBER() OVER (PARTITION BY distinct_cols ORDER BY order_cols) AS _rn
1617
+ * FROM table
1618
+ * WHERE ...
1619
+ * ) AS _distinct_subquery
1620
+ * WHERE _rn = 1
1621
+ * ORDER BY ...
1622
+ * LIMIT ... OFFSET ...
1623
+ */
1624
+ private assembleDistinctOn;
1625
+ cte: {
1626
+ with: (definitions: {
1627
+ name: string;
1628
+ query: Sql;
1629
+ }[]) => Sql;
1630
+ recursive: (name: string, anchor: Sql, recursive: Sql, union?: "all" | "distinct") => Sql;
1631
+ };
1632
+ mutations: {
1633
+ insert: (table: Sql, columns: string[], values: Sql[][], prefix?: Sql) => Sql;
1634
+ update: (table: Sql, sets: Sql, where?: Sql) => Sql;
1635
+ delete: (table: Sql, where?: Sql) => Sql;
1636
+ returning: (_columns: Sql) => Sql;
1637
+ onConflict: (_target: Sql | null, action: Sql, _targetWhere?: Sql) => Sql;
1638
+ onConflictUpdate: (sets: Sql, _setWhere?: Sql) => Sql;
1639
+ skipDuplicates: () => {
1640
+ prefix: Sql;
1641
+ suffix: Sql;
1642
+ };
1643
+ };
1644
+ joins: {
1645
+ inner: (table: Sql, condition: Sql) => Sql;
1646
+ left: (table: Sql, condition: Sql) => Sql;
1647
+ right: (table: Sql, condition: Sql) => Sql;
1648
+ full: (table: Sql, condition: Sql) => Sql;
1649
+ cross: (table: Sql) => Sql;
1650
+ lateral: (subquery: Sql, alias: string) => Sql;
1651
+ lateralLeft: (subquery: Sql, alias: string) => Sql;
1652
+ };
1653
+ setOperations: {
1654
+ union: (...queries: Sql[]) => Sql;
1655
+ unionAll: (...queries: Sql[]) => Sql;
1656
+ intersect: (...queries: Sql[]) => Sql;
1657
+ except: (left: Sql, right: Sql) => Sql;
1658
+ };
1659
+ capabilities: {
1660
+ supportsReturning: boolean;
1661
+ supportsCteWithMutations: boolean;
1662
+ supportsFullOuterJoin: boolean;
1663
+ supportsLateralJoins: boolean;
1664
+ supportsUpsertWhere: boolean;
1665
+ };
1666
+ lastInsertId: () => Sql;
1667
+ vector: {
1668
+ literal: () => never;
1669
+ l2: () => never;
1670
+ cosine: () => never;
1671
+ };
1672
+ geospatial: {
1673
+ point: () => never;
1674
+ equals: () => never;
1675
+ intersects: () => never;
1676
+ contains: () => never;
1677
+ within: () => never;
1678
+ crosses: () => never;
1679
+ overlaps: () => never;
1680
+ touches: () => never;
1681
+ covers: () => never;
1682
+ dWithin: () => never;
1683
+ };
1684
+ result: {
1685
+ parseResult: (raw: unknown, operation: Operation, next: (value?: unknown) => unknown) => unknown;
1686
+ parseRelation: (value: unknown, _type: RelationType, next: (value?: unknown) => unknown) => unknown;
1687
+ parseField: (value: unknown, fieldType: string, next: (value?: unknown) => unknown) => unknown;
1688
+ };
1689
+ }
1690
+ declare const mysqlAdapter: MySQLAdapter;
1691
+ //#endregion
1692
+ //#region src/adapters/databases/postgres/postgres-adapter.d.ts
1693
+ /**
1694
+ * PostgreSQL Database Adapter
1695
+ *
1696
+ * Implements the DatabaseAdapter interface for PostgreSQL-specific SQL generation.
1697
+ *
1698
+ * Key PostgreSQL features:
1699
+ * - Double-quote identifier escaping: "table"."column"
1700
+ * - Native ARRAY type with operators: @>, &&, ANY()
1701
+ * - ILIKE for case-insensitive matching
1702
+ * - json_build_object(), json_agg() for JSON operations
1703
+ * - RETURNING clause for mutations
1704
+ * - NULLS FIRST/LAST ordering
1705
+ * - ON CONFLICT DO UPDATE/NOTHING
1706
+ */
1707
+ declare class PostgresAdapter implements DatabaseAdapter {
1708
+ raw: (sqlString: string) => Sql;
1709
+ identifiers: {
1710
+ escape: (name: string) => Sql;
1711
+ column: (alias: string, field: string) => Sql;
1712
+ table: (tableName: string, alias: string) => Sql;
1713
+ aliased: (expression: Sql, alias: string) => Sql;
1714
+ };
1715
+ literals: {
1716
+ value: (v: unknown) => Sql;
1717
+ null: () => Sql;
1718
+ true: () => Sql;
1719
+ false: () => Sql;
1720
+ list: (values: Sql[]) => Sql;
1721
+ json: (v: unknown) => Sql;
1722
+ };
1723
+ operators: {
1724
+ eq: (left: Sql, right: Sql) => Sql;
1725
+ neq: (left: Sql, right: Sql) => Sql;
1726
+ lt: (left: Sql, right: Sql) => Sql;
1727
+ lte: (left: Sql, right: Sql) => Sql;
1728
+ gt: (left: Sql, right: Sql) => Sql;
1729
+ gte: (left: Sql, right: Sql) => Sql;
1730
+ like: (column: Sql, pattern: Sql) => Sql;
1731
+ notLike: (column: Sql, pattern: Sql) => Sql;
1732
+ ilike: (column: Sql, pattern: Sql) => Sql;
1733
+ notIlike: (column: Sql, pattern: Sql) => Sql;
1734
+ in: (column: Sql, values: Sql) => Sql;
1735
+ notIn: (column: Sql, values: Sql) => Sql;
1736
+ isNull: (expr: Sql) => Sql;
1737
+ isNotNull: (expr: Sql) => Sql;
1738
+ between: (column: Sql, min: Sql, max: Sql) => Sql;
1739
+ notBetween: (column: Sql, min: Sql, max: Sql) => Sql;
1740
+ and: (...conditions: Sql[]) => Sql;
1741
+ or: (...conditions: Sql[]) => Sql;
1742
+ not: (condition: Sql) => Sql;
1743
+ exists: (subquery: Sql) => Sql;
1744
+ notExists: (subquery: Sql) => Sql;
1745
+ };
1746
+ expressions: {
1747
+ add: (left: Sql, right: Sql) => Sql;
1748
+ subtract: (left: Sql, right: Sql) => Sql;
1749
+ multiply: (left: Sql, right: Sql) => Sql;
1750
+ divide: (left: Sql, right: Sql) => Sql;
1751
+ concat: (...parts: Sql[]) => Sql;
1752
+ upper: (expr: Sql) => Sql;
1753
+ lower: (expr: Sql) => Sql;
1754
+ coalesce: (...exprs: Sql[]) => Sql;
1755
+ greatest: (...exprs: Sql[]) => Sql;
1756
+ least: (...exprs: Sql[]) => Sql;
1757
+ cast: (expr: Sql, type: CastType) => Sql;
1758
+ };
1759
+ aggregates: {
1760
+ count: (expr?: Sql) => Sql;
1761
+ countDistinct: (expr: Sql) => Sql;
1762
+ sum: (expr: Sql) => Sql;
1763
+ avg: (expr: Sql) => Sql;
1764
+ min: (expr: Sql) => Sql;
1765
+ max: (expr: Sql) => Sql;
1766
+ };
1767
+ json: {
1768
+ object: (pairs: [string, Sql][]) => Sql;
1769
+ array: (items: Sql[]) => Sql;
1770
+ emptyArray: () => Sql;
1771
+ agg: (expr: Sql) => Sql;
1772
+ rowToJson: (alias: string) => Sql;
1773
+ objectFromColumns: (columns: [string, Sql][]) => Sql;
1774
+ extract: (column: Sql, path: string[]) => Sql;
1775
+ extractText: (column: Sql, path: string[]) => Sql;
1776
+ };
1777
+ arrays: {
1778
+ literal: (items: Sql[]) => Sql;
1779
+ has: (column: Sql, value: Sql) => Sql;
1780
+ hasEvery: (column: Sql, values: Sql) => Sql;
1781
+ hasSome: (column: Sql, values: Sql) => Sql;
1782
+ isEmpty: (column: Sql) => Sql;
1783
+ length: (column: Sql) => Sql;
1784
+ get: (column: Sql, index: Sql) => Sql;
1785
+ push: (column: Sql, value: Sql) => Sql;
1786
+ set: (column: Sql, index: Sql, value: Sql) => Sql;
1787
+ };
1788
+ orderBy: {
1789
+ asc: (column: Sql) => Sql;
1790
+ desc: (column: Sql) => Sql;
1791
+ nullsFirst: (expr: Sql) => Sql;
1792
+ nullsLast: (expr: Sql) => Sql;
1793
+ };
1794
+ clauses: {
1795
+ select: (columns: Sql) => Sql;
1796
+ selectDistinct: (columns: Sql) => Sql;
1797
+ from: (table: Sql) => Sql;
1798
+ where: (condition: Sql) => Sql;
1799
+ orderBy: (orders: Sql) => Sql;
1800
+ limit: (count: Sql) => Sql;
1801
+ offset: (count: Sql) => Sql;
1802
+ groupBy: (columns: Sql) => Sql;
1803
+ having: (condition: Sql) => Sql;
1804
+ };
1805
+ set: {
1806
+ assign: (column: Sql, value: Sql) => Sql;
1807
+ increment: (column: Sql, by: Sql) => Sql;
1808
+ decrement: (column: Sql, by: Sql) => Sql;
1809
+ multiply: (column: Sql, by: Sql) => Sql;
1810
+ divide: (column: Sql, by: Sql) => Sql;
1811
+ push: (column: Sql, value: Sql) => Sql;
1812
+ unshift: (column: Sql, value: Sql) => Sql;
1813
+ };
1814
+ filters: {
1815
+ some: (subquery: Sql) => Sql;
1816
+ every: (subquery: Sql) => Sql;
1817
+ none: (subquery: Sql) => Sql;
1818
+ is: (subquery: Sql) => Sql;
1819
+ isNot: (subquery: Sql) => Sql;
1820
+ };
1821
+ subqueries: {
1822
+ scalar: (query: Sql) => Sql;
1823
+ correlate: (query: Sql, alias: string) => Sql;
1824
+ existsCheck: (from: Sql, where: Sql) => Sql;
1825
+ };
1826
+ assemble: {
1827
+ select: (parts: QueryParts) => Sql;
1828
+ };
1829
+ cte: {
1830
+ with: (definitions: {
1831
+ name: string;
1832
+ query: Sql;
1833
+ }[]) => Sql;
1834
+ recursive: (name: string, anchor: Sql, recursive: Sql, union?: "all" | "distinct") => Sql;
1835
+ };
1836
+ mutations: {
1837
+ insert: (table: Sql, columns: string[], values: Sql[][], prefix?: Sql) => Sql;
1838
+ update: (table: Sql, sets: Sql, where?: Sql) => Sql;
1839
+ delete: (table: Sql, where?: Sql) => Sql;
1840
+ returning: (columns: Sql) => Sql;
1841
+ onConflict: (target: Sql | null, action: Sql, targetWhere?: Sql) => Sql;
1842
+ onConflictUpdate: (sets: Sql, setWhere?: Sql) => Sql;
1843
+ skipDuplicates: () => {
1844
+ prefix: Sql;
1845
+ suffix: Sql;
1846
+ };
1847
+ };
1848
+ joins: {
1849
+ inner: (table: Sql, condition: Sql) => Sql;
1850
+ left: (table: Sql, condition: Sql) => Sql;
1851
+ right: (table: Sql, condition: Sql) => Sql;
1852
+ full: (table: Sql, condition: Sql) => Sql;
1853
+ cross: (table: Sql) => Sql;
1854
+ lateral: (subquery: Sql, alias: string) => Sql;
1855
+ lateralLeft: (subquery: Sql, alias: string) => Sql;
1856
+ };
1857
+ setOperations: {
1858
+ union: (...queries: Sql[]) => Sql;
1859
+ unionAll: (...queries: Sql[]) => Sql;
1860
+ intersect: (...queries: Sql[]) => Sql;
1861
+ except: (left: Sql, right: Sql) => Sql;
1862
+ };
1863
+ capabilities: {
1864
+ supportsReturning: boolean;
1865
+ supportsCteWithMutations: boolean;
1866
+ supportsFullOuterJoin: boolean;
1867
+ supportsLateralJoins: boolean;
1868
+ supportsUpsertWhere: boolean;
1869
+ };
1870
+ lastInsertId: () => Sql;
1871
+ vector: {
1872
+ literal: (values: number[]) => Sql;
1873
+ l2: (column: Sql, vector: Sql) => Sql;
1874
+ cosine: (column: Sql, vector: Sql) => Sql;
1875
+ };
1876
+ geospatial: {
1877
+ point: (lng: Sql, lat: Sql) => Sql;
1878
+ equals: (geom1: Sql, geom2: Sql) => Sql;
1879
+ intersects: (geom1: Sql, geom2: Sql) => Sql;
1880
+ contains: (geom1: Sql, geom2: Sql) => Sql;
1881
+ within: (geom1: Sql, geom2: Sql) => Sql;
1882
+ crosses: (geom1: Sql, geom2: Sql) => Sql;
1883
+ overlaps: (geom1: Sql, geom2: Sql) => Sql;
1884
+ touches: (geom1: Sql, geom2: Sql) => Sql;
1885
+ covers: (geom1: Sql, geom2: Sql) => Sql;
1886
+ dWithin: (geom1: Sql, geom2: Sql, distance: Sql) => Sql;
1887
+ };
1888
+ result: {
1889
+ parseResult: (raw: unknown, _operation: Operation, next: (value?: unknown) => unknown) => unknown;
1890
+ parseRelation: (_value: unknown, _type: RelationType, next: (value?: unknown) => unknown) => unknown;
1891
+ parseField: (_value: unknown, _fieldType: string, next: (value?: unknown) => unknown) => unknown;
1892
+ };
1893
+ }
1894
+ declare const postgresAdapter: PostgresAdapter;
1895
+ //#endregion
1896
+ //#region src/adapters/databases/sqlite/sqlite-adapter.d.ts
1897
+ /**
1898
+ * SQLite Database Adapter
1899
+ *
1900
+ * Implements the DatabaseAdapter interface for SQLite-specific SQL generation.
1901
+ *
1902
+ * Key SQLite features:
1903
+ * - Double-quote identifier escaping: "table"."column"
1904
+ * - No native ARRAY type - uses JSON for arrays
1905
+ * - LIKE is case-insensitive for ASCII by default
1906
+ * - json_object(), json_group_array() for JSON operations (SQLite 3.38+)
1907
+ * - RETURNING clause supported (SQLite 3.35+)
1908
+ * - No NULLS FIRST/LAST ordering
1909
+ * - ON CONFLICT DO UPDATE/NOTHING (same as PostgreSQL)
1910
+ * - || for string concatenation
1911
+ * - Boolean stored as 0/1 integers
1912
+ */
1913
+ declare class SQLiteAdapter implements DatabaseAdapter {
1914
+ raw: (sqlString: string) => Sql;
1915
+ identifiers: {
1916
+ escape: (name: string) => Sql;
1917
+ column: (alias: string, field: string) => Sql;
1918
+ table: (tableName: string, alias: string) => Sql;
1919
+ aliased: (expression: Sql, alias: string) => Sql;
1920
+ };
1921
+ literals: {
1922
+ value: (v: unknown) => Sql;
1923
+ null: () => Sql;
1924
+ true: () => Sql;
1925
+ false: () => Sql;
1926
+ list: (values: Sql[]) => Sql;
1927
+ json: (v: unknown) => Sql;
1928
+ };
1929
+ operators: {
1930
+ eq: (left: Sql, right: Sql) => Sql;
1931
+ neq: (left: Sql, right: Sql) => Sql;
1932
+ lt: (left: Sql, right: Sql) => Sql;
1933
+ lte: (left: Sql, right: Sql) => Sql;
1934
+ gt: (left: Sql, right: Sql) => Sql;
1935
+ gte: (left: Sql, right: Sql) => Sql;
1936
+ like: (column: Sql, pattern: Sql) => Sql;
1937
+ notLike: (column: Sql, pattern: Sql) => Sql;
1938
+ ilike: (column: Sql, pattern: Sql) => Sql;
1939
+ notIlike: (column: Sql, pattern: Sql) => Sql;
1940
+ in: (column: Sql, values: Sql) => Sql;
1941
+ notIn: (column: Sql, values: Sql) => Sql;
1942
+ isNull: (expr: Sql) => Sql;
1943
+ isNotNull: (expr: Sql) => Sql;
1944
+ between: (column: Sql, min: Sql, max: Sql) => Sql;
1945
+ notBetween: (column: Sql, min: Sql, max: Sql) => Sql;
1946
+ and: (...conditions: Sql[]) => Sql;
1947
+ or: (...conditions: Sql[]) => Sql;
1948
+ not: (condition: Sql) => Sql;
1949
+ exists: (subquery: Sql) => Sql;
1950
+ notExists: (subquery: Sql) => Sql;
1951
+ };
1952
+ expressions: {
1953
+ add: (left: Sql, right: Sql) => Sql;
1954
+ subtract: (left: Sql, right: Sql) => Sql;
1955
+ multiply: (left: Sql, right: Sql) => Sql;
1956
+ divide: (left: Sql, right: Sql) => Sql;
1957
+ concat: (...parts: Sql[]) => Sql;
1958
+ upper: (expr: Sql) => Sql;
1959
+ lower: (expr: Sql) => Sql;
1960
+ coalesce: (...exprs: Sql[]) => Sql;
1961
+ greatest: (...exprs: Sql[]) => Sql;
1962
+ least: (...exprs: Sql[]) => Sql;
1963
+ cast: (expr: Sql, type: CastType) => Sql;
1964
+ };
1965
+ aggregates: {
1966
+ count: (expr?: Sql) => Sql;
1967
+ countDistinct: (expr: Sql) => Sql;
1968
+ sum: (expr: Sql) => Sql;
1969
+ avg: (expr: Sql) => Sql;
1970
+ min: (expr: Sql) => Sql;
1971
+ max: (expr: Sql) => Sql;
1972
+ };
1973
+ json: {
1974
+ object: (pairs: [string, Sql][]) => Sql;
1975
+ array: (items: Sql[]) => Sql;
1976
+ emptyArray: () => Sql;
1977
+ agg: (expr: Sql) => Sql;
1978
+ rowToJson: (alias: string) => Sql;
1979
+ objectFromColumns: (columns: [string, Sql][]) => Sql;
1980
+ extract: (column: Sql, path: string[]) => Sql;
1981
+ extractText: (column: Sql, path: string[]) => Sql;
1982
+ };
1983
+ arrays: {
1984
+ literal: (items: Sql[]) => Sql;
1985
+ has: (column: Sql, value: Sql) => Sql;
1986
+ hasEvery: (column: Sql, values: Sql) => Sql;
1987
+ hasSome: (column: Sql, values: Sql) => Sql;
1988
+ isEmpty: (column: Sql) => Sql;
1989
+ length: (column: Sql) => Sql;
1990
+ get: (column: Sql, index: Sql) => Sql;
1991
+ push: (column: Sql, value: Sql) => Sql;
1992
+ set: (column: Sql, index: Sql, value: Sql) => Sql;
1993
+ };
1994
+ orderBy: {
1995
+ asc: (column: Sql) => Sql;
1996
+ desc: (column: Sql) => Sql;
1997
+ nullsFirst: (expr: Sql) => Sql;
1998
+ nullsLast: (expr: Sql) => Sql;
1999
+ };
2000
+ clauses: {
2001
+ select: (columns: Sql) => Sql;
2002
+ selectDistinct: (columns: Sql) => Sql;
2003
+ from: (table: Sql) => Sql;
2004
+ where: (condition: Sql) => Sql;
2005
+ orderBy: (orders: Sql) => Sql;
2006
+ limit: (count: Sql) => Sql;
2007
+ offset: (count: Sql) => Sql;
2008
+ groupBy: (columns: Sql) => Sql;
2009
+ having: (condition: Sql) => Sql;
2010
+ };
2011
+ set: {
2012
+ assign: (column: Sql, value: Sql) => Sql;
2013
+ increment: (column: Sql, by: Sql) => Sql;
2014
+ decrement: (column: Sql, by: Sql) => Sql;
2015
+ multiply: (column: Sql, by: Sql) => Sql;
2016
+ divide: (column: Sql, by: Sql) => Sql;
2017
+ push: (column: Sql, value: Sql) => Sql;
2018
+ unshift: (column: Sql, value: Sql) => Sql;
2019
+ };
2020
+ filters: {
2021
+ some: (subquery: Sql) => Sql;
2022
+ every: (subquery: Sql) => Sql;
2023
+ none: (subquery: Sql) => Sql;
2024
+ is: (subquery: Sql) => Sql;
2025
+ isNot: (subquery: Sql) => Sql;
2026
+ };
2027
+ subqueries: {
2028
+ scalar: (query: Sql) => Sql;
2029
+ correlate: (query: Sql, alias: string) => Sql;
2030
+ existsCheck: (from: Sql, where: Sql) => Sql;
2031
+ };
2032
+ assemble: {
2033
+ select: (parts: QueryParts) => Sql;
2034
+ };
2035
+ /**
2036
+ * Simulate DISTINCT ON using ROW_NUMBER() window function.
2037
+ *
2038
+ * Generates:
2039
+ * SELECT col1, col2, ... FROM (
2040
+ * SELECT columns, ROW_NUMBER() OVER (PARTITION BY distinct_cols ORDER BY order_cols) AS _rn
2041
+ * FROM table
2042
+ * WHERE ...
2043
+ * ) AS _distinct_subquery
2044
+ * WHERE _rn = 1
2045
+ * ORDER BY ...
2046
+ * LIMIT ... OFFSET ...
2047
+ */
2048
+ private assembleDistinctOn;
2049
+ cte: {
2050
+ with: (definitions: {
2051
+ name: string;
2052
+ query: Sql;
2053
+ }[]) => Sql;
2054
+ recursive: (name: string, anchor: Sql, recursive: Sql, union?: "all" | "distinct") => Sql;
2055
+ };
2056
+ mutations: {
2057
+ insert: (table: Sql, columns: string[], values: Sql[][], prefix?: Sql) => Sql;
2058
+ update: (table: Sql, sets: Sql, where?: Sql) => Sql;
2059
+ delete: (table: Sql, where?: Sql) => Sql;
2060
+ returning: (columns: Sql) => Sql;
2061
+ onConflict: (target: Sql | null, action: Sql, targetWhere?: Sql) => Sql;
2062
+ onConflictUpdate: (sets: Sql, setWhere?: Sql) => Sql;
2063
+ skipDuplicates: () => {
2064
+ prefix: Sql;
2065
+ suffix: Sql;
2066
+ };
2067
+ };
2068
+ joins: {
2069
+ inner: (table: Sql, condition: Sql) => Sql;
2070
+ left: (table: Sql, condition: Sql) => Sql;
2071
+ right: (table: Sql, condition: Sql) => Sql;
2072
+ full: (table: Sql, condition: Sql) => Sql;
2073
+ cross: (table: Sql) => Sql;
2074
+ lateral: (_subquery: Sql, _alias: string) => Sql;
2075
+ lateralLeft: (_subquery: Sql, _alias: string) => Sql;
2076
+ };
2077
+ setOperations: {
2078
+ union: (...queries: Sql[]) => Sql;
2079
+ unionAll: (...queries: Sql[]) => Sql;
2080
+ intersect: (...queries: Sql[]) => Sql;
2081
+ except: (left: Sql, right: Sql) => Sql;
2082
+ };
2083
+ capabilities: {
2084
+ supportsReturning: boolean;
2085
+ supportsCteWithMutations: boolean;
2086
+ supportsFullOuterJoin: boolean;
2087
+ supportsLateralJoins: boolean;
2088
+ supportsUpsertWhere: boolean;
2089
+ };
2090
+ lastInsertId: () => Sql;
2091
+ vector: {
2092
+ literal: () => never;
2093
+ l2: () => never;
2094
+ cosine: () => never;
2095
+ };
2096
+ geospatial: {
2097
+ point: () => never;
2098
+ equals: () => never;
2099
+ intersects: () => never;
2100
+ contains: () => never;
2101
+ within: () => never;
2102
+ crosses: () => never;
2103
+ overlaps: () => never;
2104
+ touches: () => never;
2105
+ covers: () => never;
2106
+ dWithin: () => never;
2107
+ };
2108
+ result: {
2109
+ parseResult: (_raw: unknown, _operation: Operation, next: (value?: unknown) => unknown) => unknown;
2110
+ parseRelation: (_value: unknown, _type: RelationType, next: (value?: unknown) => unknown) => unknown;
2111
+ parseField: (_value: unknown, _fieldType: string, next: (value?: unknown) => unknown) => unknown;
2112
+ };
2113
+ }
2114
+ declare const sqliteAdapter: SQLiteAdapter;
2115
+ //#endregion
2116
+ //#region src/adapters/types.d.ts
2117
+ interface ValidationRule {
2118
+ type: string;
2119
+ params?: Record<string, unknown>;
2120
+ message?: string;
2121
+ }
2122
+ type AdapterError = ConnectionError | QueryError | ValidationError | SchemaError | ASTError;
2123
+ interface ConnectionError {
2124
+ type: "connection";
2125
+ code: string;
2126
+ message: string;
2127
+ cause?: Error;
2128
+ }
2129
+ interface QueryError {
2130
+ type: "query";
2131
+ code: string;
2132
+ message: string;
2133
+ query?: string;
2134
+ parameters?: unknown[];
2135
+ cause?: Error;
2136
+ }
2137
+ interface ValidationError {
2138
+ type: "validation";
2139
+ field: string;
2140
+ rule: string;
2141
+ message: string;
2142
+ value?: unknown;
2143
+ }
2144
+ interface SchemaError {
2145
+ type: "schema";
2146
+ message: string;
2147
+ entity?: string;
2148
+ cause?: Error;
2149
+ }
2150
+ interface ASTError {
2151
+ type: "ast";
2152
+ message: string;
2153
+ node?: string;
2154
+ cause?: Error;
2155
+ }
2156
+ //#endregion
2157
+ export { ATTR_SERVER_PORT as $, Dialect as A, VibORMError as At, ATTR_CACHE_TTL as B, ResultParser as C, MigrationError as Ct, QueryExecutionContext as D, TransactionError as Dt, DriverResultParser as E, QueryError$1 as Et, Sql as F, wrapError as Ft, ATTR_DB_OPERATION_NAME as G, ATTR_DB_COLLECTION as H, InstrumentationContext as I, ATTR_DB_QUERY_TEXT as J, ATTR_DB_QUERY_PARAMETER_PREFIX as K, ATTR_CACHE_DRIVER as L, LogFunction as M, isMigrationError as Mt, QueryResult as N, isRetryableError as Nt, TransactionBoundDriver as O, UniqueConstraintError as Ot, TransactionOptions as P, isVibORMError as Pt, ATTR_SERVER_ADDRESS as Q, ATTR_CACHE_KEY as R, RawQueryResult as S, ForeignKeyError as St, Driver as T, NotFoundError as Tt, ATTR_DB_DRIVER as U, ATTR_DB_BATCH_SIZE as V, ATTR_DB_NAMESPACE as W, ATTR_DB_SYSTEM as X, ATTR_DB_ROWS_RETURNED as Y, ATTR_ERROR_TYPE as Z, InsertParts as _, LogLevel as _t, SchemaError as a, SPAN_CACHE_SET as at, PreparedQuery as b, ConnectionError$1 as bt, SQLiteAdapter as c, SPAN_EXECUTE as ct, postgresAdapter as d, SPAN_TRANSACTION as dt, SPAN_BUILD as et, MySQLAdapter as f, SPAN_VALIDATE as ft, DeleteParts as g, LogEvent as gt, DatabaseAdapter as h, LogCallback as ht, QueryError as i, SPAN_CACHE_INVALIDATE as it, IsolationLevel as j, VibORMErrorCode as jt, BatchQuery as k, ValidationError$1 as kt, sqliteAdapter as l, SPAN_OPERATION as lt, CastType as m, InstrumentationConfig as mt, AdapterError as n, SPAN_CACHE_DELETE as nt, ValidationError as o, SPAN_CONNECT as ot, mysqlAdapter as p, VibORMSpanName as pt, ATTR_DB_QUERY_SUMMARY as q, ConnectionError as r, SPAN_CACHE_GET as rt, ValidationRule as s, SPAN_DISCONNECT as st, ASTError as t, SPAN_CACHE_CLEAR as tt, PostgresAdapter as u, SPAN_PARSE as ut, QueryParts as v, LoggingConfig as vt, AnyDriver as w, NestedWriteError as wt, QueryMetadata as x, FeatureNotSupportedError as xt, UpdateParts as y, TracingConfig as yt, ATTR_CACHE_RESULT as z };
2158
+ //# sourceMappingURL=index-BGmpst1h.d.mts.map