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.
Files changed (45) hide show
  1. package/LICENSE +201 -201
  2. package/dist/better-sqlite3-CtLaF97z-DWR9uC3b.js +129 -0
  3. package/dist/chunk-2X2C5D2I-dJHtPFe9-DxsO-1YF.js +4026 -0
  4. package/dist/d1-pK2J-_yx-BoQTXsTa.js +185 -0
  5. package/dist/dialect-pBb6Cg_F-xgpUtfmk.js +570 -0
  6. package/dist/dist-C481edUb-CHbOkeXH.js +10131 -0
  7. package/dist/dist-DUzzleZr-DxHmeYjp.js +2 -0
  8. package/dist/index.d.ts +21 -21
  9. package/dist/index.js +20396 -18921
  10. package/dist/libsql-Nq-S0r5x-d2dAzhgO.js +240 -0
  11. package/dist/logger-TIsK7375-CLNNa25D.js +652 -0
  12. package/dist/migrator-B9kYwLqO-4g9JX3_v.js +8 -0
  13. package/dist/migrator-BfTfJctM-DrNlb1BS.js +8 -0
  14. package/dist/migrator-BjoW0_3j-CD-XdZ5a.js +8 -0
  15. package/dist/migrator-CWWlo_Jk-C4Hw4PPN.js +8 -0
  16. package/dist/migrator-CpiXRkls-COYfhljd.js +24 -0
  17. package/dist/migrator-CtqJkLVI-D1lU6ZV0.js +8 -0
  18. package/dist/migrator-CxcBjmET-Dcd21VIf.js +8 -0
  19. package/dist/migrator-Cyhbhxo_-Bh7sF0R3.js +21 -0
  20. package/dist/migrator-DG1mWUoR-DVfkqn_v.js +31 -0
  21. package/dist/migrator-DrWmHwY2-YjAfotd7.js +8 -0
  22. package/dist/migrator-WAPonQxA-CRvJJhKG.js +8 -0
  23. package/dist/migrator-Zdh8WMMx-gsmNXspd.js +8 -0
  24. package/dist/migrator-xRJ6NOTS-SsAuB-Gi.js +24 -0
  25. package/dist/migrator-xbWwvFYF-BjyVdQS8.js +8 -0
  26. package/dist/mysql2-DkoPEsRu-BMwVSCmY.js +251 -0
  27. package/dist/neon-serverless-BEVFA7yv-DGSPAG1z.js +205 -0
  28. package/dist/node-postgres-DQA7bEhW-CkM_cVLD.js +216 -0
  29. package/dist/nodefs-Bc8b83o_-DetP9qUa.js +24 -0
  30. package/dist/opfs-ahp-DbstDvx--CHskKtzG.js +365 -0
  31. package/dist/pg-ylxXyvKj-Hm8vcZoi.js +279 -0
  32. package/dist/pglite-CPs4w-D9-DHOg0D8W.js +179 -0
  33. package/dist/pglite-DMWgTUE6-BOIRUWUT.js +2 -0
  34. package/dist/planetscale-serverless-DUMheN-f-Dyc_W6V_.js +172 -0
  35. package/dist/query-builder-CLJAKedv-DTZiP7B6.js +1715 -0
  36. package/dist/query-builder-CT3_liD0-hhg5kRTk.js +1347 -0
  37. package/dist/session-BOEirggu-DTmpyU_x.js +2485 -0
  38. package/dist/session-CAUQtT0A-BoVK2x7A.js +745 -0
  39. package/dist/session-Cjeygn2Z-BO0mi6pq.js +989 -0
  40. package/dist/singlestore-Cdlo23hW-BuFJ4Zqb.js +1647 -0
  41. package/dist/sql-CNZp2yLp-Bwugq384.js +611 -0
  42. package/dist/sqlite-proxy-BgUfVEbZ-CsSkc-_K.js +190 -0
  43. package/dist/src-LcyXhCXE-C_vKJiLK.js +1920 -0
  44. package/dist/vercel-postgres-BYmFKsTS-CpV2usun.js +203 -0
  45. package/package.json +7 -8
