@prisma/adapter-libsql 6.6.0-dev.32 → 6.6.0-dev.34

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 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 libsql = createClient({
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 { Client } from '@libsql/client';
2
- import { Mutex } from 'async-mutex';
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 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 LibSqlQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
11
- protected readonly client: ClientT;
5
+ export declare class PrismaLibSQL implements SqlMigrationAwareDriverAdapterFactory {
6
+ private readonly config;
12
7
  readonly provider = "sqlite";
13
8
  readonly adapterName: string;
14
- [LOCK_TAG]: Mutex;
15
- constructor(client: ClientT);
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 { Client } from '@libsql/client';
2
- import { Mutex } from 'async-mutex';
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 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 LibSqlQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
11
- protected readonly client: ClientT;
5
+ export declare class PrismaLibSQL implements SqlMigrationAwareDriverAdapterFactory {
6
+ private readonly config;
12
7
  readonly provider = "sqlite";
13
8
  readonly adapterName: string;
14
- [LOCK_TAG]: Mutex;
15
- constructor(client: ClientT);
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
@@ -20,11 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- PrismaLibSQL: () => PrismaLibSQL
23
+ PrismaLibSQL: () => PrismaLibSQLAdapterFactory
24
24
  });
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
 
@@ -256,28 +257,7 @@ var LibSqlTransaction = class extends LibSqlQueryable {
256
257
  }
257
258
  }
258
259
  };
259
- var LibSqlTransactionContext = class extends LibSqlQueryable {
260
- constructor(client, release) {
261
- super(client);
262
- this.client = client;
263
- this.release = release;
264
- }
265
- async startTransaction() {
266
- const options = {
267
- usePhantomQuery: true
268
- };
269
- const tag = "[js::startTransaction]";
270
- debug2("%s options: %O", tag, options);
271
- try {
272
- const tx = await this.client.transaction("deferred");
273
- return new LibSqlTransaction(tx, options, this.release);
274
- } catch (e) {
275
- this.release();
276
- throw e;
277
- }
278
- }
279
- };
280
- var PrismaLibSQL = class extends LibSqlQueryable {
260
+ var PrismaLibSQLAdapter = class extends LibSqlQueryable {
281
261
  constructor(client) {
282
262
  super(client);
283
263
  }
@@ -291,15 +271,48 @@ var PrismaLibSQL = class extends LibSqlQueryable {
291
271
  release();
292
272
  }
293
273
  }
294
- async transactionContext() {
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);
295
286
  const release = await this[LOCK_TAG].acquire();
296
- return new LibSqlTransactionContext(this.client, release);
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
+ }
297
294
  }
298
295
  dispose() {
299
296
  this.client.close();
300
297
  return Promise.resolve();
301
298
  }
302
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
+ }
303
316
  // Annotate the CommonJS export names for ESM import in node:
304
317
  0 && (module.exports = {
305
318
  PrismaLibSQL
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/libsql.ts
2
+ import { createClient } from "@libsql/client";
2
3
  import { Debug as Debug2, DriverAdapterError } from "@prisma/driver-adapter-utils";
3
4
  import { Mutex } from "async-mutex";
4
5
 
@@ -230,28 +231,7 @@ var LibSqlTransaction = class extends LibSqlQueryable {
230
231
  }
231
232
  }
232
233
  };
233
- var LibSqlTransactionContext = class extends LibSqlQueryable {
234
- constructor(client, release) {
235
- super(client);
236
- this.client = client;
237
- this.release = release;
238
- }
239
- async startTransaction() {
240
- const options = {
241
- usePhantomQuery: true
242
- };
243
- const tag = "[js::startTransaction]";
244
- debug2("%s options: %O", tag, options);
245
- try {
246
- const tx = await this.client.transaction("deferred");
247
- return new LibSqlTransaction(tx, options, this.release);
248
- } catch (e) {
249
- this.release();
250
- throw e;
251
- }
252
- }
253
- };
254
- var PrismaLibSQL = class extends LibSqlQueryable {
234
+ var PrismaLibSQLAdapter = class extends LibSqlQueryable {
255
235
  constructor(client) {
256
236
  super(client);
257
237
  }
@@ -265,15 +245,48 @@ var PrismaLibSQL = class extends LibSqlQueryable {
265
245
  release();
266
246
  }
267
247
  }
268
- async transactionContext() {
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);
269
260
  const release = await this[LOCK_TAG].acquire();
270
- return new LibSqlTransactionContext(this.client, release);
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
+ }
271
268
  }
272
269
  dispose() {
273
270
  this.client.close();
274
271
  return Promise.resolve();
275
272
  }
276
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
+ }
277
290
  export {
278
- PrismaLibSQL
291
+ PrismaLibSQLAdapterFactory as PrismaLibSQL
279
292
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-libsql",
3
- "version": "6.6.0-dev.32",
3
+ "version": "6.6.0-dev.34",
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.32"
35
+ "@prisma/driver-adapter-utils": "6.6.0-dev.34"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@libsql/client": "0.8.0"