@prisma/adapter-planetscale 5.20.0-dev.2 → 5.20.0-dev.20
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 +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +47 -22
- package/dist/index.mjs +47 -22
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -5,9 +5,9 @@ import type { Query } from '@prisma/driver-adapter-utils';
|
|
|
5
5
|
import type { Queryable } from '@prisma/driver-adapter-utils';
|
|
6
6
|
import type { Result } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import type { ResultSet } from '@prisma/driver-adapter-utils';
|
|
8
|
-
import type {
|
|
8
|
+
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
9
9
|
|
|
10
|
-
declare class PlanetScaleQueryable<ClientT extends planetScale.Client | planetScale.Transaction> implements Queryable {
|
|
10
|
+
declare class PlanetScaleQueryable<ClientT extends planetScale.Client | planetScale.Transaction | planetScale.Connection> implements Queryable {
|
|
11
11
|
protected client: ClientT;
|
|
12
12
|
readonly provider = "mysql";
|
|
13
13
|
readonly adapterName: string;
|
|
@@ -33,7 +33,7 @@ declare class PlanetScaleQueryable<ClientT extends planetScale.Client | planetSc
|
|
|
33
33
|
export declare class PrismaPlanetScale extends PlanetScaleQueryable<planetScale.Client> implements DriverAdapter {
|
|
34
34
|
constructor(client: planetScale.Client);
|
|
35
35
|
getConnectionInfo(): Result<ConnectionInfo>;
|
|
36
|
-
|
|
36
|
+
transactionContext(): Promise<Result<TransactionContext>>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ import type { Query } from '@prisma/driver-adapter-utils';
|
|
|
5
5
|
import type { Queryable } from '@prisma/driver-adapter-utils';
|
|
6
6
|
import type { Result } from '@prisma/driver-adapter-utils';
|
|
7
7
|
import type { ResultSet } from '@prisma/driver-adapter-utils';
|
|
8
|
-
import type {
|
|
8
|
+
import type { TransactionContext } from '@prisma/driver-adapter-utils';
|
|
9
9
|
|
|
10
|
-
declare class PlanetScaleQueryable<ClientT extends planetScale.Client | planetScale.Transaction> implements Queryable {
|
|
10
|
+
declare class PlanetScaleQueryable<ClientT extends planetScale.Client | planetScale.Transaction | planetScale.Connection> implements Queryable {
|
|
11
11
|
protected client: ClientT;
|
|
12
12
|
readonly provider = "mysql";
|
|
13
13
|
readonly adapterName: string;
|
|
@@ -33,7 +33,7 @@ declare class PlanetScaleQueryable<ClientT extends planetScale.Client | planetSc
|
|
|
33
33
|
export declare class PrismaPlanetScale extends PlanetScaleQueryable<planetScale.Client> implements DriverAdapter {
|
|
34
34
|
constructor(client: planetScale.Client);
|
|
35
35
|
getConnectionInfo(): Result<ConnectionInfo>;
|
|
36
|
-
|
|
36
|
+
transactionContext(): Promise<Result<TransactionContext>>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,20 @@ var name = "@prisma/adapter-planetscale";
|
|
|
44
44
|
// src/conversion.ts
|
|
45
45
|
var import_database = require("@planetscale/database");
|
|
46
46
|
var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
|
|
47
|
+
|
|
48
|
+
// src/text.ts
|
|
49
|
+
var decoder = new TextDecoder("utf-8");
|
|
50
|
+
function decodeUtf8(text) {
|
|
51
|
+
return text ? decoder.decode(uint8Array(text)) : "";
|
|
52
|
+
}
|
|
53
|
+
function uint8Array(text) {
|
|
54
|
+
return Uint8Array.from(bytes(text));
|
|
55
|
+
}
|
|
56
|
+
function bytes(text) {
|
|
57
|
+
return text.split("").map((c) => c.charCodeAt(0));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/conversion.ts
|
|
47
61
|
function fieldToColumnType(field) {
|
|
48
62
|
switch (field) {
|
|
49
63
|
case "INT8":
|
|
@@ -97,7 +111,7 @@ function fieldToColumnType(field) {
|
|
|
97
111
|
}
|
|
98
112
|
var cast = (field, value) => {
|
|
99
113
|
if (field.type === "JSON") {
|
|
100
|
-
return value;
|
|
114
|
+
return typeof value === "string" && value.length ? decodeUtf8(value) : value;
|
|
101
115
|
}
|
|
102
116
|
const defaultValue = (0, import_database.cast)(field, value);
|
|
103
117
|
if (defaultValue instanceof Uint8Array) {
|
|
@@ -216,40 +230,27 @@ var PlanetScaleTransaction = class extends PlanetScaleQueryable {
|
|
|
216
230
|
async commit() {
|
|
217
231
|
debug(`[js::commit]`);
|
|
218
232
|
this.txDeferred.resolve();
|
|
219
|
-
return
|
|
233
|
+
return (0, import_driver_adapter_utils2.ok)(await this.txResultPromise);
|
|
220
234
|
}
|
|
221
235
|
async rollback() {
|
|
222
236
|
debug(`[js::rollback]`);
|
|
223
237
|
this.txDeferred.reject(new RollbackError());
|
|
224
|
-
return
|
|
238
|
+
return (0, import_driver_adapter_utils2.ok)(await this.txResultPromise);
|
|
225
239
|
}
|
|
226
240
|
};
|
|
227
|
-
var
|
|
228
|
-
constructor(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
import { Client } from '@planetscale/database'
|
|
232
|
-
const client = new Client({ url })
|
|
233
|
-
const adapter = new PrismaPlanetScale(client)
|
|
234
|
-
`);
|
|
235
|
-
}
|
|
236
|
-
super(client);
|
|
237
|
-
}
|
|
238
|
-
getConnectionInfo() {
|
|
239
|
-
const url = this.client.connection()["url"];
|
|
240
|
-
const dbName = new URL(url).pathname.slice(1);
|
|
241
|
-
return (0, import_driver_adapter_utils2.ok)({
|
|
242
|
-
schemaName: dbName
|
|
243
|
-
});
|
|
241
|
+
var PlanetScaleTransactionContext = class extends PlanetScaleQueryable {
|
|
242
|
+
constructor(conn) {
|
|
243
|
+
super(conn);
|
|
244
|
+
this.conn = conn;
|
|
244
245
|
}
|
|
245
246
|
async startTransaction() {
|
|
246
247
|
const options = {
|
|
247
248
|
usePhantomQuery: true
|
|
248
249
|
};
|
|
249
250
|
const tag = "[js::startTransaction]";
|
|
250
|
-
debug(
|
|
251
|
+
debug("%s options: %O", tag, options);
|
|
251
252
|
return new Promise((resolve, reject) => {
|
|
252
|
-
const txResultPromise = this.
|
|
253
|
+
const txResultPromise = this.conn.transaction(async (tx) => {
|
|
253
254
|
const [txDeferred, deferredPromise] = createDeferred();
|
|
254
255
|
const txWrapper = new PlanetScaleTransaction(tx, options, txDeferred, txResultPromise);
|
|
255
256
|
resolve((0, import_driver_adapter_utils2.ok)(txWrapper));
|
|
@@ -263,6 +264,30 @@ const adapter = new PrismaPlanetScale(client)
|
|
|
263
264
|
});
|
|
264
265
|
}
|
|
265
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
|
+
getConnectionInfo() {
|
|
279
|
+
const url = this.client.connection()["url"];
|
|
280
|
+
const dbName = new URL(url).pathname.slice(1);
|
|
281
|
+
return (0, import_driver_adapter_utils2.ok)({
|
|
282
|
+
schemaName: dbName
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
async transactionContext() {
|
|
286
|
+
const conn = this.client.connection();
|
|
287
|
+
const ctx = new PlanetScaleTransactionContext(conn);
|
|
288
|
+
return (0, import_driver_adapter_utils2.ok)(ctx);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
266
291
|
// Annotate the CommonJS export names for ESM import in node:
|
|
267
292
|
0 && (module.exports = {
|
|
268
293
|
PrismaPlanetScale
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,20 @@ var name = "@prisma/adapter-planetscale";
|
|
|
8
8
|
// src/conversion.ts
|
|
9
9
|
import { cast as defaultCast } from "@planetscale/database";
|
|
10
10
|
import { ColumnTypeEnum } from "@prisma/driver-adapter-utils";
|
|
11
|
+
|
|
12
|
+
// src/text.ts
|
|
13
|
+
var decoder = new TextDecoder("utf-8");
|
|
14
|
+
function decodeUtf8(text) {
|
|
15
|
+
return text ? decoder.decode(uint8Array(text)) : "";
|
|
16
|
+
}
|
|
17
|
+
function uint8Array(text) {
|
|
18
|
+
return Uint8Array.from(bytes(text));
|
|
19
|
+
}
|
|
20
|
+
function bytes(text) {
|
|
21
|
+
return text.split("").map((c) => c.charCodeAt(0));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/conversion.ts
|
|
11
25
|
function fieldToColumnType(field) {
|
|
12
26
|
switch (field) {
|
|
13
27
|
case "INT8":
|
|
@@ -61,7 +75,7 @@ function fieldToColumnType(field) {
|
|
|
61
75
|
}
|
|
62
76
|
var cast = (field, value) => {
|
|
63
77
|
if (field.type === "JSON") {
|
|
64
|
-
return value;
|
|
78
|
+
return typeof value === "string" && value.length ? decodeUtf8(value) : value;
|
|
65
79
|
}
|
|
66
80
|
const defaultValue = defaultCast(field, value);
|
|
67
81
|
if (defaultValue instanceof Uint8Array) {
|
|
@@ -180,40 +194,27 @@ var PlanetScaleTransaction = class extends PlanetScaleQueryable {
|
|
|
180
194
|
async commit() {
|
|
181
195
|
debug(`[js::commit]`);
|
|
182
196
|
this.txDeferred.resolve();
|
|
183
|
-
return
|
|
197
|
+
return ok(await this.txResultPromise);
|
|
184
198
|
}
|
|
185
199
|
async rollback() {
|
|
186
200
|
debug(`[js::rollback]`);
|
|
187
201
|
this.txDeferred.reject(new RollbackError());
|
|
188
|
-
return
|
|
202
|
+
return ok(await this.txResultPromise);
|
|
189
203
|
}
|
|
190
204
|
};
|
|
191
|
-
var
|
|
192
|
-
constructor(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
import { Client } from '@planetscale/database'
|
|
196
|
-
const client = new Client({ url })
|
|
197
|
-
const adapter = new PrismaPlanetScale(client)
|
|
198
|
-
`);
|
|
199
|
-
}
|
|
200
|
-
super(client);
|
|
201
|
-
}
|
|
202
|
-
getConnectionInfo() {
|
|
203
|
-
const url = this.client.connection()["url"];
|
|
204
|
-
const dbName = new URL(url).pathname.slice(1);
|
|
205
|
-
return ok({
|
|
206
|
-
schemaName: dbName
|
|
207
|
-
});
|
|
205
|
+
var PlanetScaleTransactionContext = class extends PlanetScaleQueryable {
|
|
206
|
+
constructor(conn) {
|
|
207
|
+
super(conn);
|
|
208
|
+
this.conn = conn;
|
|
208
209
|
}
|
|
209
210
|
async startTransaction() {
|
|
210
211
|
const options = {
|
|
211
212
|
usePhantomQuery: true
|
|
212
213
|
};
|
|
213
214
|
const tag = "[js::startTransaction]";
|
|
214
|
-
debug(
|
|
215
|
+
debug("%s options: %O", tag, options);
|
|
215
216
|
return new Promise((resolve, reject) => {
|
|
216
|
-
const txResultPromise = this.
|
|
217
|
+
const txResultPromise = this.conn.transaction(async (tx) => {
|
|
217
218
|
const [txDeferred, deferredPromise] = createDeferred();
|
|
218
219
|
const txWrapper = new PlanetScaleTransaction(tx, options, txDeferred, txResultPromise);
|
|
219
220
|
resolve(ok(txWrapper));
|
|
@@ -227,6 +228,30 @@ const adapter = new PrismaPlanetScale(client)
|
|
|
227
228
|
});
|
|
228
229
|
}
|
|
229
230
|
};
|
|
231
|
+
var PrismaPlanetScale = class extends PlanetScaleQueryable {
|
|
232
|
+
constructor(client) {
|
|
233
|
+
if (!(client instanceof planetScale.Client)) {
|
|
234
|
+
throw new TypeError(`PrismaPlanetScale must be initialized with an instance of Client:
|
|
235
|
+
import { Client } from '@planetscale/database'
|
|
236
|
+
const client = new Client({ url })
|
|
237
|
+
const adapter = new PrismaPlanetScale(client)
|
|
238
|
+
`);
|
|
239
|
+
}
|
|
240
|
+
super(client);
|
|
241
|
+
}
|
|
242
|
+
getConnectionInfo() {
|
|
243
|
+
const url = this.client.connection()["url"];
|
|
244
|
+
const dbName = new URL(url).pathname.slice(1);
|
|
245
|
+
return ok({
|
|
246
|
+
schemaName: dbName
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
async transactionContext() {
|
|
250
|
+
const conn = this.client.connection();
|
|
251
|
+
const ctx = new PlanetScaleTransactionContext(conn);
|
|
252
|
+
return ok(ctx);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
230
255
|
export {
|
|
231
256
|
PrismaPlanetScale
|
|
232
257
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-planetscale",
|
|
3
|
-
"version": "5.20.0-dev.
|
|
3
|
+
"version": "5.20.0-dev.20",
|
|
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": "5.20.0-dev.
|
|
34
|
+
"@prisma/driver-adapter-utils": "5.20.0-dev.20"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@planetscale/database": "1.18.0",
|