@prisma/adapter-libsql 6.5.0-dev.3 → 6.5.0-dev.31
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 +14 -12
- package/dist/index.d.ts +14 -12
- package/dist/index.js +39 -26
- package/dist/index.mjs +42 -27
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { DriverAdapter } from '@prisma/driver-adapter-utils';
|
|
1
|
+
import { Client } from '@libsql/client';
|
|
3
2
|
import { Mutex } from 'async-mutex';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import
|
|
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';
|
|
7
|
+
import { 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
|
-
import
|
|
2
|
-
import type { DriverAdapter } from '@prisma/driver-adapter-utils';
|
|
1
|
+
import { Client } from '@libsql/client';
|
|
3
2
|
import { Mutex } from 'async-mutex';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import
|
|
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';
|
|
7
|
+
import { 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
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
27
|
// src/libsql.ts
|
|
28
|
+
var import_client = require("@libsql/client");
|
|
28
29
|
var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
|
|
29
30
|
var import_async_mutex = require("async-mutex");
|
|
30
31
|
|
|
@@ -186,15 +187,13 @@ var LibSqlQueryable = class {
|
|
|
186
187
|
async queryRaw(query) {
|
|
187
188
|
const tag = "[js::query_raw]";
|
|
188
189
|
debug2(`${tag} %O`, query);
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
};
|
|
197
|
-
});
|
|
190
|
+
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
|
|
191
|
+
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
|
|
192
|
+
return {
|
|
193
|
+
columnNames: columns,
|
|
194
|
+
columnTypes,
|
|
195
|
+
rows: rows.map((row) => mapRow(row, columnTypes))
|
|
196
|
+
};
|
|
198
197
|
}
|
|
199
198
|
/**
|
|
200
199
|
* Execute a query given as SQL, interpolating the given parameters and
|
|
@@ -204,7 +203,7 @@ var LibSqlQueryable = class {
|
|
|
204
203
|
async executeRaw(query) {
|
|
205
204
|
const tag = "[js::execute_raw]";
|
|
206
205
|
debug2(`${tag} %O`, query);
|
|
207
|
-
return (await this.performIO(query)).
|
|
206
|
+
return (await this.performIO(query)).rowsAffected ?? 0;
|
|
208
207
|
}
|
|
209
208
|
/**
|
|
210
209
|
* Run a query against the database, returning the result set.
|
|
@@ -215,23 +214,25 @@ var LibSqlQueryable = class {
|
|
|
215
214
|
const release = await this[LOCK_TAG].acquire();
|
|
216
215
|
try {
|
|
217
216
|
const result = await this.client.execute(query);
|
|
218
|
-
return
|
|
217
|
+
return result;
|
|
219
218
|
} 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;
|
|
219
|
+
this.onError(e);
|
|
231
220
|
} finally {
|
|
232
221
|
release();
|
|
233
222
|
}
|
|
234
223
|
}
|
|
224
|
+
onError(error) {
|
|
225
|
+
debug2("Error in performIO: %O", error);
|
|
226
|
+
const rawCode = error["rawCode"] ?? error.cause?.["rawCode"];
|
|
227
|
+
if (typeof rawCode === "number") {
|
|
228
|
+
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
229
|
+
kind: "sqlite",
|
|
230
|
+
extendedCode: rawCode,
|
|
231
|
+
message: error.message
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
235
236
|
};
|
|
236
237
|
var LibSqlTransaction = class extends LibSqlQueryable {
|
|
237
238
|
constructor(client, options, unlockParent) {
|
|
@@ -246,7 +247,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
246
247
|
} finally {
|
|
247
248
|
this.unlockParent();
|
|
248
249
|
}
|
|
249
|
-
return (0, import_driver_adapter_utils2.ok)(void 0);
|
|
250
250
|
}
|
|
251
251
|
async rollback() {
|
|
252
252
|
debug2(`[js::rollback]`);
|
|
@@ -257,7 +257,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
257
257
|
} finally {
|
|
258
258
|
this.unlockParent();
|
|
259
259
|
}
|
|
260
|
-
return (0, import_driver_adapter_utils2.ok)(void 0);
|
|
261
260
|
}
|
|
262
261
|
};
|
|
263
262
|
var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
@@ -274,7 +273,7 @@ var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
|
274
273
|
debug2("%s options: %O", tag, options);
|
|
275
274
|
try {
|
|
276
275
|
const tx = await this.client.transaction("deferred");
|
|
277
|
-
return
|
|
276
|
+
return new LibSqlTransaction(tx, options, this.release);
|
|
278
277
|
} catch (e) {
|
|
279
278
|
this.release();
|
|
280
279
|
throw e;
|
|
@@ -285,9 +284,23 @@ var PrismaLibSQL = class extends LibSqlQueryable {
|
|
|
285
284
|
constructor(client) {
|
|
286
285
|
super(client);
|
|
287
286
|
}
|
|
287
|
+
async executeScript(script) {
|
|
288
|
+
const release = await this[LOCK_TAG].acquire();
|
|
289
|
+
try {
|
|
290
|
+
await this.client.executeMultiple(script);
|
|
291
|
+
} catch (e) {
|
|
292
|
+
this.onError(e);
|
|
293
|
+
} finally {
|
|
294
|
+
release();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
288
297
|
async transactionContext() {
|
|
289
298
|
const release = await this[LOCK_TAG].acquire();
|
|
290
|
-
return
|
|
299
|
+
return new LibSqlTransactionContext(this.client, release);
|
|
300
|
+
}
|
|
301
|
+
dispose() {
|
|
302
|
+
this.client.close();
|
|
303
|
+
return Promise.resolve();
|
|
291
304
|
}
|
|
292
305
|
};
|
|
293
306
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/libsql.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createClient
|
|
4
|
+
} from "@libsql/client";
|
|
5
|
+
import { Debug as Debug2, DriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
3
6
|
import { Mutex } from "async-mutex";
|
|
4
7
|
|
|
5
8
|
// package.json
|
|
@@ -160,15 +163,13 @@ var LibSqlQueryable = class {
|
|
|
160
163
|
async queryRaw(query) {
|
|
161
164
|
const tag = "[js::query_raw]";
|
|
162
165
|
debug2(`${tag} %O`, query);
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
171
|
-
});
|
|
166
|
+
const { columns, rows, columnTypes: declaredColumnTypes } = await this.performIO(query);
|
|
167
|
+
const columnTypes = getColumnTypes(declaredColumnTypes, rows);
|
|
168
|
+
return {
|
|
169
|
+
columnNames: columns,
|
|
170
|
+
columnTypes,
|
|
171
|
+
rows: rows.map((row) => mapRow(row, columnTypes))
|
|
172
|
+
};
|
|
172
173
|
}
|
|
173
174
|
/**
|
|
174
175
|
* Execute a query given as SQL, interpolating the given parameters and
|
|
@@ -178,7 +179,7 @@ var LibSqlQueryable = class {
|
|
|
178
179
|
async executeRaw(query) {
|
|
179
180
|
const tag = "[js::execute_raw]";
|
|
180
181
|
debug2(`${tag} %O`, query);
|
|
181
|
-
return (await this.performIO(query)).
|
|
182
|
+
return (await this.performIO(query)).rowsAffected ?? 0;
|
|
182
183
|
}
|
|
183
184
|
/**
|
|
184
185
|
* Run a query against the database, returning the result set.
|
|
@@ -189,23 +190,25 @@ var LibSqlQueryable = class {
|
|
|
189
190
|
const release = await this[LOCK_TAG].acquire();
|
|
190
191
|
try {
|
|
191
192
|
const result = await this.client.execute(query);
|
|
192
|
-
return
|
|
193
|
+
return result;
|
|
193
194
|
} 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;
|
|
195
|
+
this.onError(e);
|
|
205
196
|
} finally {
|
|
206
197
|
release();
|
|
207
198
|
}
|
|
208
199
|
}
|
|
200
|
+
onError(error) {
|
|
201
|
+
debug2("Error in performIO: %O", error);
|
|
202
|
+
const rawCode = error["rawCode"] ?? error.cause?.["rawCode"];
|
|
203
|
+
if (typeof rawCode === "number") {
|
|
204
|
+
throw new DriverAdapterError({
|
|
205
|
+
kind: "sqlite",
|
|
206
|
+
extendedCode: rawCode,
|
|
207
|
+
message: error.message
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
209
212
|
};
|
|
210
213
|
var LibSqlTransaction = class extends LibSqlQueryable {
|
|
211
214
|
constructor(client, options, unlockParent) {
|
|
@@ -220,7 +223,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
220
223
|
} finally {
|
|
221
224
|
this.unlockParent();
|
|
222
225
|
}
|
|
223
|
-
return ok(void 0);
|
|
224
226
|
}
|
|
225
227
|
async rollback() {
|
|
226
228
|
debug2(`[js::rollback]`);
|
|
@@ -231,7 +233,6 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
231
233
|
} finally {
|
|
232
234
|
this.unlockParent();
|
|
233
235
|
}
|
|
234
|
-
return ok(void 0);
|
|
235
236
|
}
|
|
236
237
|
};
|
|
237
238
|
var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
@@ -248,7 +249,7 @@ var LibSqlTransactionContext = class extends LibSqlQueryable {
|
|
|
248
249
|
debug2("%s options: %O", tag, options);
|
|
249
250
|
try {
|
|
250
251
|
const tx = await this.client.transaction("deferred");
|
|
251
|
-
return
|
|
252
|
+
return new LibSqlTransaction(tx, options, this.release);
|
|
252
253
|
} catch (e) {
|
|
253
254
|
this.release();
|
|
254
255
|
throw e;
|
|
@@ -259,9 +260,23 @@ var PrismaLibSQL = class extends LibSqlQueryable {
|
|
|
259
260
|
constructor(client) {
|
|
260
261
|
super(client);
|
|
261
262
|
}
|
|
263
|
+
async executeScript(script) {
|
|
264
|
+
const release = await this[LOCK_TAG].acquire();
|
|
265
|
+
try {
|
|
266
|
+
await this.client.executeMultiple(script);
|
|
267
|
+
} catch (e) {
|
|
268
|
+
this.onError(e);
|
|
269
|
+
} finally {
|
|
270
|
+
release();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
262
273
|
async transactionContext() {
|
|
263
274
|
const release = await this[LOCK_TAG].acquire();
|
|
264
|
-
return
|
|
275
|
+
return new LibSqlTransactionContext(this.client, release);
|
|
276
|
+
}
|
|
277
|
+
dispose() {
|
|
278
|
+
this.client.close();
|
|
279
|
+
return Promise.resolve();
|
|
265
280
|
}
|
|
266
281
|
};
|
|
267
282
|
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.31",
|
|
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.31"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@libsql/client": "0.8.0"
|