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,279 @@
|
|
|
1
|
+
import { C as sql, _ as fillPlaceholders, b as is, d as Table, g as entityKind, i as PgArray, r as Param } from "./sql-CNZp2yLp-Bwugq384.js";
|
|
2
|
+
import { M as mapResultRow, n as DefaultLogger, o as NoopCache, x as extractTablesRelationalConfig, y as createTableRelationsHelpers } from "./logger-TIsK7375-CLNNa25D.js";
|
|
3
|
+
import { a as PgTransaction, i as PgSession, n as PgDialect, r as PgPreparedQuery, t as PgDatabase } from "./session-BOEirggu-DTmpyU_x.js";
|
|
4
|
+
import { BeginTransactionCommand, CommitTransactionCommand, ExecuteStatementCommand, RDSDataClient, RollbackTransactionCommand, TypeHint } from "@aws-sdk/client-rds-data";
|
|
5
|
+
//#region ../db/dist/pg-ylxXyvKj.js
|
|
6
|
+
function getValueFromDataApi(field) {
|
|
7
|
+
if (field.stringValue !== void 0) return field.stringValue;
|
|
8
|
+
else if (field.booleanValue !== void 0) return field.booleanValue;
|
|
9
|
+
else if (field.doubleValue !== void 0) return field.doubleValue;
|
|
10
|
+
else if (field.isNull !== void 0) return null;
|
|
11
|
+
else if (field.longValue !== void 0) return field.longValue;
|
|
12
|
+
else if (field.blobValue !== void 0) return field.blobValue;
|
|
13
|
+
else if (field.arrayValue !== void 0) {
|
|
14
|
+
if (field.arrayValue.stringValues !== void 0) return field.arrayValue.stringValues;
|
|
15
|
+
if (field.arrayValue.longValues !== void 0) return field.arrayValue.longValues;
|
|
16
|
+
if (field.arrayValue.doubleValues !== void 0) return field.arrayValue.doubleValues;
|
|
17
|
+
if (field.arrayValue.booleanValues !== void 0) return field.arrayValue.booleanValues;
|
|
18
|
+
if (field.arrayValue.arrayValues !== void 0) return field.arrayValue.arrayValues;
|
|
19
|
+
throw new Error("Unknown array type");
|
|
20
|
+
} else throw new Error("Unknown type");
|
|
21
|
+
}
|
|
22
|
+
function typingsToAwsTypeHint(typings) {
|
|
23
|
+
if (typings === "date") return TypeHint.DATE;
|
|
24
|
+
else if (typings === "decimal") return TypeHint.DECIMAL;
|
|
25
|
+
else if (typings === "json") return TypeHint.JSON;
|
|
26
|
+
else if (typings === "time") return TypeHint.TIME;
|
|
27
|
+
else if (typings === "timestamp") return TypeHint.TIMESTAMP;
|
|
28
|
+
else if (typings === "uuid") return TypeHint.UUID;
|
|
29
|
+
else return;
|
|
30
|
+
}
|
|
31
|
+
function toValueParam(value, typings) {
|
|
32
|
+
const response = {
|
|
33
|
+
value: {},
|
|
34
|
+
typeHint: typingsToAwsTypeHint(typings)
|
|
35
|
+
};
|
|
36
|
+
if (value === null) response.value = { isNull: true };
|
|
37
|
+
else if (typeof value === "string") switch (response.typeHint) {
|
|
38
|
+
case TypeHint.DATE:
|
|
39
|
+
response.value = { stringValue: value.split("T")[0] };
|
|
40
|
+
break;
|
|
41
|
+
case TypeHint.TIMESTAMP:
|
|
42
|
+
response.value = { stringValue: value.replace("T", " ").replace("Z", "") };
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
response.value = { stringValue: value };
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
else if (typeof value === "number" && Number.isInteger(value)) response.value = { longValue: value };
|
|
49
|
+
else if (typeof value === "number" && !Number.isInteger(value)) response.value = { doubleValue: value };
|
|
50
|
+
else if (typeof value === "boolean") response.value = { booleanValue: value };
|
|
51
|
+
else if (value instanceof Date) response.value = { stringValue: value.toISOString().replace("T", " ").replace("Z", "") };
|
|
52
|
+
else throw new Error(`Unknown type for ${value}`);
|
|
53
|
+
return response;
|
|
54
|
+
}
|
|
55
|
+
var AwsDataApiPreparedQuery = class extends PgPreparedQuery {
|
|
56
|
+
constructor(client, queryString, params, typings, options, cache, queryMetadata, cacheConfig, fields, transactionId, _isResponseInArrayMode, customResultMapper) {
|
|
57
|
+
super({
|
|
58
|
+
sql: queryString,
|
|
59
|
+
params
|
|
60
|
+
}, cache, queryMetadata, cacheConfig);
|
|
61
|
+
this.client = client;
|
|
62
|
+
this.queryString = queryString;
|
|
63
|
+
this.params = params;
|
|
64
|
+
this.typings = typings;
|
|
65
|
+
this.options = options;
|
|
66
|
+
this.fields = fields;
|
|
67
|
+
this.transactionId = transactionId;
|
|
68
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
69
|
+
this.customResultMapper = customResultMapper;
|
|
70
|
+
this.rawQuery = new ExecuteStatementCommand({
|
|
71
|
+
sql: queryString,
|
|
72
|
+
parameters: [],
|
|
73
|
+
secretArn: options.secretArn,
|
|
74
|
+
resourceArn: options.resourceArn,
|
|
75
|
+
database: options.database,
|
|
76
|
+
transactionId,
|
|
77
|
+
includeResultMetadata: !fields && !customResultMapper
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
static [entityKind] = "AwsDataApiPreparedQuery";
|
|
81
|
+
rawQuery;
|
|
82
|
+
async execute(placeholderValues = {}) {
|
|
83
|
+
const { fields, joinsNotNullableMap, customResultMapper } = this;
|
|
84
|
+
const result = await this.values(placeholderValues);
|
|
85
|
+
if (!fields && !customResultMapper) {
|
|
86
|
+
const { columnMetadata, rows } = result;
|
|
87
|
+
if (!columnMetadata) return result;
|
|
88
|
+
const mappedRows = rows.map((sourceRow) => {
|
|
89
|
+
const row = {};
|
|
90
|
+
for (const [index, value] of sourceRow.entries()) {
|
|
91
|
+
const metadata = columnMetadata[index];
|
|
92
|
+
if (!metadata) throw new Error(`Unexpected state: no column metadata found for index ${index}. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`);
|
|
93
|
+
if (!metadata.name) throw new Error(`Unexpected state: no column name for index ${index} found in the column metadata. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`);
|
|
94
|
+
row[metadata.name] = value;
|
|
95
|
+
}
|
|
96
|
+
return row;
|
|
97
|
+
});
|
|
98
|
+
return Object.assign(result, { rows: mappedRows });
|
|
99
|
+
}
|
|
100
|
+
return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
101
|
+
}
|
|
102
|
+
async all(placeholderValues) {
|
|
103
|
+
const result = await this.execute(placeholderValues);
|
|
104
|
+
if (!this.fields && !this.customResultMapper) return result.rows;
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
async values(placeholderValues = {}) {
|
|
108
|
+
const params = fillPlaceholders(this.params, placeholderValues ?? {});
|
|
109
|
+
this.rawQuery.input.parameters = params.map((param, index) => ({
|
|
110
|
+
name: `${index + 1}`,
|
|
111
|
+
...toValueParam(param, this.typings[index])
|
|
112
|
+
}));
|
|
113
|
+
this.options.logger?.logQuery(this.rawQuery.input.sql, this.rawQuery.input.parameters);
|
|
114
|
+
const result = await this.queryWithCache(this.queryString, params, async () => {
|
|
115
|
+
return await this.client.send(this.rawQuery);
|
|
116
|
+
});
|
|
117
|
+
const rows = result.records?.map((row) => {
|
|
118
|
+
return row.map((field) => getValueFromDataApi(field));
|
|
119
|
+
}) ?? [];
|
|
120
|
+
return {
|
|
121
|
+
...result,
|
|
122
|
+
rows
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** @internal */
|
|
126
|
+
mapResultRows(records, columnMetadata) {
|
|
127
|
+
return records.map((record) => {
|
|
128
|
+
const row = {};
|
|
129
|
+
for (const [index, field] of record.entries()) {
|
|
130
|
+
const { name } = columnMetadata[index];
|
|
131
|
+
row[name ?? index] = getValueFromDataApi(field);
|
|
132
|
+
}
|
|
133
|
+
return row;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** @internal */
|
|
137
|
+
isResponseInArrayMode() {
|
|
138
|
+
return this._isResponseInArrayMode;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var AwsDataApiSession = class AwsDataApiSession extends PgSession {
|
|
142
|
+
constructor(client, dialect, schema, options, transactionId) {
|
|
143
|
+
super(dialect);
|
|
144
|
+
this.client = client;
|
|
145
|
+
this.schema = schema;
|
|
146
|
+
this.options = options;
|
|
147
|
+
this.transactionId = transactionId;
|
|
148
|
+
this.rawQuery = {
|
|
149
|
+
secretArn: options.secretArn,
|
|
150
|
+
resourceArn: options.resourceArn,
|
|
151
|
+
database: options.database
|
|
152
|
+
};
|
|
153
|
+
this.cache = options.cache ?? new NoopCache();
|
|
154
|
+
}
|
|
155
|
+
static [entityKind] = "AwsDataApiSession";
|
|
156
|
+
/** @internal */
|
|
157
|
+
rawQuery;
|
|
158
|
+
cache;
|
|
159
|
+
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig, transactionId) {
|
|
160
|
+
return new AwsDataApiPreparedQuery(this.client, query.sql, query.params, query.typings ?? [], this.options, this.cache, queryMetadata, cacheConfig, fields, transactionId ?? this.transactionId, isResponseInArrayMode, customResultMapper);
|
|
161
|
+
}
|
|
162
|
+
execute(query) {
|
|
163
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), void 0, void 0, false, void 0, void 0, void 0, this.transactionId).execute();
|
|
164
|
+
}
|
|
165
|
+
async transaction(transaction, config) {
|
|
166
|
+
const { transactionId } = await this.client.send(new BeginTransactionCommand(this.rawQuery));
|
|
167
|
+
const session = new AwsDataApiSession(this.client, this.dialect, this.schema, this.options, transactionId);
|
|
168
|
+
const tx = new AwsDataApiTransaction(this.dialect, session, this.schema);
|
|
169
|
+
if (config) await tx.setTransaction(config);
|
|
170
|
+
try {
|
|
171
|
+
const result = await transaction(tx);
|
|
172
|
+
await this.client.send(new CommitTransactionCommand({
|
|
173
|
+
...this.rawQuery,
|
|
174
|
+
transactionId
|
|
175
|
+
}));
|
|
176
|
+
return result;
|
|
177
|
+
} catch (e) {
|
|
178
|
+
await this.client.send(new RollbackTransactionCommand({
|
|
179
|
+
...this.rawQuery,
|
|
180
|
+
transactionId
|
|
181
|
+
}));
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var AwsDataApiTransaction = class AwsDataApiTransaction extends PgTransaction {
|
|
187
|
+
static [entityKind] = "AwsDataApiTransaction";
|
|
188
|
+
async transaction(transaction) {
|
|
189
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
190
|
+
const tx = new AwsDataApiTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
|
191
|
+
await this.session.execute(sql.raw(`savepoint ${savepointName}`));
|
|
192
|
+
try {
|
|
193
|
+
const result = await transaction(tx);
|
|
194
|
+
await this.session.execute(sql.raw(`release savepoint ${savepointName}`));
|
|
195
|
+
return result;
|
|
196
|
+
} catch (e) {
|
|
197
|
+
await this.session.execute(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var AwsDataApiPgDatabase = class extends PgDatabase {
|
|
203
|
+
static [entityKind] = "AwsDataApiPgDatabase";
|
|
204
|
+
execute(query) {
|
|
205
|
+
return super.execute(query);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var AwsPgDialect = class extends PgDialect {
|
|
209
|
+
static [entityKind] = "AwsPgDialect";
|
|
210
|
+
escapeParam(num) {
|
|
211
|
+
return `:${num + 1}`;
|
|
212
|
+
}
|
|
213
|
+
buildInsertQuery({ table, values, onConflict, returning, select, withList }) {
|
|
214
|
+
const columns = table[Table.Symbol.Columns];
|
|
215
|
+
if (!select) for (const value of values) for (const fieldName of Object.keys(columns)) {
|
|
216
|
+
const colValue = value[fieldName];
|
|
217
|
+
if (is(colValue, Param) && colValue.value !== void 0 && is(colValue.encoder, PgArray) && Array.isArray(colValue.value)) value[fieldName] = sql`cast(${colValue} as ${sql.raw(colValue.encoder.getSQLType())})`;
|
|
218
|
+
}
|
|
219
|
+
return super.buildInsertQuery({
|
|
220
|
+
table,
|
|
221
|
+
values,
|
|
222
|
+
onConflict,
|
|
223
|
+
returning,
|
|
224
|
+
withList
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
buildUpdateSet(table, set) {
|
|
228
|
+
const columns = table[Table.Symbol.Columns];
|
|
229
|
+
for (const [colName, colValue] of Object.entries(set)) if (columns[colName] && is(colValue, Param) && colValue.value !== void 0 && is(colValue.encoder, PgArray) && Array.isArray(colValue.value)) set[colName] = sql`cast(${colValue} as ${sql.raw(colValue.encoder.getSQLType())})`;
|
|
230
|
+
return super.buildUpdateSet(table, set);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
function construct(client, config) {
|
|
234
|
+
const dialect = new AwsPgDialect({ casing: config.casing });
|
|
235
|
+
let logger;
|
|
236
|
+
if (config.logger === true) logger = new DefaultLogger();
|
|
237
|
+
else if (config.logger !== false) logger = config.logger;
|
|
238
|
+
let schema;
|
|
239
|
+
if (config.schema) {
|
|
240
|
+
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
241
|
+
schema = {
|
|
242
|
+
fullSchema: config.schema,
|
|
243
|
+
schema: tablesConfig.tables,
|
|
244
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
const db = new AwsDataApiPgDatabase(dialect, new AwsDataApiSession(client, dialect, schema, {
|
|
248
|
+
...config,
|
|
249
|
+
logger,
|
|
250
|
+
cache: config.cache
|
|
251
|
+
}, void 0), schema);
|
|
252
|
+
db.$client = client;
|
|
253
|
+
db.$cache = config.cache;
|
|
254
|
+
if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
|
|
255
|
+
return db;
|
|
256
|
+
}
|
|
257
|
+
function drizzle(...params) {
|
|
258
|
+
if (params[0] instanceof RDSDataClient || params[0].constructor.name !== "Object") return construct(params[0], params[1]);
|
|
259
|
+
if (params[0].client) {
|
|
260
|
+
const { client, ...drizzleConfig2 } = params[0];
|
|
261
|
+
return construct(client, drizzleConfig2);
|
|
262
|
+
}
|
|
263
|
+
const { connection, ...drizzleConfig } = params[0];
|
|
264
|
+
const { resourceArn, database, secretArn, ...rdsConfig } = connection;
|
|
265
|
+
return construct(new RDSDataClient(rdsConfig), {
|
|
266
|
+
resourceArn,
|
|
267
|
+
database,
|
|
268
|
+
secretArn,
|
|
269
|
+
...drizzleConfig
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
((drizzle2) => {
|
|
273
|
+
function mock(config) {
|
|
274
|
+
return construct({}, config);
|
|
275
|
+
}
|
|
276
|
+
drizzle2.mock = mock;
|
|
277
|
+
})(drizzle || (drizzle = {}));
|
|
278
|
+
//#endregion
|
|
279
|
+
export { AwsDataApiSession, drizzle };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { n as dn, t as Xe } from "./dist-C481edUb-CHbOkeXH.js";
|
|
2
|
+
import { C as sql, _ as fillPlaceholders, g as entityKind } from "./sql-CNZp2yLp-Bwugq384.js";
|
|
3
|
+
import { M as mapResultRow, O as isConfig, n as DefaultLogger, o as NoopCache, s as NoopLogger, x as extractTablesRelationalConfig, y as createTableRelationsHelpers } from "./logger-TIsK7375-CLNNa25D.js";
|
|
4
|
+
import { a as PgTransaction, i as PgSession, n as PgDialect, r as PgPreparedQuery, t as PgDatabase } from "./session-BOEirggu-DTmpyU_x.js";
|
|
5
|
+
//#region ../db/dist/pglite-CPs4w-D9.js
|
|
6
|
+
var PglitePreparedQuery = class extends PgPreparedQuery {
|
|
7
|
+
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper) {
|
|
8
|
+
super({
|
|
9
|
+
sql: queryString,
|
|
10
|
+
params
|
|
11
|
+
}, cache, queryMetadata, cacheConfig);
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.queryString = queryString;
|
|
14
|
+
this.params = params;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.fields = fields;
|
|
17
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
18
|
+
this.customResultMapper = customResultMapper;
|
|
19
|
+
this.rawQueryConfig = {
|
|
20
|
+
rowMode: "object",
|
|
21
|
+
parsers: {
|
|
22
|
+
[dn.TIMESTAMP]: (value) => value,
|
|
23
|
+
[dn.TIMESTAMPTZ]: (value) => value,
|
|
24
|
+
[dn.INTERVAL]: (value) => value,
|
|
25
|
+
[dn.DATE]: (value) => value,
|
|
26
|
+
[1231]: (value) => value,
|
|
27
|
+
[1115]: (value) => value,
|
|
28
|
+
[1185]: (value) => value,
|
|
29
|
+
[1187]: (value) => value,
|
|
30
|
+
[1182]: (value) => value
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
this.queryConfig = {
|
|
34
|
+
rowMode: "array",
|
|
35
|
+
parsers: {
|
|
36
|
+
[dn.TIMESTAMP]: (value) => value,
|
|
37
|
+
[dn.TIMESTAMPTZ]: (value) => value,
|
|
38
|
+
[dn.INTERVAL]: (value) => value,
|
|
39
|
+
[dn.DATE]: (value) => value,
|
|
40
|
+
[1231]: (value) => value,
|
|
41
|
+
[1115]: (value) => value,
|
|
42
|
+
[1185]: (value) => value,
|
|
43
|
+
[1187]: (value) => value,
|
|
44
|
+
[1182]: (value) => value
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
static [entityKind] = "PglitePreparedQuery";
|
|
49
|
+
rawQueryConfig;
|
|
50
|
+
queryConfig;
|
|
51
|
+
async execute(placeholderValues = {}) {
|
|
52
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
53
|
+
this.logger.logQuery(this.queryString, params);
|
|
54
|
+
const { fields, client, queryConfig, joinsNotNullableMap, customResultMapper, queryString, rawQueryConfig } = this;
|
|
55
|
+
if (!fields && !customResultMapper) return this.queryWithCache(queryString, params, async () => {
|
|
56
|
+
return await client.query(queryString, params, rawQueryConfig);
|
|
57
|
+
});
|
|
58
|
+
const result = await this.queryWithCache(queryString, params, async () => {
|
|
59
|
+
return await client.query(queryString, params, queryConfig);
|
|
60
|
+
});
|
|
61
|
+
return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
62
|
+
}
|
|
63
|
+
all(placeholderValues = {}) {
|
|
64
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
65
|
+
this.logger.logQuery(this.queryString, params);
|
|
66
|
+
return this.queryWithCache(this.queryString, params, async () => {
|
|
67
|
+
return await this.client.query(this.queryString, params, this.rawQueryConfig);
|
|
68
|
+
}).then((result) => result.rows);
|
|
69
|
+
}
|
|
70
|
+
/** @internal */
|
|
71
|
+
isResponseInArrayMode() {
|
|
72
|
+
return this._isResponseInArrayMode;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var PgliteSession = class PgliteSession extends PgSession {
|
|
76
|
+
constructor(client, dialect, schema, options = {}) {
|
|
77
|
+
super(dialect);
|
|
78
|
+
this.client = client;
|
|
79
|
+
this.schema = schema;
|
|
80
|
+
this.options = options;
|
|
81
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
82
|
+
this.cache = options.cache ?? new NoopCache();
|
|
83
|
+
}
|
|
84
|
+
static [entityKind] = "PgliteSession";
|
|
85
|
+
logger;
|
|
86
|
+
cache;
|
|
87
|
+
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
|
88
|
+
return new PglitePreparedQuery(this.client, query.sql, query.params, this.logger, this.cache, queryMetadata, cacheConfig, fields, name, isResponseInArrayMode, customResultMapper);
|
|
89
|
+
}
|
|
90
|
+
async transaction(transaction, config) {
|
|
91
|
+
return this.client.transaction(async (client) => {
|
|
92
|
+
const session = new PgliteSession(client, this.dialect, this.schema, this.options);
|
|
93
|
+
const tx = new PgliteTransaction(this.dialect, session, this.schema);
|
|
94
|
+
if (config) await tx.setTransaction(config);
|
|
95
|
+
return transaction(tx);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async count(sql2) {
|
|
99
|
+
const res = await this.execute(sql2);
|
|
100
|
+
return Number(res["rows"][0]["count"]);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var PgliteTransaction = class PgliteTransaction extends PgTransaction {
|
|
104
|
+
static [entityKind] = "PgliteTransaction";
|
|
105
|
+
async transaction(transaction) {
|
|
106
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
107
|
+
const tx = new PgliteTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
|
108
|
+
await tx.execute(sql.raw(`savepoint ${savepointName}`));
|
|
109
|
+
try {
|
|
110
|
+
const result = await transaction(tx);
|
|
111
|
+
await tx.execute(sql.raw(`release savepoint ${savepointName}`));
|
|
112
|
+
return result;
|
|
113
|
+
} catch (err) {
|
|
114
|
+
await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var PgliteDriver = class {
|
|
120
|
+
constructor(client, dialect, options = {}) {
|
|
121
|
+
this.client = client;
|
|
122
|
+
this.dialect = dialect;
|
|
123
|
+
this.options = options;
|
|
124
|
+
}
|
|
125
|
+
static [entityKind] = "PgliteDriver";
|
|
126
|
+
createSession(schema) {
|
|
127
|
+
return new PgliteSession(this.client, this.dialect, schema, {
|
|
128
|
+
logger: this.options.logger,
|
|
129
|
+
cache: this.options.cache
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var PgliteDatabase = class extends PgDatabase {
|
|
134
|
+
static [entityKind] = "PgliteDatabase";
|
|
135
|
+
};
|
|
136
|
+
function construct(client, config = {}) {
|
|
137
|
+
const dialect = new PgDialect({ casing: config.casing });
|
|
138
|
+
let logger;
|
|
139
|
+
if (config.logger === true) logger = new DefaultLogger();
|
|
140
|
+
else if (config.logger !== false) logger = config.logger;
|
|
141
|
+
let schema;
|
|
142
|
+
if (config.schema) {
|
|
143
|
+
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
144
|
+
schema = {
|
|
145
|
+
fullSchema: config.schema,
|
|
146
|
+
schema: tablesConfig.tables,
|
|
147
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const db = new PgliteDatabase(dialect, new PgliteDriver(client, dialect, {
|
|
151
|
+
logger,
|
|
152
|
+
cache: config.cache
|
|
153
|
+
}).createSession(schema), schema);
|
|
154
|
+
db.$client = client;
|
|
155
|
+
db.$cache = config.cache;
|
|
156
|
+
if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
|
|
157
|
+
return db;
|
|
158
|
+
}
|
|
159
|
+
function drizzle(...params) {
|
|
160
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(new Xe(params[0]), params[1]);
|
|
161
|
+
if (isConfig(params[0])) {
|
|
162
|
+
const { connection, client, ...drizzleConfig } = params[0];
|
|
163
|
+
if (client) return construct(client, drizzleConfig);
|
|
164
|
+
if (typeof connection === "object") {
|
|
165
|
+
const { dataDir, ...options } = connection;
|
|
166
|
+
return construct(new Xe(dataDir, options), drizzleConfig);
|
|
167
|
+
}
|
|
168
|
+
return construct(new Xe(connection), drizzleConfig);
|
|
169
|
+
}
|
|
170
|
+
return construct(params[0], params[1]);
|
|
171
|
+
}
|
|
172
|
+
((drizzle2) => {
|
|
173
|
+
function mock(config) {
|
|
174
|
+
return construct({}, config);
|
|
175
|
+
}
|
|
176
|
+
drizzle2.mock = mock;
|
|
177
|
+
})(drizzle || (drizzle = {}));
|
|
178
|
+
//#endregion
|
|
179
|
+
export { drizzle as t };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { C as sql, _ as fillPlaceholders, b as is, g as entityKind, t as Column } from "./sql-CNZp2yLp-Bwugq384.js";
|
|
2
|
+
import { M as mapResultRow, O as isConfig, n as DefaultLogger, o as NoopCache, s as NoopLogger, x as extractTablesRelationalConfig, y as createTableRelationsHelpers } from "./logger-TIsK7375-CLNNa25D.js";
|
|
3
|
+
import { t as MySqlDialect } from "./query-builder-CLJAKedv-DTZiP7B6.js";
|
|
4
|
+
import { i as MySqlTransaction, n as MySqlPreparedQuery, r as MySqlSession, t as MySqlDatabase } from "./session-CAUQtT0A-BoVK2x7A.js";
|
|
5
|
+
import { Client } from "@planetscale/database";
|
|
6
|
+
//#region ../db/dist/planetscale-serverless-DUMheN-f.js
|
|
7
|
+
var PlanetScalePreparedQuery = class extends MySqlPreparedQuery {
|
|
8
|
+
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, customResultMapper, generatedIds, returningIds) {
|
|
9
|
+
super(cache, queryMetadata, cacheConfig);
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.queryString = queryString;
|
|
12
|
+
this.params = params;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.fields = fields;
|
|
15
|
+
this.customResultMapper = customResultMapper;
|
|
16
|
+
this.generatedIds = generatedIds;
|
|
17
|
+
this.returningIds = returningIds;
|
|
18
|
+
}
|
|
19
|
+
static [entityKind] = "PlanetScalePreparedQuery";
|
|
20
|
+
rawQuery = { as: "object" };
|
|
21
|
+
query = { as: "array" };
|
|
22
|
+
async execute(placeholderValues = {}) {
|
|
23
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
24
|
+
this.logger.logQuery(this.queryString, params);
|
|
25
|
+
const { fields, client, queryString, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;
|
|
26
|
+
if (!fields && !customResultMapper) {
|
|
27
|
+
const res = await this.queryWithCache(queryString, params, async () => {
|
|
28
|
+
return await client.execute(queryString, params, rawQuery);
|
|
29
|
+
});
|
|
30
|
+
const insertId = Number.parseFloat(res.insertId);
|
|
31
|
+
const affectedRows = res.rowsAffected;
|
|
32
|
+
if (returningIds) {
|
|
33
|
+
const returningResponse = [];
|
|
34
|
+
let j = 0;
|
|
35
|
+
for (let i = insertId; i < insertId + affectedRows; i++) {
|
|
36
|
+
for (const column of returningIds) {
|
|
37
|
+
const key = returningIds[0].path[0];
|
|
38
|
+
if (is(column.field, Column)) {
|
|
39
|
+
if (column.field.primary && column.field.autoIncrement) returningResponse.push({ [key]: i });
|
|
40
|
+
if (column.field.defaultFn && generatedIds) returningResponse.push({ [key]: generatedIds[j][key] });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
j++;
|
|
44
|
+
}
|
|
45
|
+
return returningResponse;
|
|
46
|
+
}
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
const { rows } = await this.queryWithCache(queryString, params, async () => {
|
|
50
|
+
return await client.execute(queryString, params, query);
|
|
51
|
+
});
|
|
52
|
+
if (customResultMapper) return customResultMapper(rows);
|
|
53
|
+
return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
54
|
+
}
|
|
55
|
+
iterator(_placeholderValues) {
|
|
56
|
+
throw new Error("Streaming is not supported by the PlanetScale Serverless driver");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var PlanetscaleSession = class PlanetscaleSession extends MySqlSession {
|
|
60
|
+
constructor(baseClient, dialect, tx, schema, options = {}) {
|
|
61
|
+
super(dialect);
|
|
62
|
+
this.baseClient = baseClient;
|
|
63
|
+
this.schema = schema;
|
|
64
|
+
this.options = options;
|
|
65
|
+
this.client = tx ?? baseClient;
|
|
66
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
67
|
+
this.cache = options.cache ?? new NoopCache();
|
|
68
|
+
}
|
|
69
|
+
static [entityKind] = "PlanetscaleSession";
|
|
70
|
+
logger;
|
|
71
|
+
client;
|
|
72
|
+
cache;
|
|
73
|
+
prepareQuery(query, fields, customResultMapper, generatedIds, returningIds, queryMetadata, cacheConfig) {
|
|
74
|
+
return new PlanetScalePreparedQuery(this.client, query.sql, query.params, this.logger, this.cache, queryMetadata, cacheConfig, fields, customResultMapper, generatedIds, returningIds);
|
|
75
|
+
}
|
|
76
|
+
async query(query, params) {
|
|
77
|
+
this.logger.logQuery(query, params);
|
|
78
|
+
return await this.client.execute(query, params, { as: "array" });
|
|
79
|
+
}
|
|
80
|
+
async queryObjects(query, params) {
|
|
81
|
+
return this.client.execute(query, params, { as: "object" });
|
|
82
|
+
}
|
|
83
|
+
all(query) {
|
|
84
|
+
const querySql = this.dialect.sqlToQuery(query);
|
|
85
|
+
this.logger.logQuery(querySql.sql, querySql.params);
|
|
86
|
+
return this.client.execute(querySql.sql, querySql.params, { as: "object" }).then((eQuery) => eQuery.rows);
|
|
87
|
+
}
|
|
88
|
+
async count(sql2) {
|
|
89
|
+
const res = await this.execute(sql2);
|
|
90
|
+
return Number(res["rows"][0]["count"]);
|
|
91
|
+
}
|
|
92
|
+
transaction(transaction) {
|
|
93
|
+
return this.baseClient.transaction((pstx) => {
|
|
94
|
+
const session = new PlanetscaleSession(this.baseClient, this.dialect, pstx, this.schema, this.options);
|
|
95
|
+
return transaction(new PlanetScaleTransaction(this.dialect, session, this.schema));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
var PlanetScaleTransaction = class PlanetScaleTransaction extends MySqlTransaction {
|
|
100
|
+
static [entityKind] = "PlanetScaleTransaction";
|
|
101
|
+
constructor(dialect, session, schema, nestedIndex = 0) {
|
|
102
|
+
super(dialect, session, schema, nestedIndex, "planetscale");
|
|
103
|
+
}
|
|
104
|
+
async transaction(transaction) {
|
|
105
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
106
|
+
const tx = new PlanetScaleTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
|
107
|
+
await tx.execute(sql.raw(`savepoint ${savepointName}`));
|
|
108
|
+
try {
|
|
109
|
+
const result = await transaction(tx);
|
|
110
|
+
await tx.execute(sql.raw(`release savepoint ${savepointName}`));
|
|
111
|
+
return result;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var PlanetScaleDatabase = class extends MySqlDatabase {
|
|
119
|
+
static [entityKind] = "PlanetScaleDatabase";
|
|
120
|
+
};
|
|
121
|
+
function construct(client, config = {}) {
|
|
122
|
+
if (!(client instanceof Client)) throw new Error(`Warning: You need to pass an instance of Client:
|
|
123
|
+
|
|
124
|
+
import { Client } from "@planetscale/database";
|
|
125
|
+
|
|
126
|
+
const client = new Client({
|
|
127
|
+
host: process.env["DATABASE_HOST"],
|
|
128
|
+
username: process.env["DATABASE_USERNAME"],
|
|
129
|
+
password: process.env["DATABASE_PASSWORD"],
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const db = drizzle(client);
|
|
133
|
+
`);
|
|
134
|
+
const dialect = new MySqlDialect({ casing: config.casing });
|
|
135
|
+
let logger;
|
|
136
|
+
if (config.logger === true) logger = new DefaultLogger();
|
|
137
|
+
else if (config.logger !== false) logger = config.logger;
|
|
138
|
+
let schema;
|
|
139
|
+
if (config.schema) {
|
|
140
|
+
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
141
|
+
schema = {
|
|
142
|
+
fullSchema: config.schema,
|
|
143
|
+
schema: tablesConfig.tables,
|
|
144
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const db = new PlanetScaleDatabase(dialect, new PlanetscaleSession(client, dialect, void 0, schema, {
|
|
148
|
+
logger,
|
|
149
|
+
cache: config.cache
|
|
150
|
+
}), schema, "planetscale");
|
|
151
|
+
db.$client = client;
|
|
152
|
+
db.$cache = config.cache;
|
|
153
|
+
if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
|
|
154
|
+
return db;
|
|
155
|
+
}
|
|
156
|
+
function drizzle(...params) {
|
|
157
|
+
if (typeof params[0] === "string") return construct(new Client({ url: params[0] }), params[1]);
|
|
158
|
+
if (isConfig(params[0])) {
|
|
159
|
+
const { connection, client, ...drizzleConfig } = params[0];
|
|
160
|
+
if (client) return construct(client, drizzleConfig);
|
|
161
|
+
return construct(typeof connection === "string" ? new Client({ url: connection }) : new Client(connection), drizzleConfig);
|
|
162
|
+
}
|
|
163
|
+
return construct(params[0], params[1]);
|
|
164
|
+
}
|
|
165
|
+
((drizzle2) => {
|
|
166
|
+
function mock(config) {
|
|
167
|
+
return construct({}, config);
|
|
168
|
+
}
|
|
169
|
+
drizzle2.mock = mock;
|
|
170
|
+
})(drizzle || (drizzle = {}));
|
|
171
|
+
//#endregion
|
|
172
|
+
export { drizzle };
|