@prisma/adapter-libsql 6.6.0-dev.4 → 6.6.0-dev.41
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/README.md +1 -3
- package/dist/index.d.mts +8 -42
- package/dist/index.d.ts +8 -42
- package/dist/index.js +42 -33
- package/dist/index.mjs +42 -35
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -40,18 +40,16 @@ Update your Prisma Client instance to use the libSQL database Client:
|
|
|
40
40
|
// Import needed packages
|
|
41
41
|
import { PrismaClient } from '@prisma/client'
|
|
42
42
|
import { PrismaLibSQL } from '@prisma/adapter-libsql'
|
|
43
|
-
import { createClient } from '@libsql/client'
|
|
44
43
|
|
|
45
44
|
// Setup
|
|
46
45
|
const connectionString = `${process.env.TURSO_DATABASE_URL}`
|
|
47
46
|
const authToken = `${process.env.TURSO_AUTH_TOKEN}`
|
|
48
47
|
|
|
49
48
|
// Init prisma client
|
|
50
|
-
const
|
|
49
|
+
const adapter = new PrismaLibSQL({
|
|
51
50
|
url: connectionString,
|
|
52
51
|
authToken,
|
|
53
52
|
})
|
|
54
|
-
const adapter = new PrismaLibSQL(libsql)
|
|
55
53
|
const prisma = new PrismaClient({ adapter })
|
|
56
54
|
```
|
|
57
55
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,48 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
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 type { Transaction } from '@libsql/client';
|
|
8
|
-
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
1
|
+
import type { Config } from '@libsql/client';
|
|
2
|
+
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
3
|
+
import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
|
|
9
4
|
|
|
10
|
-
declare class
|
|
11
|
-
|
|
5
|
+
export declare class PrismaLibSQL implements SqlMigrationAwareDriverAdapterFactory {
|
|
6
|
+
private readonly config;
|
|
12
7
|
readonly provider = "sqlite";
|
|
13
8
|
readonly adapterName: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Execute a query given as SQL, interpolating the given parameters.
|
|
18
|
-
*/
|
|
19
|
-
queryRaw(query: SqlQuery): Promise<SqlResultSet>;
|
|
20
|
-
/**
|
|
21
|
-
* Execute a query given as SQL, interpolating the given parameters and
|
|
22
|
-
* returning the number of affected rows.
|
|
23
|
-
* Note: Queryable expects a u64, but napi.rs only supports u32.
|
|
24
|
-
*/
|
|
25
|
-
executeRaw(query: SqlQuery): Promise<number>;
|
|
26
|
-
/**
|
|
27
|
-
* Run a query against the database, returning the result set.
|
|
28
|
-
* Should the query fail due to a connection error, the connection is
|
|
29
|
-
* marked as unhealthy.
|
|
30
|
-
*/
|
|
31
|
-
private performIO;
|
|
32
|
-
protected onError(error: any): never;
|
|
9
|
+
constructor(config: Config);
|
|
10
|
+
connect(): Promise<SqlDriverAdapter>;
|
|
11
|
+
connectToShadowDb(): Promise<SqlDriverAdapter>;
|
|
33
12
|
}
|
|
34
13
|
|
|
35
|
-
declare const LOCK_TAG: unique symbol;
|
|
36
|
-
|
|
37
|
-
export declare class PrismaLibSQL extends LibSqlQueryable<StdClient> implements SqlConnection {
|
|
38
|
-
constructor(client: StdClient);
|
|
39
|
-
executeScript(script: string): Promise<void>;
|
|
40
|
-
transactionContext(): Promise<TransactionContext>;
|
|
41
|
-
dispose(): Promise<void>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
declare type StdClient = Client;
|
|
45
|
-
|
|
46
|
-
declare type TransactionClient = Transaction;
|
|
47
|
-
|
|
48
14
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
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 type { Transaction } from '@libsql/client';
|
|
8
|
-
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
1
|
+
import type { Config } from '@libsql/client';
|
|
2
|
+
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
3
|
+
import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
|
|
9
4
|
|
|
10
|
-
declare class
|
|
11
|
-
|
|
5
|
+
export declare class PrismaLibSQL implements SqlMigrationAwareDriverAdapterFactory {
|
|
6
|
+
private readonly config;
|
|
12
7
|
readonly provider = "sqlite";
|
|
13
8
|
readonly adapterName: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Execute a query given as SQL, interpolating the given parameters.
|
|
18
|
-
*/
|
|
19
|
-
queryRaw(query: SqlQuery): Promise<SqlResultSet>;
|
|
20
|
-
/**
|
|
21
|
-
* Execute a query given as SQL, interpolating the given parameters and
|
|
22
|
-
* returning the number of affected rows.
|
|
23
|
-
* Note: Queryable expects a u64, but napi.rs only supports u32.
|
|
24
|
-
*/
|
|
25
|
-
executeRaw(query: SqlQuery): Promise<number>;
|
|
26
|
-
/**
|
|
27
|
-
* Run a query against the database, returning the result set.
|
|
28
|
-
* Should the query fail due to a connection error, the connection is
|
|
29
|
-
* marked as unhealthy.
|
|
30
|
-
*/
|
|
31
|
-
private performIO;
|
|
32
|
-
protected onError(error: any): never;
|
|
9
|
+
constructor(config: Config);
|
|
10
|
+
connect(): Promise<SqlDriverAdapter>;
|
|
11
|
+
connectToShadowDb(): Promise<SqlDriverAdapter>;
|
|
33
12
|
}
|
|
34
13
|
|
|
35
|
-
declare const LOCK_TAG: unique symbol;
|
|
36
|
-
|
|
37
|
-
export declare class PrismaLibSQL extends LibSqlQueryable<StdClient> implements SqlConnection {
|
|
38
|
-
constructor(client: StdClient);
|
|
39
|
-
executeScript(script: string): Promise<void>;
|
|
40
|
-
transactionContext(): Promise<TransactionContext>;
|
|
41
|
-
dispose(): Promise<void>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
declare type StdClient = Client;
|
|
45
|
-
|
|
46
|
-
declare type TransactionClient = Transaction;
|
|
47
|
-
|
|
48
14
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ 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;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name2 in all)
|
|
9
8
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
@@ -17,16 +16,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
19
|
|
|
22
20
|
// src/index.ts
|
|
23
21
|
var index_exports = {};
|
|
24
22
|
__export(index_exports, {
|
|
25
|
-
PrismaLibSQL: () =>
|
|
23
|
+
PrismaLibSQL: () => PrismaLibSQLAdapterFactory
|
|
26
24
|
});
|
|
27
25
|
module.exports = __toCommonJS(index_exports);
|
|
28
26
|
|
|
29
27
|
// src/libsql.ts
|
|
28
|
+
var import_client = require("@libsql/client");
|
|
30
29
|
var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
|
|
31
30
|
var import_async_mutex = require("async-mutex");
|
|
32
31
|
|
|
@@ -139,11 +138,11 @@ function inferObjectType(value) {
|
|
|
139
138
|
throw new UnexpectedTypeError(value);
|
|
140
139
|
}
|
|
141
140
|
var UnexpectedTypeError = class extends Error {
|
|
141
|
+
name = "UnexpectedTypeError";
|
|
142
142
|
constructor(value) {
|
|
143
143
|
const type = typeof value;
|
|
144
144
|
const repr = type === "object" ? JSON.stringify(value) : String(value);
|
|
145
145
|
super(`unexpected value of type ${type}: ${repr}`);
|
|
146
|
-
__publicField(this, "name", "UnexpectedTypeError");
|
|
147
146
|
}
|
|
148
147
|
};
|
|
149
148
|
function mapRow(row, columnTypes) {
|
|
@@ -173,15 +172,13 @@ function mapRow(row, columnTypes) {
|
|
|
173
172
|
// src/libsql.ts
|
|
174
173
|
var debug2 = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:libsql");
|
|
175
174
|
var LOCK_TAG = Symbol();
|
|
176
|
-
var _a;
|
|
177
|
-
_a = LOCK_TAG;
|
|
178
175
|
var LibSqlQueryable = class {
|
|
179
176
|
constructor(client) {
|
|
180
177
|
this.client = client;
|
|
181
|
-
__publicField(this, "provider", "sqlite");
|
|
182
|
-
__publicField(this, "adapterName", name);
|
|
183
|
-
__publicField(this, _a, new import_async_mutex.Mutex());
|
|
184
178
|
}
|
|
179
|
+
provider = "sqlite";
|
|
180
|
+
adapterName = name;
|
|
181
|
+
[LOCK_TAG] = new import_async_mutex.Mutex();
|
|
185
182
|
/**
|
|
186
183
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
187
184
|
*/
|
|
@@ -260,28 +257,7 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
260
257
|
}
|
|
261
258
|
}
|
|
262
259
|
};
|
|
263
|
-
var
|
|
264
|
-
constructor(client, release) {
|
|
265
|
-
super(client);
|
|
266
|
-
this.client = client;
|
|
267
|
-
this.release = release;
|
|
268
|
-
}
|
|
269
|
-
async startTransaction() {
|
|
270
|
-
const options = {
|
|
271
|
-
usePhantomQuery: true
|
|
272
|
-
};
|
|
273
|
-
const tag = "[js::startTransaction]";
|
|
274
|
-
debug2("%s options: %O", tag, options);
|
|
275
|
-
try {
|
|
276
|
-
const tx = await this.client.transaction("deferred");
|
|
277
|
-
return new LibSqlTransaction(tx, options, this.release);
|
|
278
|
-
} catch (e) {
|
|
279
|
-
this.release();
|
|
280
|
-
throw e;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
var PrismaLibSQL = class extends LibSqlQueryable {
|
|
260
|
+
var PrismaLibSQLAdapter = class extends LibSqlQueryable {
|
|
285
261
|
constructor(client) {
|
|
286
262
|
super(client);
|
|
287
263
|
}
|
|
@@ -295,15 +271,48 @@ var PrismaLibSQL = class extends LibSqlQueryable {
|
|
|
295
271
|
release();
|
|
296
272
|
}
|
|
297
273
|
}
|
|
298
|
-
async
|
|
274
|
+
async startTransaction(isolationLevel) {
|
|
275
|
+
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
|
|
276
|
+
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
277
|
+
kind: "InvalidIsolationLevel",
|
|
278
|
+
level: isolationLevel
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
const options = {
|
|
282
|
+
usePhantomQuery: true
|
|
283
|
+
};
|
|
284
|
+
const tag = "[js::startTransaction]";
|
|
285
|
+
debug2("%s options: %O", tag, options);
|
|
299
286
|
const release = await this[LOCK_TAG].acquire();
|
|
300
|
-
|
|
287
|
+
try {
|
|
288
|
+
const tx = await this.client.transaction("deferred");
|
|
289
|
+
return new LibSqlTransaction(tx, options, release);
|
|
290
|
+
} catch (e) {
|
|
291
|
+
release();
|
|
292
|
+
throw e;
|
|
293
|
+
}
|
|
301
294
|
}
|
|
302
295
|
dispose() {
|
|
303
296
|
this.client.close();
|
|
304
297
|
return Promise.resolve();
|
|
305
298
|
}
|
|
306
299
|
};
|
|
300
|
+
var PrismaLibSQLAdapterFactory = class {
|
|
301
|
+
constructor(config) {
|
|
302
|
+
this.config = config;
|
|
303
|
+
}
|
|
304
|
+
provider = "sqlite";
|
|
305
|
+
adapterName = name;
|
|
306
|
+
connect() {
|
|
307
|
+
return Promise.resolve(new PrismaLibSQLAdapter(createLibSQLClient(this.config)));
|
|
308
|
+
}
|
|
309
|
+
connectToShadowDb() {
|
|
310
|
+
return Promise.resolve(new PrismaLibSQLAdapter(createLibSQLClient({ ...this.config, url: ":memory:" })));
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
function createLibSQLClient(config) {
|
|
314
|
+
return (0, import_client.createClient)(config);
|
|
315
|
+
}
|
|
307
316
|
// Annotate the CommonJS export names for ESM import in node:
|
|
308
317
|
0 && (module.exports = {
|
|
309
318
|
PrismaLibSQL
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
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
|
-
|
|
5
1
|
// src/libsql.ts
|
|
2
|
+
import { createClient } from "@libsql/client";
|
|
6
3
|
import { Debug as Debug2, DriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
7
4
|
import { Mutex } from "async-mutex";
|
|
8
5
|
|
|
@@ -115,11 +112,11 @@ function inferObjectType(value) {
|
|
|
115
112
|
throw new UnexpectedTypeError(value);
|
|
116
113
|
}
|
|
117
114
|
var UnexpectedTypeError = class extends Error {
|
|
115
|
+
name = "UnexpectedTypeError";
|
|
118
116
|
constructor(value) {
|
|
119
117
|
const type = typeof value;
|
|
120
118
|
const repr = type === "object" ? JSON.stringify(value) : String(value);
|
|
121
119
|
super(`unexpected value of type ${type}: ${repr}`);
|
|
122
|
-
__publicField(this, "name", "UnexpectedTypeError");
|
|
123
120
|
}
|
|
124
121
|
};
|
|
125
122
|
function mapRow(row, columnTypes) {
|
|
@@ -149,15 +146,13 @@ function mapRow(row, columnTypes) {
|
|
|
149
146
|
// src/libsql.ts
|
|
150
147
|
var debug2 = Debug2("prisma:driver-adapter:libsql");
|
|
151
148
|
var LOCK_TAG = Symbol();
|
|
152
|
-
var _a;
|
|
153
|
-
_a = LOCK_TAG;
|
|
154
149
|
var LibSqlQueryable = class {
|
|
155
150
|
constructor(client) {
|
|
156
151
|
this.client = client;
|
|
157
|
-
__publicField(this, "provider", "sqlite");
|
|
158
|
-
__publicField(this, "adapterName", name);
|
|
159
|
-
__publicField(this, _a, new Mutex());
|
|
160
152
|
}
|
|
153
|
+
provider = "sqlite";
|
|
154
|
+
adapterName = name;
|
|
155
|
+
[LOCK_TAG] = new Mutex();
|
|
161
156
|
/**
|
|
162
157
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
163
158
|
*/
|
|
@@ -236,28 +231,7 @@ var LibSqlTransaction = class extends LibSqlQueryable {
|
|
|
236
231
|
}
|
|
237
232
|
}
|
|
238
233
|
};
|
|
239
|
-
var
|
|
240
|
-
constructor(client, release) {
|
|
241
|
-
super(client);
|
|
242
|
-
this.client = client;
|
|
243
|
-
this.release = release;
|
|
244
|
-
}
|
|
245
|
-
async startTransaction() {
|
|
246
|
-
const options = {
|
|
247
|
-
usePhantomQuery: true
|
|
248
|
-
};
|
|
249
|
-
const tag = "[js::startTransaction]";
|
|
250
|
-
debug2("%s options: %O", tag, options);
|
|
251
|
-
try {
|
|
252
|
-
const tx = await this.client.transaction("deferred");
|
|
253
|
-
return new LibSqlTransaction(tx, options, this.release);
|
|
254
|
-
} catch (e) {
|
|
255
|
-
this.release();
|
|
256
|
-
throw e;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
var PrismaLibSQL = class extends LibSqlQueryable {
|
|
234
|
+
var PrismaLibSQLAdapter = class extends LibSqlQueryable {
|
|
261
235
|
constructor(client) {
|
|
262
236
|
super(client);
|
|
263
237
|
}
|
|
@@ -271,15 +245,48 @@ var PrismaLibSQL = class extends LibSqlQueryable {
|
|
|
271
245
|
release();
|
|
272
246
|
}
|
|
273
247
|
}
|
|
274
|
-
async
|
|
248
|
+
async startTransaction(isolationLevel) {
|
|
249
|
+
if (isolationLevel && isolationLevel !== "SERIALIZABLE") {
|
|
250
|
+
throw new DriverAdapterError({
|
|
251
|
+
kind: "InvalidIsolationLevel",
|
|
252
|
+
level: isolationLevel
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const options = {
|
|
256
|
+
usePhantomQuery: true
|
|
257
|
+
};
|
|
258
|
+
const tag = "[js::startTransaction]";
|
|
259
|
+
debug2("%s options: %O", tag, options);
|
|
275
260
|
const release = await this[LOCK_TAG].acquire();
|
|
276
|
-
|
|
261
|
+
try {
|
|
262
|
+
const tx = await this.client.transaction("deferred");
|
|
263
|
+
return new LibSqlTransaction(tx, options, release);
|
|
264
|
+
} catch (e) {
|
|
265
|
+
release();
|
|
266
|
+
throw e;
|
|
267
|
+
}
|
|
277
268
|
}
|
|
278
269
|
dispose() {
|
|
279
270
|
this.client.close();
|
|
280
271
|
return Promise.resolve();
|
|
281
272
|
}
|
|
282
273
|
};
|
|
274
|
+
var PrismaLibSQLAdapterFactory = class {
|
|
275
|
+
constructor(config) {
|
|
276
|
+
this.config = config;
|
|
277
|
+
}
|
|
278
|
+
provider = "sqlite";
|
|
279
|
+
adapterName = name;
|
|
280
|
+
connect() {
|
|
281
|
+
return Promise.resolve(new PrismaLibSQLAdapter(createLibSQLClient(this.config)));
|
|
282
|
+
}
|
|
283
|
+
connectToShadowDb() {
|
|
284
|
+
return Promise.resolve(new PrismaLibSQLAdapter(createLibSQLClient({ ...this.config, url: ":memory:" })));
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
function createLibSQLClient(config) {
|
|
288
|
+
return createClient(config);
|
|
289
|
+
}
|
|
283
290
|
export {
|
|
284
|
-
PrismaLibSQL
|
|
291
|
+
PrismaLibSQLAdapterFactory as PrismaLibSQL
|
|
285
292
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-libsql",
|
|
3
|
-
"version": "6.6.0-dev.
|
|
3
|
+
"version": "6.6.0-dev.41",
|
|
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.6.0-dev.
|
|
35
|
+
"@prisma/driver-adapter-utils": "6.6.0-dev.41"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@libsql/client": "0.8.0"
|