@leemour/cli-messaging 0.59.0 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/speech/recognize.d.ts +16 -0
- package/dist/speech/recognize.d.ts.map +1 -1
- package/dist/speech/recognize.js +19 -17
- package/dist/speech/recognize.js.map +1 -1
- package/dist/store/sqlite/drizzle/bun.d.ts +2 -0
- package/dist/store/sqlite/drizzle/bun.d.ts.map +1 -0
- package/dist/store/sqlite/drizzle/bun.js +113 -0
- package/dist/store/sqlite/drizzle/bun.js.map +7 -0
- package/dist/store/sqlite/drizzle/core.d.ts +3 -0
- package/dist/store/sqlite/drizzle/core.d.ts.map +1 -0
- package/dist/store/sqlite/drizzle/core.js +25 -0
- package/dist/store/sqlite/drizzle/core.js.map +7 -0
- package/dist/store/sqlite/drizzle/node.d.ts +2 -0
- package/dist/store/sqlite/drizzle/node.d.ts.map +1 -0
- package/dist/store/sqlite/drizzle/node.js +120 -0
- package/dist/store/sqlite/drizzle/node.js.map +7 -0
- package/dist/store/sqlite/drizzle/shared-ZF3LACGD.js +4830 -0
- package/dist/store/sqlite/drizzle/shared-ZF3LACGD.js.map +7 -0
- package/dist/store/sqlite/open.d.ts +1 -1
- package/dist/store/sqlite/open.d.ts.map +1 -1
- package/dist/store/sqlite/open.js +3 -4
- package/dist/store/sqlite/open.js.map +1 -1
- package/dist/store/sqlite/schema.d.ts.map +1 -1
- package/dist/store/sqlite/schema.js +1 -2
- package/dist/store/sqlite/schema.js.map +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,4830 @@
|
|
|
1
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/entity.js
|
|
2
|
+
var entityKind = Symbol.for("drizzle:entityKind");
|
|
3
|
+
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
4
|
+
function is(value, type) {
|
|
5
|
+
if (!value || typeof value !== "object") return false;
|
|
6
|
+
if (value instanceof type) return true;
|
|
7
|
+
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
|
|
8
|
+
let cls = Object.getPrototypeOf(value)?.constructor;
|
|
9
|
+
if (cls) while (cls) {
|
|
10
|
+
if (entityKind in cls && cls[entityKind] === type[entityKind]) return true;
|
|
11
|
+
cls = Object.getPrototypeOf(cls);
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/column-common.js
|
|
17
|
+
var OriginalColumn = Symbol.for("drizzle:OriginalColumn");
|
|
18
|
+
|
|
19
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/column.js
|
|
20
|
+
var noop = (v) => v;
|
|
21
|
+
noop.isNoop = true;
|
|
22
|
+
var Column = class {
|
|
23
|
+
static [entityKind] = "Column";
|
|
24
|
+
/** @internal */
|
|
25
|
+
codec;
|
|
26
|
+
name;
|
|
27
|
+
keyAsName;
|
|
28
|
+
primary;
|
|
29
|
+
notNull;
|
|
30
|
+
default;
|
|
31
|
+
defaultFn;
|
|
32
|
+
onUpdateFn;
|
|
33
|
+
hasDefault;
|
|
34
|
+
isUnique;
|
|
35
|
+
uniqueName;
|
|
36
|
+
uniqueType;
|
|
37
|
+
dataType;
|
|
38
|
+
columnType;
|
|
39
|
+
enumValues = void 0;
|
|
40
|
+
generated = void 0;
|
|
41
|
+
generatedIdentity = void 0;
|
|
42
|
+
length;
|
|
43
|
+
isLengthExact;
|
|
44
|
+
isAlias;
|
|
45
|
+
/** @internal */
|
|
46
|
+
config;
|
|
47
|
+
/** @internal */
|
|
48
|
+
table;
|
|
49
|
+
/** @internal */
|
|
50
|
+
onInit() {
|
|
51
|
+
}
|
|
52
|
+
constructor(table, config) {
|
|
53
|
+
this.config = config;
|
|
54
|
+
this.onInit();
|
|
55
|
+
this.table = table;
|
|
56
|
+
this.name = config.name;
|
|
57
|
+
this.isAlias = false;
|
|
58
|
+
this.keyAsName = config.keyAsName;
|
|
59
|
+
this.notNull = config.notNull;
|
|
60
|
+
this.default = config.default;
|
|
61
|
+
this.defaultFn = config.defaultFn;
|
|
62
|
+
this.onUpdateFn = config.onUpdateFn;
|
|
63
|
+
this.hasDefault = config.hasDefault;
|
|
64
|
+
this.primary = config.primaryKey;
|
|
65
|
+
this.isUnique = config.isUnique;
|
|
66
|
+
this.uniqueName = config.uniqueName;
|
|
67
|
+
this.uniqueType = config.uniqueType;
|
|
68
|
+
this.dataType = config.dataType;
|
|
69
|
+
this.columnType = config.columnType;
|
|
70
|
+
this.generated = config.generated;
|
|
71
|
+
this.generatedIdentity = config.generatedIdentity;
|
|
72
|
+
this.length = config["length"];
|
|
73
|
+
this.isLengthExact = config["isLengthExact"];
|
|
74
|
+
}
|
|
75
|
+
mapFromDriverValue = noop;
|
|
76
|
+
mapToDriverValue = noop;
|
|
77
|
+
/** @internal */
|
|
78
|
+
postBuild() {
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/** @internal */
|
|
82
|
+
shouldDisableInsert() {
|
|
83
|
+
return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
|
|
84
|
+
}
|
|
85
|
+
/** @internal */
|
|
86
|
+
[OriginalColumn]() {
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/table.utils.js
|
|
92
|
+
var TableName = Symbol.for("drizzle:Name");
|
|
93
|
+
|
|
94
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/table.js
|
|
95
|
+
var TableSchema = Symbol.for("drizzle:Schema");
|
|
96
|
+
var TableColumns = Symbol.for("drizzle:Columns");
|
|
97
|
+
var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
98
|
+
var OriginalName = Symbol.for("drizzle:OriginalName");
|
|
99
|
+
var BaseName = Symbol.for("drizzle:BaseName");
|
|
100
|
+
var IsAlias = Symbol.for("drizzle:IsAlias");
|
|
101
|
+
var ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
|
102
|
+
var IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
|
103
|
+
var Table = class {
|
|
104
|
+
static [entityKind] = "Table";
|
|
105
|
+
/** @internal */
|
|
106
|
+
static Symbol = {
|
|
107
|
+
Name: TableName,
|
|
108
|
+
Schema: TableSchema,
|
|
109
|
+
OriginalName,
|
|
110
|
+
Columns: TableColumns,
|
|
111
|
+
ExtraConfigColumns,
|
|
112
|
+
BaseName,
|
|
113
|
+
IsAlias,
|
|
114
|
+
ExtraConfigBuilder
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* @internal
|
|
118
|
+
* Can be changed if the table is aliased.
|
|
119
|
+
*/
|
|
120
|
+
[TableName];
|
|
121
|
+
/**
|
|
122
|
+
* @internal
|
|
123
|
+
* Used to store the original name of the table, before any aliasing.
|
|
124
|
+
*/
|
|
125
|
+
[OriginalName];
|
|
126
|
+
/** @internal */
|
|
127
|
+
[TableSchema];
|
|
128
|
+
/** @internal */
|
|
129
|
+
[TableColumns];
|
|
130
|
+
/** @internal */
|
|
131
|
+
[ExtraConfigColumns];
|
|
132
|
+
/**
|
|
133
|
+
* @internal
|
|
134
|
+
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
135
|
+
*/
|
|
136
|
+
[BaseName];
|
|
137
|
+
/** @internal */
|
|
138
|
+
[IsAlias] = false;
|
|
139
|
+
/** @internal */
|
|
140
|
+
[IsDrizzleTable] = true;
|
|
141
|
+
/** @internal */
|
|
142
|
+
[ExtraConfigBuilder] = void 0;
|
|
143
|
+
constructor(name2, schema, baseName) {
|
|
144
|
+
this[TableName] = this[OriginalName] = name2;
|
|
145
|
+
this[TableSchema] = schema;
|
|
146
|
+
this[BaseName] = baseName;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
function getTableName(table) {
|
|
150
|
+
return table[TableName];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/subquery.js
|
|
154
|
+
var Subquery = class {
|
|
155
|
+
static [entityKind] = "Subquery";
|
|
156
|
+
constructor(sql2, fields, alias, isWith = false, usedTables = []) {
|
|
157
|
+
this._ = {
|
|
158
|
+
brand: "Subquery",
|
|
159
|
+
sql: sql2,
|
|
160
|
+
selectedFields: fields,
|
|
161
|
+
alias,
|
|
162
|
+
isWith,
|
|
163
|
+
usedTables
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var WithSubquery = class extends Subquery {
|
|
168
|
+
static [entityKind] = "WithSubquery";
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/tracing.js
|
|
172
|
+
var tracer = { startActiveSpan(name2, fn) {
|
|
173
|
+
return fn();
|
|
174
|
+
} };
|
|
175
|
+
|
|
176
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/view-common.js
|
|
177
|
+
var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
178
|
+
|
|
179
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sql/sql.js
|
|
180
|
+
var FakePrimitiveParam = class {
|
|
181
|
+
static [entityKind] = "FakePrimitiveParam";
|
|
182
|
+
};
|
|
183
|
+
function isSQLWrapper(value) {
|
|
184
|
+
return value !== null && value !== void 0 && typeof value.getSQL === "function";
|
|
185
|
+
}
|
|
186
|
+
function mergeQueries(queries) {
|
|
187
|
+
const result = {
|
|
188
|
+
sql: "",
|
|
189
|
+
params: []
|
|
190
|
+
};
|
|
191
|
+
for (const query of queries) {
|
|
192
|
+
result.sql += query.sql;
|
|
193
|
+
result.params.push(...query.params);
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
function _mergeQueries(queries) {
|
|
198
|
+
const result = {
|
|
199
|
+
sql: "",
|
|
200
|
+
params: []
|
|
201
|
+
};
|
|
202
|
+
const sqls = [];
|
|
203
|
+
for (const query of queries) {
|
|
204
|
+
sqls.push(query.sql);
|
|
205
|
+
result.params.push(...query.params);
|
|
206
|
+
}
|
|
207
|
+
result._sql = Object.assign(sqls, { raw: sqls });
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
var StringChunk = class {
|
|
211
|
+
static [entityKind] = "StringChunk";
|
|
212
|
+
value;
|
|
213
|
+
constructor(value) {
|
|
214
|
+
this.value = Array.isArray(value) ? value : [value];
|
|
215
|
+
}
|
|
216
|
+
getSQL() {
|
|
217
|
+
return new SQL([this]);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var SQL = class SQL2 {
|
|
221
|
+
static [entityKind] = "SQL";
|
|
222
|
+
/** @internal */
|
|
223
|
+
decoder = noopDecoder;
|
|
224
|
+
/** @internal */
|
|
225
|
+
shouldInlineParams = false;
|
|
226
|
+
/** @internal */
|
|
227
|
+
usedTables = [];
|
|
228
|
+
constructor(queryChunks) {
|
|
229
|
+
this.queryChunks = queryChunks;
|
|
230
|
+
for (const chunk of queryChunks) if (is(chunk, Table)) {
|
|
231
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
232
|
+
this.usedTables.push(schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
append(query) {
|
|
236
|
+
this.queryChunks.push(...query.queryChunks);
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
toQuery(config) {
|
|
240
|
+
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
241
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
242
|
+
span?.setAttributes({
|
|
243
|
+
"drizzle.query.text": query.sql,
|
|
244
|
+
"drizzle.query.params": JSON.stringify(query.params)
|
|
245
|
+
});
|
|
246
|
+
return query;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
buildQueryFromSourceParams(chunks, _config) {
|
|
250
|
+
const config = Object.assign({}, _config, {
|
|
251
|
+
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
252
|
+
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
253
|
+
});
|
|
254
|
+
const { escapeName, escapeParam, codecs, inlineParams, paramStartIndex, invokeSource } = config;
|
|
255
|
+
const mappedChunks = chunks.map((chunk) => {
|
|
256
|
+
if (is(chunk, StringChunk)) return {
|
|
257
|
+
sql: chunk.value.join(""),
|
|
258
|
+
params: []
|
|
259
|
+
};
|
|
260
|
+
if (is(chunk, Name)) return {
|
|
261
|
+
sql: escapeName(chunk.value),
|
|
262
|
+
params: []
|
|
263
|
+
};
|
|
264
|
+
if (chunk === void 0) return {
|
|
265
|
+
sql: "",
|
|
266
|
+
params: []
|
|
267
|
+
};
|
|
268
|
+
if (Array.isArray(chunk)) {
|
|
269
|
+
const result = [new StringChunk("(")];
|
|
270
|
+
for (const [i, p] of chunk.entries()) {
|
|
271
|
+
result.push(p);
|
|
272
|
+
if (i < chunk.length - 1) result.push(new StringChunk(", "));
|
|
273
|
+
}
|
|
274
|
+
result.push(new StringChunk(")"));
|
|
275
|
+
return this.buildQueryFromSourceParams(result, config);
|
|
276
|
+
}
|
|
277
|
+
if (is(chunk, SQL2)) return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
278
|
+
...config,
|
|
279
|
+
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
280
|
+
});
|
|
281
|
+
if (is(chunk, Table)) {
|
|
282
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
283
|
+
const tableName = chunk[Table.Symbol.Name];
|
|
284
|
+
if (invokeSource === "mssql-view-with-schemabinding") return {
|
|
285
|
+
sql: (schemaName === void 0 ? escapeName("dbo") : escapeName(schemaName)) + "." + escapeName(tableName),
|
|
286
|
+
params: []
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
290
|
+
params: []
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (is(chunk, Column)) {
|
|
294
|
+
const columnName = chunk.name;
|
|
295
|
+
if (_config.invokeSource === "indexes") return {
|
|
296
|
+
sql: escapeName(columnName),
|
|
297
|
+
params: []
|
|
298
|
+
};
|
|
299
|
+
const schemaName = invokeSource === "mssql-check" ? void 0 : chunk.table[Table.Symbol.Schema];
|
|
300
|
+
return {
|
|
301
|
+
sql: chunk.isAlias ? escapeName(chunk.name) : chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
|
|
302
|
+
params: []
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
if (is(chunk, View)) {
|
|
306
|
+
const schemaName = chunk[ViewBaseConfig].schema;
|
|
307
|
+
const viewName = chunk[ViewBaseConfig].name;
|
|
308
|
+
return {
|
|
309
|
+
sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
310
|
+
params: []
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
if (is(chunk, Param)) {
|
|
314
|
+
if (is(chunk.value, SQL2)) return this.buildQueryFromSourceParams([chunk.value], config);
|
|
315
|
+
const useCodecs = codecs && is(chunk.encoder, Column);
|
|
316
|
+
if (is(chunk.value, Placeholder)) {
|
|
317
|
+
const escaped2 = escapeParam(paramStartIndex.value++, chunk);
|
|
318
|
+
chunk.codec = useCodecs ? (value) => codecs.apply(chunk.encoder, "normalizeParam", value) : void 0;
|
|
319
|
+
return {
|
|
320
|
+
sql: useCodecs ? codecs.apply(chunk.encoder, "castParam", escaped2) : escaped2,
|
|
321
|
+
params: [chunk]
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
let mappedValue;
|
|
325
|
+
if (chunk.value === null) mappedValue = chunk.value;
|
|
326
|
+
else {
|
|
327
|
+
mappedValue = chunk.encoder.mapToDriverValue.isNoop ? chunk.value : chunk.encoder.mapToDriverValue(chunk.value);
|
|
328
|
+
if (is(mappedValue, SQL2)) return this.buildQueryFromSourceParams([mappedValue], config);
|
|
329
|
+
if (useCodecs) mappedValue = codecs.apply(chunk.encoder, "normalizeParam", mappedValue);
|
|
330
|
+
}
|
|
331
|
+
if (inlineParams) return {
|
|
332
|
+
sql: this.mapInlineParam(mappedValue, config),
|
|
333
|
+
params: []
|
|
334
|
+
};
|
|
335
|
+
const escaped = escapeParam(paramStartIndex.value++, mappedValue);
|
|
336
|
+
return {
|
|
337
|
+
sql: useCodecs ? codecs.apply(chunk.encoder, "castParam", escaped) : escaped,
|
|
338
|
+
params: [mappedValue]
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
if (is(chunk, Placeholder)) return {
|
|
342
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
343
|
+
params: [chunk]
|
|
344
|
+
};
|
|
345
|
+
if (is(chunk, SQL2.Aliased) && chunk.fieldAlias !== void 0) return {
|
|
346
|
+
sql: (chunk.origin !== void 0 ? escapeName(chunk.origin) + "." : "") + escapeName(chunk.fieldAlias),
|
|
347
|
+
params: []
|
|
348
|
+
};
|
|
349
|
+
if (is(chunk, Subquery)) {
|
|
350
|
+
if (chunk._.isWith) return {
|
|
351
|
+
sql: escapeName(chunk._.alias),
|
|
352
|
+
params: []
|
|
353
|
+
};
|
|
354
|
+
return this.buildQueryFromSourceParams([
|
|
355
|
+
new StringChunk("("),
|
|
356
|
+
chunk._.sql,
|
|
357
|
+
new StringChunk(") "),
|
|
358
|
+
new Name(chunk._.alias)
|
|
359
|
+
], config);
|
|
360
|
+
}
|
|
361
|
+
if (typeof chunk === "function" && "enumName" in chunk) {
|
|
362
|
+
if ("schema" in chunk && chunk.schema) return {
|
|
363
|
+
sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName),
|
|
364
|
+
params: []
|
|
365
|
+
};
|
|
366
|
+
return {
|
|
367
|
+
sql: escapeName(chunk.enumName),
|
|
368
|
+
params: []
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
if (isSQLWrapper(chunk)) {
|
|
372
|
+
if (chunk.shouldOmitSQLParens?.()) return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
373
|
+
return this.buildQueryFromSourceParams([
|
|
374
|
+
new StringChunk("("),
|
|
375
|
+
chunk.getSQL(),
|
|
376
|
+
new StringChunk(")")
|
|
377
|
+
], config);
|
|
378
|
+
}
|
|
379
|
+
if (inlineParams) return {
|
|
380
|
+
sql: this.mapInlineParam(chunk, config),
|
|
381
|
+
params: []
|
|
382
|
+
};
|
|
383
|
+
return {
|
|
384
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
385
|
+
params: [chunk]
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
if (_config.tagged) return _mergeQueries(mappedChunks);
|
|
389
|
+
return mergeQueries(mappedChunks);
|
|
390
|
+
}
|
|
391
|
+
mapInlineParam(chunk, { escapeString }) {
|
|
392
|
+
if (chunk === null) return "null";
|
|
393
|
+
if (typeof chunk === "number" || typeof chunk === "boolean" || typeof chunk === "bigint") return chunk.toString();
|
|
394
|
+
if (typeof chunk === "string") return escapeString(chunk);
|
|
395
|
+
if (typeof chunk === "object") {
|
|
396
|
+
const mappedValueAsString = chunk.toString();
|
|
397
|
+
if (mappedValueAsString === "[object Object]") return escapeString(JSON.stringify(chunk));
|
|
398
|
+
return escapeString(mappedValueAsString);
|
|
399
|
+
}
|
|
400
|
+
throw new Error("Unexpected param value: " + chunk);
|
|
401
|
+
}
|
|
402
|
+
getSQL() {
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
as(alias) {
|
|
406
|
+
if (alias === void 0) return this;
|
|
407
|
+
return new SQL2.Aliased(this, alias);
|
|
408
|
+
}
|
|
409
|
+
mapWith(decoder) {
|
|
410
|
+
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
nullable() {
|
|
414
|
+
return this;
|
|
415
|
+
}
|
|
416
|
+
inlineParams() {
|
|
417
|
+
this.shouldInlineParams = true;
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* This method is used to conditionally include a part of the query.
|
|
422
|
+
*
|
|
423
|
+
* @param condition - Condition to check
|
|
424
|
+
* @returns itself if the condition is `true`, otherwise `undefined`
|
|
425
|
+
*/
|
|
426
|
+
if(condition) {
|
|
427
|
+
return condition ? this : void 0;
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
var Name = class {
|
|
431
|
+
static [entityKind] = "Name";
|
|
432
|
+
brand;
|
|
433
|
+
constructor(value) {
|
|
434
|
+
this.value = value;
|
|
435
|
+
}
|
|
436
|
+
getSQL() {
|
|
437
|
+
return new SQL([this]);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
function isDriverValueEncoder(value) {
|
|
441
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
442
|
+
}
|
|
443
|
+
var noopDecoder = { mapFromDriverValue: (value) => value };
|
|
444
|
+
noopDecoder.mapFromDriverValue.isNoop = true;
|
|
445
|
+
var noopEncoder = { mapToDriverValue: (value) => value };
|
|
446
|
+
noopEncoder.mapToDriverValue.isNoop = true;
|
|
447
|
+
var noopMapper = {
|
|
448
|
+
...noopDecoder,
|
|
449
|
+
...noopEncoder
|
|
450
|
+
};
|
|
451
|
+
var Param = class {
|
|
452
|
+
static [entityKind] = "Param";
|
|
453
|
+
brand;
|
|
454
|
+
/**
|
|
455
|
+
* @param value - Parameter value
|
|
456
|
+
* @param encoder - Encoder to convert the value to a driver parameter
|
|
457
|
+
*/
|
|
458
|
+
constructor(value, encoder = noopEncoder, codec) {
|
|
459
|
+
this.value = value;
|
|
460
|
+
this.encoder = encoder;
|
|
461
|
+
this.codec = codec;
|
|
462
|
+
}
|
|
463
|
+
getSQL() {
|
|
464
|
+
return new SQL([this]);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
function sql(strings, ...params) {
|
|
468
|
+
const queryChunks = [];
|
|
469
|
+
if (params.length > 0 || strings.length > 0 && strings[0] !== "") queryChunks.push(new StringChunk(strings[0]));
|
|
470
|
+
for (const [paramIndex, param2] of params.entries()) queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
471
|
+
return new SQL(queryChunks);
|
|
472
|
+
}
|
|
473
|
+
(function(_sql) {
|
|
474
|
+
function empty() {
|
|
475
|
+
return new SQL([]);
|
|
476
|
+
}
|
|
477
|
+
_sql.empty = empty;
|
|
478
|
+
function fromList(list) {
|
|
479
|
+
return new SQL(list);
|
|
480
|
+
}
|
|
481
|
+
_sql.fromList = fromList;
|
|
482
|
+
function raw(str) {
|
|
483
|
+
return new SQL([new StringChunk(str)]);
|
|
484
|
+
}
|
|
485
|
+
_sql.raw = raw;
|
|
486
|
+
function join(chunks, separator) {
|
|
487
|
+
const result = [];
|
|
488
|
+
for (const [i, chunk] of chunks.entries()) {
|
|
489
|
+
if (i > 0 && separator !== void 0) result.push(separator);
|
|
490
|
+
result.push(chunk);
|
|
491
|
+
}
|
|
492
|
+
return new SQL(result);
|
|
493
|
+
}
|
|
494
|
+
_sql.join = join;
|
|
495
|
+
function identifier(value) {
|
|
496
|
+
return new Name(value);
|
|
497
|
+
}
|
|
498
|
+
_sql.identifier = identifier;
|
|
499
|
+
function placeholder2(name2) {
|
|
500
|
+
return new Placeholder(name2);
|
|
501
|
+
}
|
|
502
|
+
_sql.placeholder = placeholder2;
|
|
503
|
+
function param2(value, encoder) {
|
|
504
|
+
return new Param(value, encoder);
|
|
505
|
+
}
|
|
506
|
+
_sql.param = param2;
|
|
507
|
+
function comment(input) {
|
|
508
|
+
const encoded = sqlCommenter(input);
|
|
509
|
+
if (!encoded.length) return void 0;
|
|
510
|
+
return sql.raw(encoded);
|
|
511
|
+
}
|
|
512
|
+
_sql.comment = comment;
|
|
513
|
+
})(sql || (sql = {}));
|
|
514
|
+
function sqlCommenter(input) {
|
|
515
|
+
const encoded = sqlCommenter.encodeInput(input);
|
|
516
|
+
if (!encoded.length) return "";
|
|
517
|
+
return `/*${encoded}*/`;
|
|
518
|
+
}
|
|
519
|
+
(function(_sqlCommenter) {
|
|
520
|
+
function merge(input1, input2) {
|
|
521
|
+
let encoded;
|
|
522
|
+
if (typeof input1 === "object" && typeof input2 === "object") encoded = encodeInput({
|
|
523
|
+
...input1,
|
|
524
|
+
...input2
|
|
525
|
+
});
|
|
526
|
+
else if (input1 && input2) encoded = [encodeInput(input1), encodeInput(input2)].filter((i) => i.length).join(",");
|
|
527
|
+
else if (input2) encoded = encodeInput(input2);
|
|
528
|
+
else if (input1) encoded = encodeInput(input1);
|
|
529
|
+
else return "";
|
|
530
|
+
if (!encoded.length) return "";
|
|
531
|
+
return `/*${encoded}*/`;
|
|
532
|
+
}
|
|
533
|
+
_sqlCommenter.merge = merge;
|
|
534
|
+
function encodeInput(input) {
|
|
535
|
+
if (typeof input === "string") {
|
|
536
|
+
if (!input.length) return input;
|
|
537
|
+
return sanitizeStringInput(input);
|
|
538
|
+
}
|
|
539
|
+
const parts = [];
|
|
540
|
+
for (const [key, value] of Object.entries(input)) {
|
|
541
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
542
|
+
const encodedKey = sanitizeObjectElement(key);
|
|
543
|
+
const encodedValue = sanitizeObjectElement(String(value));
|
|
544
|
+
parts.push(`${encodedKey}='${encodedValue}'`);
|
|
545
|
+
}
|
|
546
|
+
if (!parts.length) return "";
|
|
547
|
+
return parts.sort().join(",");
|
|
548
|
+
}
|
|
549
|
+
_sqlCommenter.encodeInput = encodeInput;
|
|
550
|
+
function sanitizeObjectElement(key) {
|
|
551
|
+
return encodeURIComponent(key).replace(/'/g, `\\'`);
|
|
552
|
+
}
|
|
553
|
+
_sqlCommenter.sanitizeObjectElement = sanitizeObjectElement;
|
|
554
|
+
function sanitizeStringInput(input) {
|
|
555
|
+
return input.replace(/\/\*/g, "/ *").replace(/\*\//g, "* /");
|
|
556
|
+
}
|
|
557
|
+
_sqlCommenter.sanitizeStringInput = sanitizeStringInput;
|
|
558
|
+
})(sqlCommenter || (sqlCommenter = {}));
|
|
559
|
+
(function(_SQL) {
|
|
560
|
+
class Aliased {
|
|
561
|
+
static [entityKind] = "SQL.Aliased";
|
|
562
|
+
/** @internal */
|
|
563
|
+
isSelectionField = false;
|
|
564
|
+
/** @internal */
|
|
565
|
+
origin;
|
|
566
|
+
constructor(sql2, fieldAlias) {
|
|
567
|
+
this.sql = sql2;
|
|
568
|
+
this.fieldAlias = fieldAlias;
|
|
569
|
+
}
|
|
570
|
+
getSQL() {
|
|
571
|
+
return this.sql;
|
|
572
|
+
}
|
|
573
|
+
/** @internal */
|
|
574
|
+
clone() {
|
|
575
|
+
return new Aliased(this.sql, this.fieldAlias);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
_SQL.Aliased = Aliased;
|
|
579
|
+
})(SQL || (SQL = {}));
|
|
580
|
+
var Placeholder = class {
|
|
581
|
+
static [entityKind] = "Placeholder";
|
|
582
|
+
constructor(name2) {
|
|
583
|
+
this.name = name2;
|
|
584
|
+
}
|
|
585
|
+
getSQL() {
|
|
586
|
+
return new SQL([this]);
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
function fillPlaceholders(params, values) {
|
|
590
|
+
return params.map((p) => {
|
|
591
|
+
if (is(p, Placeholder)) {
|
|
592
|
+
if (!(p.name in values)) throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
593
|
+
return values[p.name];
|
|
594
|
+
}
|
|
595
|
+
if (is(p, Param) && is(p.value, Placeholder)) {
|
|
596
|
+
if (!(p.value.name in values)) throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
|
597
|
+
const value = values[p.value.name];
|
|
598
|
+
if (value === null) return value;
|
|
599
|
+
const mapped = p.encoder.mapToDriverValue.isNoop ? value : p.encoder.mapToDriverValue(value);
|
|
600
|
+
return p.codec ? p.codec(mapped) : mapped;
|
|
601
|
+
}
|
|
602
|
+
return p;
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
var IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
|
|
606
|
+
var View = class {
|
|
607
|
+
static [entityKind] = "View";
|
|
608
|
+
/** @internal */
|
|
609
|
+
[ViewBaseConfig];
|
|
610
|
+
/** @internal */
|
|
611
|
+
[IsDrizzleView] = true;
|
|
612
|
+
/** @internal */
|
|
613
|
+
get [TableName]() {
|
|
614
|
+
return this[ViewBaseConfig].name;
|
|
615
|
+
}
|
|
616
|
+
/** @internal */
|
|
617
|
+
get [TableSchema]() {
|
|
618
|
+
return this[ViewBaseConfig].schema;
|
|
619
|
+
}
|
|
620
|
+
/** @internal */
|
|
621
|
+
get [IsAlias]() {
|
|
622
|
+
return this[ViewBaseConfig].isAlias;
|
|
623
|
+
}
|
|
624
|
+
/** @internal */
|
|
625
|
+
get [OriginalName]() {
|
|
626
|
+
return this[ViewBaseConfig].originalName;
|
|
627
|
+
}
|
|
628
|
+
/** @internal */
|
|
629
|
+
get [TableColumns]() {
|
|
630
|
+
return this[ViewBaseConfig].selectedFields;
|
|
631
|
+
}
|
|
632
|
+
constructor({ name: name2, schema, selectedFields, query }) {
|
|
633
|
+
this[ViewBaseConfig] = {
|
|
634
|
+
name: name2,
|
|
635
|
+
originalName: name2,
|
|
636
|
+
schema,
|
|
637
|
+
selectedFields,
|
|
638
|
+
query,
|
|
639
|
+
isExisting: !query,
|
|
640
|
+
isAlias: false
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
Column.prototype.getSQL = function() {
|
|
645
|
+
return new SQL([this]);
|
|
646
|
+
};
|
|
647
|
+
Subquery.prototype.getSQL = function() {
|
|
648
|
+
return new SQL([this]);
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
652
|
+
function bindIfParam(value, column) {
|
|
653
|
+
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) return new Param(value, column);
|
|
654
|
+
return value;
|
|
655
|
+
}
|
|
656
|
+
var eq = (left, right) => {
|
|
657
|
+
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
658
|
+
};
|
|
659
|
+
var ne = (left, right) => {
|
|
660
|
+
return sql`${left} <> ${bindIfParam(right, left)}`;
|
|
661
|
+
};
|
|
662
|
+
function and(...unfilteredConditions) {
|
|
663
|
+
const conditions = unfilteredConditions.filter((c) => c !== void 0);
|
|
664
|
+
if (conditions.length === 0) return;
|
|
665
|
+
if (conditions.length === 1) return new SQL(conditions);
|
|
666
|
+
return new SQL([
|
|
667
|
+
new StringChunk("("),
|
|
668
|
+
sql.join(conditions.map((c) => sql`(${c})`), new StringChunk(" and ")),
|
|
669
|
+
new StringChunk(")")
|
|
670
|
+
]);
|
|
671
|
+
}
|
|
672
|
+
function or(...unfilteredConditions) {
|
|
673
|
+
const conditions = unfilteredConditions.filter((c) => c !== void 0);
|
|
674
|
+
if (conditions.length === 0) return;
|
|
675
|
+
if (conditions.length === 1) return new SQL(conditions);
|
|
676
|
+
return new SQL([
|
|
677
|
+
new StringChunk("("),
|
|
678
|
+
sql.join(conditions.map((c) => sql`(${c})`), new StringChunk(" or ")),
|
|
679
|
+
new StringChunk(")")
|
|
680
|
+
]);
|
|
681
|
+
}
|
|
682
|
+
function not(condition) {
|
|
683
|
+
return is(condition, SQL) ? sql`not (${condition})` : sql`not ${condition}`;
|
|
684
|
+
}
|
|
685
|
+
var gt = (left, right) => {
|
|
686
|
+
return sql`${left} > ${bindIfParam(right, left)}`;
|
|
687
|
+
};
|
|
688
|
+
var gte = (left, right) => {
|
|
689
|
+
return sql`${left} >= ${bindIfParam(right, left)}`;
|
|
690
|
+
};
|
|
691
|
+
var lt = (left, right) => {
|
|
692
|
+
return sql`${left} < ${bindIfParam(right, left)}`;
|
|
693
|
+
};
|
|
694
|
+
var lte = (left, right) => {
|
|
695
|
+
return sql`${left} <= ${bindIfParam(right, left)}`;
|
|
696
|
+
};
|
|
697
|
+
function inArray(column, values) {
|
|
698
|
+
if (Array.isArray(values)) {
|
|
699
|
+
if (values.length === 0) return sql`false`;
|
|
700
|
+
return sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
|
|
701
|
+
}
|
|
702
|
+
return sql`${column} in ${bindIfParam(values, column)}`;
|
|
703
|
+
}
|
|
704
|
+
function notInArray(column, values) {
|
|
705
|
+
if (Array.isArray(values)) {
|
|
706
|
+
if (values.length === 0) return sql`true`;
|
|
707
|
+
return sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
|
|
708
|
+
}
|
|
709
|
+
return sql`${column} not in ${bindIfParam(values, column)}`;
|
|
710
|
+
}
|
|
711
|
+
function isNull(value) {
|
|
712
|
+
return sql`(${value} is null)`;
|
|
713
|
+
}
|
|
714
|
+
function isNotNull(value) {
|
|
715
|
+
return sql`(${value} is not null)`;
|
|
716
|
+
}
|
|
717
|
+
function exists(subquery) {
|
|
718
|
+
return sql`exists ${subquery}`;
|
|
719
|
+
}
|
|
720
|
+
function notExists(subquery) {
|
|
721
|
+
return sql`not exists ${subquery}`;
|
|
722
|
+
}
|
|
723
|
+
function between(column, min, max) {
|
|
724
|
+
return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
725
|
+
}
|
|
726
|
+
function notBetween(column, min, max) {
|
|
727
|
+
return sql`${column} not between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
728
|
+
}
|
|
729
|
+
function like(column, value) {
|
|
730
|
+
return sql`${column} like ${value}`;
|
|
731
|
+
}
|
|
732
|
+
function notLike(column, value) {
|
|
733
|
+
return sql`${column} not like ${value}`;
|
|
734
|
+
}
|
|
735
|
+
function ilike(column, value) {
|
|
736
|
+
return sql`${column} ilike ${value}`;
|
|
737
|
+
}
|
|
738
|
+
function notIlike(column, value) {
|
|
739
|
+
return sql`${column} not ilike ${value}`;
|
|
740
|
+
}
|
|
741
|
+
function arrayContains(column, values) {
|
|
742
|
+
if (Array.isArray(values)) {
|
|
743
|
+
if (values.length === 0) throw new Error("arrayContains requires at least one value");
|
|
744
|
+
const par = bindIfParam(values, column);
|
|
745
|
+
return sql`${column} @> ${sql`${Array.isArray(par) ? new Param(par) : par}`}`;
|
|
746
|
+
}
|
|
747
|
+
return sql`${column} @> ${bindIfParam(values, column)}`;
|
|
748
|
+
}
|
|
749
|
+
function arrayContained(column, values) {
|
|
750
|
+
if (Array.isArray(values)) {
|
|
751
|
+
if (values.length === 0) throw new Error("arrayContained requires at least one value");
|
|
752
|
+
const par = bindIfParam(values, column);
|
|
753
|
+
return sql`${column} <@ ${sql`${Array.isArray(par) ? new Param(par) : par}`}`;
|
|
754
|
+
}
|
|
755
|
+
return sql`${column} <@ ${bindIfParam(values, column)}`;
|
|
756
|
+
}
|
|
757
|
+
function arrayOverlaps(column, values) {
|
|
758
|
+
if (Array.isArray(values)) {
|
|
759
|
+
if (values.length === 0) throw new Error("arrayOverlaps requires at least one value");
|
|
760
|
+
const par = bindIfParam(values, column);
|
|
761
|
+
return sql`${column} && ${sql`${Array.isArray(par) ? new Param(par) : par}`}`;
|
|
762
|
+
}
|
|
763
|
+
return sql`${column} && ${bindIfParam(values, column)}`;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sql/expressions/select.js
|
|
767
|
+
function asc(column) {
|
|
768
|
+
return sql`${column} asc`;
|
|
769
|
+
}
|
|
770
|
+
function desc(column) {
|
|
771
|
+
return sql`${column} desc`;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/column-builder.js
|
|
775
|
+
var ColumnBuilder = class {
|
|
776
|
+
static [entityKind] = "ColumnBuilder";
|
|
777
|
+
/** @internal */
|
|
778
|
+
config;
|
|
779
|
+
constructor(name2, dataType, columnType) {
|
|
780
|
+
this.config = {
|
|
781
|
+
name: name2,
|
|
782
|
+
keyAsName: name2 === "",
|
|
783
|
+
notNull: false,
|
|
784
|
+
default: void 0,
|
|
785
|
+
hasDefault: false,
|
|
786
|
+
primaryKey: false,
|
|
787
|
+
isUnique: false,
|
|
788
|
+
uniqueName: void 0,
|
|
789
|
+
uniqueType: void 0,
|
|
790
|
+
dataType,
|
|
791
|
+
columnType,
|
|
792
|
+
generated: void 0
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
|
|
797
|
+
*
|
|
798
|
+
* @example
|
|
799
|
+
* ```ts
|
|
800
|
+
* const users = pgTable('users', {
|
|
801
|
+
* id: integer('id').$type<UserId>().primaryKey(),
|
|
802
|
+
* details: json('details').$type<UserDetails>().notNull(),
|
|
803
|
+
* });
|
|
804
|
+
* ```
|
|
805
|
+
*/
|
|
806
|
+
$type() {
|
|
807
|
+
return this;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Adds a `not null` clause to the column definition.
|
|
811
|
+
*
|
|
812
|
+
* Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
|
|
813
|
+
*/
|
|
814
|
+
notNull() {
|
|
815
|
+
this.config.notNull = true;
|
|
816
|
+
return this;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Adds a `default <value>` clause to the column definition.
|
|
820
|
+
*
|
|
821
|
+
* Affects the `insert` model of the table - columns *with* `default` are optional on insert.
|
|
822
|
+
*
|
|
823
|
+
* If you need to set a dynamic default value, use {@link $defaultFn} instead.
|
|
824
|
+
*/
|
|
825
|
+
default(value) {
|
|
826
|
+
this.config.default = value;
|
|
827
|
+
this.config.hasDefault = true;
|
|
828
|
+
return this;
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Adds a dynamic default value to the column.
|
|
832
|
+
* The function will be called when the row is inserted, and the returned value will be used as the column value.
|
|
833
|
+
*
|
|
834
|
+
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
835
|
+
*/
|
|
836
|
+
$defaultFn(fn) {
|
|
837
|
+
this.config.defaultFn = fn;
|
|
838
|
+
this.config.hasDefault = true;
|
|
839
|
+
return this;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Alias for {@link $defaultFn}.
|
|
843
|
+
*/
|
|
844
|
+
$default = this.$defaultFn;
|
|
845
|
+
/**
|
|
846
|
+
* Adds a dynamic update value to the column.
|
|
847
|
+
* The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
|
|
848
|
+
* If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
|
|
849
|
+
*
|
|
850
|
+
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
851
|
+
*/
|
|
852
|
+
$onUpdateFn(fn) {
|
|
853
|
+
this.config.onUpdateFn = fn;
|
|
854
|
+
this.config.hasDefault = true;
|
|
855
|
+
return this;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Alias for {@link $onUpdateFn}.
|
|
859
|
+
*/
|
|
860
|
+
$onUpdate = this.$onUpdateFn;
|
|
861
|
+
/**
|
|
862
|
+
* Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
|
|
863
|
+
*
|
|
864
|
+
* In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
|
|
865
|
+
*/
|
|
866
|
+
primaryKey() {
|
|
867
|
+
this.config.primaryKey = true;
|
|
868
|
+
this.config.notNull = true;
|
|
869
|
+
return this;
|
|
870
|
+
}
|
|
871
|
+
/** @internal Sets the name of the column to the key within the table definition if a name was not given. */
|
|
872
|
+
setName(name2, casingFn) {
|
|
873
|
+
if (this.config.name !== "") return;
|
|
874
|
+
this.config.name = casingFn(name2);
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
|
|
879
|
+
var ForeignKeyBuilder = class {
|
|
880
|
+
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
881
|
+
/** @internal */
|
|
882
|
+
reference;
|
|
883
|
+
/** @internal */
|
|
884
|
+
_onUpdate;
|
|
885
|
+
/** @internal */
|
|
886
|
+
_onDelete;
|
|
887
|
+
constructor(config, actions) {
|
|
888
|
+
this.reference = () => {
|
|
889
|
+
const { name: name2, columns, foreignColumns } = config();
|
|
890
|
+
return {
|
|
891
|
+
name: name2,
|
|
892
|
+
columns,
|
|
893
|
+
foreignTable: foreignColumns[0].table,
|
|
894
|
+
foreignColumns
|
|
895
|
+
};
|
|
896
|
+
};
|
|
897
|
+
if (actions) {
|
|
898
|
+
this._onUpdate = actions.onUpdate;
|
|
899
|
+
this._onDelete = actions.onDelete;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
onUpdate(action) {
|
|
903
|
+
this._onUpdate = action;
|
|
904
|
+
return this;
|
|
905
|
+
}
|
|
906
|
+
onDelete(action) {
|
|
907
|
+
this._onDelete = action;
|
|
908
|
+
return this;
|
|
909
|
+
}
|
|
910
|
+
/** @internal */
|
|
911
|
+
build(table) {
|
|
912
|
+
return new ForeignKey(table, this);
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
var ForeignKey = class {
|
|
916
|
+
static [entityKind] = "SQLiteForeignKey";
|
|
917
|
+
reference;
|
|
918
|
+
onUpdate;
|
|
919
|
+
onDelete;
|
|
920
|
+
constructor(table, builder) {
|
|
921
|
+
this.table = table;
|
|
922
|
+
this.reference = builder.reference;
|
|
923
|
+
this.onUpdate = builder._onUpdate;
|
|
924
|
+
this.onDelete = builder._onDelete;
|
|
925
|
+
}
|
|
926
|
+
getName() {
|
|
927
|
+
const { name: name2, columns, foreignColumns } = this.reference();
|
|
928
|
+
const columnNames = columns.map((column) => column.name);
|
|
929
|
+
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
930
|
+
const chunks = [
|
|
931
|
+
this.table[TableName],
|
|
932
|
+
...columnNames,
|
|
933
|
+
foreignColumns[0].table[TableName],
|
|
934
|
+
...foreignColumnNames
|
|
935
|
+
];
|
|
936
|
+
return name2 ?? `${chunks.join("_")}_fk`;
|
|
937
|
+
}
|
|
938
|
+
isNameExplicit() {
|
|
939
|
+
return !!this.reference().name;
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/common.js
|
|
944
|
+
var SQLiteColumnBuilder = class extends ColumnBuilder {
|
|
945
|
+
static [entityKind] = "SQLiteColumnBuilder";
|
|
946
|
+
foreignKeyConfigs = [];
|
|
947
|
+
references(ref, actions = {}) {
|
|
948
|
+
this.foreignKeyConfigs.push({
|
|
949
|
+
ref,
|
|
950
|
+
actions
|
|
951
|
+
});
|
|
952
|
+
return this;
|
|
953
|
+
}
|
|
954
|
+
unique(name2) {
|
|
955
|
+
this.config.isUnique = true;
|
|
956
|
+
this.config.uniqueName = name2;
|
|
957
|
+
return this;
|
|
958
|
+
}
|
|
959
|
+
generatedAlwaysAs(as, config) {
|
|
960
|
+
this.config.generated = {
|
|
961
|
+
as,
|
|
962
|
+
type: "always",
|
|
963
|
+
mode: config?.mode ?? "virtual"
|
|
964
|
+
};
|
|
965
|
+
return this;
|
|
966
|
+
}
|
|
967
|
+
/** @internal */
|
|
968
|
+
buildForeignKeys(column, table) {
|
|
969
|
+
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
970
|
+
return ((ref2, actions2) => {
|
|
971
|
+
const builder = new ForeignKeyBuilder(() => {
|
|
972
|
+
const foreignColumn = ref2();
|
|
973
|
+
return {
|
|
974
|
+
columns: [column],
|
|
975
|
+
foreignColumns: [foreignColumn]
|
|
976
|
+
};
|
|
977
|
+
});
|
|
978
|
+
if (actions2.onUpdate) builder.onUpdate(actions2.onUpdate);
|
|
979
|
+
if (actions2.onDelete) builder.onDelete(actions2.onDelete);
|
|
980
|
+
return builder.build(table);
|
|
981
|
+
})(ref, actions);
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
var SQLiteColumn = class extends Column {
|
|
986
|
+
static [entityKind] = "SQLiteColumn";
|
|
987
|
+
/** @internal */
|
|
988
|
+
table;
|
|
989
|
+
constructor(table, config) {
|
|
990
|
+
super(table, config);
|
|
991
|
+
this.table = table;
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/utils.js
|
|
996
|
+
var FnConstructor = Object.getPrototypeOf(() => null).constructor;
|
|
997
|
+
function makeJitQueryMapperInner(columns, joinsNotNullableMap = {}) {
|
|
998
|
+
const preFn = [];
|
|
999
|
+
const fn = [];
|
|
1000
|
+
fn.push(`const [ ${columns.map((_, i) => `c${i}`).join(", ")} ] = rows[i];`);
|
|
1001
|
+
const nullifyMap = {};
|
|
1002
|
+
const objectIds = {};
|
|
1003
|
+
const decodes = Array.from({ length: columns.length });
|
|
1004
|
+
for (let idx = 0; idx < columns.length; ++idx) {
|
|
1005
|
+
const { field, path, codec, arrayDimensions } = columns[idx];
|
|
1006
|
+
let decoder;
|
|
1007
|
+
let decoderStr;
|
|
1008
|
+
let decoderFieldDestructure;
|
|
1009
|
+
let isColumn = false;
|
|
1010
|
+
if (is(field, Column)) {
|
|
1011
|
+
isColumn = true;
|
|
1012
|
+
decoder = field;
|
|
1013
|
+
decoderFieldDestructure = `field: decoder${idx}`;
|
|
1014
|
+
} else if (is(field, SQL)) {
|
|
1015
|
+
decoder = field.decoder;
|
|
1016
|
+
decoderFieldDestructure = `field: { decoder: decoder${idx} }`;
|
|
1017
|
+
} else if (is(field, Subquery)) {
|
|
1018
|
+
decoder = field._.sql.decoder;
|
|
1019
|
+
decoderFieldDestructure = `field: { _: { sql: { decoder: decoder${idx} } } }`;
|
|
1020
|
+
} else {
|
|
1021
|
+
decoder = field.sql.decoder;
|
|
1022
|
+
decoderFieldDestructure = `field: { sql: { decoder: decoder${idx} } }`;
|
|
1023
|
+
}
|
|
1024
|
+
decoderStr = `decoder${idx}.mapFromDriverValue`;
|
|
1025
|
+
if (decoder.mapFromDriverValue.isNoop) decoderStr = "";
|
|
1026
|
+
if (decoderStr) preFn.push(`const { ${decoderFieldDestructure}${codec ? `, codec: codec${idx}` : ""} } = columns[${idx}];`);
|
|
1027
|
+
else if (codec) preFn.push(`const { codec: codec${idx} } = columns[${idx}];`);
|
|
1028
|
+
const colStr = `c${idx}`;
|
|
1029
|
+
let decodedValue = colStr;
|
|
1030
|
+
if (codec) decodedValue = `codec${idx}(${decodedValue}, ${arrayDimensions})`;
|
|
1031
|
+
if (decoderStr) decodedValue = `${decoderStr}(${decodedValue})`;
|
|
1032
|
+
decodes[idx] = colStr === decodedValue ? `${colStr}` : `${colStr} === null ? ${colStr} : ${decodedValue}`;
|
|
1033
|
+
if (path.length !== 2 || !isColumn) continue;
|
|
1034
|
+
if (objectIds[path[0]] === void 0) objectIds[path[0]] = [`c${idx}`];
|
|
1035
|
+
else objectIds[path[0]]?.push(`c${idx}`);
|
|
1036
|
+
const [objectName] = path;
|
|
1037
|
+
const tableName = getTableName(field.table);
|
|
1038
|
+
nullifyMap[objectName] = joinsNotNullableMap[tableName] ? false : typeof nullifyMap[objectName] === "string" ? nullifyMap[objectName] === tableName ? tableName : false : tableName;
|
|
1039
|
+
}
|
|
1040
|
+
fn.push(`mapped[i] = {`);
|
|
1041
|
+
let currentObjectPath = [];
|
|
1042
|
+
for (let idx = 0; idx < columns.length; ++idx) {
|
|
1043
|
+
const { path } = columns[idx];
|
|
1044
|
+
const jsonPath = path.map((e) => JSON.stringify(e));
|
|
1045
|
+
const decodedValue = decodes[idx];
|
|
1046
|
+
const objectPath = path.slice(0, -1);
|
|
1047
|
+
let commonLen = 0;
|
|
1048
|
+
while (commonLen < currentObjectPath.length && commonLen < objectPath.length && currentObjectPath[commonLen] === objectPath[commonLen]) commonLen++;
|
|
1049
|
+
for (let d = currentObjectPath.length - 1; d >= commonLen; --d) fn.push(`${" ".repeat(d + 1)}},`);
|
|
1050
|
+
for (let d = commonLen; d < objectPath.length; ++d) fn.push(`${" ".repeat(d + 1)}${jsonPath[d]}: ${d === 0 && objectPath.length === 1 && typeof nullifyMap[path[0]] === "string" ? `${objectIds[path[0]]?.map((c) => `${c} === null`).join(" && ")} ? null : {` : "{"}`);
|
|
1051
|
+
currentObjectPath = objectPath;
|
|
1052
|
+
fn.push(`${" ".repeat(path.length)}${jsonPath[path.length - 1]}: ${decodedValue},`);
|
|
1053
|
+
}
|
|
1054
|
+
for (let d = currentObjectPath.length - 1; d >= 0; --d) fn.push(`${" ".repeat(d + 1)}},`);
|
|
1055
|
+
fn.push(`};`);
|
|
1056
|
+
return `${preFn.length ? `${preFn.join("\n ")}
|
|
1057
|
+
` : ""}for (let i = 0; i < length; ++i) {
|
|
1058
|
+
${fn.join("\n ")}
|
|
1059
|
+
}`;
|
|
1060
|
+
}
|
|
1061
|
+
function makeJitQueryMapper(columns, joinsNotNullableMap) {
|
|
1062
|
+
const internals = ` "use strict";
|
|
1063
|
+
const { columns } = this;
|
|
1064
|
+
const { length } = rows;
|
|
1065
|
+
const mapped = Array.from({ length });
|
|
1066
|
+
${makeJitQueryMapperInner(columns, joinsNotNullableMap)}
|
|
1067
|
+
return mapped;
|
|
1068
|
+
//# sourceURL=drizzle:jit-query-mapper`;
|
|
1069
|
+
return Object.assign(new FnConstructor("rows", internals).bind({ columns }), { body: `function jitQueryMapper (rows) {
|
|
1070
|
+
${internals}
|
|
1071
|
+
}` });
|
|
1072
|
+
}
|
|
1073
|
+
function jitCompatCheck(isEnabled) {
|
|
1074
|
+
if (!isEnabled) return false;
|
|
1075
|
+
try {
|
|
1076
|
+
const res = new FnConstructor("input", '"use strict"; return input;')(true);
|
|
1077
|
+
if (res !== true) {
|
|
1078
|
+
console.warn("Unable to use jit mappers due to incompatibility: corrupted jit function output.\nFalling back to premade mappers.\nError details:");
|
|
1079
|
+
console.error(`Expected to receive \`true\`, got: ${res}`);
|
|
1080
|
+
}
|
|
1081
|
+
return true;
|
|
1082
|
+
} catch (e) {
|
|
1083
|
+
console.warn("Unable to use jit mappers due to incompatibility.\nFalling back to premade mappers.\nError details:");
|
|
1084
|
+
console.error(e);
|
|
1085
|
+
return false;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
function makeDefaultQueryMapper(columns, joinsNotNullableMap) {
|
|
1089
|
+
const interpretedData = columns.map(({ field, codec, arrayDimensions, path }) => {
|
|
1090
|
+
let processNullifyMap;
|
|
1091
|
+
let decoderSrc;
|
|
1092
|
+
if (is(field, Column)) {
|
|
1093
|
+
decoderSrc = field;
|
|
1094
|
+
if (joinsNotNullableMap && path.length === 2) {
|
|
1095
|
+
const objectName = path[0];
|
|
1096
|
+
processNullifyMap = (nullifyMap, value) => {
|
|
1097
|
+
if (!(objectName in nullifyMap)) nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
1098
|
+
else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) nullifyMap[objectName] = false;
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
} else if (is(field, SQL)) decoderSrc = field.decoder;
|
|
1102
|
+
else if (is(field, Subquery)) decoderSrc = field._.sql.decoder;
|
|
1103
|
+
else decoderSrc = field.sql.decoder;
|
|
1104
|
+
let decoder;
|
|
1105
|
+
if (decoderSrc.mapFromDriverValue.isNoop) decoder = codec ? (v) => codec(v, arrayDimensions) : void 0;
|
|
1106
|
+
else decoder = codec ? (v) => decoderSrc.mapFromDriverValue(codec(v, arrayDimensions)) : (v) => decoderSrc.mapFromDriverValue(v);
|
|
1107
|
+
return [decoder, processNullifyMap];
|
|
1108
|
+
});
|
|
1109
|
+
return ((rows) => rows.map((row) => {
|
|
1110
|
+
const nullifyMap = {};
|
|
1111
|
+
const result = columns.reduce((result2, { path }, columnIndex) => {
|
|
1112
|
+
let node = result2;
|
|
1113
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) if (pathChunkIndex < path.length - 1) {
|
|
1114
|
+
if (!(pathChunk in node)) node[pathChunk] = {};
|
|
1115
|
+
node = node[pathChunk];
|
|
1116
|
+
} else {
|
|
1117
|
+
const [decoder, processNullifyMap] = interpretedData[columnIndex];
|
|
1118
|
+
const rawValue = row[columnIndex];
|
|
1119
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder ? decoder(rawValue) : rawValue;
|
|
1120
|
+
processNullifyMap?.(nullifyMap, value);
|
|
1121
|
+
}
|
|
1122
|
+
return result2;
|
|
1123
|
+
}, {});
|
|
1124
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
1125
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) result[objectName] = null;
|
|
1126
|
+
}
|
|
1127
|
+
return result;
|
|
1128
|
+
}));
|
|
1129
|
+
}
|
|
1130
|
+
function orderSelectedFields(fields, pathPrefix, codecs) {
|
|
1131
|
+
return Object.entries(fields).reduce((result, [name2, field]) => {
|
|
1132
|
+
if (typeof name2 !== "string") return result;
|
|
1133
|
+
const newPath = pathPrefix ? [...pathPrefix, name2] : [name2];
|
|
1134
|
+
if (is(field, Column)) result.push({
|
|
1135
|
+
path: newPath,
|
|
1136
|
+
field,
|
|
1137
|
+
codec: codecs?.get(field, "normalize"),
|
|
1138
|
+
arrayDimensions: field.dimensions,
|
|
1139
|
+
column: field
|
|
1140
|
+
});
|
|
1141
|
+
else if (is(field, SQL) || is(field, SQL.Aliased)) {
|
|
1142
|
+
const col = getColumnFromDecoder(field);
|
|
1143
|
+
result.push(col ? {
|
|
1144
|
+
path: newPath,
|
|
1145
|
+
field,
|
|
1146
|
+
codec: codecs?.get(col, "normalize"),
|
|
1147
|
+
arrayDimensions: col.dimensions,
|
|
1148
|
+
column: col
|
|
1149
|
+
} : {
|
|
1150
|
+
path: newPath,
|
|
1151
|
+
field
|
|
1152
|
+
});
|
|
1153
|
+
} else if (is(field, Subquery)) {
|
|
1154
|
+
let column;
|
|
1155
|
+
const entry = Object.values(field._.selectedFields)[0];
|
|
1156
|
+
let fieldDecoder;
|
|
1157
|
+
if (is(entry, Column)) {
|
|
1158
|
+
column = entry;
|
|
1159
|
+
fieldDecoder = entry;
|
|
1160
|
+
} else if (is(entry, SQL)) {
|
|
1161
|
+
column = getColumnFromDecoder(entry);
|
|
1162
|
+
fieldDecoder = entry.decoder;
|
|
1163
|
+
} else {
|
|
1164
|
+
column = getColumnFromDecoder(entry);
|
|
1165
|
+
fieldDecoder = entry.sql.decoder;
|
|
1166
|
+
}
|
|
1167
|
+
if (fieldDecoder) field._.sql.decoder = fieldDecoder;
|
|
1168
|
+
result.push(column ? {
|
|
1169
|
+
path: newPath,
|
|
1170
|
+
field,
|
|
1171
|
+
codec: codecs?.get(column, "normalize"),
|
|
1172
|
+
arrayDimensions: column.dimensions,
|
|
1173
|
+
column
|
|
1174
|
+
} : {
|
|
1175
|
+
path: newPath,
|
|
1176
|
+
field
|
|
1177
|
+
});
|
|
1178
|
+
} else if (is(field, Table)) result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath, codecs));
|
|
1179
|
+
else result.push(...orderSelectedFields(field, newPath, codecs));
|
|
1180
|
+
return result;
|
|
1181
|
+
}, []);
|
|
1182
|
+
}
|
|
1183
|
+
function getColumnFromDecoder(source) {
|
|
1184
|
+
const query = source.getSQL();
|
|
1185
|
+
if (is(query.decoder, Column)) return query.decoder;
|
|
1186
|
+
}
|
|
1187
|
+
function haveSameKeys(left, right) {
|
|
1188
|
+
const leftKeys = Object.keys(left);
|
|
1189
|
+
const rightKeys = Object.keys(right);
|
|
1190
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
1191
|
+
for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
|
|
1192
|
+
return true;
|
|
1193
|
+
}
|
|
1194
|
+
function mapUpdateSet(table, values) {
|
|
1195
|
+
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
|
1196
|
+
if (is(value, SQL) || is(value, Column)) return [key, value];
|
|
1197
|
+
else return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
1198
|
+
});
|
|
1199
|
+
if (entries.length === 0) throw new Error("No values to set");
|
|
1200
|
+
return Object.fromEntries(entries);
|
|
1201
|
+
}
|
|
1202
|
+
function applyMixins(baseClass, extendedClasses) {
|
|
1203
|
+
for (const extendedClass of extendedClasses) for (const name2 of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
1204
|
+
if (name2 === "constructor") continue;
|
|
1205
|
+
Object.defineProperty(baseClass.prototype, name2, Object.getOwnPropertyDescriptor(extendedClass.prototype, name2) || /* @__PURE__ */ Object.create(null));
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
function getTableColumns(table) {
|
|
1209
|
+
return table[Table.Symbol.Columns];
|
|
1210
|
+
}
|
|
1211
|
+
function getTableLikeName(table) {
|
|
1212
|
+
return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
|
|
1213
|
+
}
|
|
1214
|
+
function getColumnNameAndConfig(a, b) {
|
|
1215
|
+
return {
|
|
1216
|
+
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
1217
|
+
config: typeof a === "object" ? a : b
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();
|
|
1221
|
+
function assertUnreachable(_x) {
|
|
1222
|
+
throw new Error("Didn't expect to get here");
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/integer.js
|
|
1226
|
+
var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
|
|
1227
|
+
static [entityKind] = "SQLiteBaseIntegerBuilder";
|
|
1228
|
+
constructor(name2, dataType, columnType) {
|
|
1229
|
+
super(name2, dataType, columnType);
|
|
1230
|
+
this.config.autoIncrement = false;
|
|
1231
|
+
}
|
|
1232
|
+
primaryKey(config) {
|
|
1233
|
+
if (config?.autoIncrement) this.config.autoIncrement = true;
|
|
1234
|
+
this.config.hasDefault = true;
|
|
1235
|
+
return super.primaryKey();
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
var SQLiteBaseInteger = class extends SQLiteColumn {
|
|
1239
|
+
static [entityKind] = "SQLiteBaseInteger";
|
|
1240
|
+
autoIncrement = this.config.autoIncrement;
|
|
1241
|
+
getSQLType() {
|
|
1242
|
+
return "integer";
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
var SQLiteIntegerBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
1246
|
+
static [entityKind] = "SQLiteIntegerBuilder";
|
|
1247
|
+
constructor(name2) {
|
|
1248
|
+
super(name2, "number int53", "SQLiteInteger");
|
|
1249
|
+
}
|
|
1250
|
+
build(table) {
|
|
1251
|
+
return new SQLiteInteger(table, this.config);
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
var SQLiteInteger = class extends SQLiteBaseInteger {
|
|
1255
|
+
static [entityKind] = "SQLiteInteger";
|
|
1256
|
+
};
|
|
1257
|
+
var SQLiteTimestampBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
1258
|
+
static [entityKind] = "SQLiteTimestampBuilder";
|
|
1259
|
+
constructor(name2, mode) {
|
|
1260
|
+
super(name2, "object date", "SQLiteTimestamp");
|
|
1261
|
+
this.config.mode = mode;
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* @deprecated Use `default()` with your own expression instead.
|
|
1265
|
+
*
|
|
1266
|
+
* Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
|
|
1267
|
+
*/
|
|
1268
|
+
defaultNow() {
|
|
1269
|
+
return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
|
|
1270
|
+
}
|
|
1271
|
+
build(table) {
|
|
1272
|
+
return new SQLiteTimestamp(table, this.config);
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
var SQLiteTimestamp = class extends SQLiteBaseInteger {
|
|
1276
|
+
static [entityKind] = "SQLiteTimestamp";
|
|
1277
|
+
mode = this.config.mode;
|
|
1278
|
+
mapFromDriverValue = (value) => {
|
|
1279
|
+
if (typeof value === "string") return new Date(value.replaceAll('"', ""));
|
|
1280
|
+
if (this.config.mode === "timestamp") return /* @__PURE__ */ new Date(value * 1e3);
|
|
1281
|
+
return new Date(value);
|
|
1282
|
+
};
|
|
1283
|
+
mapToDriverValue = (value) => {
|
|
1284
|
+
if (typeof value === "number") return value;
|
|
1285
|
+
const unix = value.getTime();
|
|
1286
|
+
if (this.config.mode === "timestamp") return Math.floor(unix / 1e3);
|
|
1287
|
+
return unix;
|
|
1288
|
+
};
|
|
1289
|
+
};
|
|
1290
|
+
var SQLiteBooleanBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
1291
|
+
static [entityKind] = "SQLiteBooleanBuilder";
|
|
1292
|
+
constructor(name2, mode) {
|
|
1293
|
+
super(name2, "boolean", "SQLiteBoolean");
|
|
1294
|
+
this.config.mode = mode;
|
|
1295
|
+
}
|
|
1296
|
+
build(table) {
|
|
1297
|
+
return new SQLiteBoolean(table, this.config);
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
var SQLiteBoolean = class extends SQLiteBaseInteger {
|
|
1301
|
+
static [entityKind] = "SQLiteBoolean";
|
|
1302
|
+
mode = this.config.mode;
|
|
1303
|
+
mapFromDriverValue = (value) => {
|
|
1304
|
+
return Number(value) === 1;
|
|
1305
|
+
};
|
|
1306
|
+
mapToDriverValue = (value) => {
|
|
1307
|
+
return value ? 1 : 0;
|
|
1308
|
+
};
|
|
1309
|
+
};
|
|
1310
|
+
function integer(a, b) {
|
|
1311
|
+
const { name: name2, config } = getColumnNameAndConfig(a, b);
|
|
1312
|
+
if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") return new SQLiteTimestampBuilder(name2, config.mode);
|
|
1313
|
+
if (config?.mode === "boolean") return new SQLiteBooleanBuilder(name2, config.mode);
|
|
1314
|
+
return new SQLiteIntegerBuilder(name2);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/real.js
|
|
1318
|
+
var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
|
|
1319
|
+
static [entityKind] = "SQLiteRealBuilder";
|
|
1320
|
+
constructor(name2) {
|
|
1321
|
+
super(name2, "number double", "SQLiteReal");
|
|
1322
|
+
}
|
|
1323
|
+
/** @internal */
|
|
1324
|
+
build(table) {
|
|
1325
|
+
return new SQLiteReal(table, this.config);
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
var SQLiteReal = class extends SQLiteColumn {
|
|
1329
|
+
static [entityKind] = "SQLiteReal";
|
|
1330
|
+
getSQLType() {
|
|
1331
|
+
return "real";
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
function real(name2) {
|
|
1335
|
+
return new SQLiteRealBuilder(name2 ?? "");
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/text.js
|
|
1339
|
+
var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
|
|
1340
|
+
static [entityKind] = "SQLiteTextBuilder";
|
|
1341
|
+
constructor(name2, config) {
|
|
1342
|
+
super(name2, config.enum?.length ? "string enum" : "string", "SQLiteText");
|
|
1343
|
+
this.config.enumValues = config.enum;
|
|
1344
|
+
this.config.length = config.length;
|
|
1345
|
+
}
|
|
1346
|
+
/** @internal */
|
|
1347
|
+
build(table) {
|
|
1348
|
+
return new SQLiteText(table, this.config);
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
var SQLiteText = class extends SQLiteColumn {
|
|
1352
|
+
static [entityKind] = "SQLiteText";
|
|
1353
|
+
enumValues = this.config.enumValues;
|
|
1354
|
+
constructor(table, config) {
|
|
1355
|
+
super(table, config);
|
|
1356
|
+
}
|
|
1357
|
+
getSQLType() {
|
|
1358
|
+
return `text${this.config.length ? `(${this.config.length})` : ""}`;
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
var SQLiteTextJsonBuilder = class extends SQLiteColumnBuilder {
|
|
1362
|
+
static [entityKind] = "SQLiteTextJsonBuilder";
|
|
1363
|
+
constructor(name2) {
|
|
1364
|
+
super(name2, "object json", "SQLiteTextJson");
|
|
1365
|
+
}
|
|
1366
|
+
/** @internal */
|
|
1367
|
+
build(table) {
|
|
1368
|
+
return new SQLiteTextJson(table, this.config);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
var SQLiteTextJson = class extends SQLiteColumn {
|
|
1372
|
+
static [entityKind] = "SQLiteTextJson";
|
|
1373
|
+
getSQLType() {
|
|
1374
|
+
return "text";
|
|
1375
|
+
}
|
|
1376
|
+
mapFromDriverValue = (value) => {
|
|
1377
|
+
return JSON.parse(value);
|
|
1378
|
+
};
|
|
1379
|
+
mapToDriverValue = (value) => {
|
|
1380
|
+
return JSON.stringify(value);
|
|
1381
|
+
};
|
|
1382
|
+
};
|
|
1383
|
+
function text(a, b = {}) {
|
|
1384
|
+
const { name: name2, config } = getColumnNameAndConfig(a, b);
|
|
1385
|
+
if (config.mode === "json") return new SQLiteTextJsonBuilder(name2);
|
|
1386
|
+
return new SQLiteTextBuilder(name2, config);
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/blob.js
|
|
1390
|
+
function hexToText(hexString) {
|
|
1391
|
+
let result = "";
|
|
1392
|
+
for (let i = 0; i < hexString.length; i += 2) {
|
|
1393
|
+
const hexPair = hexString.slice(i, i + 2);
|
|
1394
|
+
const decimalValue = Number.parseInt(hexPair, 16);
|
|
1395
|
+
result += String.fromCodePoint(decimalValue);
|
|
1396
|
+
}
|
|
1397
|
+
return result;
|
|
1398
|
+
}
|
|
1399
|
+
var SQLiteBigIntBuilder = class extends SQLiteColumnBuilder {
|
|
1400
|
+
static [entityKind] = "SQLiteBigIntBuilder";
|
|
1401
|
+
constructor(name2) {
|
|
1402
|
+
super(name2, "bigint int64", "SQLiteBigInt");
|
|
1403
|
+
}
|
|
1404
|
+
/** @internal */
|
|
1405
|
+
build(table) {
|
|
1406
|
+
return new SQLiteBigInt(table, this.config);
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
var SQLiteBigInt = class extends SQLiteColumn {
|
|
1410
|
+
static [entityKind] = "SQLiteBigInt";
|
|
1411
|
+
getSQLType() {
|
|
1412
|
+
return "blob";
|
|
1413
|
+
}
|
|
1414
|
+
mapFromDriverValue = (value) => {
|
|
1415
|
+
if (typeof value === "string") return BigInt(hexToText(value));
|
|
1416
|
+
if (typeof Buffer !== "undefined" && Buffer.from) {
|
|
1417
|
+
const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
|
|
1418
|
+
return BigInt(buf.toString("utf8"));
|
|
1419
|
+
}
|
|
1420
|
+
return BigInt(textDecoder.decode(value));
|
|
1421
|
+
};
|
|
1422
|
+
mapToDriverValue = (value) => {
|
|
1423
|
+
return Buffer.from(value.toString());
|
|
1424
|
+
};
|
|
1425
|
+
};
|
|
1426
|
+
var SQLiteBlobJsonBuilder = class extends SQLiteColumnBuilder {
|
|
1427
|
+
static [entityKind] = "SQLiteBlobJsonBuilder";
|
|
1428
|
+
constructor(name2) {
|
|
1429
|
+
super(name2, "object json", "SQLiteBlobJson");
|
|
1430
|
+
}
|
|
1431
|
+
/** @internal */
|
|
1432
|
+
build(table) {
|
|
1433
|
+
return new SQLiteBlobJson(table, this.config);
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
var SQLiteBlobJson = class extends SQLiteColumn {
|
|
1437
|
+
static [entityKind] = "SQLiteBlobJson";
|
|
1438
|
+
getSQLType() {
|
|
1439
|
+
return "blob";
|
|
1440
|
+
}
|
|
1441
|
+
mapFromDriverValue = (value) => {
|
|
1442
|
+
if (typeof value === "string") return JSON.parse(hexToText(value));
|
|
1443
|
+
if (typeof Buffer !== "undefined" && Buffer.from) {
|
|
1444
|
+
const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
|
|
1445
|
+
return JSON.parse(buf.toString("utf8"));
|
|
1446
|
+
}
|
|
1447
|
+
return JSON.parse(textDecoder.decode(value));
|
|
1448
|
+
};
|
|
1449
|
+
mapToDriverValue = (value) => {
|
|
1450
|
+
return Buffer.from(JSON.stringify(value));
|
|
1451
|
+
};
|
|
1452
|
+
};
|
|
1453
|
+
var SQLiteBlobBufferBuilder = class extends SQLiteColumnBuilder {
|
|
1454
|
+
static [entityKind] = "SQLiteBlobBufferBuilder";
|
|
1455
|
+
constructor(name2) {
|
|
1456
|
+
super(name2, "object buffer", "SQLiteBlobBuffer");
|
|
1457
|
+
}
|
|
1458
|
+
/** @internal */
|
|
1459
|
+
build(table) {
|
|
1460
|
+
return new SQLiteBlobBuffer(table, this.config);
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
var SQLiteBlobBuffer = class extends SQLiteColumn {
|
|
1464
|
+
static [entityKind] = "SQLiteBlobBuffer";
|
|
1465
|
+
mapFromDriverValue = (value) => {
|
|
1466
|
+
if (Buffer.isBuffer(value)) return value;
|
|
1467
|
+
if (typeof value === "string") return Buffer.from(value, "hex");
|
|
1468
|
+
return Buffer.from(value);
|
|
1469
|
+
};
|
|
1470
|
+
getSQLType() {
|
|
1471
|
+
return "blob";
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
function blob(a, b) {
|
|
1475
|
+
const { name: name2, config } = getColumnNameAndConfig(a, b);
|
|
1476
|
+
if (config?.mode === "bigint") return new SQLiteBigIntBuilder(name2);
|
|
1477
|
+
if (config?.mode === "buffer") return new SQLiteBlobBufferBuilder(name2);
|
|
1478
|
+
return new SQLiteBlobJsonBuilder(name2);
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/custom.js
|
|
1482
|
+
var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
|
|
1483
|
+
static [entityKind] = "SQLiteCustomColumnBuilder";
|
|
1484
|
+
constructor(name2, fieldConfig, customTypeParams) {
|
|
1485
|
+
super(name2, "custom", "SQLiteCustomColumn");
|
|
1486
|
+
this.config.fieldConfig = fieldConfig;
|
|
1487
|
+
this.config.customTypeParams = customTypeParams;
|
|
1488
|
+
}
|
|
1489
|
+
/** @internal */
|
|
1490
|
+
build(table) {
|
|
1491
|
+
return new SQLiteCustomColumn(table, this.config);
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
var SQLiteCustomColumn = class extends SQLiteColumn {
|
|
1495
|
+
static [entityKind] = "SQLiteCustomColumn";
|
|
1496
|
+
sqlName;
|
|
1497
|
+
mapTo;
|
|
1498
|
+
mapFrom;
|
|
1499
|
+
mapJson;
|
|
1500
|
+
forJsonSelect;
|
|
1501
|
+
constructor(table, config) {
|
|
1502
|
+
super(table, config);
|
|
1503
|
+
this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
|
|
1504
|
+
this.mapTo = config.customTypeParams.toDriver;
|
|
1505
|
+
this.mapFrom = config.customTypeParams.fromDriver;
|
|
1506
|
+
this.mapJson = config.customTypeParams.fromJson;
|
|
1507
|
+
this.forJsonSelect = config.customTypeParams.forJsonSelect;
|
|
1508
|
+
}
|
|
1509
|
+
getSQLType() {
|
|
1510
|
+
return this.sqlName;
|
|
1511
|
+
}
|
|
1512
|
+
mapFromDriverValue = (value) => {
|
|
1513
|
+
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
1514
|
+
};
|
|
1515
|
+
mapFromJsonValue(value) {
|
|
1516
|
+
return typeof this.mapJson === "function" ? this.mapJson(value) : this.mapFromDriverValue(value);
|
|
1517
|
+
}
|
|
1518
|
+
jsonSelectIdentifier(identifier, sql2) {
|
|
1519
|
+
if (typeof this.forJsonSelect === "function") return this.forJsonSelect(identifier, sql2);
|
|
1520
|
+
const rawType = this.getSQLType().toLowerCase();
|
|
1521
|
+
const parenPos = rawType.indexOf("(");
|
|
1522
|
+
switch (parenPos + 1 ? rawType.slice(0, parenPos) : rawType) {
|
|
1523
|
+
case "numeric":
|
|
1524
|
+
case "decimal":
|
|
1525
|
+
case "bigint":
|
|
1526
|
+
return sql2`cast(${identifier} as text)`;
|
|
1527
|
+
case "blob":
|
|
1528
|
+
return sql2`hex(${identifier})`;
|
|
1529
|
+
default:
|
|
1530
|
+
return identifier;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
mapToDriverValue = (value) => {
|
|
1534
|
+
return typeof this.mapTo === "function" ? this.mapTo(value) : value;
|
|
1535
|
+
};
|
|
1536
|
+
};
|
|
1537
|
+
function customType(customTypeParams) {
|
|
1538
|
+
return (a, b) => {
|
|
1539
|
+
const { name: name2, config } = getColumnNameAndConfig(a, b);
|
|
1540
|
+
return new SQLiteCustomColumnBuilder(name2, config, customTypeParams);
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
|
|
1545
|
+
var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
|
|
1546
|
+
static [entityKind] = "SQLiteNumericBuilder";
|
|
1547
|
+
constructor(name2) {
|
|
1548
|
+
super(name2, "string numeric", "SQLiteNumeric");
|
|
1549
|
+
}
|
|
1550
|
+
/** @internal */
|
|
1551
|
+
build(table) {
|
|
1552
|
+
return new SQLiteNumeric(table, this.config);
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
var SQLiteNumeric = class extends SQLiteColumn {
|
|
1556
|
+
static [entityKind] = "SQLiteNumeric";
|
|
1557
|
+
mapFromDriverValue = (value) => {
|
|
1558
|
+
if (typeof value === "string") return value;
|
|
1559
|
+
return String(value);
|
|
1560
|
+
};
|
|
1561
|
+
getSQLType() {
|
|
1562
|
+
return "numeric";
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
var SQLiteNumericNumberBuilder = class extends SQLiteColumnBuilder {
|
|
1566
|
+
static [entityKind] = "SQLiteNumericNumberBuilder";
|
|
1567
|
+
constructor(name2) {
|
|
1568
|
+
super(name2, "number", "SQLiteNumericNumber");
|
|
1569
|
+
}
|
|
1570
|
+
/** @internal */
|
|
1571
|
+
build(table) {
|
|
1572
|
+
return new SQLiteNumericNumber(table, this.config);
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
var SQLiteNumericNumber = class extends SQLiteColumn {
|
|
1576
|
+
static [entityKind] = "SQLiteNumericNumber";
|
|
1577
|
+
mapFromDriverValue = (value) => {
|
|
1578
|
+
if (typeof value === "number") return value;
|
|
1579
|
+
return Number(value);
|
|
1580
|
+
};
|
|
1581
|
+
mapToDriverValue = String;
|
|
1582
|
+
getSQLType() {
|
|
1583
|
+
return "numeric";
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1586
|
+
var SQLiteNumericBigIntBuilder = class extends SQLiteColumnBuilder {
|
|
1587
|
+
static [entityKind] = "SQLiteNumericBigIntBuilder";
|
|
1588
|
+
constructor(name2) {
|
|
1589
|
+
super(name2, "bigint int64", "SQLiteNumericBigInt");
|
|
1590
|
+
}
|
|
1591
|
+
/** @internal */
|
|
1592
|
+
build(table) {
|
|
1593
|
+
return new SQLiteNumericBigInt(table, this.config);
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
var SQLiteNumericBigInt = class extends SQLiteColumn {
|
|
1597
|
+
static [entityKind] = "SQLiteNumericBigInt";
|
|
1598
|
+
mapFromDriverValue = BigInt;
|
|
1599
|
+
mapToDriverValue = String;
|
|
1600
|
+
getSQLType() {
|
|
1601
|
+
return "numeric";
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
function numeric(a, b) {
|
|
1605
|
+
const { name: name2, config } = getColumnNameAndConfig(a, b);
|
|
1606
|
+
const mode = config?.mode;
|
|
1607
|
+
return mode === "number" ? new SQLiteNumericNumberBuilder(name2) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name2) : new SQLiteNumericBuilder(name2);
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/columns/all.js
|
|
1611
|
+
function getSQLiteColumnBuilders() {
|
|
1612
|
+
return {
|
|
1613
|
+
blob,
|
|
1614
|
+
customType,
|
|
1615
|
+
integer,
|
|
1616
|
+
numeric,
|
|
1617
|
+
real,
|
|
1618
|
+
text
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/casing.js
|
|
1623
|
+
function toSnakeCase(input) {
|
|
1624
|
+
return (input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []).map((word) => word.toLowerCase()).join("_");
|
|
1625
|
+
}
|
|
1626
|
+
function toCamelCase(input) {
|
|
1627
|
+
return (input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []).reduce((acc, word, i) => {
|
|
1628
|
+
return acc + (i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`);
|
|
1629
|
+
}, "");
|
|
1630
|
+
}
|
|
1631
|
+
function getCasingFn(casing) {
|
|
1632
|
+
if (casing === "snake_case") return toSnakeCase;
|
|
1633
|
+
if (casing === "camelCase") return toCamelCase;
|
|
1634
|
+
return (name2) => name2;
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/table.js
|
|
1638
|
+
var InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
|
|
1639
|
+
var SQLiteTable = class extends Table {
|
|
1640
|
+
static [entityKind] = "SQLiteTable";
|
|
1641
|
+
/** @internal */
|
|
1642
|
+
static Symbol = Object.assign({}, Table.Symbol, { InlineForeignKeys });
|
|
1643
|
+
/** @internal */
|
|
1644
|
+
[Table.Symbol.Columns];
|
|
1645
|
+
/** @internal */
|
|
1646
|
+
[InlineForeignKeys] = [];
|
|
1647
|
+
/** @internal */
|
|
1648
|
+
[Table.Symbol.ExtraConfigBuilder] = void 0;
|
|
1649
|
+
};
|
|
1650
|
+
function sqliteTableBase(name2, columns, extraConfig, schema, casing, baseName = name2) {
|
|
1651
|
+
const casingFn = getCasingFn(casing);
|
|
1652
|
+
const rawTable = new SQLiteTable(name2, schema, baseName);
|
|
1653
|
+
const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
|
|
1654
|
+
const builtColumns = Object.fromEntries(Object.entries(parsedColumns).map(([name3, colBuilderBase]) => {
|
|
1655
|
+
const colBuilder = colBuilderBase;
|
|
1656
|
+
colBuilder.setName(name3, casingFn);
|
|
1657
|
+
const column = colBuilder.build(rawTable).postBuild();
|
|
1658
|
+
rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
|
|
1659
|
+
return [name3, column];
|
|
1660
|
+
}));
|
|
1661
|
+
const table = Object.assign(rawTable, builtColumns);
|
|
1662
|
+
table[Table.Symbol.Columns] = builtColumns;
|
|
1663
|
+
table[Table.Symbol.ExtraConfigColumns] = builtColumns;
|
|
1664
|
+
if (extraConfig) table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
|
|
1665
|
+
return table;
|
|
1666
|
+
}
|
|
1667
|
+
function sqliteTableWithCasing(casing) {
|
|
1668
|
+
return (name2, columns, extraConfig) => sqliteTableBase(name2, columns, extraConfig, void 0, casing);
|
|
1669
|
+
}
|
|
1670
|
+
var sqliteTable = sqliteTableWithCasing(void 0);
|
|
1671
|
+
|
|
1672
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
1673
|
+
var IndexBuilderOn = class {
|
|
1674
|
+
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
1675
|
+
constructor(name2, unique2) {
|
|
1676
|
+
this.name = name2;
|
|
1677
|
+
this.unique = unique2;
|
|
1678
|
+
}
|
|
1679
|
+
on(...columns) {
|
|
1680
|
+
return new IndexBuilder(this.name, columns, this.unique);
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
var IndexBuilder = class {
|
|
1684
|
+
static [entityKind] = "SQLiteIndexBuilder";
|
|
1685
|
+
/** @internal */
|
|
1686
|
+
config;
|
|
1687
|
+
constructor(name2, columns, unique2) {
|
|
1688
|
+
this.config = {
|
|
1689
|
+
name: name2,
|
|
1690
|
+
columns,
|
|
1691
|
+
unique: unique2,
|
|
1692
|
+
where: void 0
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Condition for partial index.
|
|
1697
|
+
*/
|
|
1698
|
+
where(condition) {
|
|
1699
|
+
this.config.where = condition;
|
|
1700
|
+
return this;
|
|
1701
|
+
}
|
|
1702
|
+
/** @internal */
|
|
1703
|
+
build(table) {
|
|
1704
|
+
return new Index(this.config, table);
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
var Index = class {
|
|
1708
|
+
static [entityKind] = "SQLiteIndex";
|
|
1709
|
+
config;
|
|
1710
|
+
isNameExplicit;
|
|
1711
|
+
constructor(config, table) {
|
|
1712
|
+
this.config = {
|
|
1713
|
+
...config,
|
|
1714
|
+
table
|
|
1715
|
+
};
|
|
1716
|
+
this.isNameExplicit = !!config.name;
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
function index(name2) {
|
|
1720
|
+
return new IndexBuilderOn(name2, false);
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/primary-keys.js
|
|
1724
|
+
function primaryKey(...config) {
|
|
1725
|
+
if (config[0].columns) return new PrimaryKeyBuilder(config[0].columns, config[0].name);
|
|
1726
|
+
return new PrimaryKeyBuilder(config);
|
|
1727
|
+
}
|
|
1728
|
+
var PrimaryKeyBuilder = class {
|
|
1729
|
+
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
1730
|
+
/** @internal */
|
|
1731
|
+
columns;
|
|
1732
|
+
/** @internal */
|
|
1733
|
+
name;
|
|
1734
|
+
constructor(columns, name2) {
|
|
1735
|
+
this.columns = columns;
|
|
1736
|
+
this.name = name2;
|
|
1737
|
+
}
|
|
1738
|
+
/** @internal */
|
|
1739
|
+
build(table) {
|
|
1740
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
var PrimaryKey = class {
|
|
1744
|
+
static [entityKind] = "SQLitePrimaryKey";
|
|
1745
|
+
columns;
|
|
1746
|
+
name;
|
|
1747
|
+
isNameExplicit;
|
|
1748
|
+
constructor(table, columns, name2) {
|
|
1749
|
+
this.table = table;
|
|
1750
|
+
this.columns = columns;
|
|
1751
|
+
this.name = name2;
|
|
1752
|
+
this.isNameExplicit = !!name2;
|
|
1753
|
+
}
|
|
1754
|
+
getName() {
|
|
1755
|
+
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
|
|
1760
|
+
function uniqueKeyName(table, columns) {
|
|
1761
|
+
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
1762
|
+
}
|
|
1763
|
+
function unique(name2) {
|
|
1764
|
+
return new UniqueOnConstraintBuilder(name2);
|
|
1765
|
+
}
|
|
1766
|
+
var UniqueConstraintBuilder = class {
|
|
1767
|
+
static [entityKind] = "SQLiteUniqueConstraintBuilder";
|
|
1768
|
+
/** @internal */
|
|
1769
|
+
columns;
|
|
1770
|
+
constructor(columns, name2) {
|
|
1771
|
+
this.name = name2;
|
|
1772
|
+
this.columns = columns;
|
|
1773
|
+
}
|
|
1774
|
+
/** @internal */
|
|
1775
|
+
build(table) {
|
|
1776
|
+
return new UniqueConstraint(table, this.columns, this.name);
|
|
1777
|
+
}
|
|
1778
|
+
};
|
|
1779
|
+
var UniqueOnConstraintBuilder = class {
|
|
1780
|
+
static [entityKind] = "SQLiteUniqueOnConstraintBuilder";
|
|
1781
|
+
/** @internal */
|
|
1782
|
+
name;
|
|
1783
|
+
constructor(name2) {
|
|
1784
|
+
this.name = name2;
|
|
1785
|
+
}
|
|
1786
|
+
on(...columns) {
|
|
1787
|
+
return new UniqueConstraintBuilder(columns, this.name);
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
var UniqueConstraint = class {
|
|
1791
|
+
static [entityKind] = "SQLiteUniqueConstraint";
|
|
1792
|
+
columns;
|
|
1793
|
+
name;
|
|
1794
|
+
isNameExplicit;
|
|
1795
|
+
constructor(table, columns, name2) {
|
|
1796
|
+
this.table = table;
|
|
1797
|
+
this.columns = columns;
|
|
1798
|
+
this.isNameExplicit = !!name2;
|
|
1799
|
+
this.name = name2 ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
|
|
1800
|
+
}
|
|
1801
|
+
getName() {
|
|
1802
|
+
return this.name;
|
|
1803
|
+
}
|
|
1804
|
+
};
|
|
1805
|
+
|
|
1806
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/query-promise.js
|
|
1807
|
+
var QueryPromise = class {
|
|
1808
|
+
static [entityKind] = "QueryPromise";
|
|
1809
|
+
[Symbol.toStringTag] = "QueryPromise";
|
|
1810
|
+
catch(onRejected) {
|
|
1811
|
+
return this.then(void 0, onRejected);
|
|
1812
|
+
}
|
|
1813
|
+
finally(onFinally) {
|
|
1814
|
+
return this.then((value) => {
|
|
1815
|
+
onFinally?.();
|
|
1816
|
+
return value;
|
|
1817
|
+
}, (reason) => {
|
|
1818
|
+
onFinally?.();
|
|
1819
|
+
throw reason;
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
then(onFulfilled, onRejected) {
|
|
1823
|
+
return this.execute().then(onFulfilled, onRejected);
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/errors.js
|
|
1828
|
+
var DrizzleError = class extends Error {
|
|
1829
|
+
static [entityKind] = "DrizzleError";
|
|
1830
|
+
constructor({ message, cause }) {
|
|
1831
|
+
super(message);
|
|
1832
|
+
this.name = "DrizzleError";
|
|
1833
|
+
this.cause = cause;
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
var DrizzleQueryError = class DrizzleQueryError2 extends Error {
|
|
1837
|
+
static [entityKind] = "DrizzleQueryError";
|
|
1838
|
+
constructor(query, params, cause) {
|
|
1839
|
+
super(`Failed query: ${query}
|
|
1840
|
+
params: ${params}`);
|
|
1841
|
+
this.query = query;
|
|
1842
|
+
this.params = params;
|
|
1843
|
+
this.cause = cause;
|
|
1844
|
+
this.name = "DrizzleQueryError";
|
|
1845
|
+
Error.captureStackTrace(this, DrizzleQueryError2);
|
|
1846
|
+
if (cause) this.cause = cause;
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
var TransactionRollbackError = class extends DrizzleError {
|
|
1850
|
+
static [entityKind] = "TransactionRollbackError";
|
|
1851
|
+
constructor() {
|
|
1852
|
+
super({ message: "Rollback" });
|
|
1853
|
+
this.name = "TransactionRollbackError";
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
|
|
1857
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/alias.js
|
|
1858
|
+
var ColumnTableAliasProxyHandler = class {
|
|
1859
|
+
static [entityKind] = "ColumnTableAliasProxyHandler";
|
|
1860
|
+
constructor(table, ignoreColumnAlias) {
|
|
1861
|
+
this.table = table;
|
|
1862
|
+
this.ignoreColumnAlias = ignoreColumnAlias;
|
|
1863
|
+
}
|
|
1864
|
+
get(columnObj, prop) {
|
|
1865
|
+
if (prop === "table") return this.table;
|
|
1866
|
+
if (prop === "isAlias" && this.ignoreColumnAlias) return false;
|
|
1867
|
+
return columnObj[prop];
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
var ViewSelectionAliasProxyHandler = class {
|
|
1871
|
+
static [entityKind] = "ViewSelectionAliasProxyHandler";
|
|
1872
|
+
constructor(view, selection, ignoreColumnAlias) {
|
|
1873
|
+
this.view = view;
|
|
1874
|
+
this.selection = selection;
|
|
1875
|
+
this.ignoreColumnAlias = ignoreColumnAlias;
|
|
1876
|
+
}
|
|
1877
|
+
get(selection, prop) {
|
|
1878
|
+
const value = selection[prop];
|
|
1879
|
+
if (is(value, Column)) return new Proxy(value, new ColumnTableAliasProxyHandler(this.view, this.ignoreColumnAlias));
|
|
1880
|
+
if (is(value, Subquery) || is(value, SQL) || is(value, SQL.Aliased) || isSQLWrapper(value) || typeof value !== "object" || value === null) return value;
|
|
1881
|
+
return new Proxy(value, this);
|
|
1882
|
+
}
|
|
1883
|
+
};
|
|
1884
|
+
var TableAliasProxyHandler = class {
|
|
1885
|
+
static [entityKind] = "TableAliasProxyHandler";
|
|
1886
|
+
constructor(alias, replaceOriginalName, ignoreColumnAlias) {
|
|
1887
|
+
this.alias = alias;
|
|
1888
|
+
this.replaceOriginalName = replaceOriginalName;
|
|
1889
|
+
this.ignoreColumnAlias = ignoreColumnAlias;
|
|
1890
|
+
}
|
|
1891
|
+
get(target, prop) {
|
|
1892
|
+
if (prop === Table.Symbol.IsAlias) return true;
|
|
1893
|
+
if (prop === Table.Symbol.Name) return this.alias;
|
|
1894
|
+
if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) return this.alias;
|
|
1895
|
+
if (prop === ViewBaseConfig) return {
|
|
1896
|
+
...target[ViewBaseConfig],
|
|
1897
|
+
name: this.alias,
|
|
1898
|
+
isAlias: true,
|
|
1899
|
+
selectedFields: new Proxy(target[ViewBaseConfig].selectedFields, new ViewSelectionAliasProxyHandler(new Proxy(target, this), target[ViewBaseConfig].selectedFields, this.ignoreColumnAlias))
|
|
1900
|
+
};
|
|
1901
|
+
if (prop === Table.Symbol.Columns) {
|
|
1902
|
+
const columns = target[Table.Symbol.Columns];
|
|
1903
|
+
if (!columns) return columns;
|
|
1904
|
+
if (is(target, View)) return new Proxy(target[Table.Symbol.Columns], new ViewSelectionAliasProxyHandler(new Proxy(target, this), target[Table.Symbol.Columns], this.ignoreColumnAlias));
|
|
1905
|
+
const proxiedColumns = {};
|
|
1906
|
+
Object.keys(columns).map((key) => {
|
|
1907
|
+
proxiedColumns[key] = new Proxy(columns[key], new ColumnTableAliasProxyHandler(new Proxy(target, this), this.ignoreColumnAlias));
|
|
1908
|
+
});
|
|
1909
|
+
return proxiedColumns;
|
|
1910
|
+
}
|
|
1911
|
+
const value = target[prop];
|
|
1912
|
+
if (is(value, Column)) return new Proxy(value, new ColumnTableAliasProxyHandler(new Proxy(target, this), this.ignoreColumnAlias));
|
|
1913
|
+
return value;
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
var ColumnAliasProxyHandler = class {
|
|
1917
|
+
static [entityKind] = "ColumnAliasProxyHandler";
|
|
1918
|
+
constructor(alias) {
|
|
1919
|
+
this.alias = alias;
|
|
1920
|
+
}
|
|
1921
|
+
get(target, prop) {
|
|
1922
|
+
if (prop === "isAlias") return true;
|
|
1923
|
+
if (prop === "name") return this.alias;
|
|
1924
|
+
if (prop === "keyAsName") return false;
|
|
1925
|
+
if (prop === OriginalColumn) return () => target;
|
|
1926
|
+
return target[prop];
|
|
1927
|
+
}
|
|
1928
|
+
};
|
|
1929
|
+
var RelationTableAliasProxyHandler = class {
|
|
1930
|
+
static [entityKind] = "RelationTableAliasProxyHandler";
|
|
1931
|
+
constructor(alias) {
|
|
1932
|
+
this.alias = alias;
|
|
1933
|
+
}
|
|
1934
|
+
get(target, prop) {
|
|
1935
|
+
if (prop === "sourceTable") return aliasedTable(target.sourceTable, this.alias);
|
|
1936
|
+
return target[prop];
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
function aliasedTable(table, tableAlias) {
|
|
1940
|
+
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false, false));
|
|
1941
|
+
}
|
|
1942
|
+
function aliasedColumn(column, alias) {
|
|
1943
|
+
return new Proxy(column, new ColumnAliasProxyHandler(alias));
|
|
1944
|
+
}
|
|
1945
|
+
Column.prototype.as = function(alias) {
|
|
1946
|
+
return aliasedColumn(this, alias);
|
|
1947
|
+
};
|
|
1948
|
+
function getOriginalColumnFromAlias(column) {
|
|
1949
|
+
return column[OriginalColumn]();
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/relations.js
|
|
1953
|
+
var Relation = class {
|
|
1954
|
+
static [entityKind] = "RelationV2";
|
|
1955
|
+
fieldName;
|
|
1956
|
+
sourceColumns;
|
|
1957
|
+
targetColumns;
|
|
1958
|
+
alias;
|
|
1959
|
+
where;
|
|
1960
|
+
sourceTable;
|
|
1961
|
+
targetTable;
|
|
1962
|
+
through;
|
|
1963
|
+
throughTable;
|
|
1964
|
+
isReversed;
|
|
1965
|
+
/** @internal */
|
|
1966
|
+
sourceColumnTableNames = [];
|
|
1967
|
+
/** @internal */
|
|
1968
|
+
targetColumnTableNames = [];
|
|
1969
|
+
constructor(targetTable, targetTableName) {
|
|
1970
|
+
this.targetTableName = targetTableName;
|
|
1971
|
+
this.targetTable = targetTable;
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
var One = class extends Relation {
|
|
1975
|
+
static [entityKind] = "OneV2";
|
|
1976
|
+
relationType = "one";
|
|
1977
|
+
optional;
|
|
1978
|
+
constructor(tables, targetTable, targetTableName, config) {
|
|
1979
|
+
super(targetTable, targetTableName);
|
|
1980
|
+
this.alias = config?.alias;
|
|
1981
|
+
this.where = config?.where;
|
|
1982
|
+
if (config?.from) this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
|
|
1983
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
1984
|
+
this.sourceColumnTableNames.push(it._.tableName);
|
|
1985
|
+
return it._.column;
|
|
1986
|
+
});
|
|
1987
|
+
if (config?.to) this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
|
|
1988
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
1989
|
+
this.targetColumnTableNames.push(it._.tableName);
|
|
1990
|
+
return it._.column;
|
|
1991
|
+
});
|
|
1992
|
+
if (this.throughTable) this.through = {
|
|
1993
|
+
source: (Array.isArray(config?.from) ? config.from : config?.from ? [config.from] : []).map((c) => c._.through),
|
|
1994
|
+
target: (Array.isArray(config?.to) ? config.to : config?.to ? [config.to] : []).map((c) => c._.through)
|
|
1995
|
+
};
|
|
1996
|
+
this.optional = config?.optional ?? true;
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
var Many = class extends Relation {
|
|
2000
|
+
static [entityKind] = "ManyV2";
|
|
2001
|
+
relationType = "many";
|
|
2002
|
+
constructor(tables, targetTable, targetTableName, config) {
|
|
2003
|
+
super(targetTable, targetTableName);
|
|
2004
|
+
this.config = config;
|
|
2005
|
+
this.alias = config?.alias;
|
|
2006
|
+
this.where = config?.where;
|
|
2007
|
+
if (config?.from) this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
|
|
2008
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
2009
|
+
this.sourceColumnTableNames.push(it._.tableName);
|
|
2010
|
+
return it._.column;
|
|
2011
|
+
});
|
|
2012
|
+
if (config?.to) this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
|
|
2013
|
+
this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
|
|
2014
|
+
this.targetColumnTableNames.push(it._.tableName);
|
|
2015
|
+
return it._.column;
|
|
2016
|
+
});
|
|
2017
|
+
if (this.throughTable) this.through = {
|
|
2018
|
+
source: (Array.isArray(config?.from) ? config.from : config?.from ? [config.from] : []).map((c) => c._.through),
|
|
2019
|
+
target: (Array.isArray(config?.to) ? config.to : config?.to ? [config.to] : []).map((c) => c._.through)
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
var AggregatedField = class {
|
|
2024
|
+
static [entityKind] = "AggregatedField";
|
|
2025
|
+
table;
|
|
2026
|
+
onTable(table) {
|
|
2027
|
+
this.table = table;
|
|
2028
|
+
return this;
|
|
2029
|
+
}
|
|
2030
|
+
};
|
|
2031
|
+
var Count = class extends AggregatedField {
|
|
2032
|
+
static [entityKind] = "AggregatedFieldCount";
|
|
2033
|
+
query;
|
|
2034
|
+
getSQL() {
|
|
2035
|
+
if (!this.query) {
|
|
2036
|
+
if (!this.table) throw new Error("Table must be set before building aggregate field");
|
|
2037
|
+
this.query = sql`select count(*) as ${sql.identifier("r")} from ${getTableAsAliasSQL(this.table)}`.mapWith(Number);
|
|
2038
|
+
}
|
|
2039
|
+
return this.query;
|
|
2040
|
+
}
|
|
2041
|
+
};
|
|
2042
|
+
var operators = {
|
|
2043
|
+
and,
|
|
2044
|
+
between,
|
|
2045
|
+
eq,
|
|
2046
|
+
exists,
|
|
2047
|
+
gt,
|
|
2048
|
+
gte,
|
|
2049
|
+
ilike,
|
|
2050
|
+
inArray,
|
|
2051
|
+
arrayContains,
|
|
2052
|
+
arrayContained,
|
|
2053
|
+
arrayOverlaps,
|
|
2054
|
+
isNull,
|
|
2055
|
+
isNotNull,
|
|
2056
|
+
like,
|
|
2057
|
+
lt,
|
|
2058
|
+
lte,
|
|
2059
|
+
ne,
|
|
2060
|
+
not,
|
|
2061
|
+
notBetween,
|
|
2062
|
+
notExists,
|
|
2063
|
+
notLike,
|
|
2064
|
+
notIlike,
|
|
2065
|
+
notInArray,
|
|
2066
|
+
or,
|
|
2067
|
+
sql
|
|
2068
|
+
};
|
|
2069
|
+
var orderByOperators = {
|
|
2070
|
+
sql,
|
|
2071
|
+
asc,
|
|
2072
|
+
desc
|
|
2073
|
+
};
|
|
2074
|
+
function mapRelationalRow(rows, isOne, buildQueryResultSelection, parseJson = false, parseJsonIfString = false, useJsonMappers = true) {
|
|
2075
|
+
const maxIdx = isOne ? 1 : rows.length;
|
|
2076
|
+
const decoders = buildQueryResultSelection.map(({ field, codec, arrayDimensions }) => {
|
|
2077
|
+
let decoder;
|
|
2078
|
+
if (is(field, Column)) decoder = field;
|
|
2079
|
+
else if (is(field, SQL)) decoder = field.decoder;
|
|
2080
|
+
else if (is(field, SQL.Aliased)) decoder = field.sql.decoder;
|
|
2081
|
+
else if (is(field, Table) || is(field, View)) decoder = noopDecoder;
|
|
2082
|
+
else decoder = field.getSQL().decoder;
|
|
2083
|
+
if (useJsonMappers && field.mapFromJsonValue) return (v) => field.mapFromJsonValue(v);
|
|
2084
|
+
return decoder.mapFromDriverValue.isNoop ? codec ? (value) => codec(value, arrayDimensions) : void 0 : codec ? (value) => decoder.mapFromDriverValue(codec(value, arrayDimensions)) : (value) => decoder.mapFromDriverValue(value);
|
|
2085
|
+
});
|
|
2086
|
+
for (let i = 0; i < maxIdx; ++i) {
|
|
2087
|
+
const row = isOne ? rows : rows[i];
|
|
2088
|
+
for (let selectionItemIdx = 0; selectionItemIdx < buildQueryResultSelection.length; ++selectionItemIdx) {
|
|
2089
|
+
const selectionItem = buildQueryResultSelection[selectionItemIdx];
|
|
2090
|
+
if (selectionItem.selection) {
|
|
2091
|
+
if (row[selectionItem.key] === null) continue;
|
|
2092
|
+
if (parseJson) {
|
|
2093
|
+
row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
|
|
2094
|
+
if (row[selectionItem.key] === null) continue;
|
|
2095
|
+
} else if (parseJsonIfString && typeof row[selectionItem.key] === "string") row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
|
|
2096
|
+
if (selectionItem.isArray) {
|
|
2097
|
+
mapRelationalRow(row[selectionItem.key], false, selectionItem.selection, false, parseJsonIfString);
|
|
2098
|
+
continue;
|
|
2099
|
+
}
|
|
2100
|
+
mapRelationalRow(row[selectionItem.key], true, selectionItem.selection, false, parseJsonIfString);
|
|
2101
|
+
continue;
|
|
2102
|
+
}
|
|
2103
|
+
if (row[selectionItem.key] === null) continue;
|
|
2104
|
+
const decoder = decoders[selectionItemIdx];
|
|
2105
|
+
if (!decoder) continue;
|
|
2106
|
+
row[selectionItem.key] = decoder(row[selectionItem.key]);
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
return rows;
|
|
2110
|
+
}
|
|
2111
|
+
function mapRelationalRowFromArrays(rows, isOne, buildQueryResultSelection, parseJson = false, parseJsonIfString = false) {
|
|
2112
|
+
const maxIdx = isOne ? 1 : rows.length;
|
|
2113
|
+
const decoders = buildQueryResultSelection.map(({ field, codec, arrayDimensions }) => {
|
|
2114
|
+
let decoder;
|
|
2115
|
+
if (is(field, Column)) decoder = field;
|
|
2116
|
+
else if (is(field, SQL)) decoder = field.decoder;
|
|
2117
|
+
else if (is(field, SQL.Aliased)) decoder = field.sql.decoder;
|
|
2118
|
+
else if (is(field, Table) || is(field, View)) decoder = noopDecoder;
|
|
2119
|
+
else decoder = field.getSQL().decoder;
|
|
2120
|
+
return decoder.mapFromDriverValue.isNoop ? codec ? (value) => codec(value, arrayDimensions) : void 0 : codec ? (value) => decoder.mapFromDriverValue(codec(value, arrayDimensions)) : (value) => decoder.mapFromDriverValue(value);
|
|
2121
|
+
});
|
|
2122
|
+
const results = Array.from({ length: maxIdx });
|
|
2123
|
+
for (let i = 0; i < maxIdx; ++i) {
|
|
2124
|
+
const row = isOne ? rows : rows[i];
|
|
2125
|
+
const result = {};
|
|
2126
|
+
for (let selectionItemIdx = 0; selectionItemIdx < buildQueryResultSelection.length; ++selectionItemIdx) {
|
|
2127
|
+
const selectionItem = buildQueryResultSelection[selectionItemIdx];
|
|
2128
|
+
let value = row[selectionItemIdx];
|
|
2129
|
+
if (selectionItem.selection) {
|
|
2130
|
+
if (value === null) {
|
|
2131
|
+
result[selectionItem.key] = null;
|
|
2132
|
+
continue;
|
|
2133
|
+
}
|
|
2134
|
+
if (parseJson) {
|
|
2135
|
+
value = JSON.parse(value);
|
|
2136
|
+
if (value === null) {
|
|
2137
|
+
result[selectionItem.key] = null;
|
|
2138
|
+
continue;
|
|
2139
|
+
}
|
|
2140
|
+
} else if (parseJsonIfString && typeof value === "string") value = JSON.parse(value);
|
|
2141
|
+
if (selectionItem.isArray) mapRelationalRow(value, false, selectionItem.selection, false, parseJsonIfString);
|
|
2142
|
+
else mapRelationalRow(value, true, selectionItem.selection, false, parseJsonIfString);
|
|
2143
|
+
result[selectionItem.key] = value;
|
|
2144
|
+
continue;
|
|
2145
|
+
}
|
|
2146
|
+
if (value === null) {
|
|
2147
|
+
result[selectionItem.key] = null;
|
|
2148
|
+
continue;
|
|
2149
|
+
}
|
|
2150
|
+
const decoder = decoders[selectionItemIdx];
|
|
2151
|
+
result[selectionItem.key] = decoder ? decoder(value) : value;
|
|
2152
|
+
}
|
|
2153
|
+
results[i] = result;
|
|
2154
|
+
}
|
|
2155
|
+
return isOne ? results[0] : results;
|
|
2156
|
+
}
|
|
2157
|
+
function makeDefaultRqbMapper({ selection, isFirst, parseJson, parseJsonIfString, rootJsonMappers, arrayModeRoot }) {
|
|
2158
|
+
return ((rows) => {
|
|
2159
|
+
if (isFirst && !rows[0]) return rows[0];
|
|
2160
|
+
return arrayModeRoot ? mapRelationalRowFromArrays(isFirst ? rows[0] : rows, isFirst, selection, parseJson, parseJsonIfString) : mapRelationalRow(isFirst ? rows[0] : rows, isFirst, selection, parseJson, parseJsonIfString, rootJsonMappers);
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function makeJitRqbMapperInner(selection, rowExpr, selectionVar, parseJson, parseJsonIfString, useJsonMappers, preFn, counter, accessByIdx) {
|
|
2164
|
+
const bodyStmts = [];
|
|
2165
|
+
const literalEntries = [];
|
|
2166
|
+
let hasWork = false;
|
|
2167
|
+
const fieldVars = selection.map(() => `c${counter.n++}`);
|
|
2168
|
+
const destructurePieces = selection.map((item, idx) => accessByIdx ? fieldVars[idx] : `${JSON.stringify(item.key)}: ${fieldVars[idx]}`);
|
|
2169
|
+
bodyStmts.push(accessByIdx ? `let [ ${destructurePieces.join(", ")} ] = ${rowExpr};` : `let { ${destructurePieces.join(", ")} } = ${rowExpr};`);
|
|
2170
|
+
for (const [idx, { field, key, codec, isArray, selection: innerSelection, arrayDimensions }] of selection.entries()) {
|
|
2171
|
+
const sel = `${selectionVar}[${idx}]`;
|
|
2172
|
+
const keyStr = JSON.stringify(key);
|
|
2173
|
+
const slot = fieldVars[idx];
|
|
2174
|
+
if (innerSelection) {
|
|
2175
|
+
if (parseJson) {
|
|
2176
|
+
bodyStmts.push(`if (${slot} !== null) ${slot} = JSON.parse(${slot});`);
|
|
2177
|
+
hasWork = true;
|
|
2178
|
+
} else if (parseJsonIfString) {
|
|
2179
|
+
bodyStmts.push(`if (typeof ${slot} === 'string') ${slot} = JSON.parse(${slot});`);
|
|
2180
|
+
hasWork = true;
|
|
2181
|
+
}
|
|
2182
|
+
const nestedSelVar = `s${counter.n++}`;
|
|
2183
|
+
const savedPreFnLen = preFn.length;
|
|
2184
|
+
preFn.push(`const { selection: ${nestedSelVar} } = ${sel};`);
|
|
2185
|
+
if (isArray) {
|
|
2186
|
+
const j = `j${counter.n++}`;
|
|
2187
|
+
const inner = makeJitRqbMapperInner(innerSelection, `${slot}[${j}]`, nestedSelVar, false, parseJsonIfString, true, preFn, counter, false);
|
|
2188
|
+
if (inner.hasWork) {
|
|
2189
|
+
hasWork = true;
|
|
2190
|
+
bodyStmts.push(`if (${slot} !== null) {`);
|
|
2191
|
+
bodyStmts.push(` for (let ${j} = 0; ${j} < ${slot}.length; ++${j}) {`);
|
|
2192
|
+
for (const s of inner.bodyStmts) bodyStmts.push(` ${s}`);
|
|
2193
|
+
bodyStmts.push(` ${slot}[${j}] = ${inner.literal};`);
|
|
2194
|
+
bodyStmts.push(` }`);
|
|
2195
|
+
bodyStmts.push(`}`);
|
|
2196
|
+
} else preFn.splice(savedPreFnLen, 1);
|
|
2197
|
+
} else {
|
|
2198
|
+
const inner = makeJitRqbMapperInner(innerSelection, slot, nestedSelVar, false, parseJsonIfString, true, preFn, counter, false);
|
|
2199
|
+
if (inner.hasWork) {
|
|
2200
|
+
hasWork = true;
|
|
2201
|
+
bodyStmts.push(`if (${slot} !== null) {`);
|
|
2202
|
+
for (const s of inner.bodyStmts) bodyStmts.push(` ${s}`);
|
|
2203
|
+
bodyStmts.push(` ${slot} = ${inner.literal};`);
|
|
2204
|
+
bodyStmts.push(`}`);
|
|
2205
|
+
} else preFn.splice(savedPreFnLen, 1);
|
|
2206
|
+
}
|
|
2207
|
+
literalEntries.push(`${keyStr}: ${slot}`);
|
|
2208
|
+
continue;
|
|
2209
|
+
}
|
|
2210
|
+
let decoderExpr = "";
|
|
2211
|
+
let destructure = "";
|
|
2212
|
+
let bypassCodecs = false;
|
|
2213
|
+
if (is(field, Column)) {
|
|
2214
|
+
if (useJsonMappers && field.mapFromJsonValue) {
|
|
2215
|
+
bypassCodecs = true;
|
|
2216
|
+
const id = counter.n++;
|
|
2217
|
+
destructure = `field: dec${id}`;
|
|
2218
|
+
decoderExpr = `dec${id}.mapFromJsonValue`;
|
|
2219
|
+
} else if (!field.mapFromDriverValue.isNoop) {
|
|
2220
|
+
const id = counter.n++;
|
|
2221
|
+
destructure = `field: dec${id}`;
|
|
2222
|
+
decoderExpr = `dec${id}.mapFromDriverValue`;
|
|
2223
|
+
}
|
|
2224
|
+
} else if (is(field, SQL)) {
|
|
2225
|
+
if (useJsonMappers && field.decoder.mapFromJsonValue) {
|
|
2226
|
+
bypassCodecs = true;
|
|
2227
|
+
const id = counter.n++;
|
|
2228
|
+
destructure = `field: { decoder: dec${id} }`;
|
|
2229
|
+
decoderExpr = `dec${id}.mapFromJsonValue`;
|
|
2230
|
+
} else if (!field.decoder.mapFromDriverValue.isNoop) {
|
|
2231
|
+
const id = counter.n++;
|
|
2232
|
+
destructure = `field: { decoder: dec${id} }`;
|
|
2233
|
+
decoderExpr = `dec${id}.mapFromDriverValue`;
|
|
2234
|
+
}
|
|
2235
|
+
} else if (is(field, SQL.Aliased)) {
|
|
2236
|
+
if (useJsonMappers && field.sql.decoder.mapFromJsonValue) {
|
|
2237
|
+
bypassCodecs = true;
|
|
2238
|
+
const id = counter.n++;
|
|
2239
|
+
destructure = `field: { sql: { decoder: dec${id} } }`;
|
|
2240
|
+
decoderExpr = `dec${id}.mapFromJsonValue`;
|
|
2241
|
+
} else if (!field.sql.decoder.mapFromDriverValue.isNoop) {
|
|
2242
|
+
const id = counter.n++;
|
|
2243
|
+
destructure = `field: { sql: { decoder: dec${id} } }`;
|
|
2244
|
+
decoderExpr = `dec${id}.mapFromDriverValue`;
|
|
2245
|
+
}
|
|
2246
|
+
} else if (is(field, Table) || is(field, View)) {
|
|
2247
|
+
} else {
|
|
2248
|
+
const sqlExpr = field.getSQL();
|
|
2249
|
+
if (useJsonMappers && sqlExpr.decoder.mapFromJsonValue) {
|
|
2250
|
+
bypassCodecs = true;
|
|
2251
|
+
const id = counter.n++;
|
|
2252
|
+
preFn.push(`const dec${id} = ${sel}.field.getSQL().decoder;`);
|
|
2253
|
+
decoderExpr = `dec${id}.mapFromJsonValue`;
|
|
2254
|
+
} else if (!sqlExpr.decoder.mapFromDriverValue.isNoop) {
|
|
2255
|
+
const id = counter.n++;
|
|
2256
|
+
preFn.push(`const dec${id} = ${sel}.field.getSQL().decoder;`);
|
|
2257
|
+
decoderExpr = `dec${id}.mapFromDriverValue`;
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
let codecVar = "";
|
|
2261
|
+
if (!bypassCodecs && codec) codecVar = `codec${counter.n++}`;
|
|
2262
|
+
if (destructure || codecVar) {
|
|
2263
|
+
const parts = [];
|
|
2264
|
+
if (destructure) parts.push(destructure);
|
|
2265
|
+
if (codecVar) parts.push(`codec: ${codecVar}`);
|
|
2266
|
+
preFn.push(`const { ${parts.join(", ")} } = ${sel};`);
|
|
2267
|
+
}
|
|
2268
|
+
if (decoderExpr || codecVar) {
|
|
2269
|
+
hasWork = true;
|
|
2270
|
+
let decoded = slot;
|
|
2271
|
+
if (codecVar) decoded = `${codecVar}(${decoded}, ${arrayDimensions})`;
|
|
2272
|
+
if (decoderExpr) decoded = `${decoderExpr}(${decoded})`;
|
|
2273
|
+
literalEntries.push(`${keyStr}: ${slot} === null ? null : ${decoded}`);
|
|
2274
|
+
} else literalEntries.push(`${keyStr}: ${slot}`);
|
|
2275
|
+
}
|
|
2276
|
+
return {
|
|
2277
|
+
bodyStmts,
|
|
2278
|
+
literal: `{ ${literalEntries.join(", ")} }`,
|
|
2279
|
+
hasWork
|
|
2280
|
+
};
|
|
2281
|
+
}
|
|
2282
|
+
function makeJitRqbMapper({ selection, isFirst, parseJson, parseJsonIfString, rootJsonMappers, arrayModeRoot }) {
|
|
2283
|
+
const preFn = [];
|
|
2284
|
+
const inner = makeJitRqbMapperInner(selection, "row", "selection", parseJson, parseJsonIfString, arrayModeRoot ? false : rootJsonMappers, preFn, { n: 0 }, !!arrayModeRoot);
|
|
2285
|
+
const lines = [];
|
|
2286
|
+
lines.push(` "use strict";
|
|
2287
|
+
const { selection } = this;`);
|
|
2288
|
+
for (const p of preFn) lines.push(` ${p}`);
|
|
2289
|
+
if (arrayModeRoot) if (isFirst) {
|
|
2290
|
+
lines.push(` const row = rows[0];`);
|
|
2291
|
+
lines.push(` if (!row) return undefined;`);
|
|
2292
|
+
for (const s of inner.bodyStmts) lines.push(` ${s}`);
|
|
2293
|
+
lines.push(` return ${inner.literal};`);
|
|
2294
|
+
} else {
|
|
2295
|
+
lines.push(` const { length } = rows;`);
|
|
2296
|
+
lines.push(` const mapped = Array.from({ length });`);
|
|
2297
|
+
lines.push(` for (let i = 0; i < length; ++i) {`);
|
|
2298
|
+
lines.push(` const row = rows[i];`);
|
|
2299
|
+
for (const s of inner.bodyStmts) lines.push(` ${s}`);
|
|
2300
|
+
lines.push(` mapped[i] = ${inner.literal};`);
|
|
2301
|
+
lines.push(` }`);
|
|
2302
|
+
lines.push(` return mapped;`);
|
|
2303
|
+
}
|
|
2304
|
+
else if (!inner.hasWork) lines.push(isFirst ? ` return rows[0];` : ` return rows;`);
|
|
2305
|
+
else if (isFirst) {
|
|
2306
|
+
lines.push(` const row = rows[0];`);
|
|
2307
|
+
lines.push(` if (!row) return undefined;`);
|
|
2308
|
+
for (const s of inner.bodyStmts) lines.push(` ${s}`);
|
|
2309
|
+
lines.push(` rows[0] = ${inner.literal};`);
|
|
2310
|
+
lines.push(` return rows[0];`);
|
|
2311
|
+
} else {
|
|
2312
|
+
lines.push(` for (let i = 0; i < rows.length; ++i) {`);
|
|
2313
|
+
lines.push(` const row = rows[i];`);
|
|
2314
|
+
for (const s of inner.bodyStmts) lines.push(` ${s}`);
|
|
2315
|
+
lines.push(` rows[i] = ${inner.literal};`);
|
|
2316
|
+
lines.push(` }`);
|
|
2317
|
+
lines.push(` return rows;`);
|
|
2318
|
+
}
|
|
2319
|
+
lines.push(" //# sourceURL=drizzle:jit-relational-query-mapper");
|
|
2320
|
+
const compiled = lines.join("\n");
|
|
2321
|
+
return Object.assign(new FnConstructor("rows", compiled).bind({ selection }), { body: `function jitRqbMapper (rows) {
|
|
2322
|
+
${compiled}
|
|
2323
|
+
}` });
|
|
2324
|
+
}
|
|
2325
|
+
var RelationsBuilderTable = class {
|
|
2326
|
+
static [entityKind] = "RelationsBuilderTable";
|
|
2327
|
+
_;
|
|
2328
|
+
constructor(table, name2) {
|
|
2329
|
+
this._ = {
|
|
2330
|
+
name: name2,
|
|
2331
|
+
table
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
var RelationsBuilderColumn = class {
|
|
2336
|
+
static [entityKind] = "RelationsBuilderColumn";
|
|
2337
|
+
_;
|
|
2338
|
+
constructor(column, tableName, key) {
|
|
2339
|
+
this._ = {
|
|
2340
|
+
tableName,
|
|
2341
|
+
column,
|
|
2342
|
+
key
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
through(column) {
|
|
2346
|
+
return new RelationsBuilderJunctionColumn(this._.column, this._.tableName, this._.key, column);
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
var RelationsBuilderJunctionColumn = class {
|
|
2350
|
+
static [entityKind] = "RelationsBuilderColumn";
|
|
2351
|
+
_;
|
|
2352
|
+
constructor(column, tableName, key, through) {
|
|
2353
|
+
this._ = {
|
|
2354
|
+
tableName,
|
|
2355
|
+
column,
|
|
2356
|
+
through,
|
|
2357
|
+
key
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2361
|
+
var RelationsHelperStatic = class {
|
|
2362
|
+
static [entityKind] = "RelationsHelperStatic";
|
|
2363
|
+
_;
|
|
2364
|
+
constructor(tables) {
|
|
2365
|
+
this._ = { tables };
|
|
2366
|
+
const one = {};
|
|
2367
|
+
const many = {};
|
|
2368
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
2369
|
+
one[tableName] = (config) => {
|
|
2370
|
+
return new One(tables, table, tableName, config);
|
|
2371
|
+
};
|
|
2372
|
+
many[tableName] = (config) => {
|
|
2373
|
+
return new Many(tables, table, tableName, config);
|
|
2374
|
+
};
|
|
2375
|
+
}
|
|
2376
|
+
this.one = one;
|
|
2377
|
+
this.many = many;
|
|
2378
|
+
}
|
|
2379
|
+
one;
|
|
2380
|
+
many;
|
|
2381
|
+
/** @internal - to be reworked */
|
|
2382
|
+
aggs = { count() {
|
|
2383
|
+
return new Count();
|
|
2384
|
+
} };
|
|
2385
|
+
};
|
|
2386
|
+
function fieldSelectionToSQL(table, target) {
|
|
2387
|
+
const field = table[TableColumns][target];
|
|
2388
|
+
return field ? is(field, Column) ? field : is(field, SQL.Aliased) ? sql`${table}.${sql.identifier(field.fieldAlias)}` : sql`${table}.${sql.identifier(target)}` : sql`${table}.${sql.identifier(target)}`;
|
|
2389
|
+
}
|
|
2390
|
+
function relationsFieldFilterToSQL(column, filter) {
|
|
2391
|
+
if (typeof filter !== "object" || is(filter, Placeholder)) return eq(column, filter);
|
|
2392
|
+
const entries = Object.entries(filter);
|
|
2393
|
+
if (!entries.length) return void 0;
|
|
2394
|
+
const parts = [];
|
|
2395
|
+
for (const [target, value] of entries) {
|
|
2396
|
+
if (value === void 0) continue;
|
|
2397
|
+
switch (target) {
|
|
2398
|
+
case "NOT": {
|
|
2399
|
+
const res = relationsFieldFilterToSQL(column, value);
|
|
2400
|
+
if (!res) continue;
|
|
2401
|
+
parts.push(not(res));
|
|
2402
|
+
continue;
|
|
2403
|
+
}
|
|
2404
|
+
case "OR":
|
|
2405
|
+
if (!value.length) continue;
|
|
2406
|
+
parts.push(or(...value.map((subFilter) => relationsFieldFilterToSQL(column, subFilter))));
|
|
2407
|
+
continue;
|
|
2408
|
+
case "AND":
|
|
2409
|
+
if (!value.length) continue;
|
|
2410
|
+
parts.push(and(...value.map((subFilter) => relationsFieldFilterToSQL(column, subFilter))));
|
|
2411
|
+
continue;
|
|
2412
|
+
case "isNotNull":
|
|
2413
|
+
case "isNull":
|
|
2414
|
+
if (!value) continue;
|
|
2415
|
+
parts.push(operators[target](column));
|
|
2416
|
+
continue;
|
|
2417
|
+
case "in":
|
|
2418
|
+
parts.push(operators.inArray(column, value));
|
|
2419
|
+
continue;
|
|
2420
|
+
case "notIn":
|
|
2421
|
+
parts.push(operators.notInArray(column, value));
|
|
2422
|
+
continue;
|
|
2423
|
+
default:
|
|
2424
|
+
parts.push(operators[target](column, value));
|
|
2425
|
+
continue;
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
if (!parts.length) return void 0;
|
|
2429
|
+
return and(...parts);
|
|
2430
|
+
}
|
|
2431
|
+
function relationsFilterToSQL(table, filter, tableRelations = {}, tablesRelations = {}, depth = 0) {
|
|
2432
|
+
const entries = Object.entries(filter);
|
|
2433
|
+
if (!entries.length) return void 0;
|
|
2434
|
+
const parts = [];
|
|
2435
|
+
for (const [target, value] of entries) {
|
|
2436
|
+
if (value === void 0) continue;
|
|
2437
|
+
switch (target) {
|
|
2438
|
+
case "RAW": {
|
|
2439
|
+
const processed = typeof value === "function" ? value(table, operators) : value.getSQL();
|
|
2440
|
+
parts.push(processed);
|
|
2441
|
+
continue;
|
|
2442
|
+
}
|
|
2443
|
+
case "OR":
|
|
2444
|
+
if (!value?.length) continue;
|
|
2445
|
+
parts.push(or(...value.map((subFilter) => relationsFilterToSQL(table, subFilter, tableRelations, tablesRelations, depth))));
|
|
2446
|
+
continue;
|
|
2447
|
+
case "AND":
|
|
2448
|
+
if (!value?.length) continue;
|
|
2449
|
+
parts.push(and(...value.map((subFilter) => relationsFilterToSQL(table, subFilter, tableRelations, tablesRelations, depth))));
|
|
2450
|
+
continue;
|
|
2451
|
+
case "NOT": {
|
|
2452
|
+
if (value === void 0) continue;
|
|
2453
|
+
const built = relationsFilterToSQL(table, value, tableRelations, tablesRelations, depth);
|
|
2454
|
+
if (!built) continue;
|
|
2455
|
+
parts.push(not(built));
|
|
2456
|
+
continue;
|
|
2457
|
+
}
|
|
2458
|
+
default: {
|
|
2459
|
+
if (table[TableColumns][target]) {
|
|
2460
|
+
const colFilter = relationsFieldFilterToSQL(fieldSelectionToSQL(table, target), value);
|
|
2461
|
+
if (colFilter) parts.push(colFilter);
|
|
2462
|
+
continue;
|
|
2463
|
+
}
|
|
2464
|
+
const relation = tableRelations[target];
|
|
2465
|
+
if (!relation) throw new DrizzleError({ message: `Unknown relational filter field: "${target}"` });
|
|
2466
|
+
const targetTable = aliasedTable(relation.targetTable, `f${depth}`);
|
|
2467
|
+
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `ft${depth}`) : void 0;
|
|
2468
|
+
const targetConfig = tablesRelations[relation.targetTableName];
|
|
2469
|
+
const { filter: relationFilter, joinCondition } = relationToSQL(relation, table, targetTable, throughTable);
|
|
2470
|
+
const filter2 = and(relationFilter, typeof value === "boolean" ? void 0 : relationsFilterToSQL(targetTable, value, targetConfig.relations, tablesRelations, depth + 1));
|
|
2471
|
+
const subquery = throughTable ? sql`(select * from ${getTableAsAliasSQL(targetTable)} inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}${sql` where ${filter2}`.if(filter2)} limit 1)` : sql`(select * from ${getTableAsAliasSQL(targetTable)}${sql` where ${filter2}`.if(filter2)} limit 1)`;
|
|
2472
|
+
if (filter2) parts.push((value ? exists : notExists)(subquery));
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
return and(...parts);
|
|
2477
|
+
}
|
|
2478
|
+
function relationsOrderToSQL(table, orders) {
|
|
2479
|
+
if (typeof orders === "function") {
|
|
2480
|
+
const data = orders(table, orderByOperators);
|
|
2481
|
+
return is(data, SQL) ? data : Array.isArray(data) ? data.length ? sql.join(data.map((o) => is(o, SQL) ? o : asc(o)), sql`, `) : void 0 : is(data, Column) ? asc(data) : void 0;
|
|
2482
|
+
}
|
|
2483
|
+
const entries = Object.entries(orders).filter(([_, value]) => value);
|
|
2484
|
+
if (!entries.length) return void 0;
|
|
2485
|
+
return sql.join(entries.map(([target, value]) => (value === "asc" ? asc : desc)(fieldSelectionToSQL(table, target))), sql`, `);
|
|
2486
|
+
}
|
|
2487
|
+
function relationExtrasToSQL(table, extras, codecs, inJson) {
|
|
2488
|
+
const subqueries = [];
|
|
2489
|
+
const selection = [];
|
|
2490
|
+
for (const [key, field] of Object.entries(extras)) {
|
|
2491
|
+
if (!field) continue;
|
|
2492
|
+
const subq = (typeof field === "function" ? field(table, { sql: operators.sql }) : field).getSQL();
|
|
2493
|
+
const column = codecs ? getColumnFromDecoder(subq) : void 0;
|
|
2494
|
+
const query = column && (!inJson || !column.jsonSelectIdentifier) ? sql`${codecs.apply(column, inJson ? "castInJson" : "cast", sql`(${subq})`)} as ${sql.identifier(key)}` : sql`(${subq}) as ${sql.identifier(key)}`;
|
|
2495
|
+
query.decoder = subq.decoder;
|
|
2496
|
+
subqueries.push(query);
|
|
2497
|
+
selection.push(column && (!inJson || !column.mapFromJsonValue) ? {
|
|
2498
|
+
key,
|
|
2499
|
+
field: query,
|
|
2500
|
+
codec: codecs.get(column, inJson ? "normalizeInJson" : "normalize"),
|
|
2501
|
+
arrayDimensions: column.dimensions
|
|
2502
|
+
} : {
|
|
2503
|
+
key,
|
|
2504
|
+
field: query
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2507
|
+
return {
|
|
2508
|
+
sql: subqueries.length ? sql.join(subqueries, sql`, `) : void 0,
|
|
2509
|
+
selection
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
function relationToSQL(relation, sourceTable, targetTable, throughTable) {
|
|
2513
|
+
if (relation.through) {
|
|
2514
|
+
const outerColumnWhere = relation.sourceColumns.map((s, i) => {
|
|
2515
|
+
const t = relation.through.source[i];
|
|
2516
|
+
return eq(sql`${sourceTable}.${sql.identifier(s.name)}`, sql`${throughTable}.${sql.identifier(is(t._.column, Column) ? t._.column.name : t._.key)}`);
|
|
2517
|
+
});
|
|
2518
|
+
const innerColumnWhere = relation.targetColumns.map((s, i) => {
|
|
2519
|
+
const t = relation.through.target[i];
|
|
2520
|
+
return eq(sql`${throughTable}.${sql.identifier(is(t._.column, Column) ? t._.column.name : t._.key)}`, sql`${targetTable}.${sql.identifier(s.name)}`);
|
|
2521
|
+
});
|
|
2522
|
+
return {
|
|
2523
|
+
filter: and(relation.where ? relationsFilterToSQL(relation.isReversed ? sourceTable : targetTable, relation.where) : void 0, ...outerColumnWhere),
|
|
2524
|
+
joinCondition: and(...innerColumnWhere)
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
return { filter: and(...relation.sourceColumns.map((s, i) => {
|
|
2528
|
+
const t = relation.targetColumns[i];
|
|
2529
|
+
return eq(sql`${sourceTable}.${sql.identifier(s.name)}`, sql`${targetTable}.${sql.identifier(t.name)}`);
|
|
2530
|
+
}), relation.where ? relationsFilterToSQL(relation.isReversed ? sourceTable : targetTable, relation.where) : void 0) };
|
|
2531
|
+
}
|
|
2532
|
+
function getTableAsAliasSQL(table) {
|
|
2533
|
+
return sql`${table[IsAlias] ? sql`${sql`${sql.identifier(table[TableSchema] ?? "")}.`.if(table[TableSchema])}${sql.identifier(table[OriginalName])} as ${table}` : table}`;
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/logger.js
|
|
2537
|
+
var ConsoleLogWriter = class {
|
|
2538
|
+
static [entityKind] = "ConsoleLogWriter";
|
|
2539
|
+
write(message) {
|
|
2540
|
+
console.log(message);
|
|
2541
|
+
}
|
|
2542
|
+
};
|
|
2543
|
+
var DefaultLogger = class {
|
|
2544
|
+
static [entityKind] = "DefaultLogger";
|
|
2545
|
+
writer;
|
|
2546
|
+
constructor(config) {
|
|
2547
|
+
this.writer = config?.writer ?? new ConsoleLogWriter();
|
|
2548
|
+
}
|
|
2549
|
+
logQuery(query, params) {
|
|
2550
|
+
const stringifiedParams = params.map((p) => {
|
|
2551
|
+
try {
|
|
2552
|
+
return JSON.stringify(p);
|
|
2553
|
+
} catch {
|
|
2554
|
+
return String(p);
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
|
|
2558
|
+
this.writer.write(`Query: ${query}${paramsStr}`);
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
var NoopLogger = class {
|
|
2562
|
+
static [entityKind] = "NoopLogger";
|
|
2563
|
+
logQuery() {
|
|
2564
|
+
}
|
|
2565
|
+
};
|
|
2566
|
+
|
|
2567
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/utils.js
|
|
2568
|
+
function extractUsedTable(table) {
|
|
2569
|
+
if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
|
|
2570
|
+
if (is(table, Subquery)) return table._.usedTables ?? [];
|
|
2571
|
+
if (is(table, SQL)) return table.usedTables ?? [];
|
|
2572
|
+
return [];
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/view-base.js
|
|
2576
|
+
var SQLiteViewBase = class extends View {
|
|
2577
|
+
static [entityKind] = "SQLiteViewBase";
|
|
2578
|
+
};
|
|
2579
|
+
|
|
2580
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/selection-proxy.js
|
|
2581
|
+
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
2582
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
2583
|
+
config;
|
|
2584
|
+
constructor(config) {
|
|
2585
|
+
this.config = { ...config };
|
|
2586
|
+
}
|
|
2587
|
+
get(subquery, prop) {
|
|
2588
|
+
if (prop === "_") return {
|
|
2589
|
+
...subquery["_"],
|
|
2590
|
+
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
2591
|
+
};
|
|
2592
|
+
if (prop === ViewBaseConfig) return {
|
|
2593
|
+
...subquery[ViewBaseConfig],
|
|
2594
|
+
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
2595
|
+
};
|
|
2596
|
+
if (typeof prop === "symbol") return subquery[prop];
|
|
2597
|
+
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
2598
|
+
if (is(value, SQL.Aliased)) {
|
|
2599
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
2600
|
+
const newValue = value.clone();
|
|
2601
|
+
newValue.isSelectionField = true;
|
|
2602
|
+
newValue.origin = this.config.alias;
|
|
2603
|
+
return newValue;
|
|
2604
|
+
}
|
|
2605
|
+
if (is(value, SQL)) {
|
|
2606
|
+
if (this.config.sqlBehavior === "sql") return value;
|
|
2607
|
+
throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
|
|
2608
|
+
}
|
|
2609
|
+
if (is(value, Column)) {
|
|
2610
|
+
if (this.config.alias) return new Proxy(value, new ColumnTableAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false, true)), true));
|
|
2611
|
+
return value;
|
|
2612
|
+
}
|
|
2613
|
+
if (typeof value !== "object" || value === null) return value;
|
|
2614
|
+
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
2615
|
+
}
|
|
2616
|
+
};
|
|
2617
|
+
|
|
2618
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/query-builders/query-builder.js
|
|
2619
|
+
var TypedQueryBuilder = class {
|
|
2620
|
+
static [entityKind] = "TypedQueryBuilder";
|
|
2621
|
+
/** @internal */
|
|
2622
|
+
getSelectedFields() {
|
|
2623
|
+
return this._.selectedFields;
|
|
2624
|
+
}
|
|
2625
|
+
/** @internal */
|
|
2626
|
+
withoutSelectionCastCodecs() {
|
|
2627
|
+
return this;
|
|
2628
|
+
}
|
|
2629
|
+
};
|
|
2630
|
+
|
|
2631
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/select.js
|
|
2632
|
+
var SQLiteSelectBuilder = class {
|
|
2633
|
+
static [entityKind] = "SQLiteSelectBuilder";
|
|
2634
|
+
fields;
|
|
2635
|
+
session;
|
|
2636
|
+
dialect;
|
|
2637
|
+
withList;
|
|
2638
|
+
distinct;
|
|
2639
|
+
constructor(config, builder = SQLiteSelectBase) {
|
|
2640
|
+
this.builder = builder;
|
|
2641
|
+
this.fields = config.fields;
|
|
2642
|
+
this.session = config.session;
|
|
2643
|
+
this.dialect = config.dialect;
|
|
2644
|
+
this.withList = config.withList;
|
|
2645
|
+
this.distinct = config.distinct;
|
|
2646
|
+
}
|
|
2647
|
+
from(source) {
|
|
2648
|
+
const isPartialSelect = !!this.fields;
|
|
2649
|
+
let fields;
|
|
2650
|
+
if (this.fields) fields = this.fields;
|
|
2651
|
+
else if (is(source, Subquery)) fields = Object.fromEntries(Object.keys(source._.selectedFields).map((key) => [key, source[key]]));
|
|
2652
|
+
else if (is(source, SQLiteViewBase)) fields = source[ViewBaseConfig].selectedFields;
|
|
2653
|
+
else if (is(source, SQL)) fields = {};
|
|
2654
|
+
else fields = getTableColumns(source);
|
|
2655
|
+
return new this.builder({
|
|
2656
|
+
table: source,
|
|
2657
|
+
fields,
|
|
2658
|
+
isPartialSelect,
|
|
2659
|
+
session: this.session,
|
|
2660
|
+
dialect: this.dialect,
|
|
2661
|
+
withList: this.withList ?? [],
|
|
2662
|
+
distinct: this.distinct
|
|
2663
|
+
});
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
var SQLiteSelectBase = class extends TypedQueryBuilder {
|
|
2667
|
+
static [entityKind] = "SQLiteSelectQueryBuilder";
|
|
2668
|
+
_;
|
|
2669
|
+
/** @internal */
|
|
2670
|
+
config;
|
|
2671
|
+
joinsNotNullableMap;
|
|
2672
|
+
tableName;
|
|
2673
|
+
isPartialSelect;
|
|
2674
|
+
session;
|
|
2675
|
+
dialect;
|
|
2676
|
+
cacheConfig = void 0;
|
|
2677
|
+
usedTables = /* @__PURE__ */ new Set();
|
|
2678
|
+
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
2679
|
+
super();
|
|
2680
|
+
this.config = {
|
|
2681
|
+
withList,
|
|
2682
|
+
table,
|
|
2683
|
+
fields: { ...fields },
|
|
2684
|
+
distinct,
|
|
2685
|
+
setOperators: []
|
|
2686
|
+
};
|
|
2687
|
+
this.isPartialSelect = isPartialSelect;
|
|
2688
|
+
this.session = session;
|
|
2689
|
+
this.dialect = dialect;
|
|
2690
|
+
this._ = {
|
|
2691
|
+
selectedFields: fields,
|
|
2692
|
+
config: this.config
|
|
2693
|
+
};
|
|
2694
|
+
this.tableName = getTableLikeName(table);
|
|
2695
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
2696
|
+
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
2697
|
+
}
|
|
2698
|
+
/** @internal */
|
|
2699
|
+
getUsedTables() {
|
|
2700
|
+
return [...this.usedTables];
|
|
2701
|
+
}
|
|
2702
|
+
createJoin(joinType) {
|
|
2703
|
+
return (table, on) => {
|
|
2704
|
+
const baseTableName = this.tableName;
|
|
2705
|
+
const tableName = getTableLikeName(table);
|
|
2706
|
+
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
2707
|
+
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
2708
|
+
if (!this.isPartialSelect) {
|
|
2709
|
+
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
2710
|
+
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
2711
|
+
const selection = is(table, Subquery) ? table._.selectedFields : is(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
|
|
2712
|
+
this.config.fields[tableName] = selection;
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
if (typeof on === "function") on = on(new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
2716
|
+
sqlAliasedBehavior: "sql",
|
|
2717
|
+
sqlBehavior: "sql"
|
|
2718
|
+
})));
|
|
2719
|
+
if (!this.config.joins) this.config.joins = [];
|
|
2720
|
+
this.config.joins.push({
|
|
2721
|
+
on,
|
|
2722
|
+
table,
|
|
2723
|
+
joinType,
|
|
2724
|
+
alias: tableName
|
|
2725
|
+
});
|
|
2726
|
+
if (typeof tableName === "string") switch (joinType) {
|
|
2727
|
+
case "left":
|
|
2728
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
2729
|
+
break;
|
|
2730
|
+
case "right":
|
|
2731
|
+
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
2732
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
2733
|
+
break;
|
|
2734
|
+
case "cross":
|
|
2735
|
+
case "inner":
|
|
2736
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
2737
|
+
break;
|
|
2738
|
+
case "full":
|
|
2739
|
+
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
2740
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
2741
|
+
break;
|
|
2742
|
+
}
|
|
2743
|
+
return this;
|
|
2744
|
+
};
|
|
2745
|
+
}
|
|
2746
|
+
/**
|
|
2747
|
+
* Executes a `left join` operation by adding another table to the current query.
|
|
2748
|
+
*
|
|
2749
|
+
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
|
2750
|
+
*
|
|
2751
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
|
2752
|
+
*
|
|
2753
|
+
* @param table the table to join.
|
|
2754
|
+
* @param on the `on` clause.
|
|
2755
|
+
*
|
|
2756
|
+
* @example
|
|
2757
|
+
*
|
|
2758
|
+
* ```ts
|
|
2759
|
+
* // Select all users and their pets
|
|
2760
|
+
* const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
|
|
2761
|
+
* .from(users)
|
|
2762
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
2763
|
+
*
|
|
2764
|
+
* // Select userId and petId
|
|
2765
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
2766
|
+
* userId: users.id,
|
|
2767
|
+
* petId: pets.id,
|
|
2768
|
+
* })
|
|
2769
|
+
* .from(users)
|
|
2770
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
2771
|
+
* ```
|
|
2772
|
+
*/
|
|
2773
|
+
leftJoin = this.createJoin("left");
|
|
2774
|
+
/**
|
|
2775
|
+
* Executes a `right join` operation by adding another table to the current query.
|
|
2776
|
+
*
|
|
2777
|
+
* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
|
|
2778
|
+
*
|
|
2779
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
|
2780
|
+
*
|
|
2781
|
+
* @param table the table to join.
|
|
2782
|
+
* @param on the `on` clause.
|
|
2783
|
+
*
|
|
2784
|
+
* @example
|
|
2785
|
+
*
|
|
2786
|
+
* ```ts
|
|
2787
|
+
* // Select all users and their pets
|
|
2788
|
+
* const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
|
|
2789
|
+
* .from(users)
|
|
2790
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
2791
|
+
*
|
|
2792
|
+
* // Select userId and petId
|
|
2793
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
|
|
2794
|
+
* userId: users.id,
|
|
2795
|
+
* petId: pets.id,
|
|
2796
|
+
* })
|
|
2797
|
+
* .from(users)
|
|
2798
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
2799
|
+
* ```
|
|
2800
|
+
*/
|
|
2801
|
+
rightJoin = this.createJoin("right");
|
|
2802
|
+
/**
|
|
2803
|
+
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
2804
|
+
*
|
|
2805
|
+
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
|
2806
|
+
*
|
|
2807
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
|
2808
|
+
*
|
|
2809
|
+
* @param table the table to join.
|
|
2810
|
+
* @param on the `on` clause.
|
|
2811
|
+
*
|
|
2812
|
+
* @example
|
|
2813
|
+
*
|
|
2814
|
+
* ```ts
|
|
2815
|
+
* // Select all users and their pets
|
|
2816
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
2817
|
+
* .from(users)
|
|
2818
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
2819
|
+
*
|
|
2820
|
+
* // Select userId and petId
|
|
2821
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
2822
|
+
* userId: users.id,
|
|
2823
|
+
* petId: pets.id,
|
|
2824
|
+
* })
|
|
2825
|
+
* .from(users)
|
|
2826
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
2827
|
+
* ```
|
|
2828
|
+
*/
|
|
2829
|
+
innerJoin = this.createJoin("inner");
|
|
2830
|
+
/**
|
|
2831
|
+
* Executes a `full join` operation by combining rows from two tables into a new table.
|
|
2832
|
+
*
|
|
2833
|
+
* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
|
|
2834
|
+
*
|
|
2835
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
|
2836
|
+
*
|
|
2837
|
+
* @param table the table to join.
|
|
2838
|
+
* @param on the `on` clause.
|
|
2839
|
+
*
|
|
2840
|
+
* @example
|
|
2841
|
+
*
|
|
2842
|
+
* ```ts
|
|
2843
|
+
* // Select all users and their pets
|
|
2844
|
+
* const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()
|
|
2845
|
+
* .from(users)
|
|
2846
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
2847
|
+
*
|
|
2848
|
+
* // Select userId and petId
|
|
2849
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({
|
|
2850
|
+
* userId: users.id,
|
|
2851
|
+
* petId: pets.id,
|
|
2852
|
+
* })
|
|
2853
|
+
* .from(users)
|
|
2854
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
2855
|
+
* ```
|
|
2856
|
+
*/
|
|
2857
|
+
fullJoin = this.createJoin("full");
|
|
2858
|
+
/**
|
|
2859
|
+
* Executes a `cross join` operation by combining rows from two tables into a new table.
|
|
2860
|
+
*
|
|
2861
|
+
* Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
|
|
2862
|
+
*
|
|
2863
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
|
|
2864
|
+
*
|
|
2865
|
+
* @param table the table to join.
|
|
2866
|
+
*
|
|
2867
|
+
* @example
|
|
2868
|
+
*
|
|
2869
|
+
* ```ts
|
|
2870
|
+
* // Select all users, each user with every pet
|
|
2871
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
2872
|
+
* .from(users)
|
|
2873
|
+
* .crossJoin(pets)
|
|
2874
|
+
*
|
|
2875
|
+
* // Select userId and petId
|
|
2876
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
2877
|
+
* userId: users.id,
|
|
2878
|
+
* petId: pets.id,
|
|
2879
|
+
* })
|
|
2880
|
+
* .from(users)
|
|
2881
|
+
* .crossJoin(pets)
|
|
2882
|
+
* ```
|
|
2883
|
+
*/
|
|
2884
|
+
crossJoin = this.createJoin("cross");
|
|
2885
|
+
createSetOperator(type, isAll) {
|
|
2886
|
+
return (rightSelection) => {
|
|
2887
|
+
const rightSelect = typeof rightSelection === "function" ? rightSelection(getSQLiteSetOperators()) : rightSelection;
|
|
2888
|
+
if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
2889
|
+
this.config.setOperators.push({
|
|
2890
|
+
type,
|
|
2891
|
+
isAll,
|
|
2892
|
+
rightSelect
|
|
2893
|
+
});
|
|
2894
|
+
return this;
|
|
2895
|
+
};
|
|
2896
|
+
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Adds `union` set operator to the query.
|
|
2899
|
+
*
|
|
2900
|
+
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
|
2901
|
+
*
|
|
2902
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
|
2903
|
+
*
|
|
2904
|
+
* @example
|
|
2905
|
+
*
|
|
2906
|
+
* ```ts
|
|
2907
|
+
* // Select all unique names from customers and users tables
|
|
2908
|
+
* await db.select({ name: users.name })
|
|
2909
|
+
* .from(users)
|
|
2910
|
+
* .union(
|
|
2911
|
+
* db.select({ name: customers.name }).from(customers)
|
|
2912
|
+
* );
|
|
2913
|
+
* // or
|
|
2914
|
+
* import { union } from 'drizzle-orm/sqlite-core'
|
|
2915
|
+
*
|
|
2916
|
+
* await union(
|
|
2917
|
+
* db.select({ name: users.name }).from(users),
|
|
2918
|
+
* db.select({ name: customers.name }).from(customers)
|
|
2919
|
+
* );
|
|
2920
|
+
* ```
|
|
2921
|
+
*/
|
|
2922
|
+
union = this.createSetOperator("union", false);
|
|
2923
|
+
/**
|
|
2924
|
+
* Adds `union all` set operator to the query.
|
|
2925
|
+
*
|
|
2926
|
+
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
|
2927
|
+
*
|
|
2928
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
|
2929
|
+
*
|
|
2930
|
+
* @example
|
|
2931
|
+
*
|
|
2932
|
+
* ```ts
|
|
2933
|
+
* // Select all transaction ids from both online and in-store sales
|
|
2934
|
+
* await db.select({ transaction: onlineSales.transactionId })
|
|
2935
|
+
* .from(onlineSales)
|
|
2936
|
+
* .unionAll(
|
|
2937
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
2938
|
+
* );
|
|
2939
|
+
* // or
|
|
2940
|
+
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
|
2941
|
+
*
|
|
2942
|
+
* await unionAll(
|
|
2943
|
+
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
|
2944
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
2945
|
+
* );
|
|
2946
|
+
* ```
|
|
2947
|
+
*/
|
|
2948
|
+
unionAll = this.createSetOperator("union", true);
|
|
2949
|
+
/**
|
|
2950
|
+
* Adds `intersect` set operator to the query.
|
|
2951
|
+
*
|
|
2952
|
+
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
|
2953
|
+
*
|
|
2954
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
|
2955
|
+
*
|
|
2956
|
+
* @example
|
|
2957
|
+
*
|
|
2958
|
+
* ```ts
|
|
2959
|
+
* // Select course names that are offered in both departments A and B
|
|
2960
|
+
* await db.select({ courseName: depA.courseName })
|
|
2961
|
+
* .from(depA)
|
|
2962
|
+
* .intersect(
|
|
2963
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
2964
|
+
* );
|
|
2965
|
+
* // or
|
|
2966
|
+
* import { intersect } from 'drizzle-orm/sqlite-core'
|
|
2967
|
+
*
|
|
2968
|
+
* await intersect(
|
|
2969
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
2970
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
2971
|
+
* );
|
|
2972
|
+
* ```
|
|
2973
|
+
*/
|
|
2974
|
+
intersect = this.createSetOperator("intersect", false);
|
|
2975
|
+
/**
|
|
2976
|
+
* Adds `except` set operator to the query.
|
|
2977
|
+
*
|
|
2978
|
+
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
|
2979
|
+
*
|
|
2980
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
|
2981
|
+
*
|
|
2982
|
+
* @example
|
|
2983
|
+
*
|
|
2984
|
+
* ```ts
|
|
2985
|
+
* // Select all courses offered in department A but not in department B
|
|
2986
|
+
* await db.select({ courseName: depA.courseName })
|
|
2987
|
+
* .from(depA)
|
|
2988
|
+
* .except(
|
|
2989
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
2990
|
+
* );
|
|
2991
|
+
* // or
|
|
2992
|
+
* import { except } from 'drizzle-orm/sqlite-core'
|
|
2993
|
+
*
|
|
2994
|
+
* await except(
|
|
2995
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
2996
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
2997
|
+
* );
|
|
2998
|
+
* ```
|
|
2999
|
+
*/
|
|
3000
|
+
except = this.createSetOperator("except", false);
|
|
3001
|
+
/** @internal */
|
|
3002
|
+
addSetOperators(setOperators) {
|
|
3003
|
+
this.config.setOperators.push(...setOperators);
|
|
3004
|
+
return this;
|
|
3005
|
+
}
|
|
3006
|
+
/**
|
|
3007
|
+
* Adds a `where` clause to the query.
|
|
3008
|
+
*
|
|
3009
|
+
* Calling this method will select only those rows that fulfill a specified condition.
|
|
3010
|
+
*
|
|
3011
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
|
3012
|
+
*
|
|
3013
|
+
* @param where the `where` clause.
|
|
3014
|
+
*
|
|
3015
|
+
* @example
|
|
3016
|
+
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
|
3017
|
+
*
|
|
3018
|
+
* ```ts
|
|
3019
|
+
* // Select all cars with green color
|
|
3020
|
+
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
|
3021
|
+
* // or
|
|
3022
|
+
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
|
3023
|
+
* ```
|
|
3024
|
+
*
|
|
3025
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
3026
|
+
*
|
|
3027
|
+
* ```ts
|
|
3028
|
+
* // Select all BMW cars with a green color
|
|
3029
|
+
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
3030
|
+
*
|
|
3031
|
+
* // Select all cars with the green or blue color
|
|
3032
|
+
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
3033
|
+
* ```
|
|
3034
|
+
*/
|
|
3035
|
+
where(where) {
|
|
3036
|
+
if (typeof where === "function") where = where(new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
3037
|
+
sqlAliasedBehavior: "sql",
|
|
3038
|
+
sqlBehavior: "sql"
|
|
3039
|
+
})));
|
|
3040
|
+
this.config.where = where;
|
|
3041
|
+
return this;
|
|
3042
|
+
}
|
|
3043
|
+
/**
|
|
3044
|
+
* Adds a `having` clause to the query.
|
|
3045
|
+
*
|
|
3046
|
+
* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
|
|
3047
|
+
*
|
|
3048
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
|
3049
|
+
*
|
|
3050
|
+
* @param having the `having` clause.
|
|
3051
|
+
*
|
|
3052
|
+
* @example
|
|
3053
|
+
*
|
|
3054
|
+
* ```ts
|
|
3055
|
+
* // Select all brands with more than one car
|
|
3056
|
+
* await db.select({
|
|
3057
|
+
* brand: cars.brand,
|
|
3058
|
+
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
|
3059
|
+
* })
|
|
3060
|
+
* .from(cars)
|
|
3061
|
+
* .groupBy(cars.brand)
|
|
3062
|
+
* .having(({ count }) => gt(count, 1));
|
|
3063
|
+
* ```
|
|
3064
|
+
*/
|
|
3065
|
+
having(having) {
|
|
3066
|
+
if (typeof having === "function") having = having(new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
3067
|
+
sqlAliasedBehavior: "sql",
|
|
3068
|
+
sqlBehavior: "sql"
|
|
3069
|
+
})));
|
|
3070
|
+
this.config.having = having;
|
|
3071
|
+
return this;
|
|
3072
|
+
}
|
|
3073
|
+
groupBy(...columns) {
|
|
3074
|
+
if (typeof columns[0] === "function") {
|
|
3075
|
+
const groupBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
3076
|
+
sqlAliasedBehavior: "alias",
|
|
3077
|
+
sqlBehavior: "sql"
|
|
3078
|
+
})));
|
|
3079
|
+
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
|
3080
|
+
} else this.config.groupBy = columns;
|
|
3081
|
+
return this;
|
|
3082
|
+
}
|
|
3083
|
+
orderBy(...columns) {
|
|
3084
|
+
if (typeof columns[0] === "function") {
|
|
3085
|
+
const orderBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
3086
|
+
sqlAliasedBehavior: "alias",
|
|
3087
|
+
sqlBehavior: "sql"
|
|
3088
|
+
})));
|
|
3089
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
3090
|
+
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
3091
|
+
else this.config.orderBy = orderByArray;
|
|
3092
|
+
} else {
|
|
3093
|
+
const orderByArray = columns;
|
|
3094
|
+
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
3095
|
+
else this.config.orderBy = orderByArray;
|
|
3096
|
+
}
|
|
3097
|
+
return this;
|
|
3098
|
+
}
|
|
3099
|
+
/**
|
|
3100
|
+
* Adds a `limit` clause to the query.
|
|
3101
|
+
*
|
|
3102
|
+
* Calling this method will set the maximum number of rows that will be returned by this query.
|
|
3103
|
+
*
|
|
3104
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
3105
|
+
*
|
|
3106
|
+
* @param limit the `limit` clause.
|
|
3107
|
+
*
|
|
3108
|
+
* @example
|
|
3109
|
+
*
|
|
3110
|
+
* ```ts
|
|
3111
|
+
* // Get the first 10 people from this query.
|
|
3112
|
+
* await db.select().from(people).limit(10);
|
|
3113
|
+
* ```
|
|
3114
|
+
*/
|
|
3115
|
+
limit(limit) {
|
|
3116
|
+
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).limit = limit;
|
|
3117
|
+
else this.config.limit = limit;
|
|
3118
|
+
return this;
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
* Adds an `offset` clause to the query.
|
|
3122
|
+
*
|
|
3123
|
+
* Calling this method will skip a number of rows when returning results from this query.
|
|
3124
|
+
*
|
|
3125
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
3126
|
+
*
|
|
3127
|
+
* @param offset the `offset` clause.
|
|
3128
|
+
*
|
|
3129
|
+
* @example
|
|
3130
|
+
*
|
|
3131
|
+
* ```ts
|
|
3132
|
+
* // Get the 10th-20th people from this query.
|
|
3133
|
+
* await db.select().from(people).offset(10).limit(10);
|
|
3134
|
+
* ```
|
|
3135
|
+
*/
|
|
3136
|
+
offset(offset) {
|
|
3137
|
+
if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).offset = offset;
|
|
3138
|
+
else this.config.offset = offset;
|
|
3139
|
+
return this;
|
|
3140
|
+
}
|
|
3141
|
+
$withCache(config) {
|
|
3142
|
+
this.cacheConfig = config === void 0 ? {
|
|
3143
|
+
config: {},
|
|
3144
|
+
enabled: true,
|
|
3145
|
+
autoInvalidate: true
|
|
3146
|
+
} : config === false ? { enabled: false } : {
|
|
3147
|
+
enabled: true,
|
|
3148
|
+
autoInvalidate: true,
|
|
3149
|
+
...config
|
|
3150
|
+
};
|
|
3151
|
+
return this;
|
|
3152
|
+
}
|
|
3153
|
+
getSQL() {
|
|
3154
|
+
this.config.fieldsFlat = orderSelectedFields(this.config.fields);
|
|
3155
|
+
return this.dialect.buildSelectQuery(this.config);
|
|
3156
|
+
}
|
|
3157
|
+
toSQL() {
|
|
3158
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
3159
|
+
}
|
|
3160
|
+
as(alias) {
|
|
3161
|
+
const usedTables = [];
|
|
3162
|
+
usedTables.push(...extractUsedTable(this.config.table));
|
|
3163
|
+
if (this.config.joins) for (const it of this.config.joins) usedTables.push(...extractUsedTable(it.table));
|
|
3164
|
+
return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]), new SelectionProxyHandler({
|
|
3165
|
+
alias,
|
|
3166
|
+
sqlAliasedBehavior: "alias",
|
|
3167
|
+
sqlBehavior: "error"
|
|
3168
|
+
}));
|
|
3169
|
+
}
|
|
3170
|
+
/** @internal */
|
|
3171
|
+
getSelectedFields() {
|
|
3172
|
+
return new Proxy(this.config.fields, new SelectionProxyHandler({
|
|
3173
|
+
alias: this.tableName,
|
|
3174
|
+
sqlAliasedBehavior: "alias",
|
|
3175
|
+
sqlBehavior: "error"
|
|
3176
|
+
}));
|
|
3177
|
+
}
|
|
3178
|
+
/** @internal */
|
|
3179
|
+
withoutSelectionCastCodecs() {
|
|
3180
|
+
return this;
|
|
3181
|
+
}
|
|
3182
|
+
$dynamic() {
|
|
3183
|
+
return this;
|
|
3184
|
+
}
|
|
3185
|
+
};
|
|
3186
|
+
function createSetOperator(type, isAll) {
|
|
3187
|
+
return (leftSelect, rightSelect, ...restSelects) => {
|
|
3188
|
+
const setOperators = [rightSelect, ...restSelects].map((select) => ({
|
|
3189
|
+
type,
|
|
3190
|
+
isAll,
|
|
3191
|
+
rightSelect: select
|
|
3192
|
+
}));
|
|
3193
|
+
for (const setOperator of setOperators) if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
3194
|
+
return leftSelect.addSetOperators(setOperators);
|
|
3195
|
+
};
|
|
3196
|
+
}
|
|
3197
|
+
var getSQLiteSetOperators = () => ({
|
|
3198
|
+
union,
|
|
3199
|
+
unionAll,
|
|
3200
|
+
intersect,
|
|
3201
|
+
except
|
|
3202
|
+
});
|
|
3203
|
+
var union = createSetOperator("union", false);
|
|
3204
|
+
var unionAll = createSetOperator("union", true);
|
|
3205
|
+
var intersect = createSetOperator("intersect", false);
|
|
3206
|
+
var except = createSetOperator("except", false);
|
|
3207
|
+
|
|
3208
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/dialect.js
|
|
3209
|
+
var SQLiteDialect = class {
|
|
3210
|
+
static [entityKind] = "SQLiteDialect";
|
|
3211
|
+
mapperGenerators;
|
|
3212
|
+
constructor(config) {
|
|
3213
|
+
this.mapperGenerators = config?.useJitMappers ? {
|
|
3214
|
+
rows: makeJitQueryMapper,
|
|
3215
|
+
relationalRows: makeJitRqbMapper
|
|
3216
|
+
} : {
|
|
3217
|
+
rows: makeDefaultQueryMapper,
|
|
3218
|
+
relationalRows: makeDefaultRqbMapper
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
escapeName(name2) {
|
|
3222
|
+
return `"${name2.replace(/"/g, '""')}"`;
|
|
3223
|
+
}
|
|
3224
|
+
escapeParam(_num) {
|
|
3225
|
+
return "?";
|
|
3226
|
+
}
|
|
3227
|
+
escapeString(str) {
|
|
3228
|
+
return `'${str.replace(/'/g, "''")}'`;
|
|
3229
|
+
}
|
|
3230
|
+
buildWithCTE(queries) {
|
|
3231
|
+
if (!queries?.length) return void 0;
|
|
3232
|
+
const withSqlChunks = [sql`with `];
|
|
3233
|
+
for (const [i, w] of queries.entries()) {
|
|
3234
|
+
withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
|
|
3235
|
+
if (i < queries.length - 1) withSqlChunks.push(sql`, `);
|
|
3236
|
+
}
|
|
3237
|
+
withSqlChunks.push(sql` `);
|
|
3238
|
+
return sql.join(withSqlChunks);
|
|
3239
|
+
}
|
|
3240
|
+
buildDeleteQuery({ table, where, returning, withList, limit, orderBy }) {
|
|
3241
|
+
const withSql = this.buildWithCTE(withList);
|
|
3242
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
3243
|
+
return sql`${withSql}delete from ${table}${where ? sql` where ${where}` : void 0}${returningSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}`;
|
|
3244
|
+
}
|
|
3245
|
+
buildUpdateSet(table, set) {
|
|
3246
|
+
const tableColumns = table[Table.Symbol.Columns];
|
|
3247
|
+
const columnNames = Object.keys(tableColumns).filter((colName) => set[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0);
|
|
3248
|
+
const setLength = columnNames.length;
|
|
3249
|
+
return sql.join(columnNames.flatMap((colName, i) => {
|
|
3250
|
+
const col = tableColumns[colName];
|
|
3251
|
+
const onUpdateFnResult = col.onUpdateFn?.();
|
|
3252
|
+
const value = set[colName] ?? (is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col));
|
|
3253
|
+
const res = sql`${sql.identifier(col.name)} = ${value}`;
|
|
3254
|
+
if (i < setLength - 1) return [res, sql.raw(", ")];
|
|
3255
|
+
return [res];
|
|
3256
|
+
}));
|
|
3257
|
+
}
|
|
3258
|
+
buildUpdateQuery({ table, set, where, returning, withList, joins, from, limit, orderBy }) {
|
|
3259
|
+
const withSql = this.buildWithCTE(withList);
|
|
3260
|
+
const setSql = this.buildUpdateSet(table, set);
|
|
3261
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
|
3262
|
+
const joinsSql = this.buildJoins(joins);
|
|
3263
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
3264
|
+
return sql`${withSql}update ${table} set ${setSql}${fromSql}${joinsSql}${where ? sql` where ${where}` : void 0}${returningSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}`;
|
|
3265
|
+
}
|
|
3266
|
+
/**
|
|
3267
|
+
* Builds selection SQL with provided fields/expressions
|
|
3268
|
+
*
|
|
3269
|
+
* Examples:
|
|
3270
|
+
*
|
|
3271
|
+
* `select <selection> from`
|
|
3272
|
+
*
|
|
3273
|
+
* `insert ... returning <selection>`
|
|
3274
|
+
*
|
|
3275
|
+
* If `isSingleTable` is true, then columns won't be prefixed with table name
|
|
3276
|
+
*/
|
|
3277
|
+
buildSelection(fields, { isSingleTable = false } = {}) {
|
|
3278
|
+
const columnsLen = fields.length;
|
|
3279
|
+
const chunks = fields.flatMap(({ field }, i) => {
|
|
3280
|
+
const chunk = [];
|
|
3281
|
+
if (is(field, SQL.Aliased)) if (field.isSelectionField) {
|
|
3282
|
+
if (!isSingleTable && field.origin !== void 0) chunk.push(sql.identifier(field.origin), sql.raw("."));
|
|
3283
|
+
chunk.push(sql.identifier(field.fieldAlias));
|
|
3284
|
+
} else {
|
|
3285
|
+
const query = field.sql;
|
|
3286
|
+
if (isSingleTable) {
|
|
3287
|
+
const newSql = new SQL(query.queryChunks.map((c) => {
|
|
3288
|
+
if (is(c, Column)) return sql.identifier(c.name);
|
|
3289
|
+
return c;
|
|
3290
|
+
}));
|
|
3291
|
+
chunk.push(query.shouldInlineParams ? newSql.inlineParams() : newSql);
|
|
3292
|
+
} else chunk.push(query);
|
|
3293
|
+
chunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);
|
|
3294
|
+
}
|
|
3295
|
+
else if (is(field, SQL)) {
|
|
3296
|
+
const query = field;
|
|
3297
|
+
if (isSingleTable) {
|
|
3298
|
+
const newSql = new SQL(query.queryChunks.map((c) => {
|
|
3299
|
+
if (is(c, Column)) return sql.identifier(c.name);
|
|
3300
|
+
return c;
|
|
3301
|
+
}));
|
|
3302
|
+
chunk.push(query.shouldInlineParams ? newSql.inlineParams() : newSql);
|
|
3303
|
+
} else chunk.push(query);
|
|
3304
|
+
} else if (is(field, Column)) if (field.columnType === "SQLiteNumericBigInt" || field.columnType === "SQLiteNumeric") if (isSingleTable) chunk.push(field.isAlias ? sql`cast(${sql.identifier(getOriginalColumnFromAlias(field).name)} as text) as ${field}` : sql`cast(${sql.identifier(field.name)} as text)`);
|
|
3305
|
+
else chunk.push(field.isAlias ? sql`cast(${getOriginalColumnFromAlias(field)} as text) as ${field}` : sql`cast(${field} as text)`);
|
|
3306
|
+
else if (isSingleTable) chunk.push(field.isAlias ? sql`${sql.identifier(getOriginalColumnFromAlias(field).name)} as ${field}` : sql.identifier(field.name));
|
|
3307
|
+
else chunk.push(field.isAlias ? sql`${getOriginalColumnFromAlias(field)} as ${field}` : field);
|
|
3308
|
+
else if (is(field, Subquery)) if (!field._.isWith) chunk.push(sql`(${field._.sql}) ${sql.identifier(field._.alias)}`);
|
|
3309
|
+
else chunk.push(field);
|
|
3310
|
+
if (i < columnsLen - 1) chunk.push(sql`, `);
|
|
3311
|
+
return chunk;
|
|
3312
|
+
});
|
|
3313
|
+
return sql.join(chunks);
|
|
3314
|
+
}
|
|
3315
|
+
buildJoins(joins) {
|
|
3316
|
+
if (!joins || joins.length === 0) return;
|
|
3317
|
+
const joinsArray = [];
|
|
3318
|
+
if (joins) for (const [index2, joinMeta] of joins.entries()) {
|
|
3319
|
+
if (index2 === 0) joinsArray.push(sql` `);
|
|
3320
|
+
const table = joinMeta.table;
|
|
3321
|
+
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
3322
|
+
if (is(table, SQLiteTable)) {
|
|
3323
|
+
const tableName = table[SQLiteTable.Symbol.Name];
|
|
3324
|
+
const tableSchema = table[SQLiteTable.Symbol.Schema];
|
|
3325
|
+
const origTableName = table[SQLiteTable.Symbol.OriginalName];
|
|
3326
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
3327
|
+
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
3328
|
+
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
3329
|
+
if (index2 < joins.length - 1) joinsArray.push(sql` `);
|
|
3330
|
+
}
|
|
3331
|
+
return sql.join(joinsArray);
|
|
3332
|
+
}
|
|
3333
|
+
buildLimit(limit) {
|
|
3334
|
+
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
|
3335
|
+
}
|
|
3336
|
+
buildOrderBy(orderBy) {
|
|
3337
|
+
const orderByList = [];
|
|
3338
|
+
if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
|
|
3339
|
+
orderByList.push(orderByValue);
|
|
3340
|
+
if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
|
|
3341
|
+
}
|
|
3342
|
+
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
3343
|
+
}
|
|
3344
|
+
buildFromTable(table) {
|
|
3345
|
+
if (is(table, Table) && table[Table.Symbol.IsAlias]) return sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? "")}.`.if(table[Table.Symbol.Schema])}${sql.identifier(table[Table.Symbol.OriginalName])} ${sql.identifier(table[Table.Symbol.Name])}`;
|
|
3346
|
+
if (is(table, View) && table[ViewBaseConfig].isAlias) {
|
|
3347
|
+
let fullName = sql`${sql.identifier(table[ViewBaseConfig].originalName)}`;
|
|
3348
|
+
if (table[ViewBaseConfig].schema) fullName = sql`${sql.identifier(table[ViewBaseConfig].schema)}.${fullName}`;
|
|
3349
|
+
return sql`${fullName} ${sql.identifier(table[ViewBaseConfig].name)}`;
|
|
3350
|
+
}
|
|
3351
|
+
return table;
|
|
3352
|
+
}
|
|
3353
|
+
buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, distinct, setOperators }) {
|
|
3354
|
+
const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
|
|
3355
|
+
for (const f of fieldsList) if (is(f.field, Column) && getTableName(f.field.table) !== (is(table, Subquery) ? table._.alias : is(table, SQLiteViewBase) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : getTableName(table)) && !((table2) => joins?.some(({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])))(f.field.table)) {
|
|
3356
|
+
const tableName = getTableName(f.field.table);
|
|
3357
|
+
throw new Error(`Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`);
|
|
3358
|
+
}
|
|
3359
|
+
const isSingleTable = !joins || joins.length === 0;
|
|
3360
|
+
const withSql = this.buildWithCTE(withList);
|
|
3361
|
+
const distinctSql = distinct ? sql` distinct` : void 0;
|
|
3362
|
+
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
|
3363
|
+
const tableSql = this.buildFromTable(table);
|
|
3364
|
+
const joinsSql = this.buildJoins(joins);
|
|
3365
|
+
const whereSql = where ? sql` where ${where}` : void 0;
|
|
3366
|
+
const havingSql = having ? sql` having ${having}` : void 0;
|
|
3367
|
+
const groupByList = [];
|
|
3368
|
+
if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
|
|
3369
|
+
groupByList.push(groupByValue);
|
|
3370
|
+
if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
|
|
3371
|
+
}
|
|
3372
|
+
const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0}${havingSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}${offset ? sql` offset ${offset}` : void 0}`;
|
|
3373
|
+
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
3374
|
+
return finalQuery;
|
|
3375
|
+
}
|
|
3376
|
+
buildSetOperations(leftSelect, setOperators) {
|
|
3377
|
+
const [setOperator, ...rest] = setOperators;
|
|
3378
|
+
if (!setOperator) throw new Error("Cannot pass undefined values to any set operator");
|
|
3379
|
+
if (rest.length === 0) return this.buildSetOperationQuery({
|
|
3380
|
+
leftSelect,
|
|
3381
|
+
setOperator
|
|
3382
|
+
});
|
|
3383
|
+
return this.buildSetOperations(this.buildSetOperationQuery({
|
|
3384
|
+
leftSelect,
|
|
3385
|
+
setOperator
|
|
3386
|
+
}), rest);
|
|
3387
|
+
}
|
|
3388
|
+
buildSetOperationQuery({ leftSelect, setOperator: { type, isAll, rightSelect, limit, orderBy, offset } }) {
|
|
3389
|
+
const leftChunk = sql`${leftSelect.getSQL()} `;
|
|
3390
|
+
const rightChunk = sql`${rightSelect.getSQL()}`;
|
|
3391
|
+
let orderBySql;
|
|
3392
|
+
if (orderBy && orderBy.length > 0) {
|
|
3393
|
+
const orderByValues = [];
|
|
3394
|
+
for (const singleOrderBy of orderBy) if (is(singleOrderBy, SQLiteColumn)) orderByValues.push(sql.identifier(singleOrderBy.name));
|
|
3395
|
+
else if (is(singleOrderBy, SQL)) {
|
|
3396
|
+
for (let i = 0; i < singleOrderBy.queryChunks.length; i++) {
|
|
3397
|
+
const chunk = singleOrderBy.queryChunks[i];
|
|
3398
|
+
if (is(chunk, SQLiteColumn)) singleOrderBy.queryChunks[i] = sql.identifier(chunk.name);
|
|
3399
|
+
}
|
|
3400
|
+
orderByValues.push(sql`${singleOrderBy}`);
|
|
3401
|
+
} else orderByValues.push(sql`${singleOrderBy}`);
|
|
3402
|
+
orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)}`;
|
|
3403
|
+
}
|
|
3404
|
+
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
|
3405
|
+
const operatorChunk = sql.raw(`${type} ${isAll ? "all " : ""}`);
|
|
3406
|
+
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
|
3407
|
+
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
|
3408
|
+
}
|
|
3409
|
+
buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
|
3410
|
+
const valuesSqlList = [];
|
|
3411
|
+
const columns = table[Table.Symbol.Columns];
|
|
3412
|
+
const colEntries = Object.entries(columns);
|
|
3413
|
+
const colEntriesFiltered = select && !is(valuesOrSelect, SQL) ? Object.keys(valuesOrSelect.getSelectedFields()).map((key) => [key, columns[key]]) : colEntries.filter(([_, col]) => !col.shouldDisableInsert());
|
|
3414
|
+
const insertOrder = colEntriesFiltered.map(([, column]) => sql.identifier(column.name));
|
|
3415
|
+
if (select) {
|
|
3416
|
+
const select2 = valuesOrSelect;
|
|
3417
|
+
if (is(select2, SQL)) valuesSqlList.push(select2);
|
|
3418
|
+
else valuesSqlList.push(select2.getSQL());
|
|
3419
|
+
} else {
|
|
3420
|
+
const values = valuesOrSelect;
|
|
3421
|
+
valuesSqlList.push(sql.raw("values "));
|
|
3422
|
+
for (const [valueIndex, value] of values.entries()) {
|
|
3423
|
+
const valueList = [];
|
|
3424
|
+
for (const [fieldName, col] of colEntriesFiltered) {
|
|
3425
|
+
const colValue = value[fieldName];
|
|
3426
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
|
3427
|
+
let defaultValue;
|
|
3428
|
+
if (col.default !== null && col.default !== void 0) defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
|
|
3429
|
+
else if (col.defaultFn !== void 0) {
|
|
3430
|
+
const defaultFnResult = col.defaultFn();
|
|
3431
|
+
defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
|
3432
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
|
3433
|
+
const onUpdateFnResult = col.onUpdateFn();
|
|
3434
|
+
defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
|
3435
|
+
} else defaultValue = sql`null`;
|
|
3436
|
+
valueList.push(defaultValue);
|
|
3437
|
+
} else valueList.push(colValue);
|
|
3438
|
+
}
|
|
3439
|
+
valuesSqlList.push(valueList);
|
|
3440
|
+
if (valueIndex < values.length - 1) valuesSqlList.push(sql`, `);
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
const withSql = this.buildWithCTE(withList);
|
|
3444
|
+
const valuesSql = sql.join(valuesSqlList);
|
|
3445
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
3446
|
+
return sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflict?.length ? sql.join(onConflict) : void 0}${returningSql}`;
|
|
3447
|
+
}
|
|
3448
|
+
sqlToQuery(sql2, invokeSource) {
|
|
3449
|
+
return sql2.toQuery({
|
|
3450
|
+
escapeName: this.escapeName,
|
|
3451
|
+
escapeParam: this.escapeParam,
|
|
3452
|
+
escapeString: this.escapeString,
|
|
3453
|
+
invokeSource
|
|
3454
|
+
});
|
|
3455
|
+
}
|
|
3456
|
+
nestedSelectionerror() {
|
|
3457
|
+
throw new DrizzleError({ message: `Views with nested selections are not supported by the relational query builder` });
|
|
3458
|
+
}
|
|
3459
|
+
buildRqbColumn(table, column, key, inJson) {
|
|
3460
|
+
if (is(column, Column)) {
|
|
3461
|
+
const name2 = sql`${table}.${sql.identifier(column.name)}`;
|
|
3462
|
+
switch (column.columnType) {
|
|
3463
|
+
case "SQLiteBigInt":
|
|
3464
|
+
case "SQLiteBlobJson":
|
|
3465
|
+
case "SQLiteBlobBuffer":
|
|
3466
|
+
if (!inJson) return sql`${name2} as ${sql.identifier(key)}`;
|
|
3467
|
+
return sql`hex(${name2}) as ${sql.identifier(key)}`;
|
|
3468
|
+
case "SQLiteNumeric":
|
|
3469
|
+
case "SQLiteNumericNumber":
|
|
3470
|
+
case "SQLiteNumericBigInt":
|
|
3471
|
+
return sql`cast(${name2} as text) as ${sql.identifier(key)}`;
|
|
3472
|
+
case "SQLiteCustomColumn":
|
|
3473
|
+
if (!inJson) return sql`${name2} as ${sql.identifier(key)}`;
|
|
3474
|
+
return sql`${column.jsonSelectIdentifier(name2, sql)} as ${sql.identifier(key)}`;
|
|
3475
|
+
default:
|
|
3476
|
+
return sql`${name2} as ${sql.identifier(key)}`;
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
return sql`${table}.${is(column, SQL.Aliased) ? sql.identifier(column.fieldAlias) : isSQLWrapper(column) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
|
3480
|
+
}
|
|
3481
|
+
unwrapAllColumns = (table, selection, inJson) => {
|
|
3482
|
+
return sql.join(Object.entries(table[TableColumns]).map(([k, v]) => {
|
|
3483
|
+
selection.push({
|
|
3484
|
+
key: k,
|
|
3485
|
+
field: v
|
|
3486
|
+
});
|
|
3487
|
+
return this.buildRqbColumn(table, v, k, inJson);
|
|
3488
|
+
}), sql`, `);
|
|
3489
|
+
};
|
|
3490
|
+
getSelectedTableColumns = (table, columns) => {
|
|
3491
|
+
const selectedColumns = [];
|
|
3492
|
+
const columnContainer = table[TableColumns];
|
|
3493
|
+
const entries = Object.entries(columns);
|
|
3494
|
+
let colSelectionMode;
|
|
3495
|
+
for (const [k, v] of entries) {
|
|
3496
|
+
if (v === void 0) continue;
|
|
3497
|
+
colSelectionMode = colSelectionMode || v;
|
|
3498
|
+
if (v) {
|
|
3499
|
+
const column = columnContainer[k];
|
|
3500
|
+
selectedColumns.push({
|
|
3501
|
+
column,
|
|
3502
|
+
tsName: k
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
if (colSelectionMode === false) for (const [k, v] of Object.entries(columnContainer)) {
|
|
3507
|
+
if (columns[k] === false) continue;
|
|
3508
|
+
selectedColumns.push({
|
|
3509
|
+
column: v,
|
|
3510
|
+
tsName: k
|
|
3511
|
+
});
|
|
3512
|
+
}
|
|
3513
|
+
return selectedColumns;
|
|
3514
|
+
};
|
|
3515
|
+
buildColumns = (table, selection, inJson, params) => params?.columns ? (() => {
|
|
3516
|
+
const columnIdentifiers = [];
|
|
3517
|
+
const selectedColumns = this.getSelectedTableColumns(table, params?.columns);
|
|
3518
|
+
for (const { column, tsName } of selectedColumns) {
|
|
3519
|
+
columnIdentifiers.push(this.buildRqbColumn(table, column, tsName, inJson));
|
|
3520
|
+
selection.push({
|
|
3521
|
+
key: tsName,
|
|
3522
|
+
field: column
|
|
3523
|
+
});
|
|
3524
|
+
}
|
|
3525
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
|
3526
|
+
})() : this.unwrapAllColumns(table, selection, inJson);
|
|
3527
|
+
buildRelationalQuery({ schema, table, tableConfig, queryConfig: config, relationWhere, mode, isNested, errorPath, depth, throughJoin, jsonb }) {
|
|
3528
|
+
const selection = [];
|
|
3529
|
+
const isSingle = mode === "first";
|
|
3530
|
+
const params = config === true ? void 0 : config;
|
|
3531
|
+
const currentPath = errorPath ?? "";
|
|
3532
|
+
const currentDepth = depth ?? 0;
|
|
3533
|
+
if (!currentDepth) table = aliasedTable(table, `d${currentDepth}`);
|
|
3534
|
+
const limit = isSingle ? 1 : params?.limit;
|
|
3535
|
+
const offset = params?.offset;
|
|
3536
|
+
const columns = this.buildColumns(table, selection, !!isNested, params);
|
|
3537
|
+
const where = params?.where && relationWhere ? and(relationsFilterToSQL(table, params.where, tableConfig.relations, schema), relationWhere) : params?.where ? relationsFilterToSQL(table, params.where, tableConfig.relations, schema) : relationWhere;
|
|
3538
|
+
const order = params?.orderBy ? relationsOrderToSQL(table, params.orderBy) : void 0;
|
|
3539
|
+
const extras = params?.extras ? relationExtrasToSQL(table, params.extras) : void 0;
|
|
3540
|
+
if (extras) selection.push(...extras.selection);
|
|
3541
|
+
const joins = params ? (() => {
|
|
3542
|
+
const { with: joins2 } = params;
|
|
3543
|
+
if (!joins2) return;
|
|
3544
|
+
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
3545
|
+
if (!withEntries.length) return;
|
|
3546
|
+
return sql.join(withEntries.map(([k, join]) => {
|
|
3547
|
+
const relation = tableConfig.relations[k];
|
|
3548
|
+
const isSingle2 = is(relation, One);
|
|
3549
|
+
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
3550
|
+
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
|
3551
|
+
const { filter, joinCondition } = relationToSQL(relation, table, targetTable, throughTable);
|
|
3552
|
+
const throughJoin2 = throughTable ? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}` : void 0;
|
|
3553
|
+
const innerQuery = this.buildRelationalQuery({
|
|
3554
|
+
table: targetTable,
|
|
3555
|
+
mode: isSingle2 ? "first" : "many",
|
|
3556
|
+
schema,
|
|
3557
|
+
queryConfig: join,
|
|
3558
|
+
tableConfig: schema[relation.targetTableName],
|
|
3559
|
+
relationWhere: filter,
|
|
3560
|
+
isNested: true,
|
|
3561
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
|
3562
|
+
depth: currentDepth + 1,
|
|
3563
|
+
throughJoin: throughJoin2,
|
|
3564
|
+
jsonb
|
|
3565
|
+
});
|
|
3566
|
+
selection.push({
|
|
3567
|
+
field: targetTable,
|
|
3568
|
+
key: k,
|
|
3569
|
+
selection: innerQuery.selection,
|
|
3570
|
+
isArray: !isSingle2,
|
|
3571
|
+
isOptional: (relation.optional ?? false) || join !== true && !!join.where
|
|
3572
|
+
});
|
|
3573
|
+
const jsonColumns = sql.join(innerQuery.selection.map((s) => {
|
|
3574
|
+
return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
|
|
3575
|
+
}), sql`, `);
|
|
3576
|
+
const json = isNested ? jsonb : sql`json`;
|
|
3577
|
+
return isSingle2 ? sql`(select ${json}_object(${jsonColumns}) as ${sql.identifier("r")} from (${innerQuery.sql}) as ${sql.identifier("t")}) as ${sql.identifier(k)}` : sql`coalesce((select ${json}_group_array(json_object(${jsonColumns})) as ${sql.identifier("r")} from (${innerQuery.sql}) as ${sql.identifier("t")}), ${jsonb}_array()) as ${sql.identifier(k)}`;
|
|
3578
|
+
}), sql`, `);
|
|
3579
|
+
})() : void 0;
|
|
3580
|
+
const selectionArr = [
|
|
3581
|
+
columns,
|
|
3582
|
+
extras?.sql,
|
|
3583
|
+
joins
|
|
3584
|
+
].filter((e) => e !== void 0);
|
|
3585
|
+
if (!selectionArr.length) throw new DrizzleError({ message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}` });
|
|
3586
|
+
return {
|
|
3587
|
+
sql: sql`select ${sql.join(selectionArr, sql`, `)} from ${getTableAsAliasSQL(table)}${throughJoin}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`,
|
|
3588
|
+
selection
|
|
3589
|
+
};
|
|
3590
|
+
}
|
|
3591
|
+
};
|
|
3592
|
+
|
|
3593
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js
|
|
3594
|
+
var QueryBuilder = class {
|
|
3595
|
+
static [entityKind] = "SQLiteQueryBuilder";
|
|
3596
|
+
dialect;
|
|
3597
|
+
dialectConfig;
|
|
3598
|
+
constructor(dialect) {
|
|
3599
|
+
this.dialect = is(dialect, SQLiteDialect) ? dialect : void 0;
|
|
3600
|
+
this.dialectConfig = is(dialect, SQLiteDialect) ? void 0 : dialect;
|
|
3601
|
+
}
|
|
3602
|
+
$with = (alias, selection) => {
|
|
3603
|
+
const queryBuilder = this;
|
|
3604
|
+
const as = (qb) => {
|
|
3605
|
+
if (typeof qb === "function") qb = qb(queryBuilder);
|
|
3606
|
+
return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
|
|
3607
|
+
alias,
|
|
3608
|
+
sqlAliasedBehavior: "alias",
|
|
3609
|
+
sqlBehavior: "error"
|
|
3610
|
+
}));
|
|
3611
|
+
};
|
|
3612
|
+
return { as };
|
|
3613
|
+
};
|
|
3614
|
+
with(...queries) {
|
|
3615
|
+
const self = this;
|
|
3616
|
+
function select(fields) {
|
|
3617
|
+
return new SQLiteSelectBuilder({
|
|
3618
|
+
fields: fields ?? void 0,
|
|
3619
|
+
session: void 0,
|
|
3620
|
+
dialect: self.getDialect(),
|
|
3621
|
+
withList: queries
|
|
3622
|
+
});
|
|
3623
|
+
}
|
|
3624
|
+
function selectDistinct(fields) {
|
|
3625
|
+
return new SQLiteSelectBuilder({
|
|
3626
|
+
fields: fields ?? void 0,
|
|
3627
|
+
session: void 0,
|
|
3628
|
+
dialect: self.getDialect(),
|
|
3629
|
+
withList: queries,
|
|
3630
|
+
distinct: true
|
|
3631
|
+
});
|
|
3632
|
+
}
|
|
3633
|
+
return {
|
|
3634
|
+
select,
|
|
3635
|
+
selectDistinct
|
|
3636
|
+
};
|
|
3637
|
+
}
|
|
3638
|
+
select(fields) {
|
|
3639
|
+
return new SQLiteSelectBuilder({
|
|
3640
|
+
fields: fields ?? void 0,
|
|
3641
|
+
session: void 0,
|
|
3642
|
+
dialect: this.getDialect()
|
|
3643
|
+
});
|
|
3644
|
+
}
|
|
3645
|
+
selectDistinct(fields) {
|
|
3646
|
+
return new SQLiteSelectBuilder({
|
|
3647
|
+
fields: fields ?? void 0,
|
|
3648
|
+
session: void 0,
|
|
3649
|
+
dialect: this.getDialect(),
|
|
3650
|
+
distinct: true
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
getDialect() {
|
|
3654
|
+
if (!this.dialect) this.dialect = new SQLiteDialect(this.dialectConfig);
|
|
3655
|
+
return this.dialect;
|
|
3656
|
+
}
|
|
3657
|
+
};
|
|
3658
|
+
|
|
3659
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/count.js
|
|
3660
|
+
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
3661
|
+
static [entityKind] = "SQLiteCountBuilder";
|
|
3662
|
+
dialect;
|
|
3663
|
+
session;
|
|
3664
|
+
static buildCount(source, filters, parens) {
|
|
3665
|
+
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
3666
|
+
return parens ? sql`(${query})` : query;
|
|
3667
|
+
}
|
|
3668
|
+
constructor(countConfig) {
|
|
3669
|
+
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
3670
|
+
this.countConfig = countConfig;
|
|
3671
|
+
this.dialect = countConfig.dialect;
|
|
3672
|
+
this.session = countConfig.session;
|
|
3673
|
+
this.mapWith((e) => {
|
|
3674
|
+
if (typeof e === "number") return e;
|
|
3675
|
+
return Number(e ?? 0);
|
|
3676
|
+
});
|
|
3677
|
+
}
|
|
3678
|
+
executableSql;
|
|
3679
|
+
build() {
|
|
3680
|
+
if (!this.executableSql) {
|
|
3681
|
+
const { source, filters } = this.countConfig;
|
|
3682
|
+
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
3683
|
+
}
|
|
3684
|
+
return this.dialect.sqlToQuery(this.executableSql);
|
|
3685
|
+
}
|
|
3686
|
+
};
|
|
3687
|
+
|
|
3688
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/count.js
|
|
3689
|
+
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
3690
|
+
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
3691
|
+
constructor(countConfig) {
|
|
3692
|
+
super(countConfig);
|
|
3693
|
+
}
|
|
3694
|
+
/** @internal */
|
|
3695
|
+
executeRaw(placeholderValues) {
|
|
3696
|
+
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
3697
|
+
const v = rows[0]?.[0];
|
|
3698
|
+
if (typeof v === "number") return v;
|
|
3699
|
+
return v ? Number(v) : 0;
|
|
3700
|
+
}).execute(placeholderValues);
|
|
3701
|
+
}
|
|
3702
|
+
async execute(placeholderValues) {
|
|
3703
|
+
return await this.executeRaw(placeholderValues);
|
|
3704
|
+
}
|
|
3705
|
+
};
|
|
3706
|
+
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
3707
|
+
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
3708
|
+
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
3709
|
+
sync(placeholderValues) {
|
|
3710
|
+
return this.executeRaw(placeholderValues).sync();
|
|
3711
|
+
}
|
|
3712
|
+
};
|
|
3713
|
+
|
|
3714
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/query.js
|
|
3715
|
+
var RelationalQueryBuilder = class {
|
|
3716
|
+
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
3717
|
+
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
3718
|
+
this.mode = mode;
|
|
3719
|
+
this.schema = schema;
|
|
3720
|
+
this.table = table;
|
|
3721
|
+
this.tableConfig = tableConfig;
|
|
3722
|
+
this.dialect = dialect;
|
|
3723
|
+
this.session = session;
|
|
3724
|
+
this.forbidJsonb = forbidJsonb;
|
|
3725
|
+
this.builder = builder;
|
|
3726
|
+
}
|
|
3727
|
+
findMany(config) {
|
|
3728
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config ?? true, "many", this.forbidJsonb);
|
|
3729
|
+
}
|
|
3730
|
+
findFirst(config) {
|
|
3731
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config ?? true, "first", this.forbidJsonb);
|
|
3732
|
+
}
|
|
3733
|
+
};
|
|
3734
|
+
var SQLiteRelationalQuery = class {
|
|
3735
|
+
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
3736
|
+
/** @internal */
|
|
3737
|
+
mode;
|
|
3738
|
+
/** @internal */
|
|
3739
|
+
table;
|
|
3740
|
+
/** @internal */
|
|
3741
|
+
resultKind;
|
|
3742
|
+
constructor(resultKind, schema, table, tableConfig, dialect, session, config, mode, forbidJsonb) {
|
|
3743
|
+
this.schema = schema;
|
|
3744
|
+
this.tableConfig = tableConfig;
|
|
3745
|
+
this.dialect = dialect;
|
|
3746
|
+
this.session = session;
|
|
3747
|
+
this.config = config;
|
|
3748
|
+
this.forbidJsonb = forbidJsonb;
|
|
3749
|
+
this.resultKind = resultKind;
|
|
3750
|
+
this.mode = mode;
|
|
3751
|
+
this.table = table;
|
|
3752
|
+
}
|
|
3753
|
+
getSQL() {
|
|
3754
|
+
return this._getQuery().sql;
|
|
3755
|
+
}
|
|
3756
|
+
_getQuery() {
|
|
3757
|
+
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
3758
|
+
return this.dialect.buildRelationalQuery({
|
|
3759
|
+
schema: this.schema,
|
|
3760
|
+
table: this.table,
|
|
3761
|
+
tableConfig: this.tableConfig,
|
|
3762
|
+
queryConfig: this.config,
|
|
3763
|
+
mode: this.mode,
|
|
3764
|
+
jsonb
|
|
3765
|
+
});
|
|
3766
|
+
}
|
|
3767
|
+
_toSQL() {
|
|
3768
|
+
const query = this._getQuery();
|
|
3769
|
+
return {
|
|
3770
|
+
query,
|
|
3771
|
+
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
toSQL() {
|
|
3775
|
+
return this._toSQL().builtQuery;
|
|
3776
|
+
}
|
|
3777
|
+
};
|
|
3778
|
+
|
|
3779
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/query.js
|
|
3780
|
+
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
3781
|
+
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
3782
|
+
/** @internal */
|
|
3783
|
+
_prepare(prepare = false) {
|
|
3784
|
+
const { query, builtQuery } = this._toSQL();
|
|
3785
|
+
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
3786
|
+
isFirst: this.mode === "first",
|
|
3787
|
+
parseJson: true,
|
|
3788
|
+
parseJsonIfString: false,
|
|
3789
|
+
rootJsonMappers: false,
|
|
3790
|
+
selection: query.selection,
|
|
3791
|
+
arrayModeRoot: true
|
|
3792
|
+
});
|
|
3793
|
+
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
3794
|
+
}
|
|
3795
|
+
prepare() {
|
|
3796
|
+
return this._prepare(true);
|
|
3797
|
+
}
|
|
3798
|
+
async execute(placeholderValues) {
|
|
3799
|
+
return this._prepare().execute(placeholderValues);
|
|
3800
|
+
}
|
|
3801
|
+
};
|
|
3802
|
+
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
3803
|
+
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
3804
|
+
sync(placeholderValues) {
|
|
3805
|
+
return this._prepare().execute(placeholderValues).sync();
|
|
3806
|
+
}
|
|
3807
|
+
};
|
|
3808
|
+
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
3809
|
+
|
|
3810
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/delete.js
|
|
3811
|
+
var SQLiteDeleteBase = class {
|
|
3812
|
+
static [entityKind] = "SQLiteDelete";
|
|
3813
|
+
/** @internal */
|
|
3814
|
+
config;
|
|
3815
|
+
constructor(table, session, dialect, withList) {
|
|
3816
|
+
this.table = table;
|
|
3817
|
+
this.session = session;
|
|
3818
|
+
this.dialect = dialect;
|
|
3819
|
+
this.config = {
|
|
3820
|
+
table,
|
|
3821
|
+
withList
|
|
3822
|
+
};
|
|
3823
|
+
}
|
|
3824
|
+
/**
|
|
3825
|
+
* Adds a `where` clause to the query.
|
|
3826
|
+
*
|
|
3827
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
3828
|
+
*
|
|
3829
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
3830
|
+
*
|
|
3831
|
+
* @param where the `where` clause.
|
|
3832
|
+
*
|
|
3833
|
+
* @example
|
|
3834
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
3835
|
+
*
|
|
3836
|
+
* ```ts
|
|
3837
|
+
* // Delete all cars with green color
|
|
3838
|
+
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
3839
|
+
* // or
|
|
3840
|
+
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
3841
|
+
* ```
|
|
3842
|
+
*
|
|
3843
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
3844
|
+
*
|
|
3845
|
+
* ```ts
|
|
3846
|
+
* // Delete all BMW cars with a green color
|
|
3847
|
+
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
3848
|
+
*
|
|
3849
|
+
* // Delete all cars with the green or blue color
|
|
3850
|
+
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
3851
|
+
* ```
|
|
3852
|
+
*/
|
|
3853
|
+
where(where) {
|
|
3854
|
+
this.config.where = where;
|
|
3855
|
+
return this;
|
|
3856
|
+
}
|
|
3857
|
+
orderBy(...columns) {
|
|
3858
|
+
if (typeof columns[0] === "function") {
|
|
3859
|
+
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
3860
|
+
sqlAliasedBehavior: "alias",
|
|
3861
|
+
sqlBehavior: "sql"
|
|
3862
|
+
})));
|
|
3863
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
3864
|
+
this.config.orderBy = orderByArray;
|
|
3865
|
+
} else {
|
|
3866
|
+
const orderByArray = columns;
|
|
3867
|
+
this.config.orderBy = orderByArray;
|
|
3868
|
+
}
|
|
3869
|
+
return this;
|
|
3870
|
+
}
|
|
3871
|
+
limit(limit) {
|
|
3872
|
+
this.config.limit = limit;
|
|
3873
|
+
return this;
|
|
3874
|
+
}
|
|
3875
|
+
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
3876
|
+
this.config.returning = orderSelectedFields(fields);
|
|
3877
|
+
return this;
|
|
3878
|
+
}
|
|
3879
|
+
getSQL() {
|
|
3880
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
3881
|
+
}
|
|
3882
|
+
toSQL() {
|
|
3883
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
3884
|
+
}
|
|
3885
|
+
$dynamic() {
|
|
3886
|
+
return this;
|
|
3887
|
+
}
|
|
3888
|
+
};
|
|
3889
|
+
|
|
3890
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/delete.js
|
|
3891
|
+
var SQLiteAsyncDeleteBase = class extends SQLiteDeleteBase {
|
|
3892
|
+
static [entityKind] = "SQLiteAsyncDelete";
|
|
3893
|
+
/** @internal */
|
|
3894
|
+
_prepare(prepare = false) {
|
|
3895
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), "arrays", prepare, this.config.returning ? "all" : "run", this.config.returning ? this.dialect.mapperGenerators.rows(this.config.returning, void 0) : void 0, {
|
|
3896
|
+
type: "delete",
|
|
3897
|
+
tables: extractUsedTable(this.config.table)
|
|
3898
|
+
});
|
|
3899
|
+
}
|
|
3900
|
+
prepare() {
|
|
3901
|
+
return this._prepare(true);
|
|
3902
|
+
}
|
|
3903
|
+
run = (placeholderValues) => {
|
|
3904
|
+
return this._prepare().run(placeholderValues);
|
|
3905
|
+
};
|
|
3906
|
+
all = (placeholderValues) => {
|
|
3907
|
+
return this._prepare().all(placeholderValues);
|
|
3908
|
+
};
|
|
3909
|
+
get = (placeholderValues) => {
|
|
3910
|
+
return this._prepare().get(placeholderValues);
|
|
3911
|
+
};
|
|
3912
|
+
values = (placeholderValues) => {
|
|
3913
|
+
return this._prepare().values(placeholderValues);
|
|
3914
|
+
};
|
|
3915
|
+
async execute(placeholderValues) {
|
|
3916
|
+
return this._prepare().execute(placeholderValues);
|
|
3917
|
+
}
|
|
3918
|
+
};
|
|
3919
|
+
applyMixins(SQLiteAsyncDeleteBase, [QueryPromise]);
|
|
3920
|
+
|
|
3921
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/insert.js
|
|
3922
|
+
var SQLiteInsertBuilder = class {
|
|
3923
|
+
static [entityKind] = "SQLiteInsertBuilder";
|
|
3924
|
+
constructor(table, session, dialect, withList, builder = SQLiteInsertBase) {
|
|
3925
|
+
this.table = table;
|
|
3926
|
+
this.session = session;
|
|
3927
|
+
this.dialect = dialect;
|
|
3928
|
+
this.withList = withList;
|
|
3929
|
+
this.builder = builder;
|
|
3930
|
+
}
|
|
3931
|
+
values(values) {
|
|
3932
|
+
values = Array.isArray(values) ? values : [values];
|
|
3933
|
+
if (values.length === 0) throw new Error("values() must be called with at least one value");
|
|
3934
|
+
const mappedValues = values.map((entry) => {
|
|
3935
|
+
const result = {};
|
|
3936
|
+
const cols = this.table[Table.Symbol.Columns];
|
|
3937
|
+
for (const colKey of Object.keys(entry)) {
|
|
3938
|
+
const colValue = entry[colKey];
|
|
3939
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
|
3940
|
+
}
|
|
3941
|
+
return result;
|
|
3942
|
+
});
|
|
3943
|
+
return new this.builder(this.table, mappedValues, this.session, this.dialect, this.withList);
|
|
3944
|
+
}
|
|
3945
|
+
select(selectQuery) {
|
|
3946
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
|
3947
|
+
if (!is(select, SQL)) {
|
|
3948
|
+
const insertCols = Object.keys(this.table[Table.Symbol.Columns]);
|
|
3949
|
+
const selected = Object.keys(select._.selectedFields);
|
|
3950
|
+
for (const col of selected) if (!insertCols.includes(col)) throw new Error(`Insert select error: column "${col}" does not exist in table "${this.table[Table.Symbol.Name]}"`);
|
|
3951
|
+
}
|
|
3952
|
+
return new this.builder(this.table, select, this.session, this.dialect, this.withList, true);
|
|
3953
|
+
}
|
|
3954
|
+
};
|
|
3955
|
+
var SQLiteInsertBase = class {
|
|
3956
|
+
static [entityKind] = "SQLiteInsert";
|
|
3957
|
+
/** @internal */
|
|
3958
|
+
config;
|
|
3959
|
+
constructor(table, values, session, dialect, withList, select) {
|
|
3960
|
+
this.session = session;
|
|
3961
|
+
this.dialect = dialect;
|
|
3962
|
+
this.config = {
|
|
3963
|
+
table,
|
|
3964
|
+
values,
|
|
3965
|
+
withList,
|
|
3966
|
+
select
|
|
3967
|
+
};
|
|
3968
|
+
}
|
|
3969
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
|
3970
|
+
this.config.returning = orderSelectedFields(fields);
|
|
3971
|
+
return this;
|
|
3972
|
+
}
|
|
3973
|
+
/**
|
|
3974
|
+
* Adds an `on conflict do nothing` clause to the query.
|
|
3975
|
+
*
|
|
3976
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
|
3977
|
+
*
|
|
3978
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
|
3979
|
+
*
|
|
3980
|
+
* @param config The `target` and `where` clauses.
|
|
3981
|
+
*
|
|
3982
|
+
* @example
|
|
3983
|
+
* ```ts
|
|
3984
|
+
* // Insert one row and cancel the insert if there's a conflict
|
|
3985
|
+
* await db.insert(cars)
|
|
3986
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
3987
|
+
* .onConflictDoNothing();
|
|
3988
|
+
*
|
|
3989
|
+
* // Explicitly specify conflict target
|
|
3990
|
+
* await db.insert(cars)
|
|
3991
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
3992
|
+
* .onConflictDoNothing({ target: cars.id });
|
|
3993
|
+
* ```
|
|
3994
|
+
*/
|
|
3995
|
+
onConflictDoNothing(config = {}) {
|
|
3996
|
+
if (!this.config.onConflict) this.config.onConflict = [];
|
|
3997
|
+
if (config.target === void 0) this.config.onConflict.push(sql` on conflict do nothing`);
|
|
3998
|
+
else {
|
|
3999
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
|
4000
|
+
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
|
4001
|
+
this.config.onConflict.push(sql` on conflict ${targetSql} do nothing${whereSql}`);
|
|
4002
|
+
}
|
|
4003
|
+
return this;
|
|
4004
|
+
}
|
|
4005
|
+
/**
|
|
4006
|
+
* Adds an `on conflict do update` clause to the query.
|
|
4007
|
+
*
|
|
4008
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
|
4009
|
+
*
|
|
4010
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
|
4011
|
+
*
|
|
4012
|
+
* @param config The `target`, `set` and `where` clauses.
|
|
4013
|
+
*
|
|
4014
|
+
* @example
|
|
4015
|
+
* ```ts
|
|
4016
|
+
* // Update the row if there's a conflict
|
|
4017
|
+
* await db.insert(cars)
|
|
4018
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
4019
|
+
* .onConflictDoUpdate({
|
|
4020
|
+
* target: cars.id,
|
|
4021
|
+
* set: { brand: 'Porsche' }
|
|
4022
|
+
* });
|
|
4023
|
+
*
|
|
4024
|
+
* // Upsert with 'where' clause
|
|
4025
|
+
* await db.insert(cars)
|
|
4026
|
+
* .values({ id: 1, brand: 'BMW' })
|
|
4027
|
+
* .onConflictDoUpdate({
|
|
4028
|
+
* target: cars.id,
|
|
4029
|
+
* set: { brand: 'newBMW' },
|
|
4030
|
+
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
|
4031
|
+
* });
|
|
4032
|
+
* ```
|
|
4033
|
+
*/
|
|
4034
|
+
onConflictDoUpdate(config) {
|
|
4035
|
+
if (config.where && (config.targetWhere || config.setWhere)) throw new Error('You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.');
|
|
4036
|
+
if (!this.config.onConflict) this.config.onConflict = [];
|
|
4037
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
|
4038
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
|
4039
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
|
4040
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
|
4041
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
|
4042
|
+
this.config.onConflict.push(sql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`);
|
|
4043
|
+
return this;
|
|
4044
|
+
}
|
|
4045
|
+
getSQL() {
|
|
4046
|
+
return this.dialect.buildInsertQuery(this.config);
|
|
4047
|
+
}
|
|
4048
|
+
toSQL() {
|
|
4049
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
4050
|
+
}
|
|
4051
|
+
$dynamic() {
|
|
4052
|
+
return this;
|
|
4053
|
+
}
|
|
4054
|
+
};
|
|
4055
|
+
|
|
4056
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/insert.js
|
|
4057
|
+
var SQLiteAsyncInsertBase = class extends SQLiteInsertBase {
|
|
4058
|
+
static [entityKind] = "SQLiteAsyncInsert";
|
|
4059
|
+
/** @internal */
|
|
4060
|
+
_prepare(prepare = false) {
|
|
4061
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), "arrays", prepare, this.config.returning ? "all" : "run", this.config.returning ? this.dialect.mapperGenerators.rows(this.config.returning, void 0) : void 0, {
|
|
4062
|
+
type: "insert",
|
|
4063
|
+
tables: extractUsedTable(this.config.table)
|
|
4064
|
+
});
|
|
4065
|
+
}
|
|
4066
|
+
prepare() {
|
|
4067
|
+
return this._prepare(true);
|
|
4068
|
+
}
|
|
4069
|
+
run = (placeholderValues) => {
|
|
4070
|
+
return this._prepare().run(placeholderValues);
|
|
4071
|
+
};
|
|
4072
|
+
all = (placeholderValues) => {
|
|
4073
|
+
return this._prepare().all(placeholderValues);
|
|
4074
|
+
};
|
|
4075
|
+
get = (placeholderValues) => {
|
|
4076
|
+
return this._prepare().get(placeholderValues);
|
|
4077
|
+
};
|
|
4078
|
+
values = (placeholderValues) => {
|
|
4079
|
+
return this._prepare().values(placeholderValues);
|
|
4080
|
+
};
|
|
4081
|
+
async execute() {
|
|
4082
|
+
return this._prepare().execute();
|
|
4083
|
+
}
|
|
4084
|
+
};
|
|
4085
|
+
applyMixins(SQLiteAsyncInsertBase, [QueryPromise]);
|
|
4086
|
+
|
|
4087
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/raw.js
|
|
4088
|
+
var SQLiteRaw = class {
|
|
4089
|
+
static [entityKind] = "SQLiteRaw";
|
|
4090
|
+
constructor(prepared, sql2, query) {
|
|
4091
|
+
this.prepared = prepared;
|
|
4092
|
+
this.sql = sql2;
|
|
4093
|
+
this.query = query;
|
|
4094
|
+
}
|
|
4095
|
+
getSQL() {
|
|
4096
|
+
return this.sql;
|
|
4097
|
+
}
|
|
4098
|
+
getQuery() {
|
|
4099
|
+
return this.query;
|
|
4100
|
+
}
|
|
4101
|
+
_prepare() {
|
|
4102
|
+
return this.prepared;
|
|
4103
|
+
}
|
|
4104
|
+
};
|
|
4105
|
+
|
|
4106
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/raw.js
|
|
4107
|
+
var SQLiteAsyncRaw = class extends SQLiteRaw {
|
|
4108
|
+
static [entityKind] = "SQLiteAsyncRaw";
|
|
4109
|
+
constructor(prepared, sql2, query) {
|
|
4110
|
+
super(prepared, sql2, query);
|
|
4111
|
+
}
|
|
4112
|
+
execute(placeholderValues) {
|
|
4113
|
+
return this.prepared.execute(placeholderValues);
|
|
4114
|
+
}
|
|
4115
|
+
};
|
|
4116
|
+
applyMixins(SQLiteAsyncRaw, [QueryPromise]);
|
|
4117
|
+
|
|
4118
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/select.js
|
|
4119
|
+
var SQLiteAsyncSelectBase = class extends SQLiteSelectBase {
|
|
4120
|
+
static [entityKind] = "SQLiteAsyncSelect";
|
|
4121
|
+
/** @internal */
|
|
4122
|
+
_prepare(prepare = false) {
|
|
4123
|
+
const query = this.dialect.sqlToQuery(this.getSQL());
|
|
4124
|
+
const fieldsList = this.config.fieldsFlat;
|
|
4125
|
+
const mapper = this.dialect.mapperGenerators.rows(fieldsList, this.joinsNotNullableMap);
|
|
4126
|
+
return this.session.prepareQuery(query, "arrays", prepare, "all", mapper, {
|
|
4127
|
+
type: "select",
|
|
4128
|
+
tables: [...this.usedTables]
|
|
4129
|
+
}, this.cacheConfig);
|
|
4130
|
+
}
|
|
4131
|
+
prepare() {
|
|
4132
|
+
return this._prepare(true);
|
|
4133
|
+
}
|
|
4134
|
+
run = (placeholderValues) => {
|
|
4135
|
+
return this._prepare().run(placeholderValues);
|
|
4136
|
+
};
|
|
4137
|
+
all = (placeholderValues) => {
|
|
4138
|
+
return this._prepare().all(placeholderValues);
|
|
4139
|
+
};
|
|
4140
|
+
get = (placeholderValues) => {
|
|
4141
|
+
return this._prepare().get(placeholderValues);
|
|
4142
|
+
};
|
|
4143
|
+
values = (placeholderValues) => {
|
|
4144
|
+
return this._prepare().values(placeholderValues);
|
|
4145
|
+
};
|
|
4146
|
+
async execute() {
|
|
4147
|
+
return this._prepare().execute();
|
|
4148
|
+
}
|
|
4149
|
+
};
|
|
4150
|
+
applyMixins(SQLiteAsyncSelectBase, [QueryPromise]);
|
|
4151
|
+
|
|
4152
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/query-builders/update.js
|
|
4153
|
+
var SQLiteUpdateBuilder = class {
|
|
4154
|
+
static [entityKind] = "SQLiteUpdateBuilder";
|
|
4155
|
+
constructor(table, session, dialect, withList, builder = SQLiteUpdateBase) {
|
|
4156
|
+
this.table = table;
|
|
4157
|
+
this.session = session;
|
|
4158
|
+
this.dialect = dialect;
|
|
4159
|
+
this.withList = withList;
|
|
4160
|
+
this.builder = builder;
|
|
4161
|
+
}
|
|
4162
|
+
set(values) {
|
|
4163
|
+
return new this.builder(this.table, mapUpdateSet(this.table, values), this.session, this.dialect, this.withList);
|
|
4164
|
+
}
|
|
4165
|
+
};
|
|
4166
|
+
var SQLiteUpdateBase = class {
|
|
4167
|
+
static [entityKind] = "SQLiteUpdate";
|
|
4168
|
+
/** @internal */
|
|
4169
|
+
config;
|
|
4170
|
+
constructor(table, set, session, dialect, withList) {
|
|
4171
|
+
this.session = session;
|
|
4172
|
+
this.dialect = dialect;
|
|
4173
|
+
this.config = {
|
|
4174
|
+
set,
|
|
4175
|
+
table,
|
|
4176
|
+
withList,
|
|
4177
|
+
joins: []
|
|
4178
|
+
};
|
|
4179
|
+
}
|
|
4180
|
+
from(source) {
|
|
4181
|
+
this.config.from = source;
|
|
4182
|
+
return this;
|
|
4183
|
+
}
|
|
4184
|
+
createJoin(joinType) {
|
|
4185
|
+
return ((table, on) => {
|
|
4186
|
+
const tableName = getTableLikeName(table);
|
|
4187
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
4188
|
+
if (typeof on === "function") {
|
|
4189
|
+
const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
|
|
4190
|
+
on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
4191
|
+
sqlAliasedBehavior: "sql",
|
|
4192
|
+
sqlBehavior: "sql"
|
|
4193
|
+
})), from && new Proxy(from, new SelectionProxyHandler({
|
|
4194
|
+
sqlAliasedBehavior: "sql",
|
|
4195
|
+
sqlBehavior: "sql"
|
|
4196
|
+
})));
|
|
4197
|
+
}
|
|
4198
|
+
this.config.joins.push({
|
|
4199
|
+
on,
|
|
4200
|
+
table,
|
|
4201
|
+
joinType,
|
|
4202
|
+
alias: tableName
|
|
4203
|
+
});
|
|
4204
|
+
return this;
|
|
4205
|
+
});
|
|
4206
|
+
}
|
|
4207
|
+
leftJoin = this.createJoin("left");
|
|
4208
|
+
rightJoin = this.createJoin("right");
|
|
4209
|
+
innerJoin = this.createJoin("inner");
|
|
4210
|
+
fullJoin = this.createJoin("full");
|
|
4211
|
+
/**
|
|
4212
|
+
* Adds a 'where' clause to the query.
|
|
4213
|
+
*
|
|
4214
|
+
* Calling this method will update only those rows that fulfill a specified condition.
|
|
4215
|
+
*
|
|
4216
|
+
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
4217
|
+
*
|
|
4218
|
+
* @param where the 'where' clause.
|
|
4219
|
+
*
|
|
4220
|
+
* @example
|
|
4221
|
+
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
|
4222
|
+
*
|
|
4223
|
+
* ```ts
|
|
4224
|
+
* // Update all cars with green color
|
|
4225
|
+
* db.update(cars).set({ color: 'red' })
|
|
4226
|
+
* .where(eq(cars.color, 'green'));
|
|
4227
|
+
* // or
|
|
4228
|
+
* db.update(cars).set({ color: 'red' })
|
|
4229
|
+
* .where(sql`${cars.color} = 'green'`)
|
|
4230
|
+
* ```
|
|
4231
|
+
*
|
|
4232
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
4233
|
+
*
|
|
4234
|
+
* ```ts
|
|
4235
|
+
* // Update all BMW cars with a green color
|
|
4236
|
+
* db.update(cars).set({ color: 'red' })
|
|
4237
|
+
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
4238
|
+
*
|
|
4239
|
+
* // Update all cars with the green or blue color
|
|
4240
|
+
* db.update(cars).set({ color: 'red' })
|
|
4241
|
+
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
4242
|
+
* ```
|
|
4243
|
+
*/
|
|
4244
|
+
where(where) {
|
|
4245
|
+
this.config.where = where;
|
|
4246
|
+
return this;
|
|
4247
|
+
}
|
|
4248
|
+
orderBy(...columns) {
|
|
4249
|
+
if (typeof columns[0] === "function") {
|
|
4250
|
+
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
4251
|
+
sqlAliasedBehavior: "alias",
|
|
4252
|
+
sqlBehavior: "sql"
|
|
4253
|
+
})));
|
|
4254
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
4255
|
+
this.config.orderBy = orderByArray;
|
|
4256
|
+
} else {
|
|
4257
|
+
const orderByArray = columns;
|
|
4258
|
+
this.config.orderBy = orderByArray;
|
|
4259
|
+
}
|
|
4260
|
+
return this;
|
|
4261
|
+
}
|
|
4262
|
+
limit(limit) {
|
|
4263
|
+
this.config.limit = limit;
|
|
4264
|
+
return this;
|
|
4265
|
+
}
|
|
4266
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
|
4267
|
+
this.config.returning = orderSelectedFields(fields);
|
|
4268
|
+
return this;
|
|
4269
|
+
}
|
|
4270
|
+
getSQL() {
|
|
4271
|
+
return this.dialect.buildUpdateQuery(this.config);
|
|
4272
|
+
}
|
|
4273
|
+
toSQL() {
|
|
4274
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
4275
|
+
}
|
|
4276
|
+
$dynamic() {
|
|
4277
|
+
return this;
|
|
4278
|
+
}
|
|
4279
|
+
};
|
|
4280
|
+
|
|
4281
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/update.js
|
|
4282
|
+
var SQLiteAsyncUpdateBase = class extends SQLiteUpdateBase {
|
|
4283
|
+
static [entityKind] = "SQLiteAsyncUpdate";
|
|
4284
|
+
/** @internal */
|
|
4285
|
+
_prepare(prepare = false) {
|
|
4286
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), "arrays", prepare, this.config.returning ? "all" : "run", this.config.returning ? this.dialect.mapperGenerators.rows(this.config.returning, void 0) : void 0, {
|
|
4287
|
+
type: "update",
|
|
4288
|
+
tables: extractUsedTable(this.config.table)
|
|
4289
|
+
});
|
|
4290
|
+
}
|
|
4291
|
+
prepare() {
|
|
4292
|
+
return this._prepare(true);
|
|
4293
|
+
}
|
|
4294
|
+
run = (placeholderValues) => {
|
|
4295
|
+
return this._prepare().run(placeholderValues);
|
|
4296
|
+
};
|
|
4297
|
+
all = (placeholderValues) => {
|
|
4298
|
+
return this._prepare().all(placeholderValues);
|
|
4299
|
+
};
|
|
4300
|
+
get = (placeholderValues) => {
|
|
4301
|
+
return this._prepare().get(placeholderValues);
|
|
4302
|
+
};
|
|
4303
|
+
values = (placeholderValues) => {
|
|
4304
|
+
return this._prepare().values(placeholderValues);
|
|
4305
|
+
};
|
|
4306
|
+
async execute() {
|
|
4307
|
+
return this.config.returning ? this.all() : this.run();
|
|
4308
|
+
}
|
|
4309
|
+
};
|
|
4310
|
+
applyMixins(SQLiteAsyncUpdateBase, [QueryPromise]);
|
|
4311
|
+
|
|
4312
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/db.js
|
|
4313
|
+
var SQLiteAsyncDatabase = class {
|
|
4314
|
+
static [entityKind] = "BaseSQLiteDatabase";
|
|
4315
|
+
query;
|
|
4316
|
+
constructor(resultKind, dialect, session, relations, forbidJsonb) {
|
|
4317
|
+
this.resultKind = resultKind;
|
|
4318
|
+
this.dialect = dialect;
|
|
4319
|
+
this.session = session;
|
|
4320
|
+
this.forbidJsonb = forbidJsonb;
|
|
4321
|
+
this._ = {
|
|
4322
|
+
relations,
|
|
4323
|
+
session,
|
|
4324
|
+
resultKind
|
|
4325
|
+
};
|
|
4326
|
+
this.query = {};
|
|
4327
|
+
for (const [tableName, relation] of Object.entries(relations)) this.query[tableName] = new RelationalQueryBuilder(resultKind, relations, relations[relation.name].table, relation, dialect, session, forbidJsonb, resultKind === "sync" ? SQLiteSyncRelationalQuery : SQLiteAsyncRelationalQuery);
|
|
4328
|
+
this.$cache = { invalidate: async (_params) => {
|
|
4329
|
+
} };
|
|
4330
|
+
}
|
|
4331
|
+
/**
|
|
4332
|
+
* Creates a subquery that defines a temporary named result set as a CTE.
|
|
4333
|
+
*
|
|
4334
|
+
* It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
|
|
4335
|
+
*
|
|
4336
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
4337
|
+
*
|
|
4338
|
+
* @param alias The alias for the subquery.
|
|
4339
|
+
*
|
|
4340
|
+
* Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
|
|
4341
|
+
*
|
|
4342
|
+
* @example
|
|
4343
|
+
*
|
|
4344
|
+
* ```ts
|
|
4345
|
+
* // Create a subquery with alias 'sq' and use it in the select query
|
|
4346
|
+
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
4347
|
+
*
|
|
4348
|
+
* const result = await db.with(sq).select().from(sq);
|
|
4349
|
+
* ```
|
|
4350
|
+
*
|
|
4351
|
+
* To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
|
|
4352
|
+
*
|
|
4353
|
+
* ```ts
|
|
4354
|
+
* // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
|
|
4355
|
+
* const sq = db.$with('sq').as(db.select({
|
|
4356
|
+
* name: sql<string>`upper(${users.name})`.as('name'),
|
|
4357
|
+
* })
|
|
4358
|
+
* .from(users));
|
|
4359
|
+
*
|
|
4360
|
+
* const result = await db.with(sq).select({ name: sq.name }).from(sq);
|
|
4361
|
+
* ```
|
|
4362
|
+
*/
|
|
4363
|
+
$with = (alias, selection) => {
|
|
4364
|
+
const self = this;
|
|
4365
|
+
const as = (qb) => {
|
|
4366
|
+
if (typeof qb === "function") qb = qb(new QueryBuilder(self.dialect));
|
|
4367
|
+
return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
|
|
4368
|
+
alias,
|
|
4369
|
+
sqlAliasedBehavior: "alias",
|
|
4370
|
+
sqlBehavior: "error"
|
|
4371
|
+
}));
|
|
4372
|
+
};
|
|
4373
|
+
return { as };
|
|
4374
|
+
};
|
|
4375
|
+
$count(source, filters) {
|
|
4376
|
+
return this.resultKind === "async" ? new SQLiteAsyncCountBuilder({
|
|
4377
|
+
source,
|
|
4378
|
+
filters,
|
|
4379
|
+
session: this.session,
|
|
4380
|
+
dialect: this.dialect
|
|
4381
|
+
}) : new SQLiteSyncCountBuilder({
|
|
4382
|
+
source,
|
|
4383
|
+
filters,
|
|
4384
|
+
session: this.session,
|
|
4385
|
+
dialect: this.dialect
|
|
4386
|
+
});
|
|
4387
|
+
}
|
|
4388
|
+
/**
|
|
4389
|
+
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
4390
|
+
*
|
|
4391
|
+
* This method allows the main query to reference a temporary named result set.
|
|
4392
|
+
*
|
|
4393
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
4394
|
+
*
|
|
4395
|
+
* @param queries The CTEs to incorporate into the main query.
|
|
4396
|
+
*
|
|
4397
|
+
* @example
|
|
4398
|
+
*
|
|
4399
|
+
* ```ts
|
|
4400
|
+
* // Define a subquery 'sq' as a CTE using $with
|
|
4401
|
+
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
4402
|
+
*
|
|
4403
|
+
* // Incorporate the CTE 'sq' into the main query and select from it
|
|
4404
|
+
* const result = await db.with(sq).select().from(sq);
|
|
4405
|
+
* ```
|
|
4406
|
+
*/
|
|
4407
|
+
with(...queries) {
|
|
4408
|
+
const self = this;
|
|
4409
|
+
function select(fields) {
|
|
4410
|
+
return new SQLiteSelectBuilder({
|
|
4411
|
+
fields: fields ?? void 0,
|
|
4412
|
+
session: self.session,
|
|
4413
|
+
dialect: self.dialect,
|
|
4414
|
+
withList: queries
|
|
4415
|
+
}, SQLiteAsyncSelectBase);
|
|
4416
|
+
}
|
|
4417
|
+
function selectDistinct(fields) {
|
|
4418
|
+
return new SQLiteSelectBuilder({
|
|
4419
|
+
fields: fields ?? void 0,
|
|
4420
|
+
session: self.session,
|
|
4421
|
+
dialect: self.dialect,
|
|
4422
|
+
withList: queries,
|
|
4423
|
+
distinct: true
|
|
4424
|
+
}, SQLiteAsyncSelectBase);
|
|
4425
|
+
}
|
|
4426
|
+
function update(table) {
|
|
4427
|
+
return new SQLiteUpdateBuilder(table, self.session, self.dialect, queries, SQLiteAsyncUpdateBase);
|
|
4428
|
+
}
|
|
4429
|
+
function insert(into) {
|
|
4430
|
+
return new SQLiteInsertBuilder(into, self.session, self.dialect, queries, SQLiteAsyncInsertBase);
|
|
4431
|
+
}
|
|
4432
|
+
function delete_(from) {
|
|
4433
|
+
return new SQLiteAsyncDeleteBase(from, self.session, self.dialect, queries);
|
|
4434
|
+
}
|
|
4435
|
+
return {
|
|
4436
|
+
select,
|
|
4437
|
+
selectDistinct,
|
|
4438
|
+
update,
|
|
4439
|
+
insert,
|
|
4440
|
+
delete: delete_
|
|
4441
|
+
};
|
|
4442
|
+
}
|
|
4443
|
+
select(fields) {
|
|
4444
|
+
return new SQLiteSelectBuilder({
|
|
4445
|
+
fields: fields ?? void 0,
|
|
4446
|
+
session: this.session,
|
|
4447
|
+
dialect: this.dialect
|
|
4448
|
+
}, SQLiteAsyncSelectBase);
|
|
4449
|
+
}
|
|
4450
|
+
selectDistinct(fields) {
|
|
4451
|
+
return new SQLiteSelectBuilder({
|
|
4452
|
+
fields: fields ?? void 0,
|
|
4453
|
+
session: this.session,
|
|
4454
|
+
dialect: this.dialect,
|
|
4455
|
+
distinct: true
|
|
4456
|
+
}, SQLiteAsyncSelectBase);
|
|
4457
|
+
}
|
|
4458
|
+
/**
|
|
4459
|
+
* Creates an update query.
|
|
4460
|
+
*
|
|
4461
|
+
* Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
|
|
4462
|
+
*
|
|
4463
|
+
* Use `.set()` method to specify which values to update.
|
|
4464
|
+
*
|
|
4465
|
+
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
4466
|
+
*
|
|
4467
|
+
* @param table The table to update.
|
|
4468
|
+
*
|
|
4469
|
+
* @example
|
|
4470
|
+
*
|
|
4471
|
+
* ```ts
|
|
4472
|
+
* // Update all rows in the 'cars' table
|
|
4473
|
+
* await db.update(cars).set({ color: 'red' });
|
|
4474
|
+
*
|
|
4475
|
+
* // Update rows with filters and conditions
|
|
4476
|
+
* await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
|
|
4477
|
+
*
|
|
4478
|
+
* // Update with returning clause
|
|
4479
|
+
* const updatedCar: Car[] = await db.update(cars)
|
|
4480
|
+
* .set({ color: 'red' })
|
|
4481
|
+
* .where(eq(cars.id, 1))
|
|
4482
|
+
* .returning();
|
|
4483
|
+
* ```
|
|
4484
|
+
*/
|
|
4485
|
+
update(table) {
|
|
4486
|
+
return new SQLiteUpdateBuilder(table, this.session, this.dialect, void 0, SQLiteAsyncUpdateBase);
|
|
4487
|
+
}
|
|
4488
|
+
$cache;
|
|
4489
|
+
/**
|
|
4490
|
+
* Creates an insert query.
|
|
4491
|
+
*
|
|
4492
|
+
* Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
|
|
4493
|
+
*
|
|
4494
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert}
|
|
4495
|
+
*
|
|
4496
|
+
* @param table The table to insert into.
|
|
4497
|
+
*
|
|
4498
|
+
* @example
|
|
4499
|
+
*
|
|
4500
|
+
* ```ts
|
|
4501
|
+
* // Insert one row
|
|
4502
|
+
* await db.insert(cars).values({ brand: 'BMW' });
|
|
4503
|
+
*
|
|
4504
|
+
* // Insert multiple rows
|
|
4505
|
+
* await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
|
|
4506
|
+
*
|
|
4507
|
+
* // Insert with returning clause
|
|
4508
|
+
* const insertedCar: Car[] = await db.insert(cars)
|
|
4509
|
+
* .values({ brand: 'BMW' })
|
|
4510
|
+
* .returning();
|
|
4511
|
+
* ```
|
|
4512
|
+
*/
|
|
4513
|
+
insert(into) {
|
|
4514
|
+
return new SQLiteInsertBuilder(into, this.session, this.dialect, void 0, SQLiteAsyncInsertBase);
|
|
4515
|
+
}
|
|
4516
|
+
/**
|
|
4517
|
+
* Creates a delete query.
|
|
4518
|
+
*
|
|
4519
|
+
* Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
|
|
4520
|
+
*
|
|
4521
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
4522
|
+
*
|
|
4523
|
+
* @param table The table to delete from.
|
|
4524
|
+
*
|
|
4525
|
+
* @example
|
|
4526
|
+
*
|
|
4527
|
+
* ```ts
|
|
4528
|
+
* // Delete all rows in the 'cars' table
|
|
4529
|
+
* await db.delete(cars);
|
|
4530
|
+
*
|
|
4531
|
+
* // Delete rows with filters and conditions
|
|
4532
|
+
* await db.delete(cars).where(eq(cars.color, 'green'));
|
|
4533
|
+
*
|
|
4534
|
+
* // Delete with returning clause
|
|
4535
|
+
* const deletedCar: Car[] = await db.delete(cars)
|
|
4536
|
+
* .where(eq(cars.id, 1))
|
|
4537
|
+
* .returning();
|
|
4538
|
+
* ```
|
|
4539
|
+
*/
|
|
4540
|
+
delete(from) {
|
|
4541
|
+
return new SQLiteAsyncDeleteBase(from, this.session, this.dialect);
|
|
4542
|
+
}
|
|
4543
|
+
run(query) {
|
|
4544
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
4545
|
+
const builtQuery = this.dialect.sqlToQuery(sequel);
|
|
4546
|
+
const prepared = this.session.prepareQuery(builtQuery, "raw", false, "run");
|
|
4547
|
+
if (this.resultKind === "async") return new SQLiteAsyncRaw(prepared, sequel, builtQuery);
|
|
4548
|
+
return this.session.run(sequel);
|
|
4549
|
+
}
|
|
4550
|
+
all(query) {
|
|
4551
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
4552
|
+
const builtQuery = this.dialect.sqlToQuery(sequel);
|
|
4553
|
+
const prepared = this.session.prepareQuery(builtQuery, "objects", false, "all");
|
|
4554
|
+
if (this.resultKind === "async") return new SQLiteAsyncRaw(prepared, sequel, builtQuery);
|
|
4555
|
+
return this.session.objects(sequel);
|
|
4556
|
+
}
|
|
4557
|
+
get(query) {
|
|
4558
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
4559
|
+
const builtQuery = this.dialect.sqlToQuery(sequel);
|
|
4560
|
+
const prepared = this.session.prepareQuery(builtQuery, "objects", false, "get");
|
|
4561
|
+
if (this.resultKind === "async") return new SQLiteAsyncRaw(prepared, sequel, builtQuery);
|
|
4562
|
+
return this.session.object(sequel);
|
|
4563
|
+
}
|
|
4564
|
+
values(query) {
|
|
4565
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
4566
|
+
const builtQuery = this.dialect.sqlToQuery(sequel);
|
|
4567
|
+
const prepared = this.session.prepareQuery(builtQuery, "objects", false, "values");
|
|
4568
|
+
if (this.resultKind === "async") return new SQLiteAsyncRaw(prepared, sequel, builtQuery);
|
|
4569
|
+
return this.session.arrays(sequel);
|
|
4570
|
+
}
|
|
4571
|
+
transaction(transaction, config) {
|
|
4572
|
+
return this.session.transaction(transaction, config);
|
|
4573
|
+
}
|
|
4574
|
+
};
|
|
4575
|
+
|
|
4576
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/session.js
|
|
4577
|
+
var SQLitePreparedQuery = class {
|
|
4578
|
+
static [entityKind] = "SQLiteBasePreparedQuery";
|
|
4579
|
+
/** @internal */
|
|
4580
|
+
mapper;
|
|
4581
|
+
/** @internal */
|
|
4582
|
+
executeMethod;
|
|
4583
|
+
constructor(executeMethod, query, mapper, mode) {
|
|
4584
|
+
this.query = query;
|
|
4585
|
+
this.mode = mode;
|
|
4586
|
+
this.mapper = mapper;
|
|
4587
|
+
this.executeMethod = executeMethod;
|
|
4588
|
+
}
|
|
4589
|
+
getQuery() {
|
|
4590
|
+
return this.query;
|
|
4591
|
+
}
|
|
4592
|
+
};
|
|
4593
|
+
var SQLiteSession = class {
|
|
4594
|
+
static [entityKind] = "SQLiteSession";
|
|
4595
|
+
constructor(dialect) {
|
|
4596
|
+
this.dialect = dialect;
|
|
4597
|
+
}
|
|
4598
|
+
};
|
|
4599
|
+
|
|
4600
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/cache/core/cache.js
|
|
4601
|
+
var Cache = class {
|
|
4602
|
+
static [entityKind] = "Cache";
|
|
4603
|
+
};
|
|
4604
|
+
var NoopCache = class extends Cache {
|
|
4605
|
+
static [entityKind] = "NoopCache";
|
|
4606
|
+
strategy() {
|
|
4607
|
+
return "all";
|
|
4608
|
+
}
|
|
4609
|
+
async get(_key) {
|
|
4610
|
+
}
|
|
4611
|
+
async put(_hashedQuery, _response, _tables, _config) {
|
|
4612
|
+
}
|
|
4613
|
+
async onMutate(_params) {
|
|
4614
|
+
}
|
|
4615
|
+
};
|
|
4616
|
+
var strategyFor = async (query, params, queryMetadata, withCacheConfig) => {
|
|
4617
|
+
if (!queryMetadata) return { type: "skip" };
|
|
4618
|
+
const { type, tables } = queryMetadata;
|
|
4619
|
+
if ((type === "insert" || type === "update" || type === "delete") && tables.length > 0) return {
|
|
4620
|
+
type: "invalidate",
|
|
4621
|
+
tables
|
|
4622
|
+
};
|
|
4623
|
+
if (!withCacheConfig) return { type: "skip" };
|
|
4624
|
+
if (!withCacheConfig.enabled) return { type: "skip" };
|
|
4625
|
+
if (type === "select") return {
|
|
4626
|
+
type: "try",
|
|
4627
|
+
key: withCacheConfig.tag ?? await hashQuery(query, params),
|
|
4628
|
+
isTag: typeof withCacheConfig.tag !== "undefined",
|
|
4629
|
+
autoInvalidate: withCacheConfig.autoInvalidate,
|
|
4630
|
+
tables: queryMetadata.tables,
|
|
4631
|
+
config: withCacheConfig.config
|
|
4632
|
+
};
|
|
4633
|
+
return { type: "skip" };
|
|
4634
|
+
};
|
|
4635
|
+
async function hashQuery(sql2, params) {
|
|
4636
|
+
const dataToHash = `${sql2}-${JSON.stringify(params, (_, v) => typeof v === "bigint" ? `${v}n` : v)}`;
|
|
4637
|
+
const data = new TextEncoder().encode(dataToHash);
|
|
4638
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
4639
|
+
return [...new Uint8Array(hashBuffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
4640
|
+
}
|
|
4641
|
+
|
|
4642
|
+
// node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.5/node_modules/drizzle-orm/sqlite-core/async/session.js
|
|
4643
|
+
var ExecuteResultSync = class extends QueryPromise {
|
|
4644
|
+
static [entityKind] = "ExecuteResultSync";
|
|
4645
|
+
constructor(resultCb) {
|
|
4646
|
+
super();
|
|
4647
|
+
this.resultCb = resultCb;
|
|
4648
|
+
}
|
|
4649
|
+
async execute() {
|
|
4650
|
+
return this.resultCb();
|
|
4651
|
+
}
|
|
4652
|
+
sync() {
|
|
4653
|
+
return this.resultCb();
|
|
4654
|
+
}
|
|
4655
|
+
};
|
|
4656
|
+
var SQLiteAsyncPreparedQuery = class extends SQLitePreparedQuery {
|
|
4657
|
+
static [entityKind] = "SQLiteAsyncPreparedQuery";
|
|
4658
|
+
fastPath;
|
|
4659
|
+
constructor(resultKind, executeMethod = "all", executors, query, mapper, mode, logger, cache, queryMetadata, cacheConfig) {
|
|
4660
|
+
super(executeMethod, query, mapper, mode);
|
|
4661
|
+
this.resultKind = resultKind;
|
|
4662
|
+
this.executors = executors;
|
|
4663
|
+
this.logger = logger;
|
|
4664
|
+
this.cache = cache;
|
|
4665
|
+
this.queryMetadata = queryMetadata;
|
|
4666
|
+
this.cacheConfig = cacheConfig;
|
|
4667
|
+
if (cache && cache.strategy() === "all" && cacheConfig === void 0) this.cacheConfig = {
|
|
4668
|
+
enabled: true,
|
|
4669
|
+
autoInvalidate: true
|
|
4670
|
+
};
|
|
4671
|
+
if (!this.cacheConfig?.enabled) this.cacheConfig = void 0;
|
|
4672
|
+
this.fastPath = cacheConfig === void 0 && (cache === void 0 || is(cache, NoopCache));
|
|
4673
|
+
}
|
|
4674
|
+
/** @internal */
|
|
4675
|
+
async queryWithCache(queryString, params, executeMethod, query) {
|
|
4676
|
+
const cacheStrat = this.cache !== void 0 && !is(this.cache, NoopCache) ? await strategyFor(queryString, params, this.queryMetadata, this.cacheConfig) : { type: "skip" };
|
|
4677
|
+
if (cacheStrat.type === "skip") return query().catch((e) => {
|
|
4678
|
+
throw new DrizzleQueryError(queryString, params, e);
|
|
4679
|
+
});
|
|
4680
|
+
const cache = this.cache;
|
|
4681
|
+
if (cacheStrat.type === "invalidate") return Promise.all([query(), cache.onMutate({ tables: cacheStrat.tables })]).then((res) => res[0]).catch((e) => {
|
|
4682
|
+
throw new DrizzleQueryError(queryString, params, e);
|
|
4683
|
+
});
|
|
4684
|
+
if (cacheStrat.type === "try") {
|
|
4685
|
+
const { tables, key: _key, isTag, autoInvalidate, config } = cacheStrat;
|
|
4686
|
+
const key = `${executeMethod}_${_key}`;
|
|
4687
|
+
const fromCache = await cache.get(key, tables, isTag, autoInvalidate);
|
|
4688
|
+
if (fromCache === void 0) {
|
|
4689
|
+
const result = await query().catch((e) => {
|
|
4690
|
+
throw new DrizzleQueryError(queryString, params, e);
|
|
4691
|
+
});
|
|
4692
|
+
await cache.put(key, result, autoInvalidate ? tables : [], isTag, config);
|
|
4693
|
+
return result;
|
|
4694
|
+
}
|
|
4695
|
+
return fromCache;
|
|
4696
|
+
}
|
|
4697
|
+
assertUnreachable(cacheStrat);
|
|
4698
|
+
}
|
|
4699
|
+
run(placeholderValues = {}) {
|
|
4700
|
+
const { query, logger, executors, fastPath, resultKind } = this;
|
|
4701
|
+
const sql2 = query._sql ? query._sql.join(" ") : query.sql;
|
|
4702
|
+
const params = query.params.length === 0 ? query.params : fillPlaceholders(query.params, placeholderValues);
|
|
4703
|
+
logger.logQuery(sql2, params);
|
|
4704
|
+
if (resultKind === "sync") try {
|
|
4705
|
+
return executors.run(params);
|
|
4706
|
+
} catch (e) {
|
|
4707
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4708
|
+
}
|
|
4709
|
+
return fastPath ? executors.run(params).catch((e) => {
|
|
4710
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4711
|
+
}) : this.queryWithCache(sql2, params, "run", () => executors.run(params));
|
|
4712
|
+
}
|
|
4713
|
+
all(placeholderValues = {}) {
|
|
4714
|
+
const { query, logger, executors, mapper, fastPath, resultKind } = this;
|
|
4715
|
+
const sql2 = query._sql ? query._sql.join(" ") : query.sql;
|
|
4716
|
+
const params = query.params.length === 0 ? query.params : fillPlaceholders(query.params, placeholderValues);
|
|
4717
|
+
logger.logQuery(sql2, params);
|
|
4718
|
+
if (resultKind === "sync") {
|
|
4719
|
+
let res2;
|
|
4720
|
+
try {
|
|
4721
|
+
res2 = executors.all(params);
|
|
4722
|
+
} catch (e) {
|
|
4723
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4724
|
+
}
|
|
4725
|
+
if (!mapper) return res2;
|
|
4726
|
+
return mapper(res2);
|
|
4727
|
+
}
|
|
4728
|
+
const res = fastPath ? executors.all(params).catch((e) => {
|
|
4729
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4730
|
+
}) : this.queryWithCache(sql2, params, "all", () => executors.all(params));
|
|
4731
|
+
if (!mapper) return res;
|
|
4732
|
+
return res.then((rows) => mapper(rows));
|
|
4733
|
+
}
|
|
4734
|
+
get(placeholderValues = {}) {
|
|
4735
|
+
const { query, logger, executors, mapper, fastPath, resultKind } = this;
|
|
4736
|
+
const sql2 = query._sql ? query._sql.join(" ") : query.sql;
|
|
4737
|
+
const params = query.params.length === 0 ? query.params : fillPlaceholders(query.params, placeholderValues);
|
|
4738
|
+
logger.logQuery(sql2, params);
|
|
4739
|
+
if (resultKind === "sync") {
|
|
4740
|
+
let res2;
|
|
4741
|
+
try {
|
|
4742
|
+
res2 = executors.get(params);
|
|
4743
|
+
} catch (e) {
|
|
4744
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4745
|
+
}
|
|
4746
|
+
if (!res2) return void 0;
|
|
4747
|
+
if (!mapper) return res2;
|
|
4748
|
+
return mapper([res2])[0];
|
|
4749
|
+
}
|
|
4750
|
+
const res = fastPath ? executors.get(params).catch((e) => {
|
|
4751
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4752
|
+
}) : this.queryWithCache(sql2, params, "get", () => executors.get(params));
|
|
4753
|
+
if (!mapper) return res.then((row) => row ? row : void 0);
|
|
4754
|
+
return res.then((row) => row ? mapper([row])[0] : void 0);
|
|
4755
|
+
}
|
|
4756
|
+
values(placeholderValues = {}) {
|
|
4757
|
+
const { query, logger, executors, fastPath, resultKind } = this;
|
|
4758
|
+
const sql2 = query._sql ? query._sql.join(" ") : query.sql;
|
|
4759
|
+
const params = query.params.length === 0 ? query.params : fillPlaceholders(query.params, placeholderValues);
|
|
4760
|
+
logger.logQuery(sql2, params);
|
|
4761
|
+
if (resultKind === "sync") try {
|
|
4762
|
+
return executors.values(params);
|
|
4763
|
+
} catch (e) {
|
|
4764
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4765
|
+
}
|
|
4766
|
+
return fastPath ? executors.values(params).catch((e) => {
|
|
4767
|
+
throw new DrizzleQueryError(sql2, params, e);
|
|
4768
|
+
}) : this.queryWithCache(sql2, params, "values", () => executors.values(params));
|
|
4769
|
+
}
|
|
4770
|
+
execute(placeholderValues) {
|
|
4771
|
+
if (this.resultKind === "async") return this[this.executeMethod](placeholderValues);
|
|
4772
|
+
return new ExecuteResultSync(() => this[this.executeMethod](placeholderValues));
|
|
4773
|
+
}
|
|
4774
|
+
};
|
|
4775
|
+
var SQLiteAsyncSession = class extends SQLiteSession {
|
|
4776
|
+
static [entityKind] = "SQLiteAsyncSession";
|
|
4777
|
+
constructor(dialect, resultKind) {
|
|
4778
|
+
super(dialect);
|
|
4779
|
+
this.resultKind = resultKind;
|
|
4780
|
+
}
|
|
4781
|
+
run(query) {
|
|
4782
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), "raw", false).run();
|
|
4783
|
+
}
|
|
4784
|
+
objects(query) {
|
|
4785
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), "objects", false).all();
|
|
4786
|
+
}
|
|
4787
|
+
object(query) {
|
|
4788
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), "objects", false).get();
|
|
4789
|
+
}
|
|
4790
|
+
arrays(query) {
|
|
4791
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), "arrays", false).all();
|
|
4792
|
+
}
|
|
4793
|
+
array(query) {
|
|
4794
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), "arrays", false).get();
|
|
4795
|
+
}
|
|
4796
|
+
};
|
|
4797
|
+
var SQLiteAsyncTransaction = class extends SQLiteAsyncDatabase {
|
|
4798
|
+
static [entityKind] = "SQLiteAsyncTransaction";
|
|
4799
|
+
constructor(resultType, dialect, session, relations, nestedIndex = 0, forbidJsonb) {
|
|
4800
|
+
super(resultType, dialect, session, relations, forbidJsonb);
|
|
4801
|
+
this.nestedIndex = nestedIndex;
|
|
4802
|
+
}
|
|
4803
|
+
rollback() {
|
|
4804
|
+
throw new TransactionRollbackError();
|
|
4805
|
+
}
|
|
4806
|
+
};
|
|
4807
|
+
|
|
4808
|
+
export {
|
|
4809
|
+
entityKind,
|
|
4810
|
+
sql,
|
|
4811
|
+
DrizzleQueryError,
|
|
4812
|
+
eq,
|
|
4813
|
+
desc,
|
|
4814
|
+
jitCompatCheck,
|
|
4815
|
+
DefaultLogger,
|
|
4816
|
+
NoopLogger,
|
|
4817
|
+
integer,
|
|
4818
|
+
real,
|
|
4819
|
+
text,
|
|
4820
|
+
sqliteTable,
|
|
4821
|
+
index,
|
|
4822
|
+
primaryKey,
|
|
4823
|
+
unique,
|
|
4824
|
+
SQLiteDialect,
|
|
4825
|
+
SQLiteAsyncDatabase,
|
|
4826
|
+
SQLiteAsyncPreparedQuery,
|
|
4827
|
+
SQLiteAsyncSession,
|
|
4828
|
+
SQLiteAsyncTransaction
|
|
4829
|
+
};
|
|
4830
|
+
//# sourceMappingURL=shared-ZF3LACGD.js.map
|