@@ -0,0 +1,24 @@
1
+ import { C as sql } from "./sql-CNZp2yLp-Bwugq384.js";
2
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
3
+ //#region ../db/dist/migrator-CpiXRkls.js
4
+ async function migrate(db, config) {
5
+ const migrations = readMigrationFiles(config);
6
+ const migrationsTable = config.migrationsTable ?? "__drizzle_migrations";
7
+ const migrationTableCreate = sql`
8
+ CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
9
+ id SERIAL PRIMARY KEY,
10
+ hash text NOT NULL,
11
+ created_at numeric
12
+ )
13
+ `;
14
+ await db.session.run(migrationTableCreate);
15
+ const lastDbMigration = (await db.values(sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`))[0] ?? void 0;
16
+ const statementToBatch = [];
17
+ for (const migration of migrations) if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
18
+ for (const stmt of migration.sql) statementToBatch.push(db.run(sql.raw(stmt)));
19
+ statementToBatch.push(db.run(sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`));
20
+ }
21
+ await db.session.migrate(statementToBatch);
22
+ }
23
+ //#endregion
24
+ export { migrate };
@@ -0,0 +1,8 @@
1
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
+ //#region ../db/dist/migrator-CtqJkLVI.js
3
+ async function migrate(db, config) {
4
+ const migrations = readMigrationFiles(config);
5
+ await db.dialect.migrate(migrations, db.session, config);
6
+ }
7
+ //#endregion
8
+ export { migrate };
@@ -0,0 +1,8 @@
1
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
+ //#region ../db/dist/migrator-CxcBjmET.js
3
+ async function migrate(db, config) {
4
+ const migrations = readMigrationFiles(config);
5
+ await db.dialect.migrate(migrations, db.session, config);
6
+ }
7
+ //#endregion
8
+ export { migrate };
@@ -0,0 +1,21 @@
1
+ import { C as sql } from "./sql-CNZp2yLp-Bwugq384.js";
2
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
3
+ //#region ../db/dist/migrator-Cyhbhxo_.js
4
+ async function migrate(db, callback, config) {
5
+ const migrations = readMigrationFiles(config);
6
+ const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
7
+ const migrationTableCreate = sql`
8
+ CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
9
+ id SERIAL PRIMARY KEY,
10
+ hash text NOT NULL,
11
+ created_at numeric
12
+ )
13
+ `;
14
+ await db.run(migrationTableCreate);
15
+ const lastDbMigration = (await db.values(sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`))[0] ?? void 0;
16
+ const queriesToRun = [];
17
+ for (const migration of migrations) if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) queriesToRun.push(...migration.sql, `INSERT INTO \`${migrationsTable}\` ("hash", "created_at") VALUES('${migration.hash}', '${migration.folderMillis}')`);
18
+ await callback(queriesToRun);
19
+ }
20
+ //#endregion
21
+ export { migrate };
@@ -0,0 +1,31 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ //#region ../db/dist/migrator-DG1mWUoR.js
4
+ function readMigrationFiles(config) {
5
+ const migrationFolderTo = config.migrationsFolder;
6
+ const migrationQueries = [];
7
+ const journalPath = `${migrationFolderTo}/meta/_journal.json`;
8
+ if (!fs.existsSync(journalPath)) throw new Error(`Can't find meta/_journal.json file`);
9
+ const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
10
+ const journal = JSON.parse(journalAsString);
11
+ for (const journalEntry of journal.entries) {
12
+ const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
13
+ try {
14
+ const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
15
+ const result = query.split("--> statement-breakpoint").map((it) => {
16
+ return it;
17
+ });
18
+ migrationQueries.push({
19
+ sql: result,
20
+ bps: journalEntry.breakpoints,
21
+ folderMillis: journalEntry.when,
22
+ hash: crypto.createHash("sha256").update(query).digest("hex")
23
+ });
24
+ } catch {
25
+ throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
26
+ }
27
+ }
28
+ return migrationQueries;
29
+ }
30
+ //#endregion
31
+ export { readMigrationFiles as t };
@@ -0,0 +1,8 @@
1
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
+ //#region ../db/dist/migrator-DrWmHwY2.js
3
+ async function migrate(db, config) {
4
+ const migrations = readMigrationFiles(config);
5
+ await db.dialect.migrate(migrations, db.session, config);
6
+ }
7
+ //#endregion
8
+ export { migrate };
@@ -0,0 +1,8 @@
1
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
+ //#region ../db/dist/migrator-WAPonQxA.js
3
+ async function migrate(db, config) {
4
+ const migrations = readMigrationFiles(config);
5
+ await db.dialect.migrate(migrations, db.session, config);
6
+ }
7
+ //#endregion
8
+ export { migrate };
@@ -0,0 +1,8 @@
1
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
+ //#region ../db/dist/migrator-Zdh8WMMx.js
3
+ async function migrate(db, config) {
4
+ const migrations = readMigrationFiles(config);
5
+ await db.dialect.migrate(migrations, db.session, config);
6
+ }
7
+ //#endregion
8
+ export { migrate };
@@ -0,0 +1,24 @@
1
+ import { C as sql } from "./sql-CNZp2yLp-Bwugq384.js";
2
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
3
+ //#region ../db/dist/migrator-xRJ6NOTS.js
4
+ async function migrate(db, config) {
5
+ const migrations = readMigrationFiles(config);
6
+ const migrationsTable = config.migrationsTable ?? "__drizzle_migrations";
7
+ const migrationTableCreate = sql`
8
+ CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
9
+ id SERIAL PRIMARY KEY,
10
+ hash text NOT NULL,
11
+ created_at numeric
12
+ )
13
+ `;
14
+ await db.session.run(migrationTableCreate);
15
+ const lastDbMigration = (await db.values(sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`))[0] ?? void 0;
16
+ const statementToBatch = [];
17
+ for (const migration of migrations) if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
18
+ for (const stmt of migration.sql) statementToBatch.push(db.run(sql.raw(stmt)));
19
+ statementToBatch.push(db.run(sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${sql.raw(`'${migration.hash}'`)}, ${sql.raw(`${migration.folderMillis}`)})`));
20
+ }
21
+ if (statementToBatch.length > 0) await db.session.batch(statementToBatch);
22
+ }
23
+ //#endregion
24
+ export { migrate };
@@ -0,0 +1,8 @@
1
+ import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
+ //#region ../db/dist/migrator-xbWwvFYF.js
3
+ async function migrate(db, config) {
4
+ const migrations = readMigrationFiles(config);
5
+ await db.dialect.migrate(migrations, db.session, config);
6
+ }
7
+ //#endregion
8
+ export { migrate };
@@ -0,0 +1,251 @@
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, r as DrizzleError, 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 { createPool } from "mysql2";
6
+ import { once } from "node:events";
7
+ //#region ../db/dist/mysql2-DkoPEsRu.js
8
+ var MySql2PreparedQuery = class extends MySqlPreparedQuery {
9
+ constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, customResultMapper, generatedIds, returningIds) {
10
+ super(cache, queryMetadata, cacheConfig);
11
+ this.client = client;
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
+ this.rawQuery = {
19
+ sql: queryString,
20
+ typeCast: function(field, next) {
21
+ if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") return field.string();
22
+ return next();
23
+ }
24
+ };
25
+ this.query = {
26
+ sql: queryString,
27
+ rowsAsArray: true,
28
+ typeCast: function(field, next) {
29
+ if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") return field.string();
30
+ return next();
31
+ }
32
+ };
33
+ }
34
+ static [entityKind] = "MySql2PreparedQuery";
35
+ rawQuery;
36
+ query;
37
+ async execute(placeholderValues = {}) {
38
+ const params = fillPlaceholders(this.params, placeholderValues);
39
+ this.logger.logQuery(this.rawQuery.sql, params);
40
+ const { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;
41
+ if (!fields && !customResultMapper) {
42
+ const res = await this.queryWithCache(rawQuery.sql, params, async () => {
43
+ return await client.query(rawQuery, params);
44
+ });
45
+ const insertId = res[0].insertId;
46
+ const affectedRows = res[0].affectedRows;
47
+ if (returningIds) {
48
+ const returningResponse = [];
49
+ let j = 0;
50
+ for (let i = insertId; i < insertId + affectedRows; i++) {
51
+ for (const column of returningIds) {
52
+ const key = returningIds[0].path[0];
53
+ if (is(column.field, Column)) {
54
+ if (column.field.primary && column.field.autoIncrement) returningResponse.push({ [key]: i });
55
+ if (column.field.defaultFn && generatedIds) returningResponse.push({ [key]: generatedIds[j][key] });
56
+ }
57
+ }
58
+ j++;
59
+ }
60
+ return returningResponse;
61
+ }
62
+ return res;
63
+ }
64
+ const rows = (await this.queryWithCache(query.sql, params, async () => {
65
+ return await client.query(query, params);
66
+ }))[0];
67
+ if (customResultMapper) return customResultMapper(rows);
68
+ return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
69
+ }
70
+ async *iterator(placeholderValues = {}) {
71
+ const params = fillPlaceholders(this.params, placeholderValues);
72
+ const conn = (isPool(this.client) ? await this.client.getConnection() : this.client).connection;
73
+ const { fields, query, rawQuery, joinsNotNullableMap, client, customResultMapper } = this;
74
+ const hasRowsMapper = Boolean(fields || customResultMapper);
75
+ const stream = (hasRowsMapper ? conn.query(query, params) : conn.query(rawQuery, params)).stream();
76
+ function dataListener() {
77
+ stream.pause();
78
+ }
79
+ stream.on("data", dataListener);
80
+ try {
81
+ const onEnd = once(stream, "end");
82
+ const onError = once(stream, "error");
83
+ while (true) {
84
+ stream.resume();
85
+ const row = await Promise.race([
86
+ onEnd,
87
+ onError,
88
+ new Promise((resolve) => stream.once("data", resolve))
89
+ ]);
90
+ if (row === void 0 || Array.isArray(row) && row.length === 0) break;
91
+ else if (row instanceof Error) throw row;
92
+ else if (hasRowsMapper) if (customResultMapper) {
93
+ const mappedRow = customResultMapper([row]);
94
+ yield Array.isArray(mappedRow) ? mappedRow[0] : mappedRow;
95
+ } else yield mapResultRow(fields, row, joinsNotNullableMap);
96
+ else yield row;
97
+ }
98
+ } finally {
99
+ stream.off("data", dataListener);
100
+ if (isPool(client)) conn.end();
101
+ }
102
+ }
103
+ };
104
+ var MySql2Session = class MySql2Session extends MySqlSession {
105
+ constructor(client, dialect, schema, options) {
106
+ super(dialect);
107
+ this.client = client;
108
+ this.schema = schema;
109
+ this.options = options;
110
+ this.logger = options.logger ?? new NoopLogger();
111
+ this.cache = options.cache ?? new NoopCache();
112
+ this.mode = options.mode;
113
+ }
114
+ static [entityKind] = "MySql2Session";
115
+ logger;
116
+ mode;
117
+ cache;
118
+ prepareQuery(query, fields, customResultMapper, generatedIds, returningIds, queryMetadata, cacheConfig) {
119
+ return new MySql2PreparedQuery(this.client, query.sql, query.params, this.logger, this.cache, queryMetadata, cacheConfig, fields, customResultMapper, generatedIds, returningIds);
120
+ }
121
+ /**
122
+ * @internal
123
+ * What is its purpose?
124
+ */
125
+ async query(query, params) {
126
+ this.logger.logQuery(query, params);
127
+ return await this.client.query({
128
+ sql: query,
129
+ values: params,
130
+ rowsAsArray: true,
131
+ typeCast: function(field, next) {
132
+ if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") return field.string();
133
+ return next();
134
+ }
135
+ });
136
+ }
137
+ all(query) {
138
+ const querySql = this.dialect.sqlToQuery(query);
139
+ this.logger.logQuery(querySql.sql, querySql.params);
140
+ return this.client.execute(querySql.sql, querySql.params).then((result) => result[0]);
141
+ }
142
+ async transaction(transaction, config) {
143
+ const session = isPool(this.client) ? new MySql2Session(await this.client.getConnection(), this.dialect, this.schema, this.options) : this;
144
+ const tx = new MySql2Transaction(this.dialect, session, this.schema, 0, this.mode);
145
+ if (config) {
146
+ const setTransactionConfigSql = this.getSetTransactionSQL(config);
147
+ if (setTransactionConfigSql) await tx.execute(setTransactionConfigSql);
148
+ const startTransactionSql = this.getStartTransactionSQL(config);
149
+ await (startTransactionSql ? tx.execute(startTransactionSql) : tx.execute(sql`begin`));
150
+ } else await tx.execute(sql`begin`);
151
+ try {
152
+ const result = await transaction(tx);
153
+ await tx.execute(sql`commit`);
154
+ return result;
155
+ } catch (err) {
156
+ await tx.execute(sql`rollback`);
157
+ throw err;
158
+ } finally {
159
+ if (isPool(this.client)) session.client.release();
160
+ }
161
+ }
162
+ };
163
+ var MySql2Transaction = class MySql2Transaction extends MySqlTransaction {
164
+ static [entityKind] = "MySql2Transaction";
165
+ async transaction(transaction) {
166
+ const savepointName = `sp${this.nestedIndex + 1}`;
167
+ const tx = new MySql2Transaction(this.dialect, this.session, this.schema, this.nestedIndex + 1, this.mode);
168
+ await tx.execute(sql.raw(`savepoint ${savepointName}`));
169
+ try {
170
+ const result = await transaction(tx);
171
+ await tx.execute(sql.raw(`release savepoint ${savepointName}`));
172
+ return result;
173
+ } catch (err) {
174
+ await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
175
+ throw err;
176
+ }
177
+ }
178
+ };
179
+ function isPool(client) {
180
+ return "getConnection" in client;
181
+ }
182
+ var MySql2Driver = class {
183
+ constructor(client, dialect, options = {}) {
184
+ this.client = client;
185
+ this.dialect = dialect;
186
+ this.options = options;
187
+ }
188
+ static [entityKind] = "MySql2Driver";
189
+ createSession(schema, mode) {
190
+ return new MySql2Session(this.client, this.dialect, schema, {
191
+ logger: this.options.logger,
192
+ mode,
193
+ cache: this.options.cache
194
+ });
195
+ }
196
+ };
197
+ var MySql2Database = class extends MySqlDatabase {
198
+ static [entityKind] = "MySql2Database";
199
+ };
200
+ function construct(client, config = {}) {
201
+ const dialect = new MySqlDialect({ casing: config.casing });
202
+ let logger;
203
+ if (config.logger === true) logger = new DefaultLogger();
204
+ else if (config.logger !== false) logger = config.logger;
205
+ const clientForInstance = isCallbackClient(client) ? client.promise() : client;
206
+ let schema;
207
+ if (config.schema) {
208
+ if (config.mode === void 0) throw new DrizzleError({ message: "You need to specify \"mode\": \"planetscale\" or \"default\" when providing a schema. Read more: https://orm.drizzle.team/docs/rqb#modes" });
209
+ const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
210
+ schema = {
211
+ fullSchema: config.schema,
212
+ schema: tablesConfig.tables,
213
+ tableNamesMap: tablesConfig.tableNamesMap
214
+ };
215
+ }
216
+ const mode = config.mode ?? "default";
217
+ const db = new MySql2Database(dialect, new MySql2Driver(clientForInstance, dialect, {
218
+ logger,
219
+ cache: config.cache
220
+ }).createSession(schema, mode), schema, mode);
221
+ db.$client = client;
222
+ db.$cache = config.cache;
223
+ if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
224
+ return db;
225
+ }
226
+ function isCallbackClient(client) {
227
+ return typeof client.promise === "function";
228
+ }
229
+ function drizzle(...params) {
230
+ if (typeof params[0] === "string") {
231
+ const connectionString = params[0];
232
+ return construct(createPool({ uri: connectionString }), params[1]);
233
+ }
234
+ if (isConfig(params[0])) {
235
+ const { connection, client, ...drizzleConfig } = params[0];
236
+ if (client) return construct(client, drizzleConfig);
237
+ return construct(typeof connection === "string" ? createPool({
238
+ uri: connection,
239
+ supportBigNumbers: true
240
+ }) : createPool(connection), drizzleConfig);
241
+ }
242
+ return construct(params[0], params[1]);
243
+ }
244
+ ((drizzle2) => {
245
+ function mock(config) {
246
+ return construct({}, config);
247
+ }
248
+ drizzle2.mock = mock;
249
+ })(drizzle || (drizzle = {}));
250
+ //#endregion
251
+ export { drizzle };
@@ -0,0 +1,205 @@
1
+ import { C as sql, _ as fillPlaceholders, g as entityKind } 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 { a as PgTransaction, i as PgSession, n as PgDialect, r as PgPreparedQuery, t as PgDatabase } from "./session-BOEirggu-DTmpyU_x.js";
4
+ import { Pool, neonConfig, types } from "@neondatabase/serverless";
5
+ //#region ../db/dist/neon-serverless-BEVFA7yv.js
6
+ var NeonPreparedQuery = 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.params = params;
14
+ this.logger = logger;
15
+ this.fields = fields;
16
+ this._isResponseInArrayMode = _isResponseInArrayMode;
17
+ this.customResultMapper = customResultMapper;
18
+ this.rawQueryConfig = {
19
+ name,
20
+ text: queryString,
21
+ types: { getTypeParser: (typeId, format) => {
22
+ if (typeId === types.builtins.TIMESTAMPTZ) return (val) => val;
23
+ if (typeId === types.builtins.TIMESTAMP) return (val) => val;
24
+ if (typeId === types.builtins.DATE) return (val) => val;
25
+ if (typeId === types.builtins.INTERVAL) return (val) => val;
26
+ if (typeId === 1231) return (val) => val;
27
+ if (typeId === 1115) return (val) => val;
28
+ if (typeId === 1185) return (val) => val;
29
+ if (typeId === 1187) return (val) => val;
30
+ if (typeId === 1182) return (val) => val;
31
+ return types.getTypeParser(typeId, format);
32
+ } }
33
+ };
34
+ this.queryConfig = {
35
+ name,
36
+ text: queryString,
37
+ rowMode: "array",
38
+ types: { getTypeParser: (typeId, format) => {
39
+ if (typeId === types.builtins.TIMESTAMPTZ) return (val) => val;
40
+ if (typeId === types.builtins.TIMESTAMP) return (val) => val;
41
+ if (typeId === types.builtins.DATE) return (val) => val;
42
+ if (typeId === types.builtins.INTERVAL) return (val) => val;
43
+ if (typeId === 1231) return (val) => val;
44
+ if (typeId === 1115) return (val) => val;
45
+ if (typeId === 1185) return (val) => val;
46
+ if (typeId === 1187) return (val) => val;
47
+ if (typeId === 1182) return (val) => val;
48
+ return types.getTypeParser(typeId, format);
49
+ } }
50
+ };
51
+ }
52
+ static [entityKind] = "NeonPreparedQuery";
53
+ rawQueryConfig;
54
+ queryConfig;
55
+ async execute(placeholderValues = {}) {
56
+ const params = fillPlaceholders(this.params, placeholderValues);
57
+ this.logger.logQuery(this.rawQueryConfig.text, params);
58
+ const { fields, client, rawQueryConfig: rawQuery, queryConfig: query, joinsNotNullableMap, customResultMapper } = this;
59
+ if (!fields && !customResultMapper) return await this.queryWithCache(rawQuery.text, params, async () => {
60
+ return await client.query(rawQuery, params);
61
+ });
62
+ const result = await this.queryWithCache(query.text, params, async () => {
63
+ return await client.query(query, params);
64
+ });
65
+ return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
66
+ }
67
+ all(placeholderValues = {}) {
68
+ const params = fillPlaceholders(this.params, placeholderValues);
69
+ this.logger.logQuery(this.rawQueryConfig.text, params);
70
+ return this.queryWithCache(this.rawQueryConfig.text, params, async () => {
71
+ return await this.client.query(this.rawQueryConfig, params);
72
+ }).then((result) => result.rows);
73
+ }
74
+ values(placeholderValues = {}) {
75
+ const params = fillPlaceholders(this.params, placeholderValues);
76
+ this.logger.logQuery(this.rawQueryConfig.text, params);
77
+ return this.queryWithCache(this.queryConfig.text, params, async () => {
78
+ return await this.client.query(this.queryConfig, params);
79
+ }).then((result) => result.rows);
80
+ }
81
+ /** @internal */
82
+ isResponseInArrayMode() {
83
+ return this._isResponseInArrayMode;
84
+ }
85
+ };
86
+ var NeonSession = class NeonSession extends PgSession {
87
+ constructor(client, dialect, schema, options = {}) {
88
+ super(dialect);
89
+ this.client = client;
90
+ this.schema = schema;
91
+ this.options = options;
92
+ this.logger = options.logger ?? new NoopLogger();
93
+ this.cache = options.cache ?? new NoopCache();
94
+ }
95
+ static [entityKind] = "NeonSession";
96
+ logger;
97
+ cache;
98
+ prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
99
+ return new NeonPreparedQuery(this.client, query.sql, query.params, this.logger, this.cache, queryMetadata, cacheConfig, fields, name, isResponseInArrayMode, customResultMapper);
100
+ }
101
+ async query(query, params) {
102
+ this.logger.logQuery(query, params);
103
+ return await this.client.query({
104
+ rowMode: "array",
105
+ text: query,
106
+ values: params
107
+ });
108
+ }
109
+ async queryObjects(query, params) {
110
+ return this.client.query(query, params);
111
+ }
112
+ async count(sql2) {
113
+ const res = await this.execute(sql2);
114
+ return Number(res["rows"][0]["count"]);
115
+ }
116
+ async transaction(transaction, config = {}) {
117
+ const session = this.client instanceof Pool ? new NeonSession(await this.client.connect(), this.dialect, this.schema, this.options) : this;
118
+ const tx = new NeonTransaction(this.dialect, session, this.schema);
119
+ await tx.execute(sql`begin ${tx.getTransactionConfigSQL(config)}`);
120
+ try {
121
+ const result = await transaction(tx);
122
+ await tx.execute(sql`commit`);
123
+ return result;
124
+ } catch (error) {
125
+ await tx.execute(sql`rollback`);
126
+ throw error;
127
+ } finally {
128
+ if (this.client instanceof Pool) session.client.release();
129
+ }
130
+ }
131
+ };
132
+ var NeonTransaction = class NeonTransaction extends PgTransaction {
133
+ static [entityKind] = "NeonTransaction";
134
+ async transaction(transaction) {
135
+ const savepointName = `sp${this.nestedIndex + 1}`;
136
+ const tx = new NeonTransaction(this.dialect, this.session, this.schema, this.nestedIndex + 1);
137
+ await tx.execute(sql.raw(`savepoint ${savepointName}`));
138
+ try {
139
+ const result = await transaction(tx);
140
+ await tx.execute(sql.raw(`release savepoint ${savepointName}`));
141
+ return result;
142
+ } catch (e) {
143
+ await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
144
+ throw e;
145
+ }
146
+ }
147
+ };
148
+ var NeonDriver = class {
149
+ constructor(client, dialect, options = {}) {
150
+ this.client = client;
151
+ this.dialect = dialect;
152
+ this.options = options;
153
+ }
154
+ static [entityKind] = "NeonDriver";
155
+ createSession(schema) {
156
+ return new NeonSession(this.client, this.dialect, schema, {
157
+ logger: this.options.logger,
158
+ cache: this.options.cache
159
+ });
160
+ }
161
+ };
162
+ var NeonDatabase = class extends PgDatabase {
163
+ static [entityKind] = "NeonServerlessDatabase";
164
+ };
165
+ function construct(client, config = {}) {
166
+ const dialect = new PgDialect({ casing: config.casing });
167
+ let logger;
168
+ if (config.logger === true) logger = new DefaultLogger();
169
+ else if (config.logger !== false) logger = config.logger;
170
+ let schema;
171
+ if (config.schema) {
172
+ const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
173
+ schema = {
174
+ fullSchema: config.schema,
175
+ schema: tablesConfig.tables,
176
+ tableNamesMap: tablesConfig.tableNamesMap
177
+ };
178
+ }
179
+ const db = new NeonDatabase(dialect, new NeonDriver(client, dialect, {
180
+ logger,
181
+ cache: config.cache
182
+ }).createSession(schema), schema);
183
+ db.$client = client;
184
+ db.$cache = config.cache;
185
+ if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
186
+ return db;
187
+ }
188
+ function drizzle(...params) {
189
+ if (typeof params[0] === "string") return construct(new Pool({ connectionString: params[0] }), params[1]);
190
+ if (isConfig(params[0])) {
191
+ const { connection, client, ws, ...drizzleConfig } = params[0];
192
+ if (ws) neonConfig.webSocketConstructor = ws;
193
+ if (client) return construct(client, drizzleConfig);
194
+ return construct(typeof connection === "string" ? new Pool({ connectionString: connection }) : new Pool(connection), drizzleConfig);
195
+ }
196
+ return construct(params[0], params[1]);
197
+ }
198
+ ((drizzle2) => {
199
+ function mock(config) {
200
+ return construct({}, config);
201
+ }
202
+ drizzle2.mock = mock;
203
+ })(drizzle || (drizzle = {}));
204
+ //#endregion
205
+ export { drizzle };