@prisma/adapter-planetscale 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 +1 -3
- package/dist/index.d.mts +6 -33
- package/dist/index.d.ts +6 -33
- package/dist/index.js +46 -44
- package/dist/index.mjs +46 -44
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,7 +50,6 @@ Update your Prisma Client instance to use the PlanetsScale serverless driver:
|
|
|
50
50
|
|
|
51
51
|
```ts
|
|
52
52
|
// Import needed packages
|
|
53
|
-
import { Client } from '@planetscale/database'
|
|
54
53
|
import { PrismaPlanetScale } from '@prisma/adapter-planetscale'
|
|
55
54
|
import { PrismaClient } from '@prisma/client'
|
|
56
55
|
import { fetch as undiciFetch } from 'undici'
|
|
@@ -59,8 +58,7 @@ import { fetch as undiciFetch } from 'undici'
|
|
|
59
58
|
const connectionString = `${process.env.DATABASE_URL}`
|
|
60
59
|
|
|
61
60
|
// Init prisma client
|
|
62
|
-
const
|
|
63
|
-
const adapter = new PrismaPlanetScale(client)
|
|
61
|
+
const adapter = new PrismaPlanetScale({ url: connectionString, fetch: undiciFetch })
|
|
64
62
|
const prisma = new PrismaClient({ adapter })
|
|
65
63
|
|
|
66
64
|
// Use Prisma Client as normal
|
package/dist/index.d.mts
CHANGED
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
|
|
2
1
|
import * as planetScale from '@planetscale/database';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
6
|
-
import type { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
7
|
-
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
2
|
+
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
3
|
+
import type { SqlDriverAdapterFactory } from '@prisma/driver-adapter-utils';
|
|
8
4
|
|
|
9
|
-
declare class
|
|
10
|
-
|
|
5
|
+
export declare class PrismaPlanetScale implements SqlDriverAdapterFactory {
|
|
6
|
+
private readonly config;
|
|
11
7
|
readonly provider = "mysql";
|
|
12
8
|
readonly adapterName: string;
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
* Execute a query given as SQL, interpolating the given parameters.
|
|
16
|
-
*/
|
|
17
|
-
queryRaw(query: SqlQuery): Promise<SqlResultSet>;
|
|
18
|
-
/**
|
|
19
|
-
* Execute a query given as SQL, interpolating the given parameters and
|
|
20
|
-
* returning the number of affected rows.
|
|
21
|
-
* Note: Queryable expects a u64, but napi.rs only supports u32.
|
|
22
|
-
*/
|
|
23
|
-
executeRaw(query: SqlQuery): Promise<number>;
|
|
24
|
-
/**
|
|
25
|
-
* Run a query against the database, returning the result set.
|
|
26
|
-
* Should the query fail due to a connection error, the connection is
|
|
27
|
-
* marked as unhealthy.
|
|
28
|
-
*/
|
|
29
|
-
private performIO;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export declare class PrismaPlanetScale extends PlanetScaleQueryable<planetScale.Client> implements SqlConnection {
|
|
33
|
-
constructor(client: planetScale.Client);
|
|
34
|
-
executeScript(_script: string): Promise<void>;
|
|
35
|
-
getConnectionInfo(): ConnectionInfo;
|
|
36
|
-
transactionContext(): Promise<TransactionContext>;
|
|
37
|
-
dispose(): Promise<void>;
|
|
9
|
+
constructor(config: planetScale.Config);
|
|
10
|
+
connect(): Promise<SqlDriverAdapter>;
|
|
38
11
|
}
|
|
39
12
|
|
|
40
13
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
|
|
2
1
|
import * as planetScale from '@planetscale/database';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { SqlQueryable } from '@prisma/driver-adapter-utils';
|
|
6
|
-
import type { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
7
|
-
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
2
|
+
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
|
|
3
|
+
import type { SqlDriverAdapterFactory } from '@prisma/driver-adapter-utils';
|
|
8
4
|
|
|
9
|
-
declare class
|
|
10
|
-
|
|
5
|
+
export declare class PrismaPlanetScale implements SqlDriverAdapterFactory {
|
|
6
|
+
private readonly config;
|
|
11
7
|
readonly provider = "mysql";
|
|
12
8
|
readonly adapterName: string;
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
* Execute a query given as SQL, interpolating the given parameters.
|
|
16
|
-
*/
|
|
17
|
-
queryRaw(query: SqlQuery): Promise<SqlResultSet>;
|
|
18
|
-
/**
|
|
19
|
-
* Execute a query given as SQL, interpolating the given parameters and
|
|
20
|
-
* returning the number of affected rows.
|
|
21
|
-
* Note: Queryable expects a u64, but napi.rs only supports u32.
|
|
22
|
-
*/
|
|
23
|
-
executeRaw(query: SqlQuery): Promise<number>;
|
|
24
|
-
/**
|
|
25
|
-
* Run a query against the database, returning the result set.
|
|
26
|
-
* Should the query fail due to a connection error, the connection is
|
|
27
|
-
* marked as unhealthy.
|
|
28
|
-
*/
|
|
29
|
-
private performIO;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export declare class PrismaPlanetScale extends PlanetScaleQueryable<planetScale.Client> implements SqlConnection {
|
|
33
|
-
constructor(client: planetScale.Client);
|
|
34
|
-
executeScript(_script: string): Promise<void>;
|
|
35
|
-
getConnectionInfo(): ConnectionInfo;
|
|
36
|
-
transactionContext(): Promise<TransactionContext>;
|
|
37
|
-
dispose(): Promise<void>;
|
|
9
|
+
constructor(config: planetScale.Config);
|
|
10
|
+
connect(): Promise<SqlDriverAdapter>;
|
|
38
11
|
}
|
|
39
12
|
|
|
40
13
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
PrismaPlanetScale: () =>
|
|
33
|
+
PrismaPlanetScale: () => PrismaPlanetScaleAdapterFactory
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
@@ -189,20 +189,23 @@ var PlanetScaleQueryable = class {
|
|
|
189
189
|
return result;
|
|
190
190
|
} catch (e) {
|
|
191
191
|
const error = e;
|
|
192
|
-
|
|
193
|
-
const parsed = parseErrorMessage(error.message);
|
|
194
|
-
if (parsed) {
|
|
195
|
-
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
196
|
-
kind: "mysql",
|
|
197
|
-
...parsed
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
debug("Error in performIO: %O", error);
|
|
202
|
-
throw error;
|
|
192
|
+
onError(error);
|
|
203
193
|
}
|
|
204
194
|
}
|
|
205
195
|
};
|
|
196
|
+
function onError(error) {
|
|
197
|
+
if (error.name === "DatabaseError") {
|
|
198
|
+
const parsed = parseErrorMessage(error.message);
|
|
199
|
+
if (parsed) {
|
|
200
|
+
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
201
|
+
kind: "mysql",
|
|
202
|
+
...parsed
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
debug("Error in performIO: %O", error);
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
206
209
|
function parseErrorMessage(message) {
|
|
207
210
|
const regex = /^(.*) \(errno (\d+)\) \(sqlstate ([A-Z0-9]+)\)/;
|
|
208
211
|
const match = message.match(regex);
|
|
@@ -236,19 +239,35 @@ var PlanetScaleTransaction = class extends PlanetScaleQueryable {
|
|
|
236
239
|
return await this.txResultPromise;
|
|
237
240
|
}
|
|
238
241
|
};
|
|
239
|
-
var
|
|
240
|
-
constructor(
|
|
241
|
-
super(
|
|
242
|
-
|
|
242
|
+
var PrismaPlanetScaleAdapter = class extends PlanetScaleQueryable {
|
|
243
|
+
constructor(client) {
|
|
244
|
+
super(client);
|
|
245
|
+
}
|
|
246
|
+
executeScript(_script) {
|
|
247
|
+
throw new Error("Not implemented yet");
|
|
243
248
|
}
|
|
244
|
-
|
|
249
|
+
getConnectionInfo() {
|
|
250
|
+
const url = this.client.connection()["url"];
|
|
251
|
+
const dbName = new URL(url).pathname.slice(1);
|
|
252
|
+
return {
|
|
253
|
+
schemaName: dbName
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
async startTransaction(isolationLevel) {
|
|
245
257
|
const options = {
|
|
246
258
|
usePhantomQuery: true
|
|
247
259
|
};
|
|
248
260
|
const tag = "[js::startTransaction]";
|
|
249
261
|
debug("%s options: %O", tag, options);
|
|
262
|
+
const conn = this.client.connection();
|
|
263
|
+
if (isolationLevel) {
|
|
264
|
+
await conn.execute(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`).catch((error) => onError(error));
|
|
265
|
+
}
|
|
266
|
+
return this.startTransactionInner(conn, options);
|
|
267
|
+
}
|
|
268
|
+
async startTransactionInner(conn, options) {
|
|
250
269
|
return new Promise((resolve, reject) => {
|
|
251
|
-
const txResultPromise =
|
|
270
|
+
const txResultPromise = conn.transaction(async (tx) => {
|
|
252
271
|
const [txDeferred, deferredPromise] = createDeferred();
|
|
253
272
|
const txWrapper = new PlanetScaleTransaction(tx, options, txDeferred, txResultPromise);
|
|
254
273
|
resolve(txWrapper);
|
|
@@ -261,34 +280,17 @@ var PlanetScaleTransactionContext = class extends PlanetScaleQueryable {
|
|
|
261
280
|
});
|
|
262
281
|
});
|
|
263
282
|
}
|
|
264
|
-
|
|
265
|
-
var PrismaPlanetScale = class extends PlanetScaleQueryable {
|
|
266
|
-
constructor(client) {
|
|
267
|
-
if (!(client instanceof planetScale.Client)) {
|
|
268
|
-
throw new TypeError(`PrismaPlanetScale must be initialized with an instance of Client:
|
|
269
|
-
import { Client } from '@planetscale/database'
|
|
270
|
-
const client = new Client({ url })
|
|
271
|
-
const adapter = new PrismaPlanetScale(client)
|
|
272
|
-
`);
|
|
273
|
-
}
|
|
274
|
-
super(client);
|
|
275
|
-
}
|
|
276
|
-
executeScript(_script) {
|
|
277
|
-
throw new Error("Not implemented yet");
|
|
278
|
-
}
|
|
279
|
-
getConnectionInfo() {
|
|
280
|
-
const url = this.client.connection()["url"];
|
|
281
|
-
const dbName = new URL(url).pathname.slice(1);
|
|
282
|
-
return {
|
|
283
|
-
schemaName: dbName
|
|
284
|
-
};
|
|
283
|
+
async dispose() {
|
|
285
284
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
285
|
+
};
|
|
286
|
+
var PrismaPlanetScaleAdapterFactory = class {
|
|
287
|
+
constructor(config) {
|
|
288
|
+
this.config = config;
|
|
290
289
|
}
|
|
291
|
-
|
|
290
|
+
provider = "mysql";
|
|
291
|
+
adapterName = name;
|
|
292
|
+
async connect() {
|
|
293
|
+
return new PrismaPlanetScaleAdapter(new planetScale.Client(this.config));
|
|
292
294
|
}
|
|
293
295
|
};
|
|
294
296
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -153,20 +153,23 @@ var PlanetScaleQueryable = class {
|
|
|
153
153
|
return result;
|
|
154
154
|
} catch (e) {
|
|
155
155
|
const error = e;
|
|
156
|
-
|
|
157
|
-
const parsed = parseErrorMessage(error.message);
|
|
158
|
-
if (parsed) {
|
|
159
|
-
throw new DriverAdapterError({
|
|
160
|
-
kind: "mysql",
|
|
161
|
-
...parsed
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
debug("Error in performIO: %O", error);
|
|
166
|
-
throw error;
|
|
156
|
+
onError(error);
|
|
167
157
|
}
|
|
168
158
|
}
|
|
169
159
|
};
|
|
160
|
+
function onError(error) {
|
|
161
|
+
if (error.name === "DatabaseError") {
|
|
162
|
+
const parsed = parseErrorMessage(error.message);
|
|
163
|
+
if (parsed) {
|
|
164
|
+
throw new DriverAdapterError({
|
|
165
|
+
kind: "mysql",
|
|
166
|
+
...parsed
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
debug("Error in performIO: %O", error);
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
170
173
|
function parseErrorMessage(message) {
|
|
171
174
|
const regex = /^(.*) \(errno (\d+)\) \(sqlstate ([A-Z0-9]+)\)/;
|
|
172
175
|
const match = message.match(regex);
|
|
@@ -200,19 +203,35 @@ var PlanetScaleTransaction = class extends PlanetScaleQueryable {
|
|
|
200
203
|
return await this.txResultPromise;
|
|
201
204
|
}
|
|
202
205
|
};
|
|
203
|
-
var
|
|
204
|
-
constructor(
|
|
205
|
-
super(
|
|
206
|
-
|
|
206
|
+
var PrismaPlanetScaleAdapter = class extends PlanetScaleQueryable {
|
|
207
|
+
constructor(client) {
|
|
208
|
+
super(client);
|
|
209
|
+
}
|
|
210
|
+
executeScript(_script) {
|
|
211
|
+
throw new Error("Not implemented yet");
|
|
207
212
|
}
|
|
208
|
-
|
|
213
|
+
getConnectionInfo() {
|
|
214
|
+
const url = this.client.connection()["url"];
|
|
215
|
+
const dbName = new URL(url).pathname.slice(1);
|
|
216
|
+
return {
|
|
217
|
+
schemaName: dbName
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
async startTransaction(isolationLevel) {
|
|
209
221
|
const options = {
|
|
210
222
|
usePhantomQuery: true
|
|
211
223
|
};
|
|
212
224
|
const tag = "[js::startTransaction]";
|
|
213
225
|
debug("%s options: %O", tag, options);
|
|
226
|
+
const conn = this.client.connection();
|
|
227
|
+
if (isolationLevel) {
|
|
228
|
+
await conn.execute(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`).catch((error) => onError(error));
|
|
229
|
+
}
|
|
230
|
+
return this.startTransactionInner(conn, options);
|
|
231
|
+
}
|
|
232
|
+
async startTransactionInner(conn, options) {
|
|
214
233
|
return new Promise((resolve, reject) => {
|
|
215
|
-
const txResultPromise =
|
|
234
|
+
const txResultPromise = conn.transaction(async (tx) => {
|
|
216
235
|
const [txDeferred, deferredPromise] = createDeferred();
|
|
217
236
|
const txWrapper = new PlanetScaleTransaction(tx, options, txDeferred, txResultPromise);
|
|
218
237
|
resolve(txWrapper);
|
|
@@ -225,36 +244,19 @@ var PlanetScaleTransactionContext = class extends PlanetScaleQueryable {
|
|
|
225
244
|
});
|
|
226
245
|
});
|
|
227
246
|
}
|
|
228
|
-
|
|
229
|
-
var PrismaPlanetScale = class extends PlanetScaleQueryable {
|
|
230
|
-
constructor(client) {
|
|
231
|
-
if (!(client instanceof planetScale.Client)) {
|
|
232
|
-
throw new TypeError(`PrismaPlanetScale must be initialized with an instance of Client:
|
|
233
|
-
import { Client } from '@planetscale/database'
|
|
234
|
-
const client = new Client({ url })
|
|
235
|
-
const adapter = new PrismaPlanetScale(client)
|
|
236
|
-
`);
|
|
237
|
-
}
|
|
238
|
-
super(client);
|
|
239
|
-
}
|
|
240
|
-
executeScript(_script) {
|
|
241
|
-
throw new Error("Not implemented yet");
|
|
242
|
-
}
|
|
243
|
-
getConnectionInfo() {
|
|
244
|
-
const url = this.client.connection()["url"];
|
|
245
|
-
const dbName = new URL(url).pathname.slice(1);
|
|
246
|
-
return {
|
|
247
|
-
schemaName: dbName
|
|
248
|
-
};
|
|
247
|
+
async dispose() {
|
|
249
248
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
};
|
|
250
|
+
var PrismaPlanetScaleAdapterFactory = class {
|
|
251
|
+
constructor(config) {
|
|
252
|
+
this.config = config;
|
|
254
253
|
}
|
|
255
|
-
|
|
254
|
+
provider = "mysql";
|
|
255
|
+
adapterName = name;
|
|
256
|
+
async connect() {
|
|
257
|
+
return new PrismaPlanetScaleAdapter(new planetScale.Client(this.config));
|
|
256
258
|
}
|
|
257
259
|
};
|
|
258
260
|
export {
|
|
259
|
-
PrismaPlanetScale
|
|
261
|
+
PrismaPlanetScaleAdapterFactory as PrismaPlanetScale
|
|
260
262
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-planetscale",
|
|
3
|
-
"version": "6.6.0-dev.
|
|
3
|
+
"version": "6.6.0-dev.34",
|
|
4
4
|
"description": "Prisma's driver adapter for \"@planetscale/database\"",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"sideEffects": false,
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@prisma/driver-adapter-utils": "6.6.0-dev.
|
|
34
|
+
"@prisma/driver-adapter-utils": "6.6.0-dev.34"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@planetscale/database": "1.19.0",
|