azure-mock 2.20.0 → 2.22.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/LICENSE +201 -201
- package/dist/better-sqlite3-CtLaF97z-DWR9uC3b.js +129 -0
- package/dist/chunk-2X2C5D2I-dJHtPFe9-DxsO-1YF.js +4026 -0
- package/dist/d1-pK2J-_yx-BoQTXsTa.js +185 -0
- package/dist/dialect-pBb6Cg_F-xgpUtfmk.js +570 -0
- package/dist/dist-C481edUb-CHbOkeXH.js +10131 -0
- package/dist/dist-DUzzleZr-DxHmeYjp.js +2 -0
- package/dist/index.d.ts +21 -21
- package/dist/index.js +20396 -18921
- package/dist/libsql-Nq-S0r5x-d2dAzhgO.js +240 -0
- package/dist/logger-TIsK7375-CLNNa25D.js +652 -0
- package/dist/migrator-B9kYwLqO-4g9JX3_v.js +8 -0
- package/dist/migrator-BfTfJctM-DrNlb1BS.js +8 -0
- package/dist/migrator-BjoW0_3j-CD-XdZ5a.js +8 -0
- package/dist/migrator-CWWlo_Jk-C4Hw4PPN.js +8 -0
- package/dist/migrator-CpiXRkls-COYfhljd.js +24 -0
- package/dist/migrator-CtqJkLVI-D1lU6ZV0.js +8 -0
- package/dist/migrator-CxcBjmET-Dcd21VIf.js +8 -0
- package/dist/migrator-Cyhbhxo_-Bh7sF0R3.js +21 -0
- package/dist/migrator-DG1mWUoR-DVfkqn_v.js +31 -0
- package/dist/migrator-DrWmHwY2-YjAfotd7.js +8 -0
- package/dist/migrator-WAPonQxA-CRvJJhKG.js +8 -0
- package/dist/migrator-Zdh8WMMx-gsmNXspd.js +8 -0
- package/dist/migrator-xRJ6NOTS-SsAuB-Gi.js +24 -0
- package/dist/migrator-xbWwvFYF-BjyVdQS8.js +8 -0
- package/dist/mysql2-DkoPEsRu-BMwVSCmY.js +251 -0
- package/dist/neon-serverless-BEVFA7yv-DGSPAG1z.js +205 -0
- package/dist/node-postgres-DQA7bEhW-CkM_cVLD.js +216 -0
- package/dist/nodefs-Bc8b83o_-DetP9qUa.js +24 -0
- package/dist/opfs-ahp-DbstDvx--CHskKtzG.js +365 -0
- package/dist/pg-ylxXyvKj-Hm8vcZoi.js +279 -0
- package/dist/pglite-CPs4w-D9-DHOg0D8W.js +179 -0
- package/dist/pglite-DMWgTUE6-BOIRUWUT.js +2 -0
- package/dist/planetscale-serverless-DUMheN-f-Dyc_W6V_.js +172 -0
- package/dist/query-builder-CLJAKedv-DTZiP7B6.js +1715 -0
- package/dist/query-builder-CT3_liD0-hhg5kRTk.js +1347 -0
- package/dist/session-BOEirggu-DTmpyU_x.js +2485 -0
- package/dist/session-CAUQtT0A-BoVK2x7A.js +745 -0
- package/dist/session-Cjeygn2Z-BO0mi6pq.js +989 -0
- package/dist/singlestore-Cdlo23hW-BuFJ4Zqb.js +1647 -0
- package/dist/sql-CNZp2yLp-Bwugq384.js +611 -0
- package/dist/sqlite-proxy-BgUfVEbZ-CsSkc-_K.js +190 -0
- package/dist/src-LcyXhCXE-C_vKJiLK.js +1920 -0
- package/dist/vercel-postgres-BYmFKsTS-CpV2usun.js +203 -0
- package/package.json +7 -8
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
//#region ../db/dist/sql-CNZp2yLp.js
|
|
2
|
+
const entityKind = Symbol.for("drizzle:entityKind");
|
|
3
|
+
function is(value, type) {
|
|
4
|
+
if (!value || typeof value !== "object") return false;
|
|
5
|
+
if (value instanceof type) return true;
|
|
6
|
+
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.`);
|
|
7
|
+
let cls = Object.getPrototypeOf(value).constructor;
|
|
8
|
+
if (cls) while (cls) {
|
|
9
|
+
if (entityKind in cls && cls[entityKind] === type[entityKind]) return true;
|
|
10
|
+
cls = Object.getPrototypeOf(cls);
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const TableName = Symbol.for("drizzle:Name");
|
|
15
|
+
const Schema = Symbol.for("drizzle:Schema");
|
|
16
|
+
const Columns = Symbol.for("drizzle:Columns");
|
|
17
|
+
const ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
18
|
+
const OriginalName = Symbol.for("drizzle:OriginalName");
|
|
19
|
+
const BaseName = Symbol.for("drizzle:BaseName");
|
|
20
|
+
const IsAlias = Symbol.for("drizzle:IsAlias");
|
|
21
|
+
const ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
|
22
|
+
const IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
|
23
|
+
var Table = class {
|
|
24
|
+
static [entityKind] = "Table";
|
|
25
|
+
/** @internal */
|
|
26
|
+
static Symbol = {
|
|
27
|
+
Name: TableName,
|
|
28
|
+
Schema,
|
|
29
|
+
OriginalName,
|
|
30
|
+
Columns,
|
|
31
|
+
ExtraConfigColumns,
|
|
32
|
+
BaseName,
|
|
33
|
+
IsAlias,
|
|
34
|
+
ExtraConfigBuilder
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
* Can be changed if the table is aliased.
|
|
39
|
+
*/
|
|
40
|
+
[TableName];
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
* Used to store the original name of the table, before any aliasing.
|
|
44
|
+
*/
|
|
45
|
+
[OriginalName];
|
|
46
|
+
/** @internal */
|
|
47
|
+
[Schema];
|
|
48
|
+
/** @internal */
|
|
49
|
+
[Columns];
|
|
50
|
+
/** @internal */
|
|
51
|
+
[ExtraConfigColumns];
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
55
|
+
*/
|
|
56
|
+
[BaseName];
|
|
57
|
+
/** @internal */
|
|
58
|
+
[IsAlias] = false;
|
|
59
|
+
/** @internal */
|
|
60
|
+
[IsDrizzleTable] = true;
|
|
61
|
+
/** @internal */
|
|
62
|
+
[ExtraConfigBuilder] = void 0;
|
|
63
|
+
constructor(name, schema, baseName) {
|
|
64
|
+
this[TableName] = this[OriginalName] = name;
|
|
65
|
+
this[Schema] = schema;
|
|
66
|
+
this[BaseName] = baseName;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function getTableName(table) {
|
|
70
|
+
return table[TableName];
|
|
71
|
+
}
|
|
72
|
+
function getTableUniqueName(table) {
|
|
73
|
+
return `${table[Schema] ?? "public"}.${table[TableName]}`;
|
|
74
|
+
}
|
|
75
|
+
var Column = class {
|
|
76
|
+
constructor(table, config) {
|
|
77
|
+
this.table = table;
|
|
78
|
+
this.config = config;
|
|
79
|
+
this.name = config.name;
|
|
80
|
+
this.keyAsName = config.keyAsName;
|
|
81
|
+
this.notNull = config.notNull;
|
|
82
|
+
this.default = config.default;
|
|
83
|
+
this.defaultFn = config.defaultFn;
|
|
84
|
+
this.onUpdateFn = config.onUpdateFn;
|
|
85
|
+
this.hasDefault = config.hasDefault;
|
|
86
|
+
this.primary = config.primaryKey;
|
|
87
|
+
this.isUnique = config.isUnique;
|
|
88
|
+
this.uniqueName = config.uniqueName;
|
|
89
|
+
this.uniqueType = config.uniqueType;
|
|
90
|
+
this.dataType = config.dataType;
|
|
91
|
+
this.columnType = config.columnType;
|
|
92
|
+
this.generated = config.generated;
|
|
93
|
+
this.generatedIdentity = config.generatedIdentity;
|
|
94
|
+
}
|
|
95
|
+
static [entityKind] = "Column";
|
|
96
|
+
name;
|
|
97
|
+
keyAsName;
|
|
98
|
+
primary;
|
|
99
|
+
notNull;
|
|
100
|
+
default;
|
|
101
|
+
defaultFn;
|
|
102
|
+
onUpdateFn;
|
|
103
|
+
hasDefault;
|
|
104
|
+
isUnique;
|
|
105
|
+
uniqueName;
|
|
106
|
+
uniqueType;
|
|
107
|
+
dataType;
|
|
108
|
+
columnType;
|
|
109
|
+
enumValues = void 0;
|
|
110
|
+
generated = void 0;
|
|
111
|
+
generatedIdentity = void 0;
|
|
112
|
+
config;
|
|
113
|
+
mapFromDriverValue(value) {
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
mapToDriverValue(value) {
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
shouldDisableInsert() {
|
|
120
|
+
return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
function uniqueKeyName(table, columns) {
|
|
124
|
+
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
125
|
+
}
|
|
126
|
+
function parsePgArrayValue(arrayString, startFrom, inQuotes) {
|
|
127
|
+
for (let i = startFrom; i < arrayString.length; i++) {
|
|
128
|
+
const char = arrayString[i];
|
|
129
|
+
if (char === "\\") {
|
|
130
|
+
i++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (char === "\"") return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i + 1];
|
|
134
|
+
if (inQuotes) continue;
|
|
135
|
+
if (char === "," || char === "}") return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i];
|
|
136
|
+
}
|
|
137
|
+
return [arrayString.slice(startFrom).replace(/\\/g, ""), arrayString.length];
|
|
138
|
+
}
|
|
139
|
+
function parsePgNestedArray(arrayString, startFrom = 0) {
|
|
140
|
+
const result = [];
|
|
141
|
+
let i = startFrom;
|
|
142
|
+
let lastCharIsComma = false;
|
|
143
|
+
while (i < arrayString.length) {
|
|
144
|
+
const char = arrayString[i];
|
|
145
|
+
if (char === ",") {
|
|
146
|
+
if (lastCharIsComma || i === startFrom) result.push("");
|
|
147
|
+
lastCharIsComma = true;
|
|
148
|
+
i++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
lastCharIsComma = false;
|
|
152
|
+
if (char === "\\") {
|
|
153
|
+
i += 2;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (char === "\"") {
|
|
157
|
+
const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
|
|
158
|
+
result.push(value2);
|
|
159
|
+
i = startFrom2;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (char === "}") return [result, i + 1];
|
|
163
|
+
if (char === "{") {
|
|
164
|
+
const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
|
|
165
|
+
result.push(value2);
|
|
166
|
+
i = startFrom2;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
|
|
170
|
+
result.push(value);
|
|
171
|
+
i = newStartFrom;
|
|
172
|
+
}
|
|
173
|
+
return [result, i];
|
|
174
|
+
}
|
|
175
|
+
function parsePgArray(arrayString) {
|
|
176
|
+
const [result] = parsePgNestedArray(arrayString, 1);
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
function makePgArray(array) {
|
|
180
|
+
return `{${array.map((item) => {
|
|
181
|
+
if (Array.isArray(item)) return makePgArray(item);
|
|
182
|
+
if (typeof item === "string") return `"${item.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
183
|
+
return `${item}`;
|
|
184
|
+
}).join(",")}}`;
|
|
185
|
+
}
|
|
186
|
+
var PgColumn = class extends Column {
|
|
187
|
+
constructor(table, config) {
|
|
188
|
+
if (!config.uniqueName) config.uniqueName = uniqueKeyName(table, [config.name]);
|
|
189
|
+
super(table, config);
|
|
190
|
+
this.table = table;
|
|
191
|
+
}
|
|
192
|
+
static [entityKind] = "PgColumn";
|
|
193
|
+
};
|
|
194
|
+
var PgArray = class PgArray extends PgColumn {
|
|
195
|
+
constructor(table, config, baseColumn, range) {
|
|
196
|
+
super(table, config);
|
|
197
|
+
this.baseColumn = baseColumn;
|
|
198
|
+
this.range = range;
|
|
199
|
+
this.size = config.size;
|
|
200
|
+
}
|
|
201
|
+
size;
|
|
202
|
+
static [entityKind] = "PgArray";
|
|
203
|
+
getSQLType() {
|
|
204
|
+
return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
|
|
205
|
+
}
|
|
206
|
+
mapFromDriverValue(value) {
|
|
207
|
+
if (typeof value === "string") value = parsePgArray(value);
|
|
208
|
+
return value.map((v) => this.baseColumn.mapFromDriverValue(v));
|
|
209
|
+
}
|
|
210
|
+
mapToDriverValue(value, isNestedArray = false) {
|
|
211
|
+
const a = value.map((v) => v === null ? null : is(this.baseColumn, PgArray) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v));
|
|
212
|
+
if (isNestedArray) return a;
|
|
213
|
+
return makePgArray(a);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const isPgEnumSym = Symbol.for("drizzle:isPgEnum");
|
|
217
|
+
function isPgEnum(obj) {
|
|
218
|
+
return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
|
|
219
|
+
}
|
|
220
|
+
var Subquery = class {
|
|
221
|
+
static [entityKind] = "Subquery";
|
|
222
|
+
constructor(sql, fields, alias, isWith = false, usedTables = []) {
|
|
223
|
+
this._ = {
|
|
224
|
+
brand: "Subquery",
|
|
225
|
+
sql,
|
|
226
|
+
selectedFields: fields,
|
|
227
|
+
alias,
|
|
228
|
+
isWith,
|
|
229
|
+
usedTables
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var WithSubquery = class extends Subquery {
|
|
234
|
+
static [entityKind] = "WithSubquery";
|
|
235
|
+
};
|
|
236
|
+
var version = "0.45.2";
|
|
237
|
+
const tracer = { startActiveSpan(name, fn) {
|
|
238
|
+
return fn();
|
|
239
|
+
} };
|
|
240
|
+
const ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
241
|
+
function isSQLWrapper(value) {
|
|
242
|
+
return value !== null && value !== void 0 && typeof value.getSQL === "function";
|
|
243
|
+
}
|
|
244
|
+
function mergeQueries(queries) {
|
|
245
|
+
const result = {
|
|
246
|
+
sql: "",
|
|
247
|
+
params: []
|
|
248
|
+
};
|
|
249
|
+
for (const query of queries) {
|
|
250
|
+
result.sql += query.sql;
|
|
251
|
+
result.params.push(...query.params);
|
|
252
|
+
if (query.typings?.length) {
|
|
253
|
+
if (!result.typings) result.typings = [];
|
|
254
|
+
result.typings.push(...query.typings);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
var StringChunk = class {
|
|
260
|
+
static [entityKind] = "StringChunk";
|
|
261
|
+
value;
|
|
262
|
+
constructor(value) {
|
|
263
|
+
this.value = Array.isArray(value) ? value : [value];
|
|
264
|
+
}
|
|
265
|
+
getSQL() {
|
|
266
|
+
return new SQL([this]);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
var SQL = class SQL {
|
|
270
|
+
constructor(queryChunks) {
|
|
271
|
+
this.queryChunks = queryChunks;
|
|
272
|
+
for (const chunk of queryChunks) if (is(chunk, Table)) {
|
|
273
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
274
|
+
this.usedTables.push(schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
static [entityKind] = "SQL";
|
|
278
|
+
/** @internal */
|
|
279
|
+
decoder = noopDecoder;
|
|
280
|
+
shouldInlineParams = false;
|
|
281
|
+
/** @internal */
|
|
282
|
+
usedTables = [];
|
|
283
|
+
append(query) {
|
|
284
|
+
this.queryChunks.push(...query.queryChunks);
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
toQuery(config) {
|
|
288
|
+
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
289
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
290
|
+
span?.setAttributes({
|
|
291
|
+
"drizzle.query.text": query.sql,
|
|
292
|
+
"drizzle.query.params": JSON.stringify(query.params)
|
|
293
|
+
});
|
|
294
|
+
return query;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
buildQueryFromSourceParams(chunks, _config) {
|
|
298
|
+
const config = Object.assign({}, _config, {
|
|
299
|
+
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
300
|
+
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
301
|
+
});
|
|
302
|
+
const { casing, escapeName, escapeParam, prepareTyping, inlineParams, paramStartIndex } = config;
|
|
303
|
+
return mergeQueries(chunks.map((chunk) => {
|
|
304
|
+
if (is(chunk, StringChunk)) return {
|
|
305
|
+
sql: chunk.value.join(""),
|
|
306
|
+
params: []
|
|
307
|
+
};
|
|
308
|
+
if (is(chunk, Name)) return {
|
|
309
|
+
sql: escapeName(chunk.value),
|
|
310
|
+
params: []
|
|
311
|
+
};
|
|
312
|
+
if (chunk === void 0) return {
|
|
313
|
+
sql: "",
|
|
314
|
+
params: []
|
|
315
|
+
};
|
|
316
|
+
if (Array.isArray(chunk)) {
|
|
317
|
+
const result = [new StringChunk("(")];
|
|
318
|
+
for (const [i, p] of chunk.entries()) {
|
|
319
|
+
result.push(p);
|
|
320
|
+
if (i < chunk.length - 1) result.push(new StringChunk(", "));
|
|
321
|
+
}
|
|
322
|
+
result.push(new StringChunk(")"));
|
|
323
|
+
return this.buildQueryFromSourceParams(result, config);
|
|
324
|
+
}
|
|
325
|
+
if (is(chunk, SQL)) return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
326
|
+
...config,
|
|
327
|
+
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
328
|
+
});
|
|
329
|
+
if (is(chunk, Table)) {
|
|
330
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
331
|
+
const tableName = chunk[Table.Symbol.Name];
|
|
332
|
+
return {
|
|
333
|
+
sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
334
|
+
params: []
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (is(chunk, Column)) {
|
|
338
|
+
const columnName = casing.getColumnCasing(chunk);
|
|
339
|
+
if (_config.invokeSource === "indexes") return {
|
|
340
|
+
sql: escapeName(columnName),
|
|
341
|
+
params: []
|
|
342
|
+
};
|
|
343
|
+
const schemaName = chunk.table[Table.Symbol.Schema];
|
|
344
|
+
return {
|
|
345
|
+
sql: chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
|
|
346
|
+
params: []
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
if (is(chunk, View)) {
|
|
350
|
+
const schemaName = chunk[ViewBaseConfig].schema;
|
|
351
|
+
const viewName = chunk[ViewBaseConfig].name;
|
|
352
|
+
return {
|
|
353
|
+
sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
354
|
+
params: []
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
if (is(chunk, Param)) {
|
|
358
|
+
if (is(chunk.value, Placeholder)) return {
|
|
359
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
360
|
+
params: [chunk],
|
|
361
|
+
typings: ["none"]
|
|
362
|
+
};
|
|
363
|
+
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
364
|
+
if (is(mappedValue, SQL)) return this.buildQueryFromSourceParams([mappedValue], config);
|
|
365
|
+
if (inlineParams) return {
|
|
366
|
+
sql: this.mapInlineParam(mappedValue, config),
|
|
367
|
+
params: []
|
|
368
|
+
};
|
|
369
|
+
let typings = ["none"];
|
|
370
|
+
if (prepareTyping) typings = [prepareTyping(chunk.encoder)];
|
|
371
|
+
return {
|
|
372
|
+
sql: escapeParam(paramStartIndex.value++, mappedValue),
|
|
373
|
+
params: [mappedValue],
|
|
374
|
+
typings
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (is(chunk, Placeholder)) return {
|
|
378
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
379
|
+
params: [chunk],
|
|
380
|
+
typings: ["none"]
|
|
381
|
+
};
|
|
382
|
+
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== void 0) return {
|
|
383
|
+
sql: escapeName(chunk.fieldAlias),
|
|
384
|
+
params: []
|
|
385
|
+
};
|
|
386
|
+
if (is(chunk, Subquery)) {
|
|
387
|
+
if (chunk._.isWith) return {
|
|
388
|
+
sql: escapeName(chunk._.alias),
|
|
389
|
+
params: []
|
|
390
|
+
};
|
|
391
|
+
return this.buildQueryFromSourceParams([
|
|
392
|
+
new StringChunk("("),
|
|
393
|
+
chunk._.sql,
|
|
394
|
+
new StringChunk(") "),
|
|
395
|
+
new Name(chunk._.alias)
|
|
396
|
+
], config);
|
|
397
|
+
}
|
|
398
|
+
if (isPgEnum(chunk)) {
|
|
399
|
+
if (chunk.schema) return {
|
|
400
|
+
sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName),
|
|
401
|
+
params: []
|
|
402
|
+
};
|
|
403
|
+
return {
|
|
404
|
+
sql: escapeName(chunk.enumName),
|
|
405
|
+
params: []
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
if (isSQLWrapper(chunk)) {
|
|
409
|
+
if (chunk.shouldOmitSQLParens?.()) return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
410
|
+
return this.buildQueryFromSourceParams([
|
|
411
|
+
new StringChunk("("),
|
|
412
|
+
chunk.getSQL(),
|
|
413
|
+
new StringChunk(")")
|
|
414
|
+
], config);
|
|
415
|
+
}
|
|
416
|
+
if (inlineParams) return {
|
|
417
|
+
sql: this.mapInlineParam(chunk, config),
|
|
418
|
+
params: []
|
|
419
|
+
};
|
|
420
|
+
return {
|
|
421
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
422
|
+
params: [chunk],
|
|
423
|
+
typings: ["none"]
|
|
424
|
+
};
|
|
425
|
+
}));
|
|
426
|
+
}
|
|
427
|
+
mapInlineParam(chunk, { escapeString }) {
|
|
428
|
+
if (chunk === null) return "null";
|
|
429
|
+
if (typeof chunk === "number" || typeof chunk === "boolean") return chunk.toString();
|
|
430
|
+
if (typeof chunk === "string") return escapeString(chunk);
|
|
431
|
+
if (typeof chunk === "object") {
|
|
432
|
+
const mappedValueAsString = chunk.toString();
|
|
433
|
+
if (mappedValueAsString === "[object Object]") return escapeString(JSON.stringify(chunk));
|
|
434
|
+
return escapeString(mappedValueAsString);
|
|
435
|
+
}
|
|
436
|
+
throw new Error("Unexpected param value: " + chunk);
|
|
437
|
+
}
|
|
438
|
+
getSQL() {
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
as(alias) {
|
|
442
|
+
if (alias === void 0) return this;
|
|
443
|
+
return new SQL.Aliased(this, alias);
|
|
444
|
+
}
|
|
445
|
+
mapWith(decoder) {
|
|
446
|
+
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
inlineParams() {
|
|
450
|
+
this.shouldInlineParams = true;
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* This method is used to conditionally include a part of the query.
|
|
455
|
+
*
|
|
456
|
+
* @param condition - Condition to check
|
|
457
|
+
* @returns itself if the condition is `true`, otherwise `undefined`
|
|
458
|
+
*/
|
|
459
|
+
if(condition) {
|
|
460
|
+
return condition ? this : void 0;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
var Name = class {
|
|
464
|
+
constructor(value) {
|
|
465
|
+
this.value = value;
|
|
466
|
+
}
|
|
467
|
+
static [entityKind] = "Name";
|
|
468
|
+
brand;
|
|
469
|
+
getSQL() {
|
|
470
|
+
return new SQL([this]);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
function isDriverValueEncoder(value) {
|
|
474
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
475
|
+
}
|
|
476
|
+
const noopDecoder = { mapFromDriverValue: (value) => value };
|
|
477
|
+
const noopEncoder = { mapToDriverValue: (value) => value };
|
|
478
|
+
({
|
|
479
|
+
...noopDecoder,
|
|
480
|
+
...noopEncoder
|
|
481
|
+
});
|
|
482
|
+
var Param = class {
|
|
483
|
+
/**
|
|
484
|
+
* @param value - Parameter value
|
|
485
|
+
* @param encoder - Encoder to convert the value to a driver parameter
|
|
486
|
+
*/
|
|
487
|
+
constructor(value, encoder = noopEncoder) {
|
|
488
|
+
this.value = value;
|
|
489
|
+
this.encoder = encoder;
|
|
490
|
+
}
|
|
491
|
+
static [entityKind] = "Param";
|
|
492
|
+
brand;
|
|
493
|
+
getSQL() {
|
|
494
|
+
return new SQL([this]);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
function sql(strings, ...params) {
|
|
498
|
+
const queryChunks = [];
|
|
499
|
+
if (params.length > 0 || strings.length > 0 && strings[0] !== "") queryChunks.push(new StringChunk(strings[0]));
|
|
500
|
+
for (const [paramIndex, param2] of params.entries()) queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
501
|
+
return new SQL(queryChunks);
|
|
502
|
+
}
|
|
503
|
+
((sql2) => {
|
|
504
|
+
function empty() {
|
|
505
|
+
return new SQL([]);
|
|
506
|
+
}
|
|
507
|
+
sql2.empty = empty;
|
|
508
|
+
function fromList(list) {
|
|
509
|
+
return new SQL(list);
|
|
510
|
+
}
|
|
511
|
+
sql2.fromList = fromList;
|
|
512
|
+
function raw(str) {
|
|
513
|
+
return new SQL([new StringChunk(str)]);
|
|
514
|
+
}
|
|
515
|
+
sql2.raw = raw;
|
|
516
|
+
function join(chunks, separator) {
|
|
517
|
+
const result = [];
|
|
518
|
+
for (const [i, chunk] of chunks.entries()) {
|
|
519
|
+
if (i > 0 && separator !== void 0) result.push(separator);
|
|
520
|
+
result.push(chunk);
|
|
521
|
+
}
|
|
522
|
+
return new SQL(result);
|
|
523
|
+
}
|
|
524
|
+
sql2.join = join;
|
|
525
|
+
function identifier(value) {
|
|
526
|
+
return new Name(value);
|
|
527
|
+
}
|
|
528
|
+
sql2.identifier = identifier;
|
|
529
|
+
function placeholder2(name2) {
|
|
530
|
+
return new Placeholder(name2);
|
|
531
|
+
}
|
|
532
|
+
sql2.placeholder = placeholder2;
|
|
533
|
+
function param2(value, encoder) {
|
|
534
|
+
return new Param(value, encoder);
|
|
535
|
+
}
|
|
536
|
+
sql2.param = param2;
|
|
537
|
+
})(sql || (sql = {}));
|
|
538
|
+
((SQL2) => {
|
|
539
|
+
class Aliased {
|
|
540
|
+
constructor(sql2, fieldAlias) {
|
|
541
|
+
this.sql = sql2;
|
|
542
|
+
this.fieldAlias = fieldAlias;
|
|
543
|
+
}
|
|
544
|
+
static [entityKind] = "SQL.Aliased";
|
|
545
|
+
/** @internal */
|
|
546
|
+
isSelectionField = false;
|
|
547
|
+
getSQL() {
|
|
548
|
+
return this.sql;
|
|
549
|
+
}
|
|
550
|
+
/** @internal */
|
|
551
|
+
clone() {
|
|
552
|
+
return new Aliased(this.sql, this.fieldAlias);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
SQL2.Aliased = Aliased;
|
|
556
|
+
})(SQL || (SQL = {}));
|
|
557
|
+
var Placeholder = class {
|
|
558
|
+
constructor(name2) {
|
|
559
|
+
this.name = name2;
|
|
560
|
+
}
|
|
561
|
+
static [entityKind] = "Placeholder";
|
|
562
|
+
getSQL() {
|
|
563
|
+
return new SQL([this]);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
function fillPlaceholders(params, values) {
|
|
567
|
+
return params.map((p) => {
|
|
568
|
+
if (is(p, Placeholder)) {
|
|
569
|
+
if (!(p.name in values)) throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
570
|
+
return values[p.name];
|
|
571
|
+
}
|
|
572
|
+
if (is(p, Param) && is(p.value, Placeholder)) {
|
|
573
|
+
if (!(p.value.name in values)) throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
|
574
|
+
return p.encoder.mapToDriverValue(values[p.value.name]);
|
|
575
|
+
}
|
|
576
|
+
return p;
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
const IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
|
|
580
|
+
var View = class {
|
|
581
|
+
static [entityKind] = "View";
|
|
582
|
+
/** @internal */
|
|
583
|
+
[ViewBaseConfig];
|
|
584
|
+
/** @internal */
|
|
585
|
+
[IsDrizzleView] = true;
|
|
586
|
+
constructor({ name: name2, schema, selectedFields, query }) {
|
|
587
|
+
this[ViewBaseConfig] = {
|
|
588
|
+
name: name2,
|
|
589
|
+
originalName: name2,
|
|
590
|
+
schema,
|
|
591
|
+
selectedFields,
|
|
592
|
+
query,
|
|
593
|
+
isExisting: !query,
|
|
594
|
+
isAlias: false
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
getSQL() {
|
|
598
|
+
return new SQL([this]);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
Column.prototype.getSQL = function() {
|
|
602
|
+
return new SQL([this]);
|
|
603
|
+
};
|
|
604
|
+
Table.prototype.getSQL = function() {
|
|
605
|
+
return new SQL([this]);
|
|
606
|
+
};
|
|
607
|
+
Subquery.prototype.getSQL = function() {
|
|
608
|
+
return new SQL([this]);
|
|
609
|
+
};
|
|
610
|
+
//#endregion
|
|
611
|
+
export { sql as C, isSQLWrapper as S, version as T, fillPlaceholders as _, PgColumn as a, is as b, Schema as c, Table as d, TableName as f, entityKind as g, WithSubquery as h, PgArray as i, StringChunk as l, ViewBaseConfig as m, Columns as n, Placeholder as o, View as p, Param as r, SQL as s, Column as t, Subquery as u, getTableName as v, tracer as w, isDriverValueEncoder as x, getTableUniqueName as y };
|