@prisma/adapter-planetscale 6.6.0-dev.5 → 6.6.0-dev.52
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 +48 -48
- package/dist/index.mjs +48 -50
- 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
|
@@ -5,7 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
8
|
var __export = (target, all) => {
|
|
10
9
|
for (var name2 in all)
|
|
11
10
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
@@ -27,12 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
26
|
mod
|
|
28
27
|
));
|
|
29
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
29
|
|
|
32
30
|
// src/index.ts
|
|
33
31
|
var index_exports = {};
|
|
34
32
|
__export(index_exports, {
|
|
35
|
-
PrismaPlanetScale: () =>
|
|
33
|
+
PrismaPlanetScale: () => PrismaPlanetScaleAdapterFactory
|
|
36
34
|
});
|
|
37
35
|
module.exports = __toCommonJS(index_exports);
|
|
38
36
|
|
|
@@ -148,9 +146,9 @@ var RollbackError = class _RollbackError extends Error {
|
|
|
148
146
|
var PlanetScaleQueryable = class {
|
|
149
147
|
constructor(client) {
|
|
150
148
|
this.client = client;
|
|
151
|
-
__publicField(this, "provider", "mysql");
|
|
152
|
-
__publicField(this, "adapterName", name);
|
|
153
149
|
}
|
|
150
|
+
provider = "mysql";
|
|
151
|
+
adapterName = name;
|
|
154
152
|
/**
|
|
155
153
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
156
154
|
*/
|
|
@@ -191,20 +189,23 @@ var PlanetScaleQueryable = class {
|
|
|
191
189
|
return result;
|
|
192
190
|
} catch (e) {
|
|
193
191
|
const error = e;
|
|
194
|
-
|
|
195
|
-
const parsed = parseErrorMessage(error.message);
|
|
196
|
-
if (parsed) {
|
|
197
|
-
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
198
|
-
kind: "mysql",
|
|
199
|
-
...parsed
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
debug("Error in performIO: %O", error);
|
|
204
|
-
throw error;
|
|
192
|
+
onError(error);
|
|
205
193
|
}
|
|
206
194
|
}
|
|
207
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
|
+
}
|
|
208
209
|
function parseErrorMessage(message) {
|
|
209
210
|
const regex = /^(.*) \(errno (\d+)\) \(sqlstate ([A-Z0-9]+)\)/;
|
|
210
211
|
const match = message.match(regex);
|
|
@@ -238,19 +239,35 @@ var PlanetScaleTransaction = class extends PlanetScaleQueryable {
|
|
|
238
239
|
return await this.txResultPromise;
|
|
239
240
|
}
|
|
240
241
|
};
|
|
241
|
-
var
|
|
242
|
-
constructor(
|
|
243
|
-
super(
|
|
244
|
-
|
|
242
|
+
var PrismaPlanetScaleAdapter = class extends PlanetScaleQueryable {
|
|
243
|
+
constructor(client) {
|
|
244
|
+
super(client);
|
|
245
|
+
}
|
|
246
|
+
executeScript(_script) {
|
|
247
|
+
throw new Error("Not implemented yet");
|
|
245
248
|
}
|
|
246
|
-
|
|
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) {
|
|
247
257
|
const options = {
|
|
248
258
|
usePhantomQuery: true
|
|
249
259
|
};
|
|
250
260
|
const tag = "[js::startTransaction]";
|
|
251
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) {
|
|
252
269
|
return new Promise((resolve, reject) => {
|
|
253
|
-
const txResultPromise =
|
|
270
|
+
const txResultPromise = conn.transaction(async (tx) => {
|
|
254
271
|
const [txDeferred, deferredPromise] = createDeferred();
|
|
255
272
|
const txWrapper = new PlanetScaleTransaction(tx, options, txDeferred, txResultPromise);
|
|
256
273
|
resolve(txWrapper);
|
|
@@ -263,34 +280,17 @@ var PlanetScaleTransactionContext = class extends PlanetScaleQueryable {
|
|
|
263
280
|
});
|
|
264
281
|
});
|
|
265
282
|
}
|
|
266
|
-
|
|
267
|
-
var PrismaPlanetScale = class extends PlanetScaleQueryable {
|
|
268
|
-
constructor(client) {
|
|
269
|
-
if (!(client instanceof planetScale.Client)) {
|
|
270
|
-
throw new TypeError(`PrismaPlanetScale must be initialized with an instance of Client:
|
|
271
|
-
import { Client } from '@planetscale/database'
|
|
272
|
-
const client = new Client({ url })
|
|
273
|
-
const adapter = new PrismaPlanetScale(client)
|
|
274
|
-
`);
|
|
275
|
-
}
|
|
276
|
-
super(client);
|
|
277
|
-
}
|
|
278
|
-
executeScript(_script) {
|
|
279
|
-
throw new Error("Not implemented yet");
|
|
280
|
-
}
|
|
281
|
-
getConnectionInfo() {
|
|
282
|
-
const url = this.client.connection()["url"];
|
|
283
|
-
const dbName = new URL(url).pathname.slice(1);
|
|
284
|
-
return {
|
|
285
|
-
schemaName: dbName
|
|
286
|
-
};
|
|
283
|
+
async dispose() {
|
|
287
284
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
285
|
+
};
|
|
286
|
+
var PrismaPlanetScaleAdapterFactory = class {
|
|
287
|
+
constructor(config) {
|
|
288
|
+
this.config = config;
|
|
292
289
|
}
|
|
293
|
-
|
|
290
|
+
provider = "mysql";
|
|
291
|
+
adapterName = name;
|
|
292
|
+
async connect() {
|
|
293
|
+
return new PrismaPlanetScaleAdapter(new planetScale.Client(this.config));
|
|
294
294
|
}
|
|
295
295
|
};
|
|
296
296
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
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/planetscale.ts
|
|
6
2
|
import * as planetScale from "@planetscale/database";
|
|
7
3
|
import { Debug, DriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
@@ -114,9 +110,9 @@ var RollbackError = class _RollbackError extends Error {
|
|
|
114
110
|
var PlanetScaleQueryable = class {
|
|
115
111
|
constructor(client) {
|
|
116
112
|
this.client = client;
|
|
117
|
-
__publicField(this, "provider", "mysql");
|
|
118
|
-
__publicField(this, "adapterName", name);
|
|
119
113
|
}
|
|
114
|
+
provider = "mysql";
|
|
115
|
+
adapterName = name;
|
|
120
116
|
/**
|
|
121
117
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
122
118
|
*/
|
|
@@ -157,20 +153,23 @@ var PlanetScaleQueryable = class {
|
|
|
157
153
|
return result;
|
|
158
154
|
} catch (e) {
|
|
159
155
|
const error = e;
|
|
160
|
-
|
|
161
|
-
const parsed = parseErrorMessage(error.message);
|
|
162
|
-
if (parsed) {
|
|
163
|
-
throw new DriverAdapterError({
|
|
164
|
-
kind: "mysql",
|
|
165
|
-
...parsed
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
debug("Error in performIO: %O", error);
|
|
170
|
-
throw error;
|
|
156
|
+
onError(error);
|
|
171
157
|
}
|
|
172
158
|
}
|
|
173
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
|
+
}
|
|
174
173
|
function parseErrorMessage(message) {
|
|
175
174
|
const regex = /^(.*) \(errno (\d+)\) \(sqlstate ([A-Z0-9]+)\)/;
|
|
176
175
|
const match = message.match(regex);
|
|
@@ -204,19 +203,35 @@ var PlanetScaleTransaction = class extends PlanetScaleQueryable {
|
|
|
204
203
|
return await this.txResultPromise;
|
|
205
204
|
}
|
|
206
205
|
};
|
|
207
|
-
var
|
|
208
|
-
constructor(
|
|
209
|
-
super(
|
|
210
|
-
|
|
206
|
+
var PrismaPlanetScaleAdapter = class extends PlanetScaleQueryable {
|
|
207
|
+
constructor(client) {
|
|
208
|
+
super(client);
|
|
209
|
+
}
|
|
210
|
+
executeScript(_script) {
|
|
211
|
+
throw new Error("Not implemented yet");
|
|
212
|
+
}
|
|
213
|
+
getConnectionInfo() {
|
|
214
|
+
const url = this.client.connection()["url"];
|
|
215
|
+
const dbName = new URL(url).pathname.slice(1);
|
|
216
|
+
return {
|
|
217
|
+
schemaName: dbName
|
|
218
|
+
};
|
|
211
219
|
}
|
|
212
|
-
async startTransaction() {
|
|
220
|
+
async startTransaction(isolationLevel) {
|
|
213
221
|
const options = {
|
|
214
222
|
usePhantomQuery: true
|
|
215
223
|
};
|
|
216
224
|
const tag = "[js::startTransaction]";
|
|
217
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) {
|
|
218
233
|
return new Promise((resolve, reject) => {
|
|
219
|
-
const txResultPromise =
|
|
234
|
+
const txResultPromise = conn.transaction(async (tx) => {
|
|
220
235
|
const [txDeferred, deferredPromise] = createDeferred();
|
|
221
236
|
const txWrapper = new PlanetScaleTransaction(tx, options, txDeferred, txResultPromise);
|
|
222
237
|
resolve(txWrapper);
|
|
@@ -229,36 +244,19 @@ var PlanetScaleTransactionContext = class extends PlanetScaleQueryable {
|
|
|
229
244
|
});
|
|
230
245
|
});
|
|
231
246
|
}
|
|
232
|
-
|
|
233
|
-
var PrismaPlanetScale = class extends PlanetScaleQueryable {
|
|
234
|
-
constructor(client) {
|
|
235
|
-
if (!(client instanceof planetScale.Client)) {
|
|
236
|
-
throw new TypeError(`PrismaPlanetScale must be initialized with an instance of Client:
|
|
237
|
-
import { Client } from '@planetscale/database'
|
|
238
|
-
const client = new Client({ url })
|
|
239
|
-
const adapter = new PrismaPlanetScale(client)
|
|
240
|
-
`);
|
|
241
|
-
}
|
|
242
|
-
super(client);
|
|
243
|
-
}
|
|
244
|
-
executeScript(_script) {
|
|
245
|
-
throw new Error("Not implemented yet");
|
|
246
|
-
}
|
|
247
|
-
getConnectionInfo() {
|
|
248
|
-
const url = this.client.connection()["url"];
|
|
249
|
-
const dbName = new URL(url).pathname.slice(1);
|
|
250
|
-
return {
|
|
251
|
-
schemaName: dbName
|
|
252
|
-
};
|
|
247
|
+
async dispose() {
|
|
253
248
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
249
|
+
};
|
|
250
|
+
var PrismaPlanetScaleAdapterFactory = class {
|
|
251
|
+
constructor(config) {
|
|
252
|
+
this.config = config;
|
|
258
253
|
}
|
|
259
|
-
|
|
254
|
+
provider = "mysql";
|
|
255
|
+
adapterName = name;
|
|
256
|
+
async connect() {
|
|
257
|
+
return new PrismaPlanetScaleAdapter(new planetScale.Client(this.config));
|
|
260
258
|
}
|
|
261
259
|
};
|
|
262
260
|
export {
|
|
263
|
-
PrismaPlanetScale
|
|
261
|
+
PrismaPlanetScaleAdapterFactory as PrismaPlanetScale
|
|
264
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.52",
|
|
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.52"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@planetscale/database": "1.19.0",
|