@rudderjs/database 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +70 -0
  2. package/dist/db.d.ts +21 -3
  3. package/dist/db.d.ts.map +1 -1
  4. package/dist/db.js +27 -5
  5. package/dist/db.js.map +1 -1
  6. package/dist/index.d.ts +14 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +23 -4
  9. package/dist/index.js.map +1 -1
  10. package/dist/native/adapter.d.ts +202 -0
  11. package/dist/native/adapter.d.ts.map +1 -0
  12. package/dist/native/adapter.js +440 -0
  13. package/dist/native/adapter.js.map +1 -0
  14. package/dist/native/compiler.d.ts +371 -0
  15. package/dist/native/compiler.d.ts.map +1 -0
  16. package/dist/native/compiler.js +978 -0
  17. package/dist/native/compiler.js.map +1 -0
  18. package/dist/native/dialect-mysql.d.ts +26 -0
  19. package/dist/native/dialect-mysql.d.ts.map +1 -0
  20. package/dist/native/dialect-mysql.js +188 -0
  21. package/dist/native/dialect-mysql.js.map +1 -0
  22. package/dist/native/dialect-pg.d.ts +26 -0
  23. package/dist/native/dialect-pg.d.ts.map +1 -0
  24. package/dist/native/dialect-pg.js +192 -0
  25. package/dist/native/dialect-pg.js.map +1 -0
  26. package/dist/native/dialect.d.ts +255 -0
  27. package/dist/native/dialect.d.ts.map +1 -0
  28. package/dist/native/dialect.js +237 -0
  29. package/dist/native/dialect.js.map +1 -0
  30. package/dist/native/driver.d.ts +37 -0
  31. package/dist/native/driver.d.ts.map +1 -0
  32. package/dist/native/driver.js +19 -0
  33. package/dist/native/driver.js.map +1 -0
  34. package/dist/native/drivers/better-sqlite3.d.ts +56 -0
  35. package/dist/native/drivers/better-sqlite3.d.ts.map +1 -0
  36. package/dist/native/drivers/better-sqlite3.js +171 -0
  37. package/dist/native/drivers/better-sqlite3.js.map +1 -0
  38. package/dist/native/drivers/mysql.d.ts +30 -0
  39. package/dist/native/drivers/mysql.d.ts.map +1 -0
  40. package/dist/native/drivers/mysql.js +176 -0
  41. package/dist/native/drivers/mysql.js.map +1 -0
  42. package/dist/native/drivers/postgres.d.ts +57 -0
  43. package/dist/native/drivers/postgres.d.ts.map +1 -0
  44. package/dist/native/drivers/postgres.js +155 -0
  45. package/dist/native/drivers/postgres.js.map +1 -0
  46. package/dist/native/errors.d.ts +43 -0
  47. package/dist/native/errors.d.ts.map +1 -0
  48. package/dist/native/errors.js +64 -0
  49. package/dist/native/errors.js.map +1 -0
  50. package/dist/native/index.d.ts +27 -0
  51. package/dist/native/index.d.ts.map +1 -0
  52. package/dist/native/index.js +55 -0
  53. package/dist/native/index.js.map +1 -0
  54. package/dist/native/isolation.d.ts +14 -0
  55. package/dist/native/isolation.d.ts.map +1 -0
  56. package/dist/native/isolation.js +37 -0
  57. package/dist/native/isolation.js.map +1 -0
  58. package/dist/native/query-builder.d.ts +303 -0
  59. package/dist/native/query-builder.d.ts.map +1 -0
  60. package/dist/native/query-builder.js +984 -0
  61. package/dist/native/query-builder.js.map +1 -0
  62. package/dist/native/replica-picker.d.ts +22 -0
  63. package/dist/native/replica-picker.d.ts.map +1 -0
  64. package/dist/native/replica-picker.js +65 -0
  65. package/dist/native/replica-picker.js.map +1 -0
  66. package/dist/native/schema/alter-blueprint.d.ts +37 -0
  67. package/dist/native/schema/alter-blueprint.d.ts.map +1 -0
  68. package/dist/native/schema/alter-blueprint.js +56 -0
  69. package/dist/native/schema/alter-blueprint.js.map +1 -0
  70. package/dist/native/schema/blueprint.d.ts +151 -0
  71. package/dist/native/schema/blueprint.d.ts.map +1 -0
  72. package/dist/native/schema/blueprint.js +286 -0
  73. package/dist/native/schema/blueprint.js.map +1 -0
  74. package/dist/native/schema/column.d.ts +168 -0
  75. package/dist/native/schema/column.d.ts.map +1 -0
  76. package/dist/native/schema/column.js +190 -0
  77. package/dist/native/schema/column.js.map +1 -0
  78. package/dist/native/schema/ddl-compiler.d.ts +34 -0
  79. package/dist/native/schema/ddl-compiler.d.ts.map +1 -0
  80. package/dist/native/schema/ddl-compiler.js +352 -0
  81. package/dist/native/schema/ddl-compiler.js.map +1 -0
  82. package/dist/native/schema/inspect.d.ts +67 -0
  83. package/dist/native/schema/inspect.d.ts.map +1 -0
  84. package/dist/native/schema/inspect.js +312 -0
  85. package/dist/native/schema/inspect.js.map +1 -0
  86. package/dist/native/schema/introspect.d.ts +34 -0
  87. package/dist/native/schema/introspect.d.ts.map +1 -0
  88. package/dist/native/schema/introspect.js +101 -0
  89. package/dist/native/schema/introspect.js.map +1 -0
  90. package/dist/native/schema/migration.d.ts +8 -0
  91. package/dist/native/schema/migration.d.ts.map +1 -0
  92. package/dist/native/schema/migration.js +19 -0
  93. package/dist/native/schema/migration.js.map +1 -0
  94. package/dist/native/schema/migrator.d.ts +144 -0
  95. package/dist/native/schema/migrator.d.ts.map +1 -0
  96. package/dist/native/schema/migrator.js +240 -0
  97. package/dist/native/schema/migrator.js.map +1 -0
  98. package/dist/native/schema/rebuild.d.ts +11 -0
  99. package/dist/native/schema/rebuild.d.ts.map +1 -0
  100. package/dist/native/schema/rebuild.js +92 -0
  101. package/dist/native/schema/rebuild.js.map +1 -0
  102. package/dist/native/schema/schema-builder.d.ts +46 -0
  103. package/dist/native/schema/schema-builder.d.ts.map +1 -0
  104. package/dist/native/schema/schema-builder.js +153 -0
  105. package/dist/native/schema/schema-builder.js.map +1 -0
  106. package/dist/native/schema/schema-facade.d.ts +63 -0
  107. package/dist/native/schema/schema-facade.d.ts.map +1 -0
  108. package/dist/native/schema/schema-facade.js +124 -0
  109. package/dist/native/schema/schema-facade.js.map +1 -0
  110. package/dist/native/schema/schema-types.d.ts +27 -0
  111. package/dist/native/schema/schema-types.d.ts.map +1 -0
  112. package/dist/native/schema/schema-types.js +52 -0
  113. package/dist/native/schema/schema-types.js.map +1 -0
  114. package/dist/native/schema/types-generator.d.ts +73 -0
  115. package/dist/native/schema/types-generator.d.ts.map +1 -0
  116. package/dist/native/schema/types-generator.js +181 -0
  117. package/dist/native/schema/types-generator.js.map +1 -0
  118. package/dist/registry-bridge.d.ts +24 -4
  119. package/dist/registry-bridge.d.ts.map +1 -1
  120. package/dist/registry-bridge.js +20 -0
  121. package/dist/registry-bridge.js.map +1 -1
  122. package/dist/sticky.d.ts +22 -0
  123. package/dist/sticky.d.ts.map +1 -0
  124. package/dist/sticky.js +61 -0
  125. package/dist/sticky.js.map +1 -0
  126. package/package.json +32 -2
