drizzle-orm 1.0.0-beta.1-dfa4db3 → 1.0.0-beta.1-03a5cdc
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/aws-data-api/pg/session.cjs +3 -1
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.js +3 -1
- package/aws-data-api/pg/session.js.map +1 -1
- package/package.json +126 -73
- package/pg-core/session.cjs +2 -2
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +1 -1
- package/pg-core/session.d.ts +1 -1
- package/pg-core/session.js +2 -2
- package/pg-core/session.js.map +1 -1
- package/sqlite-cloud/driver.cjs +114 -0
- package/sqlite-cloud/driver.cjs.map +1 -0
- package/sqlite-cloud/driver.d.cts +33 -0
- package/sqlite-cloud/driver.d.ts +33 -0
- package/sqlite-cloud/driver.js +78 -0
- package/sqlite-cloud/driver.js.map +1 -0
- package/sqlite-cloud/index.cjs +25 -0
- package/sqlite-cloud/index.cjs.map +1 -0
- package/sqlite-cloud/index.d.cts +2 -0
- package/sqlite-cloud/index.d.ts +2 -0
- package/sqlite-cloud/index.js +3 -0
- package/sqlite-cloud/index.js.map +1 -0
- package/sqlite-cloud/migrator.cjs +69 -0
- package/sqlite-cloud/migrator.cjs.map +1 -0
- package/sqlite-cloud/migrator.d.cts +4 -0
- package/sqlite-cloud/migrator.d.ts +4 -0
- package/sqlite-cloud/migrator.js +45 -0
- package/sqlite-cloud/migrator.js.map +1 -0
- package/sqlite-cloud/session.cjs +254 -0
- package/sqlite-cloud/session.cjs.map +1 -0
- package/sqlite-cloud/session.d.cts +70 -0
- package/sqlite-cloud/session.d.ts +70 -0
- package/sqlite-cloud/session.js +228 -0
- package/sqlite-cloud/session.js.map +1 -0
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var session_exports = {};
|
|
20
|
+
__export(session_exports, {
|
|
21
|
+
SQLiteCloudPreparedQuery: () => SQLiteCloudPreparedQuery,
|
|
22
|
+
SQLiteCloudSession: () => SQLiteCloudSession,
|
|
23
|
+
SQLiteCloudTransaction: () => SQLiteCloudTransaction
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(session_exports);
|
|
26
|
+
var import_core = require("../cache/core/index.cjs");
|
|
27
|
+
var import_entity = require("../entity.cjs");
|
|
28
|
+
var import_errors = require("../errors.cjs");
|
|
29
|
+
var import_logger = require("../logger.cjs");
|
|
30
|
+
var import_sql = require("../sql/sql.cjs");
|
|
31
|
+
var import_sqlite_core = require("../sqlite-core/index.cjs");
|
|
32
|
+
var import_session = require("../sqlite-core/session.cjs");
|
|
33
|
+
var import_utils = require("../utils.cjs");
|
|
34
|
+
class SQLiteCloudSession extends import_session.SQLiteSession {
|
|
35
|
+
constructor(client, dialect, relations, schema, options) {
|
|
36
|
+
super(dialect);
|
|
37
|
+
this.client = client;
|
|
38
|
+
this.relations = relations;
|
|
39
|
+
this.schema = schema;
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.logger = options.logger ?? new import_logger.NoopLogger();
|
|
42
|
+
this.cache = options.cache ?? new import_core.NoopCache();
|
|
43
|
+
}
|
|
44
|
+
static [import_entity.entityKind] = "SQLiteCloudSession";
|
|
45
|
+
logger;
|
|
46
|
+
cache;
|
|
47
|
+
prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
|
48
|
+
const stmt = this.client.prepare(query.sql);
|
|
49
|
+
return new SQLiteCloudPreparedQuery(
|
|
50
|
+
stmt,
|
|
51
|
+
query,
|
|
52
|
+
this.logger,
|
|
53
|
+
this.cache,
|
|
54
|
+
queryMetadata,
|
|
55
|
+
cacheConfig,
|
|
56
|
+
fields,
|
|
57
|
+
executeMethod,
|
|
58
|
+
isResponseInArrayMode,
|
|
59
|
+
customResultMapper
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
prepareRelationalQuery(query, fields, executeMethod, customResultMapper) {
|
|
63
|
+
const stmt = this.client.prepare(query.sql);
|
|
64
|
+
return new SQLiteCloudPreparedQuery(
|
|
65
|
+
stmt,
|
|
66
|
+
query,
|
|
67
|
+
this.logger,
|
|
68
|
+
this.cache,
|
|
69
|
+
void 0,
|
|
70
|
+
void 0,
|
|
71
|
+
fields,
|
|
72
|
+
executeMethod,
|
|
73
|
+
false,
|
|
74
|
+
customResultMapper,
|
|
75
|
+
true
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
async run(query) {
|
|
79
|
+
const staticQuery = this.dialect.sqlToQuery(query);
|
|
80
|
+
try {
|
|
81
|
+
return await this.prepareOneTimeQuery(staticQuery, void 0, "run", false).run();
|
|
82
|
+
} catch (err) {
|
|
83
|
+
throw new import_errors.DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async all(query) {
|
|
87
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).all();
|
|
88
|
+
}
|
|
89
|
+
async get(query) {
|
|
90
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
|
|
91
|
+
}
|
|
92
|
+
async values(query) {
|
|
93
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
|
|
94
|
+
}
|
|
95
|
+
async transaction(transaction, config) {
|
|
96
|
+
const tx = new SQLiteCloudTransaction(
|
|
97
|
+
"async",
|
|
98
|
+
this.dialect,
|
|
99
|
+
this,
|
|
100
|
+
this.relations,
|
|
101
|
+
this.schema
|
|
102
|
+
);
|
|
103
|
+
await tx.run(import_sql.sql`BEGIN${import_sql.sql` ${import_sql.sql.raw(config?.behavior ?? "")}`.if(config?.behavior)} TRANSACTION`);
|
|
104
|
+
try {
|
|
105
|
+
const result = await transaction(tx);
|
|
106
|
+
await tx.run(import_sql.sql`COMMIT`);
|
|
107
|
+
return result;
|
|
108
|
+
} catch (err) {
|
|
109
|
+
await tx.run(import_sql.sql`ROLLBACK`);
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class SQLiteCloudTransaction extends import_sqlite_core.SQLiteTransaction {
|
|
115
|
+
static [import_entity.entityKind] = "SQLiteCloudTransaction";
|
|
116
|
+
async transaction(transaction) {
|
|
117
|
+
const savepointName = `sp${this.nestedIndex}`;
|
|
118
|
+
const tx = new SQLiteCloudTransaction(
|
|
119
|
+
"async",
|
|
120
|
+
this.dialect,
|
|
121
|
+
this.session,
|
|
122
|
+
this.relations,
|
|
123
|
+
this.schema,
|
|
124
|
+
this.nestedIndex + 1
|
|
125
|
+
);
|
|
126
|
+
await this.session.run(import_sql.sql.raw(`savepoint ${savepointName}`));
|
|
127
|
+
try {
|
|
128
|
+
const result = await transaction(tx);
|
|
129
|
+
await this.session.run(import_sql.sql.raw(`release savepoint ${savepointName}`));
|
|
130
|
+
return result;
|
|
131
|
+
} catch (err) {
|
|
132
|
+
await this.session.run(import_sql.sql.raw(`rollback to savepoint ${savepointName}`));
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
class SQLiteCloudPreparedQuery extends import_session.SQLitePreparedQuery {
|
|
138
|
+
constructor(stmt, query, logger, cache, queryMetadata, cacheConfig, fields, executeMethod, _isResponseInArrayMode, customResultMapper, isRqbV2Query) {
|
|
139
|
+
super("async", executeMethod, query, cache, queryMetadata, cacheConfig);
|
|
140
|
+
this.stmt = stmt;
|
|
141
|
+
this.logger = logger;
|
|
142
|
+
this.fields = fields;
|
|
143
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
144
|
+
this.customResultMapper = customResultMapper;
|
|
145
|
+
this.isRqbV2Query = isRqbV2Query;
|
|
146
|
+
}
|
|
147
|
+
static [import_entity.entityKind] = "SQLiteCloudPreparedQuery";
|
|
148
|
+
async run(placeholderValues) {
|
|
149
|
+
const { stmt, query, logger } = this;
|
|
150
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
151
|
+
logger.logQuery(query.sql, params);
|
|
152
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
153
|
+
return await new Promise((resolve, reject) => {
|
|
154
|
+
(params.length ? stmt.bind(...params) : stmt).run((e, d) => {
|
|
155
|
+
if (e) return reject(e);
|
|
156
|
+
return resolve(d);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
async all(placeholderValues) {
|
|
162
|
+
if (this.isRqbV2Query) return await this.allRqbV2(placeholderValues);
|
|
163
|
+
const { fields, logger, query, customResultMapper, joinsNotNullableMap, stmt } = this;
|
|
164
|
+
if (!fields && !customResultMapper) {
|
|
165
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
166
|
+
logger.logQuery(query.sql, params);
|
|
167
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
168
|
+
return await new Promise((resolve, reject) => {
|
|
169
|
+
(params.length ? stmt.bind(...params) : stmt).all((e, d) => {
|
|
170
|
+
if (e) return reject(e);
|
|
171
|
+
return resolve(d.map((v) => Object.fromEntries(Object.entries(v))));
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const rows = await this.values(placeholderValues);
|
|
177
|
+
return rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
|
|
178
|
+
}
|
|
179
|
+
async allRqbV2(placeholderValues) {
|
|
180
|
+
const { logger, query, customResultMapper, stmt } = this;
|
|
181
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
182
|
+
logger.logQuery(query.sql, params);
|
|
183
|
+
const rows = await new Promise((resolve, reject) => {
|
|
184
|
+
(params.length ? stmt.bind(...params) : stmt).all((e, d) => {
|
|
185
|
+
if (e) return reject(e);
|
|
186
|
+
return resolve(d.map((v) => Object.fromEntries(Object.entries(v))));
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
return customResultMapper(rows);
|
|
190
|
+
}
|
|
191
|
+
async get(placeholderValues) {
|
|
192
|
+
if (this.isRqbV2Query) return await this.getRqbV2(placeholderValues);
|
|
193
|
+
const { fields, logger, query, stmt, customResultMapper, joinsNotNullableMap } = this;
|
|
194
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
195
|
+
if (!fields && !customResultMapper) {
|
|
196
|
+
logger.logQuery(query.sql, params);
|
|
197
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
198
|
+
return await new Promise((resolve, reject) => {
|
|
199
|
+
(params.length ? stmt.bind(...params) : stmt).get((e, d) => {
|
|
200
|
+
if (e) return reject(e);
|
|
201
|
+
return resolve(d ? Object.fromEntries(Object.entries(d)) : d);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const row = await this.queryWithCache(query.sql, params, async () => {
|
|
207
|
+
return await new Promise((resolve, reject) => {
|
|
208
|
+
(params.length ? stmt.bind(...params) : stmt).get((e, d) => {
|
|
209
|
+
if (e) return reject(e);
|
|
210
|
+
return resolve(d ? d.getData() : d);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
if (row === void 0) return row;
|
|
215
|
+
return (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap);
|
|
216
|
+
}
|
|
217
|
+
async getRqbV2(placeholderValues) {
|
|
218
|
+
const { logger, query, stmt, customResultMapper } = this;
|
|
219
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
220
|
+
logger.logQuery(query.sql, params);
|
|
221
|
+
const row = await new Promise((resolve, reject) => {
|
|
222
|
+
(params.length ? stmt.bind(...params) : stmt).get((e, d) => {
|
|
223
|
+
if (e) return reject(e);
|
|
224
|
+
return resolve(d ? Object.fromEntries(Object.entries(d)) : d);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
if (row === void 0) return row;
|
|
228
|
+
return customResultMapper([row]);
|
|
229
|
+
}
|
|
230
|
+
async values(placeholderValues) {
|
|
231
|
+
const { logger, stmt, query } = this;
|
|
232
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
233
|
+
logger.logQuery(query.sql, params);
|
|
234
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
235
|
+
return await new Promise((resolve, reject) => {
|
|
236
|
+
(params.length ? stmt.bind(...params) : stmt).all((e, d) => {
|
|
237
|
+
if (e) return reject(e);
|
|
238
|
+
return resolve(d.map((v) => v.getData()));
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/** @internal */
|
|
244
|
+
isResponseInArrayMode() {
|
|
245
|
+
return this._isResponseInArrayMode;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
249
|
+
0 && (module.exports = {
|
|
250
|
+
SQLiteCloudPreparedQuery,
|
|
251
|
+
SQLiteCloudSession,
|
|
252
|
+
SQLiteCloudTransaction
|
|
253
|
+
});
|
|
254
|
+
//# sourceMappingURL=session.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/sqlite-cloud/session.ts"],"sourcesContent":["import type { Database, SQLiteCloudRow, SQLiteCloudRowset } from '@sqlitecloud/drivers';\nimport type * as V1 from '~/_relations.ts';\nimport { type Cache, NoopCache } from '~/cache/core/index.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { fillPlaceholders, type Query, type SQL, sql } from '~/sql/sql.ts';\nimport type { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';\nimport { SQLiteTransaction } from '~/sqlite-core/index.ts';\nimport type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types.ts';\nimport type {\n\tPreparedQueryConfig as PreparedQueryConfigBase,\n\tResult,\n\tSQLiteExecuteMethod,\n\tSQLiteTransactionConfig,\n} from '~/sqlite-core/session.ts';\nimport { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { mapResultRow } from '~/utils.ts';\nimport type { SQLiteCloudRunResult } from './driver.ts';\n\nexport interface SQLiteCloudSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\ntype PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;\n\nexport class SQLiteCloudSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends SQLiteSession<'async', SQLiteCloudRunResult, TFullSchema, TRelations, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SQLiteCloudSession';\n\n\tprivate logger: Logger;\n\tprivate cache: Cache;\n\n\tconstructor(\n\t\tprivate client: Database,\n\t\tdialect: SQLiteAsyncDialect,\n\t\tprivate relations: TRelations,\n\t\tprivate schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: SQLiteCloudSessionOptions,\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.cache = options.cache ?? new NoopCache();\n\t}\n\n\tprepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\texecuteMethod: SQLiteExecuteMethod,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => unknown,\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t): SQLiteCloudPreparedQuery<T> {\n\t\tconst stmt = this.client.prepare(query.sql);\n\n\t\treturn new SQLiteCloudPreparedQuery(\n\t\t\tstmt,\n\t\t\tquery,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tqueryMetadata,\n\t\t\tcacheConfig,\n\t\t\tfields,\n\t\t\texecuteMethod,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\texecuteMethod: SQLiteExecuteMethod,\n\t\tcustomResultMapper: (rows: Record<string, unknown>[]) => unknown,\n\t): SQLiteCloudPreparedQuery<T, true> {\n\t\tconst stmt = this.client.prepare(query.sql);\n\n\t\treturn new SQLiteCloudPreparedQuery(\n\t\t\tstmt,\n\t\t\tquery,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfields,\n\t\t\texecuteMethod,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\toverride async run(query: SQL): Result<'async', SQLiteCloudRunResult> {\n\t\tconst staticQuery = this.dialect.sqlToQuery(query);\n\t\ttry {\n\t\t\treturn await this.prepareOneTimeQuery(staticQuery, undefined, 'run', false).run() as Result<\n\t\t\t\t'async',\n\t\t\t\tSQLiteCloudRunResult\n\t\t\t>;\n\t\t} catch (err) {\n\t\t\tthrow new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });\n\t\t}\n\t}\n\n\toverride async all<T = unknown>(query: SQL): Result<'async', T[]> {\n\t\treturn await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), undefined, 'run', false).all() as Result<\n\t\t\t'async',\n\t\t\tT[]\n\t\t>;\n\t}\n\n\toverride async get<T = unknown>(query: SQL): Result<'async', T> {\n\t\treturn await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), undefined, 'run', false).get() as Result<\n\t\t\t'async',\n\t\t\tT\n\t\t>;\n\t}\n\n\toverride async values<T extends any[] = unknown[]>(\n\t\tquery: SQL,\n\t): Result<'async', T[]> {\n\t\treturn await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), undefined, 'run', false).values() as Result<\n\t\t\t'async',\n\t\t\tT[]\n\t\t>;\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SQLiteCloudTransaction<TFullSchema, TRelations, TSchema>,\n\t\t) => Promise<T>,\n\t\tconfig?: SQLiteTransactionConfig,\n\t): Promise<T> {\n\t\tconst tx = new SQLiteCloudTransaction(\n\t\t\t'async',\n\t\t\tthis.dialect,\n\t\t\tthis,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t);\n\t\tawait tx.run(sql`BEGIN${sql` ${sql.raw(config?.behavior ?? '')}`.if(config?.behavior)} TRANSACTION`);\n\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait tx.run(sql`COMMIT`);\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait tx.run(sql`ROLLBACK`);\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nexport class SQLiteCloudTransaction<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends SQLiteTransaction<'async', SQLiteCloudRunResult, TFullSchema, TRelations, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SQLiteCloudTransaction';\n\n\toverride async transaction<T>(\n\t\ttransaction: (tx: SQLiteCloudTransaction<TFullSchema, TRelations, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\tconst savepointName = `sp${this.nestedIndex}`;\n\t\tconst tx = new SQLiteCloudTransaction(\n\t\t\t'async',\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t\tthis.nestedIndex + 1,\n\t\t);\n\t\tawait this.session.run(sql.raw(`savepoint ${savepointName}`));\n\t\ttry {\n\t\t\tconst result = await transaction(tx);\n\t\t\tawait this.session.run(sql.raw(`release savepoint ${savepointName}`));\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tawait this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\nexport class SQLiteCloudPreparedQuery<\n\tT extends PreparedQueryConfig = PreparedQueryConfig,\n\tTIsRqbV2 extends boolean = false,\n> extends SQLitePreparedQuery<\n\t{\n\t\ttype: 'async';\n\t\trun: SQLiteCloudRunResult;\n\t\tall: T['all'];\n\t\tget: T['get'];\n\t\tvalues: T['values'];\n\t\texecute: T['execute'];\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'SQLiteCloudPreparedQuery';\n\n\tconstructor(\n\t\tprivate stmt: ReturnType<Database['prepare']>,\n\t\tquery: Query,\n\t\tprivate logger: Logger,\n\t\tcache: Cache,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\t/** @internal */ public fields: SelectedFieldsOrdered | undefined,\n\t\texecuteMethod: SQLiteExecuteMethod,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t) => unknown,\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper('async', executeMethod, query, cache, queryMetadata, cacheConfig);\n\t}\n\n\tasync run(placeholderValues?: Record<string, unknown>): Promise<SQLiteCloudRunResult> {\n\t\tconst { stmt, query, logger } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\treturn await new Promise<any>((resolve, reject) => {\n\t\t\t\t(params.length ? stmt.bind(...params) : stmt).run((e: Error | null, d: SQLiteCloudRowset) => {\n\t\t\t\t\tif (e) return reject(e);\n\n\t\t\t\t\treturn resolve(d);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\n\tasync all(placeholderValues?: Record<string, unknown>): Promise<T['all']> {\n\t\tif (this.isRqbV2Query) return await this.allRqbV2(placeholderValues);\n\n\t\tconst { fields, logger, query, customResultMapper, joinsNotNullableMap, stmt } = this;\n\t\tif (!fields && !customResultMapper) {\n\t\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\t\tlogger.logQuery(query.sql, params);\n\t\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\t\treturn await new Promise<any>((resolve, reject) => {\n\t\t\t\t\t(params.length ? stmt.bind(...params) : stmt).all((e: Error | null, d: SQLiteCloudRowset) => {\n\t\t\t\t\t\tif (e) return reject(e);\n\n\t\t\t\t\t\treturn resolve(d.map((v) => Object.fromEntries(Object.entries(v))));\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tconst rows = await this.values(placeholderValues) as unknown[][];\n\n\t\treturn rows.map((row) => mapResultRow(fields!, row, joinsNotNullableMap));\n\t}\n\n\tprivate async allRqbV2(placeholderValues?: Record<string, unknown>): Promise<T['all']> {\n\t\tconst { logger, query, customResultMapper, stmt } = this;\n\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\n\t\tconst rows = await new Promise<any>((resolve, reject) => {\n\t\t\t(params.length ? stmt.bind(...params) : stmt).all((e: Error | null, d: SQLiteCloudRowset) => {\n\t\t\t\tif (e) return reject(e);\n\n\t\t\t\treturn resolve(d.map((v) => Object.fromEntries(Object.entries(v))));\n\t\t\t});\n\t\t});\n\n\t\treturn (customResultMapper as (\n\t\t\trows: Record<string, unknown>[],\n\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t) => unknown)(rows as Record<string, unknown>[]) as T['all'];\n\t}\n\n\tasync get(placeholderValues?: Record<string, unknown>): Promise<T['get']> {\n\t\tif (this.isRqbV2Query) return await this.getRqbV2(placeholderValues);\n\n\t\tconst { fields, logger, query, stmt, customResultMapper, joinsNotNullableMap } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\tlogger.logQuery(query.sql, params);\n\t\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\t\treturn await new Promise<any>((resolve, reject) => {\n\t\t\t\t\t(params.length ? stmt.bind(...params) : stmt).get((e: Error | null, d: SQLiteCloudRow | undefined) => {\n\t\t\t\t\t\tif (e) return reject(e);\n\n\t\t\t\t\t\treturn resolve(d ? Object.fromEntries(Object.entries(d)) : d);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tconst row = await this.queryWithCache(query.sql, params, async () => {\n\t\t\treturn await new Promise<any>((resolve, reject) => {\n\t\t\t\t(params.length ? stmt.bind(...params) : stmt).get((e: Error | null, d: SQLiteCloudRow | undefined) => {\n\t\t\t\t\tif (e) return reject(e);\n\n\t\t\t\t\treturn resolve(d ? d.getData() : d);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\n\t\tif (row === undefined) return row;\n\n\t\treturn mapResultRow(fields!, row, joinsNotNullableMap);\n\t}\n\n\tprivate async getRqbV2(placeholderValues?: Record<string, unknown>) {\n\t\tconst { logger, query, stmt, customResultMapper } = this;\n\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\n\t\tconst row = await new Promise<any>((resolve, reject) => {\n\t\t\t(params.length ? stmt.bind(...params) : stmt).get((e: Error | null, d: SQLiteCloudRow | undefined) => {\n\t\t\t\tif (e) return reject(e);\n\n\t\t\t\treturn resolve(d ? Object.fromEntries(Object.entries(d)) : d);\n\t\t\t});\n\t\t});\n\n\t\tif (row === undefined) return row;\n\n\t\treturn (customResultMapper as (\n\t\t\trows: Record<string, unknown>[],\n\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t) => unknown)([row] as Record<string, unknown>[]) as T['get'];\n\t}\n\n\tasync values(placeholderValues?: Record<string, unknown>): Promise<T['values']> {\n\t\tconst { logger, stmt, query } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\treturn await new Promise<any>((resolve, reject) => {\n\t\t\t\t(params.length ? stmt.bind(...params) : stmt).all((e: Error | null, d: SQLiteCloudRowset) => {\n\t\t\t\t\tif (e) return reject(e);\n\n\t\t\t\t\treturn (resolve(d.map((v) => v.getData())));\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayM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AG,MAAM,IAAI,MAAM,IAAI,CAAC,GAAiB,MAAkC;AACrG,YAAI,EAAG,QAAO,OAAO,CAAC;AAEtB,eAAO,QAAQ,IAAI,OAAO,YAAY,OAAO,QAAQ,CAAC,CAAC,IAAI,CAAC;AAAA,MAC7D,CAAC;AAAA,IACF,CAAC;AAED,QAAI,QAAQ,OAAW,QAAO;AAE9B,WAAQ,mBAGM,CAAC,GAAG,CAA8B;AAAA,EACjD;AAAA,EAEA,MAAM,OAAO,mBAAmE;AAC/E,UAAM,EAAE,QAAQ,MAAM,MAAM,IAAI;AAChC,UAAM,aAAS,6BAAiB,MAAM,QAAQ,qBAAqB,CAAC,CAAC;AACrE,WAAO,SAAS,MAAM,KAAK,MAAM;AACjC,WAAO,MAAM,KAAK,eAAe,MAAM,KAAK,QAAQ,YAAY;AAC/D,aAAO,MAAM,IAAI,QAAa,CAAC,SAAS,WAAW;AAClD,SAAC,OAAO,SAAS,KAAK,KAAK,GAAG,MAAM,IAAI,MAAM,IAAI,CAAC,GAAiB,MAAyB;AAC5F,cAAI,EAAG,QAAO,OAAO,CAAC;AAEtB,iBAAQ,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAAA,QAC1C,CAAC;AAAA,MACF,CAAC;AAAA,IACF,CAAC;AAAA,EACF;AAAA;AAAA,EAGA,wBAAiC;AAChC,WAAO,KAAK;AAAA,EACb;AACD;","names":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Database } from '@sqlitecloud/drivers';
|
|
2
|
+
import type * as V1 from "../_relations.cjs";
|
|
3
|
+
import { type Cache } from "../cache/core/index.cjs";
|
|
4
|
+
import type { WithCacheConfig } from "../cache/core/types.cjs";
|
|
5
|
+
import { entityKind } from "../entity.cjs";
|
|
6
|
+
import type { Logger } from "../logger.cjs";
|
|
7
|
+
import type { AnyRelations } from "../relations.cjs";
|
|
8
|
+
import { type Query, type SQL } from "../sql/sql.cjs";
|
|
9
|
+
import type { SQLiteAsyncDialect } from "../sqlite-core/dialect.cjs";
|
|
10
|
+
import { SQLiteTransaction } from "../sqlite-core/index.cjs";
|
|
11
|
+
import type { SelectedFieldsOrdered } from "../sqlite-core/query-builders/select.types.cjs";
|
|
12
|
+
import type { PreparedQueryConfig as PreparedQueryConfigBase, Result, SQLiteExecuteMethod, SQLiteTransactionConfig } from "../sqlite-core/session.cjs";
|
|
13
|
+
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.cjs";
|
|
14
|
+
import type { SQLiteCloudRunResult } from "./driver.cjs";
|
|
15
|
+
export interface SQLiteCloudSessionOptions {
|
|
16
|
+
logger?: Logger;
|
|
17
|
+
cache?: Cache;
|
|
18
|
+
}
|
|
19
|
+
type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
|
|
20
|
+
export declare class SQLiteCloudSession<TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends SQLiteSession<'async', SQLiteCloudRunResult, TFullSchema, TRelations, TSchema> {
|
|
21
|
+
private client;
|
|
22
|
+
private relations;
|
|
23
|
+
private schema;
|
|
24
|
+
private options;
|
|
25
|
+
static readonly [entityKind]: string;
|
|
26
|
+
private logger;
|
|
27
|
+
private cache;
|
|
28
|
+
constructor(client: Database, dialect: SQLiteAsyncDialect, relations: TRelations, schema: V1.RelationalSchemaConfig<TSchema> | undefined, options: SQLiteCloudSessionOptions);
|
|
29
|
+
prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => unknown, queryMetadata?: {
|
|
30
|
+
type: 'select' | 'update' | 'delete' | 'insert';
|
|
31
|
+
tables: string[];
|
|
32
|
+
}, cacheConfig?: WithCacheConfig): SQLiteCloudPreparedQuery<T>;
|
|
33
|
+
prepareRelationalQuery<T extends Omit<PreparedQueryConfig, 'run'>>(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper: (rows: Record<string, unknown>[]) => unknown): SQLiteCloudPreparedQuery<T, true>;
|
|
34
|
+
run(query: SQL): Result<'async', SQLiteCloudRunResult>;
|
|
35
|
+
all<T = unknown>(query: SQL): Result<'async', T[]>;
|
|
36
|
+
get<T = unknown>(query: SQL): Result<'async', T>;
|
|
37
|
+
values<T extends any[] = unknown[]>(query: SQL): Result<'async', T[]>;
|
|
38
|
+
transaction<T>(transaction: (tx: SQLiteCloudTransaction<TFullSchema, TRelations, TSchema>) => Promise<T>, config?: SQLiteTransactionConfig): Promise<T>;
|
|
39
|
+
}
|
|
40
|
+
export declare class SQLiteCloudTransaction<TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends SQLiteTransaction<'async', SQLiteCloudRunResult, TFullSchema, TRelations, TSchema> {
|
|
41
|
+
static readonly [entityKind]: string;
|
|
42
|
+
transaction<T>(transaction: (tx: SQLiteCloudTransaction<TFullSchema, TRelations, TSchema>) => Promise<T>): Promise<T>;
|
|
43
|
+
}
|
|
44
|
+
export declare class SQLiteCloudPreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig, TIsRqbV2 extends boolean = false> extends SQLitePreparedQuery<{
|
|
45
|
+
type: 'async';
|
|
46
|
+
run: SQLiteCloudRunResult;
|
|
47
|
+
all: T['all'];
|
|
48
|
+
get: T['get'];
|
|
49
|
+
values: T['values'];
|
|
50
|
+
execute: T['execute'];
|
|
51
|
+
}> {
|
|
52
|
+
private stmt;
|
|
53
|
+
private logger;
|
|
54
|
+
private _isResponseInArrayMode;
|
|
55
|
+
private customResultMapper?;
|
|
56
|
+
private isRqbV2Query?;
|
|
57
|
+
static readonly [entityKind]: string;
|
|
58
|
+
constructor(stmt: ReturnType<Database['prepare']>, query: Query, logger: Logger, cache: Cache, queryMetadata: {
|
|
59
|
+
type: 'select' | 'update' | 'delete' | 'insert';
|
|
60
|
+
tables: string[];
|
|
61
|
+
} | undefined, cacheConfig: WithCacheConfig | undefined,
|
|
62
|
+
/** @internal */ fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][], mapColumnValue?: (value: unknown) => unknown) => unknown) | undefined, isRqbV2Query?: TIsRqbV2 | undefined);
|
|
63
|
+
run(placeholderValues?: Record<string, unknown>): Promise<SQLiteCloudRunResult>;
|
|
64
|
+
all(placeholderValues?: Record<string, unknown>): Promise<T['all']>;
|
|
65
|
+
private allRqbV2;
|
|
66
|
+
get(placeholderValues?: Record<string, unknown>): Promise<T['get']>;
|
|
67
|
+
private getRqbV2;
|
|
68
|
+
values(placeholderValues?: Record<string, unknown>): Promise<T['values']>;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Database } from '@sqlitecloud/drivers';
|
|
2
|
+
import type * as V1 from "../_relations.js";
|
|
3
|
+
import { type Cache } from "../cache/core/index.js";
|
|
4
|
+
import type { WithCacheConfig } from "../cache/core/types.js";
|
|
5
|
+
import { entityKind } from "../entity.js";
|
|
6
|
+
import type { Logger } from "../logger.js";
|
|
7
|
+
import type { AnyRelations } from "../relations.js";
|
|
8
|
+
import { type Query, type SQL } from "../sql/sql.js";
|
|
9
|
+
import type { SQLiteAsyncDialect } from "../sqlite-core/dialect.js";
|
|
10
|
+
import { SQLiteTransaction } from "../sqlite-core/index.js";
|
|
11
|
+
import type { SelectedFieldsOrdered } from "../sqlite-core/query-builders/select.types.js";
|
|
12
|
+
import type { PreparedQueryConfig as PreparedQueryConfigBase, Result, SQLiteExecuteMethod, SQLiteTransactionConfig } from "../sqlite-core/session.js";
|
|
13
|
+
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.js";
|
|
14
|
+
import type { SQLiteCloudRunResult } from "./driver.js";
|
|
15
|
+
export interface SQLiteCloudSessionOptions {
|
|
16
|
+
logger?: Logger;
|
|
17
|
+
cache?: Cache;
|
|
18
|
+
}
|
|
19
|
+
type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
|
|
20
|
+
export declare class SQLiteCloudSession<TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends SQLiteSession<'async', SQLiteCloudRunResult, TFullSchema, TRelations, TSchema> {
|
|
21
|
+
private client;
|
|
22
|
+
private relations;
|
|
23
|
+
private schema;
|
|
24
|
+
private options;
|
|
25
|
+
static readonly [entityKind]: string;
|
|
26
|
+
private logger;
|
|
27
|
+
private cache;
|
|
28
|
+
constructor(client: Database, dialect: SQLiteAsyncDialect, relations: TRelations, schema: V1.RelationalSchemaConfig<TSchema> | undefined, options: SQLiteCloudSessionOptions);
|
|
29
|
+
prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => unknown, queryMetadata?: {
|
|
30
|
+
type: 'select' | 'update' | 'delete' | 'insert';
|
|
31
|
+
tables: string[];
|
|
32
|
+
}, cacheConfig?: WithCacheConfig): SQLiteCloudPreparedQuery<T>;
|
|
33
|
+
prepareRelationalQuery<T extends Omit<PreparedQueryConfig, 'run'>>(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper: (rows: Record<string, unknown>[]) => unknown): SQLiteCloudPreparedQuery<T, true>;
|
|
34
|
+
run(query: SQL): Result<'async', SQLiteCloudRunResult>;
|
|
35
|
+
all<T = unknown>(query: SQL): Result<'async', T[]>;
|
|
36
|
+
get<T = unknown>(query: SQL): Result<'async', T>;
|
|
37
|
+
values<T extends any[] = unknown[]>(query: SQL): Result<'async', T[]>;
|
|
38
|
+
transaction<T>(transaction: (tx: SQLiteCloudTransaction<TFullSchema, TRelations, TSchema>) => Promise<T>, config?: SQLiteTransactionConfig): Promise<T>;
|
|
39
|
+
}
|
|
40
|
+
export declare class SQLiteCloudTransaction<TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends SQLiteTransaction<'async', SQLiteCloudRunResult, TFullSchema, TRelations, TSchema> {
|
|
41
|
+
static readonly [entityKind]: string;
|
|
42
|
+
transaction<T>(transaction: (tx: SQLiteCloudTransaction<TFullSchema, TRelations, TSchema>) => Promise<T>): Promise<T>;
|
|
43
|
+
}
|
|
44
|
+
export declare class SQLiteCloudPreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig, TIsRqbV2 extends boolean = false> extends SQLitePreparedQuery<{
|
|
45
|
+
type: 'async';
|
|
46
|
+
run: SQLiteCloudRunResult;
|
|
47
|
+
all: T['all'];
|
|
48
|
+
get: T['get'];
|
|
49
|
+
values: T['values'];
|
|
50
|
+
execute: T['execute'];
|
|
51
|
+
}> {
|
|
52
|
+
private stmt;
|
|
53
|
+
private logger;
|
|
54
|
+
private _isResponseInArrayMode;
|
|
55
|
+
private customResultMapper?;
|
|
56
|
+
private isRqbV2Query?;
|
|
57
|
+
static readonly [entityKind]: string;
|
|
58
|
+
constructor(stmt: ReturnType<Database['prepare']>, query: Query, logger: Logger, cache: Cache, queryMetadata: {
|
|
59
|
+
type: 'select' | 'update' | 'delete' | 'insert';
|
|
60
|
+
tables: string[];
|
|
61
|
+
} | undefined, cacheConfig: WithCacheConfig | undefined,
|
|
62
|
+
/** @internal */ fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][], mapColumnValue?: (value: unknown) => unknown) => unknown) | undefined, isRqbV2Query?: TIsRqbV2 | undefined);
|
|
63
|
+
run(placeholderValues?: Record<string, unknown>): Promise<SQLiteCloudRunResult>;
|
|
64
|
+
all(placeholderValues?: Record<string, unknown>): Promise<T['all']>;
|
|
65
|
+
private allRqbV2;
|
|
66
|
+
get(placeholderValues?: Record<string, unknown>): Promise<T['get']>;
|
|
67
|
+
private getRqbV2;
|
|
68
|
+
values(placeholderValues?: Record<string, unknown>): Promise<T['values']>;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { NoopCache } from "../cache/core/index.js";
|
|
2
|
+
import { entityKind } from "../entity.js";
|
|
3
|
+
import { DrizzleError } from "../errors.js";
|
|
4
|
+
import { NoopLogger } from "../logger.js";
|
|
5
|
+
import { fillPlaceholders, sql } from "../sql/sql.js";
|
|
6
|
+
import { SQLiteTransaction } from "../sqlite-core/index.js";
|
|
7
|
+
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.js";
|
|
8
|
+
import { mapResultRow } from "../utils.js";
|
|
9
|
+
class SQLiteCloudSession extends SQLiteSession {
|
|
10
|
+
constructor(client, dialect, relations, schema, options) {
|
|
11
|
+
super(dialect);
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.relations = relations;
|
|
14
|
+
this.schema = schema;
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
17
|
+
this.cache = options.cache ?? new NoopCache();
|
|
18
|
+
}
|
|
19
|
+
static [entityKind] = "SQLiteCloudSession";
|
|
20
|
+
logger;
|
|
21
|
+
cache;
|
|
22
|
+
prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
|
23
|
+
const stmt = this.client.prepare(query.sql);
|
|
24
|
+
return new SQLiteCloudPreparedQuery(
|
|
25
|
+
stmt,
|
|
26
|
+
query,
|
|
27
|
+
this.logger,
|
|
28
|
+
this.cache,
|
|
29
|
+
queryMetadata,
|
|
30
|
+
cacheConfig,
|
|
31
|
+
fields,
|
|
32
|
+
executeMethod,
|
|
33
|
+
isResponseInArrayMode,
|
|
34
|
+
customResultMapper
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
prepareRelationalQuery(query, fields, executeMethod, customResultMapper) {
|
|
38
|
+
const stmt = this.client.prepare(query.sql);
|
|
39
|
+
return new SQLiteCloudPreparedQuery(
|
|
40
|
+
stmt,
|
|
41
|
+
query,
|
|
42
|
+
this.logger,
|
|
43
|
+
this.cache,
|
|
44
|
+
void 0,
|
|
45
|
+
void 0,
|
|
46
|
+
fields,
|
|
47
|
+
executeMethod,
|
|
48
|
+
false,
|
|
49
|
+
customResultMapper,
|
|
50
|
+
true
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
async run(query) {
|
|
54
|
+
const staticQuery = this.dialect.sqlToQuery(query);
|
|
55
|
+
try {
|
|
56
|
+
return await this.prepareOneTimeQuery(staticQuery, void 0, "run", false).run();
|
|
57
|
+
} catch (err) {
|
|
58
|
+
throw new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async all(query) {
|
|
62
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).all();
|
|
63
|
+
}
|
|
64
|
+
async get(query) {
|
|
65
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
|
|
66
|
+
}
|
|
67
|
+
async values(query) {
|
|
68
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
|
|
69
|
+
}
|
|
70
|
+
async transaction(transaction, config) {
|
|
71
|
+
const tx = new SQLiteCloudTransaction(
|
|
72
|
+
"async",
|
|
73
|
+
this.dialect,
|
|
74
|
+
this,
|
|
75
|
+
this.relations,
|
|
76
|
+
this.schema
|
|
77
|
+
);
|
|
78
|
+
await tx.run(sql`BEGIN${sql` ${sql.raw(config?.behavior ?? "")}`.if(config?.behavior)} TRANSACTION`);
|
|
79
|
+
try {
|
|
80
|
+
const result = await transaction(tx);
|
|
81
|
+
await tx.run(sql`COMMIT`);
|
|
82
|
+
return result;
|
|
83
|
+
} catch (err) {
|
|
84
|
+
await tx.run(sql`ROLLBACK`);
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
class SQLiteCloudTransaction extends SQLiteTransaction {
|
|
90
|
+
static [entityKind] = "SQLiteCloudTransaction";
|
|
91
|
+
async transaction(transaction) {
|
|
92
|
+
const savepointName = `sp${this.nestedIndex}`;
|
|
93
|
+
const tx = new SQLiteCloudTransaction(
|
|
94
|
+
"async",
|
|
95
|
+
this.dialect,
|
|
96
|
+
this.session,
|
|
97
|
+
this.relations,
|
|
98
|
+
this.schema,
|
|
99
|
+
this.nestedIndex + 1
|
|
100
|
+
);
|
|
101
|
+
await this.session.run(sql.raw(`savepoint ${savepointName}`));
|
|
102
|
+
try {
|
|
103
|
+
const result = await transaction(tx);
|
|
104
|
+
await this.session.run(sql.raw(`release savepoint ${savepointName}`));
|
|
105
|
+
return result;
|
|
106
|
+
} catch (err) {
|
|
107
|
+
await this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class SQLiteCloudPreparedQuery extends SQLitePreparedQuery {
|
|
113
|
+
constructor(stmt, query, logger, cache, queryMetadata, cacheConfig, fields, executeMethod, _isResponseInArrayMode, customResultMapper, isRqbV2Query) {
|
|
114
|
+
super("async", executeMethod, query, cache, queryMetadata, cacheConfig);
|
|
115
|
+
this.stmt = stmt;
|
|
116
|
+
this.logger = logger;
|
|
117
|
+
this.fields = fields;
|
|
118
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
119
|
+
this.customResultMapper = customResultMapper;
|
|
120
|
+
this.isRqbV2Query = isRqbV2Query;
|
|
121
|
+
}
|
|
122
|
+
static [entityKind] = "SQLiteCloudPreparedQuery";
|
|
123
|
+
async run(placeholderValues) {
|
|
124
|
+
const { stmt, query, logger } = this;
|
|
125
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
126
|
+
logger.logQuery(query.sql, params);
|
|
127
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
128
|
+
return await new Promise((resolve, reject) => {
|
|
129
|
+
(params.length ? stmt.bind(...params) : stmt).run((e, d) => {
|
|
130
|
+
if (e) return reject(e);
|
|
131
|
+
return resolve(d);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async all(placeholderValues) {
|
|
137
|
+
if (this.isRqbV2Query) return await this.allRqbV2(placeholderValues);
|
|
138
|
+
const { fields, logger, query, customResultMapper, joinsNotNullableMap, stmt } = this;
|
|
139
|
+
if (!fields && !customResultMapper) {
|
|
140
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
141
|
+
logger.logQuery(query.sql, params);
|
|
142
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
143
|
+
return await new Promise((resolve, reject) => {
|
|
144
|
+
(params.length ? stmt.bind(...params) : stmt).all((e, d) => {
|
|
145
|
+
if (e) return reject(e);
|
|
146
|
+
return resolve(d.map((v) => Object.fromEntries(Object.entries(v))));
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const rows = await this.values(placeholderValues);
|
|
152
|
+
return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
153
|
+
}
|
|
154
|
+
async allRqbV2(placeholderValues) {
|
|
155
|
+
const { logger, query, customResultMapper, stmt } = this;
|
|
156
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
157
|
+
logger.logQuery(query.sql, params);
|
|
158
|
+
const rows = await new Promise((resolve, reject) => {
|
|
159
|
+
(params.length ? stmt.bind(...params) : stmt).all((e, d) => {
|
|
160
|
+
if (e) return reject(e);
|
|
161
|
+
return resolve(d.map((v) => Object.fromEntries(Object.entries(v))));
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
return customResultMapper(rows);
|
|
165
|
+
}
|
|
166
|
+
async get(placeholderValues) {
|
|
167
|
+
if (this.isRqbV2Query) return await this.getRqbV2(placeholderValues);
|
|
168
|
+
const { fields, logger, query, stmt, customResultMapper, joinsNotNullableMap } = this;
|
|
169
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
170
|
+
if (!fields && !customResultMapper) {
|
|
171
|
+
logger.logQuery(query.sql, params);
|
|
172
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
173
|
+
return await new Promise((resolve, reject) => {
|
|
174
|
+
(params.length ? stmt.bind(...params) : stmt).get((e, d) => {
|
|
175
|
+
if (e) return reject(e);
|
|
176
|
+
return resolve(d ? Object.fromEntries(Object.entries(d)) : d);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
const row = await this.queryWithCache(query.sql, params, async () => {
|
|
182
|
+
return await new Promise((resolve, reject) => {
|
|
183
|
+
(params.length ? stmt.bind(...params) : stmt).get((e, d) => {
|
|
184
|
+
if (e) return reject(e);
|
|
185
|
+
return resolve(d ? d.getData() : d);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
if (row === void 0) return row;
|
|
190
|
+
return mapResultRow(fields, row, joinsNotNullableMap);
|
|
191
|
+
}
|
|
192
|
+
async getRqbV2(placeholderValues) {
|
|
193
|
+
const { logger, query, stmt, customResultMapper } = this;
|
|
194
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
195
|
+
logger.logQuery(query.sql, params);
|
|
196
|
+
const row = await new Promise((resolve, reject) => {
|
|
197
|
+
(params.length ? stmt.bind(...params) : stmt).get((e, d) => {
|
|
198
|
+
if (e) return reject(e);
|
|
199
|
+
return resolve(d ? Object.fromEntries(Object.entries(d)) : d);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
if (row === void 0) return row;
|
|
203
|
+
return customResultMapper([row]);
|
|
204
|
+
}
|
|
205
|
+
async values(placeholderValues) {
|
|
206
|
+
const { logger, stmt, query } = this;
|
|
207
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
208
|
+
logger.logQuery(query.sql, params);
|
|
209
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
210
|
+
return await new Promise((resolve, reject) => {
|
|
211
|
+
(params.length ? stmt.bind(...params) : stmt).all((e, d) => {
|
|
212
|
+
if (e) return reject(e);
|
|
213
|
+
return resolve(d.map((v) => v.getData()));
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/** @internal */
|
|
219
|
+
isResponseInArrayMode() {
|
|
220
|
+
return this._isResponseInArrayMode;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
SQLiteCloudPreparedQuery,
|
|
225
|
+
SQLiteCloudSession,
|
|
226
|
+
SQLiteCloudTransaction
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=session.js.map
|