@prisma/adapter-libsql 6.5.0-dev.7 → 6.5.0-dev.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +44 -30
- package/dist/index.mjs +47 -31
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { Client } from '@libsql/client';
|
|
2
|
-
import type { DriverAdapter } from '@prisma/driver-adapter-utils';
|
|
3
2
|
import { Mutex } from 'async-mutex';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
3
|
+
import type { SqlConnection } from '@prisma/driver-adapter-utils';
|
|
4
|
+
import type { SqlQuery } from '@prisma/driver-adapter-utils';
|
|
5
|
+
import type { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
6
|
+
import type { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
8
7
|
import type { Transaction } from '@libsql/client';
|
|
9
8
|
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
10
9
|
|
|
11
|
-
declare class LibSqlQueryable<ClientT extends StdClient | TransactionClient> implements
|
|
10
|
+
declare class LibSqlQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
|
|
12
11
|
protected readonly client: ClientT;
|
|
13
12
|
readonly provider = "sqlite";
|
|
14
13
|
readonly adapterName: string;
|
|
@@ -17,26 +16,29 @@ declare class LibSqlQueryable<ClientT extends StdClient | TransactionClient> imp
|
|
|
17
16
|
/**
|
|
18
17
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
19
18
|
*/
|
|
20
|
-
queryRaw(query:
|
|
19
|
+
queryRaw(query: SqlQuery): Promise<SqlResultSet>;
|
|
21
20
|
/**
|
|
22
21
|
* Execute a query given as SQL, interpolating the given parameters and
|
|
23
22
|
* returning the number of affected rows.
|
|
24
23
|
* Note: Queryable expects a u64, but napi.rs only supports u32.
|
|
25
24
|
*/
|
|
26
|
-
executeRaw(query:
|
|
25
|
+
executeRaw(query: SqlQuery): Promise<number>;
|
|
27
26
|
/**
|
|
28
27
|
* Run a query against the database, returning the result set.
|
|
29
28
|
* Should the query fail due to a connection error, the connection is
|
|
30
29
|
* marked as unhealthy.
|
|
31
30
|
*/
|
|
32
31
|
private performIO;
|
|
32
|
+
protected onError(error: any): never;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
declare const LOCK_TAG: unique symbol;
|
|
36
36
|
|
|
37
|
-
export declare class PrismaLibSQL extends LibSqlQueryable<StdClient> implements
|
|
37
|
+
export declare class PrismaLibSQL extends LibSqlQueryable<StdClient> implements SqlConnection {
|
|
38
38
|
constructor(client: StdClient);
|
|
39
|
-
|
|
39
|
+
executeScript(script: string): Promise<void>;
|
|
40
|
+
transactionContext(): Promise<TransactionContext>;
|
|
41
|
+
dispose(): Promise<void>;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
declare type StdClient = Client;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { Client } from '@libsql/client';
|
|
2
|
-
import type { DriverAdapter } from '@prisma/driver-adapter-utils';
|
|
3
2
|
import { Mutex } from 'async-mutex';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
3
|
+
import type { SqlConnection } from '@prisma/driver-adapter-utils';
|
|
4
|
+
import type { SqlQuery } from '@prisma/driver-adapter-utils';
|
|
5
|
+
import type { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
6
|
+
import type { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
8
7
|
import type { Transaction } from '@libsql/client';
|
|
9
8
|
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
10
9
|
|
|
11
|
-
declare class LibSqlQueryable<ClientT extends StdClient | TransactionClient> implements
|
|
10
|
+
declare class LibSqlQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
|
|
12
11
|
protected readonly client: ClientT;
|
|
13
12
|
readonly provider = "sqlite";
|
|
14
13
|
readonly adapterName: string;
|
|
@@ -17,26 +16,29 @@ declare class LibSqlQueryable<ClientT extends StdClient | TransactionClient> imp
|
|
|
17
16
|
/**
|
|
18
17
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
19
18
|
*/
|
|
20
|
-
queryRaw(query:
|
|
19
|
+
queryRaw(query: SqlQuery): Promise<SqlResultSet>;
|
|
21
20
|
/**
|
|
22
21
|
* Execute a query given as SQL, interpolating the given parameters and
|
|
23
22
|
* returning the number of affected rows.
|
|
24
23
|
* Note: Queryable expects a u64, but napi.rs only supports u32.
|
|
25
24
|
*/
|
|
26
|
-
executeRaw(query:
|
|
25
|
+
executeRaw(query: SqlQuery): Promise<number>;
|
|
27
26
|
/**
|
|
28
27
|
* Run a query against the database, returning the result set.
|
|
29
28
|
* Should the query fail due to a connection error, the connection is
|
|
30
29
|
* marked as unhealthy.
|
|
31
30
|
*/
|
|
32
31
|
private performIO;
|
|
32
|
+
protected onError(error: any): never;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
declare const LOCK_TAG: unique symbol;
|
|
36
36
|
|
|
37
|
-
export declare class PrismaLibSQL extends LibSqlQueryable<StdClient> implements
|
|
37
|
+
export declare class PrismaLibSQL extends LibSqlQueryable<StdClient> implements SqlConnection {
|
|
38
38
|
constructor(client: StdClient);
|
|
39
|
-
|
|
39
|
+
executeScript(script: string): Promise<void>;
|
|
40
|
+
transactionContext(): Promise<TransactionContext>;
|
|
41
|
+
dispose(): Promise<void>;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
declare type StdClient = Client;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name2 in all)
|
|
8
9
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
@@ -16,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
return to;
|
|
17
18
|
};
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
21
|
|
|
20
22
|
// src/index.ts
|
|
21
23
|
var index_exports = {};
|
|
@@ -141,7 +143,7 @@ var UnexpectedTypeError = class extends Error {
|
|
|
141
143
|
const type = typeof value;
|
|
142
144
|
const repr = type === "object" ? JSON.stringify(value) : String(value);
|
|
143
145
|
super(`unexpected value of type ${type}: ${repr}`);
|
|
144
|
-
this
|
|
146
|
+
__publicField(this, "name", "UnexpectedTypeError");
|
|
145
147
|
}
|
|
146
148
|
};
|
|
147
149
|
function mapRow(row, columnTypes) {
|
|
@@ -176,9 +178,9 @@ _a = LOCK_TAG;
|
|
|
176
178
|
var LibSqlQueryable = class {
|
|
177
179
|
constructor(client) {
|
|
178
180
|
this.client = client;
|
|
179
|
-
this
|
|
180
|
-
this
|
|
181
|
-
this
|
|
181
|
+
__publicField(this, "provider", "sqlite");
|
|
182
|
+
__publicField(this, "adapterName", name);
|
|
183
|
+
__publicField(this, _a, new import_async_mutex.Mutex());
|
|
182
184
|
}
|
|
183
185
|
/**
|
|
184
186
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
@@ -186,15 +188,13 @@ var LibSqlQueryable = class {
|
|
|
186
188
|
async queryRaw(query) {
|
|
187
189
|
const tag = "[js::query_raw]";
|
|
188
190
|
debug2(`${tag} %O`, query);
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
};
|
|
197
|
-
});
|
|
191
|
+
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
|
|
192
|
+
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
|
|
193
|
+
return {
|
|
194
|
+
columnNames: columns,
|
|
195
|
+
columnTypes,
|
|
196
|
+
rows: rows.map((row) => mapRow(row, columnTypes))
|
|
197
|
+
};
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
200
200
|
* Execute a query given as SQL, interpolating the given parameters and
|
|
@@ -204,7 +204,7 @@ var LibSqlQueryable = class {
|
|
|
204
204
|
async executeRaw(query) {
|
|
205
205
|
const tag = "[js::execute_raw]";
|
|
206
206
|
debug2(`${tag} %O`, query);
|
|
207
|
-
return (await this.performIO(query)).
|
|
207
|
+
return (await this.performIO(query)).rowsAffected ?? 0;
|
|
208
208
|
}
|
|
209
209
|
/**
|
|
210
210
|
* Run a query against the database, returning the result set.
|
|
@@ -215,23 +215,25 @@ var LibSqlQueryable = class {
|
|
|
215
215
|
const release = await this[LOCK_TAG].acquire();
|
|
216
216
|
try {
|
|
217
217
|
const result = await this.client.execute(query);
|
|
218
|
-
return
|
|
218
|
+
return result;
|
|
219
219
|
} catch (e) {
|
|
220
|
-
|
|
221
|
-
debug2("Error in performIO: %O", error);
|
|
222
|
-
const rawCode = error["rawCode"] ?? e.cause?.["rawCode"];
|
|
223
|
-
if (typeof rawCode === "number") {
|
|
224
|
-
return (0, import_driver_adapter_utils2.err)({
|
|
225
|
-
kind: "sqlite",
|
|
226
|
-
extendedCode: rawCode,
|
|
227
|
-
message: error.message
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
throw error;
|
|
220
|
+
this.onError(e);
|
|
231
221
|
} finally {
|
|
232
222
|
release();
|
|
233
223
|
}
|
|
234
224
|
}
|
|
225
|
+
onError(error) {
|
|
226
|
+
debug2("Error in performIO: %O", error);
|
|
227
|
+
const rawCode = error["rawCode"] ?? error.cause?.["rawCode"];
|
|
228
|
+
if (typeof rawCode === "number") {
|
|
229
|
+
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
230
|
+
kind: "sqlite",
|
|
231
|
+
extendedCode: rawCode,
|
|
232
|
+
message: error.message
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
235
237
|
};
|
|
236
238
|
var LibSqlTransaction = class extends LibSqlQueryable {
|
|
237
239
|
constructor(client, options, unlockParent) {
|
|
@@ -246,7 +248,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
246
248
|
} finally {
|
|
247
249
|
this.unlockParent();
|
|
248
250
|
}
|
|
249
|
-
return (0, import_driver_adapter_utils2.ok)(void 0);
|
|
250
251
|
}
|
|
251
252
|
async rollback() {
|
|
252
253
|
debug2(`[js::rollback]`);
|
|
@@ -257,7 +258,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
257
258
|
} finally {
|
|
258
259
|
this.unlockParent();
|
|
259
260
|
}
|
|
260
|
-
return (0, import_driver_adapter_utils2.ok)(void 0);
|
|
261
261
|
}
|
|
262
262
|
};
|
|
263
263
|
var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
@@ -274,7 +274,7 @@ var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
|
274
274
|
debug2("%s options: %O", tag, options);
|
|
275
275
|
try {
|
|
276
276
|
const tx = await this.client.transaction("deferred");
|
|
277
|
-
return
|
|
277
|
+
return new LibSqlTransaction(tx, options, this.release);
|
|
278
278
|
} catch (e) {
|
|
279
279
|
this.release();
|
|
280
280
|
throw e;
|
|
@@ -285,9 +285,23 @@ var PrismaLibSQL = class extends LibSqlQueryable {
|
|
|
285
285
|
constructor(client) {
|
|
286
286
|
super(client);
|
|
287
287
|
}
|
|
288
|
+
async executeScript(script) {
|
|
289
|
+
const release = await this[LOCK_TAG].acquire();
|
|
290
|
+
try {
|
|
291
|
+
await this.client.executeMultiple(script);
|
|
292
|
+
} catch (e) {
|
|
293
|
+
this.onError(e);
|
|
294
|
+
} finally {
|
|
295
|
+
release();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
288
298
|
async transactionContext() {
|
|
289
299
|
const release = await this[LOCK_TAG].acquire();
|
|
290
|
-
return
|
|
300
|
+
return new LibSqlTransactionContext(this.client, release);
|
|
301
|
+
}
|
|
302
|
+
dispose() {
|
|
303
|
+
this.client.close();
|
|
304
|
+
return Promise.resolve();
|
|
291
305
|
}
|
|
292
306
|
};
|
|
293
307
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
1
5
|
// src/libsql.ts
|
|
2
|
-
import { Debug as Debug2,
|
|
6
|
+
import { Debug as Debug2, DriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
3
7
|
import { Mutex } from "async-mutex";
|
|
4
8
|
|
|
5
9
|
// package.json
|
|
@@ -115,7 +119,7 @@ var UnexpectedTypeError = class extends Error {
|
|
|
115
119
|
const type = typeof value;
|
|
116
120
|
const repr = type === "object" ? JSON.stringify(value) : String(value);
|
|
117
121
|
super(`unexpected value of type ${type}: ${repr}`);
|
|
118
|
-
this
|
|
122
|
+
__publicField(this, "name", "UnexpectedTypeError");
|
|
119
123
|
}
|
|
120
124
|
};
|
|
121
125
|
function mapRow(row, columnTypes) {
|
|
@@ -150,9 +154,9 @@ _a = LOCK_TAG;
|
|
|
150
154
|
var LibSqlQueryable = class {
|
|
151
155
|
constructor(client) {
|
|
152
156
|
this.client = client;
|
|
153
|
-
this
|
|
154
|
-
this
|
|
155
|
-
this
|
|
157
|
+
__publicField(this, "provider", "sqlite");
|
|
158
|
+
__publicField(this, "adapterName", name);
|
|
159
|
+
__publicField(this, _a, new Mutex());
|
|
156
160
|
}
|
|
157
161
|
/**
|
|
158
162
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
@@ -160,15 +164,13 @@ var LibSqlQueryable = class {
|
|
|
160
164
|
async queryRaw(query) {
|
|
161
165
|
const tag = "[js::query_raw]";
|
|
162
166
|
debug2(`${tag} %O`, query);
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
171
|
-
});
|
|
167
|
+
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
|
|
168
|
+
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
|
|
169
|
+
return {
|
|
170
|
+
columnNames: columns,
|
|
171
|
+
columnTypes,
|
|
172
|
+
rows: rows.map((row) => mapRow(row, columnTypes))
|
|
173
|
+
};
|
|
172
174
|
}
|
|
173
175
|
/**
|
|
174
176
|
* Execute a query given as SQL, interpolating the given parameters and
|
|
@@ -178,7 +180,7 @@ var LibSqlQueryable = class {
|
|
|
178
180
|
async executeRaw(query) {
|
|
179
181
|
const tag = "[js::execute_raw]";
|
|
180
182
|
debug2(`${tag} %O`, query);
|
|
181
|
-
return (await this.performIO(query)).
|
|
183
|
+
return (await this.performIO(query)).rowsAffected ?? 0;
|
|
182
184
|
}
|
|
183
185
|
/**
|
|
184
186
|
* Run a query against the database, returning the result set.
|
|
@@ -189,23 +191,25 @@ var LibSqlQueryable = class {
|
|
|
189
191
|
const release = await this[LOCK_TAG].acquire();
|
|
190
192
|
try {
|
|
191
193
|
const result = await this.client.execute(query);
|
|
192
|
-
return
|
|
194
|
+
return result;
|
|
193
195
|
} catch (e) {
|
|
194
|
-
|
|
195
|
-
debug2("Error in performIO: %O", error);
|
|
196
|
-
const rawCode = error["rawCode"] ?? e.cause?.["rawCode"];
|
|
197
|
-
if (typeof rawCode === "number") {
|
|
198
|
-
return err({
|
|
199
|
-
kind: "sqlite",
|
|
200
|
-
extendedCode: rawCode,
|
|
201
|
-
message: error.message
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
throw error;
|
|
196
|
+
this.onError(e);
|
|
205
197
|
} finally {
|
|
206
198
|
release();
|
|
207
199
|
}
|
|
208
200
|
}
|
|
201
|
+
onError(error) {
|
|
202
|
+
debug2("Error in performIO: %O", error);
|
|
203
|
+
const rawCode = error["rawCode"] ?? error.cause?.["rawCode"];
|
|
204
|
+
if (typeof rawCode === "number") {
|
|
205
|
+
throw new DriverAdapterError({
|
|
206
|
+
kind: "sqlite",
|
|
207
|
+
extendedCode: rawCode,
|
|
208
|
+
message: error.message
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
209
213
|
};
|
|
210
214
|
var LibSqlTransaction = class extends LibSqlQueryable {
|
|
211
215
|
constructor(client, options, unlockParent) {
|
|
@@ -220,7 +224,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
220
224
|
} finally {
|
|
221
225
|
this.unlockParent();
|
|
222
226
|
}
|
|
223
|
-
return ok(void 0);
|
|
224
227
|
}
|
|
225
228
|
async rollback() {
|
|
226
229
|
debug2(`[js::rollback]`);
|
|
@@ -231,7 +234,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
231
234
|
} finally {
|
|
232
235
|
this.unlockParent();
|
|
233
236
|
}
|
|
234
|
-
return ok(void 0);
|
|
235
237
|
}
|
|
236
238
|
};
|
|
237
239
|
var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
@@ -248,7 +250,7 @@ var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
|
248
250
|
debug2("%s options: %O", tag, options);
|
|
249
251
|
try {
|
|
250
252
|
const tx = await this.client.transaction("deferred");
|
|
251
|
-
return
|
|
253
|
+
return new LibSqlTransaction(tx, options, this.release);
|
|
252
254
|
} catch (e) {
|
|
253
255
|
this.release();
|
|
254
256
|
throw e;
|
|
@@ -259,9 +261,23 @@ var PrismaLibSQL = class extends LibSqlQueryable {
|
|
|
259
261
|
constructor(client) {
|
|
260
262
|
super(client);
|
|
261
263
|
}
|
|
264
|
+
async executeScript(script) {
|
|
265
|
+
const release = await this[LOCK_TAG].acquire();
|
|
266
|
+
try {
|
|
267
|
+
await this.client.executeMultiple(script);
|
|
268
|
+
} catch (e) {
|
|
269
|
+
this.onError(e);
|
|
270
|
+
} finally {
|
|
271
|
+
release();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
262
274
|
async transactionContext() {
|
|
263
275
|
const release = await this[LOCK_TAG].acquire();
|
|
264
|
-
return
|
|
276
|
+
return new LibSqlTransactionContext(this.client, release);
|
|
277
|
+
}
|
|
278
|
+
dispose() {
|
|
279
|
+
this.client.close();
|
|
280
|
+
return Promise.resolve();
|
|
265
281
|
}
|
|
266
282
|
};
|
|
267
283
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-libsql",
|
|
3
|
-
"version": "6.5.0-dev.
|
|
3
|
+
"version": "6.5.0-dev.71",
|
|
4
4
|
"description": "Prisma's driver adapter for libSQL and Turso",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"sideEffects": false,
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"async-mutex": "0.5.0",
|
|
35
|
-
"@prisma/driver-adapter-utils": "6.5.0-dev.
|
|
35
|
+
"@prisma/driver-adapter-utils": "6.5.0-dev.71"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@libsql/client": "0.8.0"
|