@@ -0,0 +1,371 @@
1
+ import type { WhereClause, WhereOperator, OrderClause, RelationExistencePredicate, AggregateRequest, LockOptions } from '@rudderjs/contracts';
2
+ import { type Dialect, type DatePart, type JsonPathSegment } from './dialect.js';
3
+ /** A raw SQL fragment + its `?`-placeholder bindings, threaded through a clause. */
4
+ export interface RawFragment {
5
+ sql: string;
6
+ bindings: readonly unknown[];
7
+ }
8
+ /**
9
+ * A node in the WHERE condition tree.
10
+ *
11
+ * - `clause` — a single `column <op> value` predicate.
12
+ * - `group` — a parenthesized sub-tree with its own boolean roots, produced by
13
+ * `whereGroup` / `orWhereGroup`. Nesting is unbounded. `negated: true`
14
+ * (from `whereNot` / `orWhereNot`) wraps the parenthesized tree in `NOT`.
15
+ * - `date` — a date-component predicate (`whereDate`/`whereTime`/`whereDay`/
16
+ * `whereMonth`/`whereYear`): the column runs through the dialect's
17
+ * `dateExtract` seam, the value binds.
18
+ * - `json` — a JSON-path comparison (`where('meta->prefs->lang', …)`): the
19
+ * column + validated segments run through the dialect's `jsonExtract` seam,
20
+ * the value binds (booleans normalized via `jsonBoolean`).
21
+ * - `jsonContains` / `jsonLength` — `whereJsonContains` / `whereJsonLength`
22
+ * predicates through the matching dialect seams.
23
+ *
24
+ * Each node carries `boolean: 'AND' | 'OR'` recording how it joins to the
25
+ * predicate *before* it at the same level. The first node's boolean is ignored.
26
+ */
27
+ export type ConditionNode = {
28
+ kind: 'clause';
29
+ boolean: 'AND' | 'OR';
30
+ clause: WhereClause;
31
+ } | {
32
+ kind: 'group';
33
+ boolean: 'AND' | 'OR';
34
+ children: ConditionNode[];
35
+ negated?: boolean;
36
+ } | {
37
+ kind: 'raw';
38
+ boolean: 'AND' | 'OR';
39
+ raw: RawFragment;
40
+ } | {
41
+ kind: 'column';
42
+ boolean: 'AND' | 'OR';
43
+ left: string;
44
+ operator: WhereOperator;
45
+ right: string;
46
+ } | {
47
+ kind: 'date';
48
+ boolean: 'AND' | 'OR';
49
+ part: DatePart;
50
+ column: string;
51
+ operator: WhereOperator;
52
+ value: unknown;
53
+ } | {
54
+ kind: 'json';
55
+ boolean: 'AND' | 'OR';
56
+ column: string;
57
+ segments: readonly JsonPathSegment[];
58
+ operator: WhereOperator;
59
+ value: unknown;
60
+ } | {
61
+ kind: 'jsonContains';
62
+ boolean: 'AND' | 'OR';
63
+ column: string;
64
+ segments: readonly JsonPathSegment[];
65
+ value: unknown;
66
+ negated: boolean;
67
+ } | {
68
+ kind: 'jsonLength';
69
+ boolean: 'AND' | 'OR';
70
+ column: string;
71
+ segments: readonly JsonPathSegment[];
72
+ operator: WhereOperator;
73
+ value: number;
74
+ } | {
75
+ kind: 'exists';
76
+ boolean: 'AND' | 'OR';
77
+ negated: boolean;
78
+ body: SubqueryBody;
79
+ };
80
+ /**
81
+ * A subquery body — another native query's captured state (`Model.query()` /
82
+ * `adapter.query(...)` chains) or a raw SQL fragment. Shared by CTE bodies
83
+ * ({@link CteNode}) and `whereExists` predicates. Builder-backed bodies keep
84
+ * their own UNION members but drop ORDER BY / LIMIT (same rule as `union()`).
85
+ */
86
+ export type SubqueryBody = {
87
+ kind: 'state';
88
+ state: NativeQueryState;
89
+ } | {
90
+ kind: 'raw';
91
+ raw: RawFragment;
92
+ };
93
+ /**
94
+ * A single ORDER BY entry — either a structured `column direction` clause or a
95
+ * raw SQL fragment from `orderByRaw` / `orderBy(raw(...))`.
96
+ */
97
+ export type OrderItem = OrderClause | {
98
+ kind: 'raw';
99
+ raw: RawFragment;
100
+ };
101
+ /**
102
+ * One common table expression from `withExpression` / `withRecursiveExpression`.
103
+ * The body is either another native query's state (`Model.query()` /
104
+ * `adapter.query(...)` chains, captured like a UNION member) or a raw SQL
105
+ * fragment — recursive bodies are usually raw, because they reference the CTE's
106
+ * own name (`… UNION ALL SELECT … FROM cte_name …`), which a table-rooted
107
+ * builder can't express. `columns` (optional) emits the explicit column list
108
+ * (`name (col1, col2)`) most useful on recursive CTEs.
109
+ */
110
+ export interface CteNode {
111
+ name: string;
112
+ recursive: boolean;
113
+ columns?: readonly string[];
114
+ body: SubqueryBody;
115
+ }
116
+ /** The four join flavors. `cross` carries no ON conditions. */
117
+ export type JoinType = 'inner' | 'left' | 'right' | 'cross';
118
+ /**
119
+ * One condition inside a join's ON clause.
120
+ * - `on` — column-vs-column (`"posts"."userId" = "users"."id"`); nothing binds.
121
+ * - `where` — column-vs-value (`"posts"."active" = ?`); the value binds.
122
+ */
123
+ export type JoinCondition = {
124
+ kind: 'on';
125
+ boolean: 'AND' | 'OR';
126
+ left: string;
127
+ operator: WhereOperator;
128
+ right: string;
129
+ } | {
130
+ kind: 'where';
131
+ boolean: 'AND' | 'OR';
132
+ clause: WhereClause;
133
+ };
134
+ /** A single JOIN: type + table + its ON condition list (empty for `cross`). */
135
+ export interface JoinNode {
136
+ type: JoinType;
137
+ table: string;
138
+ conditions: JoinCondition[];
139
+ }
140
+ /** Window functions `selectWindow` accepts. The map to SQL names lives in
141
+ * {@link WINDOW_FUNCTION_SQL} — like the isolation-level map, the closed set
142
+ * IS the injection gate (the function name is spliced, never bound). All five
143
+ * are zero-argument ranking functions with identical syntax on SQLite ≥3.25,
144
+ * Postgres, and MySQL 8 — no dialect seam needed. */
145
+ export type WindowFunction = 'rowNumber' | 'rank' | 'denseRank' | 'percentRank' | 'cumeDist';
146
+ /** Runtime membership check for {@link WindowFunction} — the builder's
147
+ * injection gate for the spliced function name (JS callers bypass the TS
148
+ * union). */
149
+ export declare function isWindowFunction(fn: string): fn is WindowFunction;
150
+ /** One `fn() OVER (PARTITION BY … ORDER BY …) AS alias` projection entry from
151
+ * `selectWindow`. Identifiers quote at compile time; directions are validated
152
+ * to `asc`/`desc` by the builder. No bindings — the whole entry is identifiers
153
+ * + keywords. */
154
+ export interface WindowSelect {
155
+ fn: WindowFunction;
156
+ as: string;
157
+ partitionBy: string[];
158
+ orderBy: Array<{
159
+ column: string;
160
+ direction: 'asc' | 'desc';
161
+ }>;
162
+ }
163
+ /**
164
+ * One entry in a HAVING clause.
165
+ * - `clause` — `column <op> value` (the value binds); the column may be a
166
+ * SELECT alias (`having('post_count', '>', 3)`).
167
+ * - `raw` — a raw fragment, e.g. `havingRaw('COUNT(*) > ?', [3])` (the
168
+ * portable way to filter on an aggregate — Postgres won't accept an alias here).
169
+ */
170
+ export type HavingNode = {
171
+ kind: 'clause';
172
+ boolean: 'AND' | 'OR';
173
+ clause: WhereClause;
174
+ } | {
175
+ kind: 'raw';
176
+ boolean: 'AND' | 'OR';
177
+ raw: RawFragment;
178
+ };
179
+ /**
180
+ * Everything the read compiler needs from a query. The `NativeQueryBuilder`
181
+ * accumulates this; the compiler is otherwise stateless.
182
+ */
183
+ export interface NativeQueryState {
184
+ table: string;
185
+ primaryKey: string;
186
+ conditions: ConditionNode[];
187
+ orders: OrderItem[];
188
+ limitN: number | null;
189
+ offsetN: number | null;
190
+ /** Structured projection columns from `select(...)`. When present (with or
191
+ * without `rawSelects`) they REPLACE the default `*`. Each is identifier-
192
+ * quoted (qualified `table.col` supported); raw aliasing goes via `selectRaw`. */
193
+ selects?: string[];
194
+ /** Raw projection fragments from `selectRaw`. When present they REPLACE the
195
+ * default `*` (Laravel semantics — `selectRaw` is a projection, not additive).
196
+ * Combined with `selects` in call order (structured first, then raw). */
197
+ rawSelects?: RawFragment[];
198
+ /** JOIN clauses from `join`/`leftJoin`/`rightJoin`/`crossJoin`, emitted
199
+ * between FROM and WHERE in declaration order. */
200
+ joins?: JoinNode[];
201
+ /** `GROUP BY` columns from `groupBy(...)`, emitted after WHERE. Quoted
202
+ * (qualified `table.col` supported); no bindings. */
203
+ groupBy?: string[];
204
+ /** `HAVING` predicates from `having`/`havingRaw`, emitted after GROUP BY.
205
+ * Their bound values follow the WHERE's and precede ORDER BY's. */
206
+ having?: HavingNode[];
207
+ /** `UNION` / `UNION ALL` members from `union(...)`/`unionAll(...)`. Each member's
208
+ * own ORDER BY / LIMIT / OFFSET / lock are ignored — the BASE query's apply to
209
+ * the whole combined result. Member bindings follow the base body's in order. */
210
+ unions?: Array<{
211
+ all: boolean;
212
+ state: NativeQueryState;
213
+ }>;
214
+ /** Common table expressions from `withExpression(...)`/`withRecursiveExpression(...)`.
215
+ * Emitted as a `WITH [RECURSIVE] name [(cols)] AS (body), …` prefix on reads
216
+ * (`compileSelect` + `compileCount`); their bindings come FIRST (SQL text
217
+ * order — the WITH clause precedes the main SELECT). */
218
+ ctes?: CteNode[];
219
+ /** `SELECT DISTINCT` from `distinct()` — de-duplicates the projected rows. */
220
+ distinct?: boolean;
221
+ /** Window-function projections from `selectWindow(...)`. ADDITIVE — appended
222
+ * to the projection (after structured/raw selects, or after the default `*`
223
+ * when none replace it), unlike `selectRaw`'s REPLACE semantics: a ranking
224
+ * column is almost always wanted *alongside* the row. */
225
+ windows?: WindowSelect[];
226
+ /** Soft-delete scoping resolved by the builder from the Model + with/onlyTrashed. */
227
+ softDelete: 'exclude' | 'only' | 'with';
228
+ /** Column the soft-delete filter targets. Default `deletedAt`. */
229
+ deletedAtColumn: string;
230
+ /** Correlated EXISTS / NOT EXISTS predicates from `whereRelationExists`
231
+ * (`whereHas` / `whereDoesntHave`). AND-merged into the WHERE. */
232
+ relationExists?: RelationExistencePredicate[];
233
+ /** Aggregate subselect requests from `withAggregate` (`withCount`/`withSum`/…).
234
+ * Each becomes a `(subselect) AS alias` column in the SELECT list. */
235
+ aggregates?: AggregateRequest[];
236
+ /** Pessimistic row lock from `lockForUpdate()` / `sharedLock()`. Emitted as
237
+ * the dialect's `FOR UPDATE` / `FOR SHARE` suffix after ORDER BY / LIMIT
238
+ * (no-op on SQLite). `null`/absent = no lock. */
239
+ lock?: 'update' | 'shared' | null;
240
+ /** Wait behavior for the lock (`SKIP LOCKED` / `NOWAIT` on pg/mysql) —
241
+ * already validated mutually exclusive by the QueryBuilder. Only consulted
242
+ * when `lock` is set. `null`/absent = default blocking wait. */
243
+ lockOptions?: LockOptions | null;
244
+ }
245
+ /** A compiled statement: parameterized SQL + the positional bindings. */
246
+ export interface CompiledQuery {
247
+ sql: string;
248
+ bindings: unknown[];
249
+ }
250
+ /**
251
+ * Accumulates positional bindings and hands out the matching placeholder. One
252
+ * instance per compile so `$n` indices (Postgres, later) stay correct across
253
+ * the whole statement, not per-fragment.
254
+ */
255
+ declare class Bindings {
256
+ private readonly dialect;
257
+ readonly values: unknown[];
258
+ constructor(dialect: Dialect);
259
+ add(value: unknown): string;
260
+ }
261
+ /**
262
+ * Compile a SELECT for the read terminals (`get`/`all`/`first`/`find`).
263
+ *
264
+ * `overrides` lets terminals tweak the shape without mutating state:
265
+ * - `limit` — force a LIMIT (e.g. `first()` → 1), overriding `state.limitN`.
266
+ * - `selectColumns` — projection list; defaults to `*`.
267
+ * - `extraConditions` — additional clauses AND-ed in (e.g. `find(id)` → PK match),
268
+ * applied at the top level *outside* the user predicate parens.
269
+ */
270
+ export declare function compileSelect(state: NativeQueryState, dialect: Dialect, overrides?: {
271
+ limit?: number | null;
272
+ selectColumns?: string;
273
+ extraConditions?: ConditionNode[];
274
+ }): CompiledQuery;
275
+ /** Compile `SELECT COUNT(*) AS count FROM ... WHERE ...` for `count()` /
276
+ * `paginate()` totals. Orders/limit/offset are irrelevant to a count. */
277
+ export declare function compileCount(state: NativeQueryState, dialect: Dialect): CompiledQuery;
278
+ /** Shared options for write compilers. */
279
+ interface WriteOpts {
280
+ /** Clauses AND-ed onto the WHERE (e.g. the primary-key match for by-id writes). */
281
+ extraConditions?: ConditionNode[];
282
+ /** Append `RETURNING *` so the executor returns the affected rows. */
283
+ returning?: boolean;
284
+ }
285
+ /**
286
+ * Compile an INSERT for one or more rows. Single-row (`create`) and multi-row
287
+ * (`insertMany`) share this. The column list is the first-seen union of every
288
+ * row's defined keys; a row missing a union column binds `null`. With
289
+ * `returning`, appends `RETURNING *` (single-row `create` reads the inserted
290
+ * row back). Throws on an empty `rows` array — callers guard the no-op.
291
+ */
292
+ export declare function compileInsert(state: NativeQueryState, dialect: Dialect, rows: Array<Record<string, unknown>>, opts?: {
293
+ returning?: boolean;
294
+ upsert?: {
295
+ uniqueBy: readonly string[];
296
+ update: readonly string[];
297
+ };
298
+ }): CompiledQuery;
299
+ /**
300
+ * Compile `INSERT INTO table (cols) SELECT …` for `insertUsing(columns, query)`
301
+ * — the rows come from a subquery (builder state or raw SQL), not VALUES
302
+ * tuples. Column names are identifier-quoted; the subquery compiles through
303
+ * the shared {@link Bindings} (raw `?` placeholders rebound per dialect). The
304
+ * column list is REQUIRED — the subquery's projection order must be pinned to
305
+ * named target columns, a bare `INSERT INTO t SELECT …` is a column-order
306
+ * footgun.
307
+ */
308
+ export declare function compileInsertUsing(state: NativeQueryState, dialect: Dialect, columns: readonly string[], body: SubqueryBody, opts?: {
309
+ returning?: boolean;
310
+ }): CompiledQuery;
311
+ /**
312
+ * Compile `UPDATE <table> SET col = ? [, …] [WHERE …] [RETURNING *]`.
313
+ *
314
+ * SET bindings are emitted before WHERE bindings, matching positional `?`
315
+ * order. `undefined`-valued columns are dropped (see {@link definedEntries}).
316
+ * Throws when there's nothing to set.
317
+ *
318
+ * Arrow-path keys (`'meta->prefs->lang'`) write into a JSON column via the
319
+ * dialect's `jsonSet` seam — see {@link compileJsonSetClause}. Payloads with
320
+ * no arrow key take the original plain path (byte-identical SQL).
321
+ */
322
+ export declare function compileUpdate(state: NativeQueryState, dialect: Dialect, data: Record<string, unknown>, opts?: WriteOpts): CompiledQuery;
323
+ /**
324
+ * Compile an atomic counter update: `UPDATE <table> SET col = col + ? [, extra = ?]
325
+ * [WHERE …] [RETURNING *]`. `delta` is the signed amount (decrement passes a
326
+ * negative). `extra` columns are written in the same statement. Pure SQL —
327
+ * `col = col + ?` reads and writes atomically at the DB, safe under concurrency.
328
+ */
329
+ export declare function compileIncrement(state: NativeQueryState, dialect: Dialect, column: string, delta: number, extra: Record<string, unknown>, opts?: WriteOpts): CompiledQuery;
330
+ /** Compile `DELETE FROM <table> [WHERE …] [RETURNING *]`. With `returning`,
331
+ * the executor returns the deleted rows so the caller can take `rows.length`
332
+ * as the affected count (no driver `changes` metadata needed). */
333
+ export declare function compileDelete(state: NativeQueryState, dialect: Dialect, opts?: WriteOpts): CompiledQuery;
334
+ /**
335
+ * Compile a correlated `EXISTS (…)` / `NOT EXISTS (…)` fragment for a
336
+ * {@link RelationExistencePredicate}. Shares the caller's {@link Bindings} so
337
+ * its parameters stay in positional order with the surrounding WHERE.
338
+ *
339
+ * - **Direct** (hasMany/hasOne/belongsTo/morphMany/morphOne): single subquery
340
+ * joining `related.relatedColumn = outer.parentColumn`, plus `extraEquals`
341
+ * (morph discriminator) on the related table and the constraint wheres.
342
+ * - **Through-pivot** (belongsToMany/morphToMany/morphedByMany): nested EXISTS —
343
+ * pivot rows for this parent (+ `extraEquals` on the pivot) whose related row
344
+ * exists (+ constraint wheres on the related table).
345
+ *
346
+ * Soft-delete scoping is intentionally NOT applied here — it's the constrain
347
+ * callback's responsibility (documented), matching the other adapters.
348
+ */
349
+ export declare function compileExists(outerTable: string, predicate: RelationExistencePredicate, dialect: Dialect, b: Bindings): string;
350
+ /**
351
+ * Compile one aggregate request into a correlated subselect expression, aliased
352
+ * as `(…) AS "alias"`, for injection into the main SELECT list. `exists` wraps
353
+ * the COUNT in `(… ) > 0`. Mirrors the orm-drizzle aggregate-subquery shape.
354
+ */
355
+ export declare function compileAggregateSubselect(outerTable: string, req: AggregateRequest, dialect: Dialect, b: Bindings): string;
356
+ /**
357
+ * Compile a single-scalar aggregate terminal — `SELECT fn(col) AS value FROM
358
+ * table WHERE <wheres>` — for the `_aggregate(fn, column?)` contract method
359
+ * (powers `instance.loadSum`/`loadMin`/etc.). `count`/`exists` ignore the
360
+ * column and use `COUNT(*)`; the builder coerces the scalar afterward.
361
+ */
362
+ export declare function compileScalarAggregate(state: NativeQueryState, dialect: Dialect, fn: AggregateRequest['fn'], column: string | undefined): CompiledQuery;
363
+ /** Engine-internal seam — exported for the query builder so it can share one
364
+ * `Bindings` run across the WHERE (clauses + EXISTS fragments) and the
365
+ * SELECT-list aggregate subselects. Construction is otherwise module-private.
366
+ * (Deliberately NOT tagged internal: `stripInternal` would drop it from the
367
+ * emitted d.ts, and it is consumed cross-package by @rudderjs/orm's engine
368
+ * suites until PR-A3.) */
369
+ export declare function makeBindings(dialect: Dialect): Bindings;
370
+ export type { Bindings };
371
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/native/compiler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,WAAW,EACX,0BAA0B,EAC1B,gBAAgB,EAChB,WAAW,EACZ,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAiB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAsB,MAAM,cAAc,CAAA;AAGnH,oFAAoF;AACpF,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAO,MAAM,CAAA;IAChB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,aAAa,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GACvF;IAAE,IAAI,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