@prisma/adapter-mariadb 6.15.0-dev.3 → 6.15.0-dev.30
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 +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +69 -12
- package/dist/index.mjs +69 -12
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -30,11 +30,9 @@ declare class MariaDbQueryable<Connection extends mariadb.Pool | mariadb.Connect
|
|
|
30
30
|
|
|
31
31
|
export declare class PrismaMariaDb implements SqlDriverAdapterFactory {
|
|
32
32
|
#private;
|
|
33
|
-
private readonly config;
|
|
34
|
-
private readonly options?;
|
|
35
33
|
readonly provider = "mysql";
|
|
36
34
|
readonly adapterName: string;
|
|
37
|
-
constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions
|
|
35
|
+
constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions);
|
|
38
36
|
connect(): Promise<PrismaMariaDbAdapter>;
|
|
39
37
|
}
|
|
40
38
|
|
|
@@ -51,6 +49,7 @@ declare class PrismaMariaDbAdapter extends MariaDbQueryable<mariadb.Pool> implem
|
|
|
51
49
|
|
|
52
50
|
declare type PrismaMariadbOptions = {
|
|
53
51
|
database?: string;
|
|
52
|
+
onConnectionError?: (err: mariadb.SqlError) => void;
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -30,11 +30,9 @@ declare class MariaDbQueryable<Connection extends mariadb.Pool | mariadb.Connect
|
|
|
30
30
|
|
|
31
31
|
export declare class PrismaMariaDb implements SqlDriverAdapterFactory {
|
|
32
32
|
#private;
|
|
33
|
-
private readonly config;
|
|
34
|
-
private readonly options?;
|
|
35
33
|
readonly provider = "mysql";
|
|
36
34
|
readonly adapterName: string;
|
|
37
|
-
constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions
|
|
35
|
+
constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions);
|
|
38
36
|
connect(): Promise<PrismaMariaDbAdapter>;
|
|
39
37
|
}
|
|
40
38
|
|
|
@@ -51,6 +49,7 @@ declare class PrismaMariaDbAdapter extends MariaDbQueryable<mariadb.Pool> implem
|
|
|
51
49
|
|
|
52
50
|
declare type PrismaMariadbOptions = {
|
|
53
51
|
database?: string;
|
|
52
|
+
onConnectionError?: (err: mariadb.SqlError) => void;
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -102,8 +102,35 @@ function mapColumnType(field) {
|
|
|
102
102
|
throw new Error(`Unsupported column type: ${field.type}`);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
function mapArg(arg) {
|
|
106
|
-
if (arg
|
|
105
|
+
function mapArg(arg, argType) {
|
|
106
|
+
if (arg === null) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (typeof arg === "string" && argType.scalarType === "bigint") {
|
|
110
|
+
return BigInt(arg);
|
|
111
|
+
}
|
|
112
|
+
if (typeof arg === "string" && argType.scalarType === "datetime") {
|
|
113
|
+
arg = new Date(arg);
|
|
114
|
+
}
|
|
115
|
+
if (arg instanceof Date) {
|
|
116
|
+
switch (argType.dbType) {
|
|
117
|
+
case "TIME" /* TIME */:
|
|
118
|
+
case "TIME2" /* TIME2 */:
|
|
119
|
+
return formatTime(arg);
|
|
120
|
+
case "DATE" /* DATE */:
|
|
121
|
+
case "NEWDATE" /* NEWDATE */:
|
|
122
|
+
return formatDate(arg);
|
|
123
|
+
default:
|
|
124
|
+
return formatDateTime(arg);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (typeof arg === "string" && argType.scalarType === "bytes") {
|
|
128
|
+
return Buffer.from(arg, "base64");
|
|
129
|
+
}
|
|
130
|
+
if (Array.isArray(arg) && argType.scalarType === "bytes") {
|
|
131
|
+
return Buffer.from(arg);
|
|
132
|
+
}
|
|
133
|
+
if (ArrayBuffer.isView(arg)) {
|
|
107
134
|
return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
|
|
108
135
|
}
|
|
109
136
|
return arg;
|
|
@@ -119,7 +146,7 @@ function mapRow(row, fields) {
|
|
|
119
146
|
case "TIMESTAMP2" /* TIMESTAMP2 */:
|
|
120
147
|
case "DATETIME" /* DATETIME */:
|
|
121
148
|
case "DATETIME2" /* DATETIME2 */:
|
|
122
|
-
return (/* @__PURE__ */ new Date(`${value}Z`)).toISOString();
|
|
149
|
+
return (/* @__PURE__ */ new Date(`${value}Z`)).toISOString().replace(/(\.000)?Z$/, "+00:00");
|
|
123
150
|
}
|
|
124
151
|
if (Buffer.isBuffer(value)) {
|
|
125
152
|
return Array.from(value);
|
|
@@ -136,6 +163,20 @@ var typeCast = (field, next) => {
|
|
|
136
163
|
}
|
|
137
164
|
return next();
|
|
138
165
|
};
|
|
166
|
+
function formatDateTime(date) {
|
|
167
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
168
|
+
const ms = date.getUTCMilliseconds();
|
|
169
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
170
|
+
}
|
|
171
|
+
function formatDate(date) {
|
|
172
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
173
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
174
|
+
}
|
|
175
|
+
function formatTime(date) {
|
|
176
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
177
|
+
const ms = date.getUTCMilliseconds();
|
|
178
|
+
return pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
179
|
+
}
|
|
139
180
|
|
|
140
181
|
// src/errors.ts
|
|
141
182
|
function convertDriverError(error) {
|
|
@@ -286,9 +327,9 @@ var MariaDbQueryable = class {
|
|
|
286
327
|
return (await this.performIO(query)).affectedRows ?? 0;
|
|
287
328
|
}
|
|
288
329
|
async performIO(query) {
|
|
289
|
-
const { sql, args
|
|
330
|
+
const { sql, args } = query;
|
|
290
331
|
try {
|
|
291
|
-
const
|
|
332
|
+
const req = {
|
|
292
333
|
sql,
|
|
293
334
|
rowsAsArray: true,
|
|
294
335
|
dateStrings: true,
|
|
@@ -300,7 +341,8 @@ var MariaDbQueryable = class {
|
|
|
300
341
|
bitOneIsBoolean: false,
|
|
301
342
|
typeCast
|
|
302
343
|
};
|
|
303
|
-
|
|
344
|
+
const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
345
|
+
return await this.client.query(req, values);
|
|
304
346
|
} catch (e) {
|
|
305
347
|
const error = e;
|
|
306
348
|
onError(error);
|
|
@@ -347,6 +389,10 @@ var PrismaMariaDbAdapter = class extends MariaDbQueryable {
|
|
|
347
389
|
const tag = "[js::startTransaction]";
|
|
348
390
|
debug("%s options: %O", tag, options);
|
|
349
391
|
const conn = await this.client.getConnection().catch((error) => onError(error));
|
|
392
|
+
conn.on("error", (err) => {
|
|
393
|
+
debug(`Error from connection: ${err.message} %O`, err);
|
|
394
|
+
this.options?.onConnectionError?.(err);
|
|
395
|
+
});
|
|
350
396
|
try {
|
|
351
397
|
const tx = new MariaDbTransaction(conn, options);
|
|
352
398
|
if (isolationLevel) {
|
|
@@ -371,19 +417,21 @@ var PrismaMariaDbAdapter = class extends MariaDbQueryable {
|
|
|
371
417
|
}
|
|
372
418
|
};
|
|
373
419
|
var PrismaMariaDbAdapterFactory = class {
|
|
374
|
-
constructor(config, options) {
|
|
375
|
-
this.config = config;
|
|
376
|
-
this.options = options;
|
|
377
|
-
}
|
|
378
420
|
provider = "mysql";
|
|
379
421
|
adapterName = name;
|
|
380
422
|
#capabilities;
|
|
423
|
+
#config;
|
|
424
|
+
#options;
|
|
425
|
+
constructor(config, options) {
|
|
426
|
+
this.#config = rewriteConnectionString(config);
|
|
427
|
+
this.#options = options;
|
|
428
|
+
}
|
|
381
429
|
async connect() {
|
|
382
|
-
const pool = mariadb.createPool(this
|
|
430
|
+
const pool = mariadb.createPool(this.#config);
|
|
383
431
|
if (this.#capabilities === void 0) {
|
|
384
432
|
this.#capabilities = await getCapabilities(pool);
|
|
385
433
|
}
|
|
386
|
-
return new PrismaMariaDbAdapter(pool, this.#capabilities, this
|
|
434
|
+
return new PrismaMariaDbAdapter(pool, this.#capabilities, this.#options);
|
|
387
435
|
}
|
|
388
436
|
};
|
|
389
437
|
async function getCapabilities(pool) {
|
|
@@ -413,6 +461,15 @@ function inferCapabilities(version) {
|
|
|
413
461
|
const supportsRelationJoins = !isMariaDB && (major > 8 || major === 8 && minor >= 0 && patch >= 13);
|
|
414
462
|
return { supportsRelationJoins };
|
|
415
463
|
}
|
|
464
|
+
function rewriteConnectionString(config) {
|
|
465
|
+
if (typeof config !== "string") {
|
|
466
|
+
return config;
|
|
467
|
+
}
|
|
468
|
+
if (!config.startsWith("mysql://")) {
|
|
469
|
+
return config;
|
|
470
|
+
}
|
|
471
|
+
return config.replace(/^mysql:\/\//, "mariadb://");
|
|
472
|
+
}
|
|
416
473
|
// Annotate the CommonJS export names for ESM import in node:
|
|
417
474
|
0 && (module.exports = {
|
|
418
475
|
PrismaMariaDb
|
package/dist/index.mjs
CHANGED
|
@@ -66,8 +66,35 @@ function mapColumnType(field) {
|
|
|
66
66
|
throw new Error(`Unsupported column type: ${field.type}`);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
function mapArg(arg) {
|
|
70
|
-
if (arg
|
|
69
|
+
function mapArg(arg, argType) {
|
|
70
|
+
if (arg === null) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (typeof arg === "string" && argType.scalarType === "bigint") {
|
|
74
|
+
return BigInt(arg);
|
|
75
|
+
}
|
|
76
|
+
if (typeof arg === "string" && argType.scalarType === "datetime") {
|
|
77
|
+
arg = new Date(arg);
|
|
78
|
+
}
|
|
79
|
+
if (arg instanceof Date) {
|
|
80
|
+
switch (argType.dbType) {
|
|
81
|
+
case "TIME" /* TIME */:
|
|
82
|
+
case "TIME2" /* TIME2 */:
|
|
83
|
+
return formatTime(arg);
|
|
84
|
+
case "DATE" /* DATE */:
|
|
85
|
+
case "NEWDATE" /* NEWDATE */:
|
|
86
|
+
return formatDate(arg);
|
|
87
|
+
default:
|
|
88
|
+
return formatDateTime(arg);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (typeof arg === "string" && argType.scalarType === "bytes") {
|
|
92
|
+
return Buffer.from(arg, "base64");
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(arg) && argType.scalarType === "bytes") {
|
|
95
|
+
return Buffer.from(arg);
|
|
96
|
+
}
|
|
97
|
+
if (ArrayBuffer.isView(arg)) {
|
|
71
98
|
return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
|
|
72
99
|
}
|
|
73
100
|
return arg;
|
|
@@ -83,7 +110,7 @@ function mapRow(row, fields) {
|
|
|
83
110
|
case "TIMESTAMP2" /* TIMESTAMP2 */:
|
|
84
111
|
case "DATETIME" /* DATETIME */:
|
|
85
112
|
case "DATETIME2" /* DATETIME2 */:
|
|
86
|
-
return (/* @__PURE__ */ new Date(`${value}Z`)).toISOString();
|
|
113
|
+
return (/* @__PURE__ */ new Date(`${value}Z`)).toISOString().replace(/(\.000)?Z$/, "+00:00");
|
|
87
114
|
}
|
|
88
115
|
if (Buffer.isBuffer(value)) {
|
|
89
116
|
return Array.from(value);
|
|
@@ -100,6 +127,20 @@ var typeCast = (field, next) => {
|
|
|
100
127
|
}
|
|
101
128
|
return next();
|
|
102
129
|
};
|
|
130
|
+
function formatDateTime(date) {
|
|
131
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
132
|
+
const ms = date.getUTCMilliseconds();
|
|
133
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
134
|
+
}
|
|
135
|
+
function formatDate(date) {
|
|
136
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
137
|
+
return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
|
|
138
|
+
}
|
|
139
|
+
function formatTime(date) {
|
|
140
|
+
const pad = (n, z = 2) => String(n).padStart(z, "0");
|
|
141
|
+
const ms = date.getUTCMilliseconds();
|
|
142
|
+
return pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
|
|
143
|
+
}
|
|
103
144
|
|
|
104
145
|
// src/errors.ts
|
|
105
146
|
function convertDriverError(error) {
|
|
@@ -250,9 +291,9 @@ var MariaDbQueryable = class {
|
|
|
250
291
|
return (await this.performIO(query)).affectedRows ?? 0;
|
|
251
292
|
}
|
|
252
293
|
async performIO(query) {
|
|
253
|
-
const { sql, args
|
|
294
|
+
const { sql, args } = query;
|
|
254
295
|
try {
|
|
255
|
-
const
|
|
296
|
+
const req = {
|
|
256
297
|
sql,
|
|
257
298
|
rowsAsArray: true,
|
|
258
299
|
dateStrings: true,
|
|
@@ -264,7 +305,8 @@ var MariaDbQueryable = class {
|
|
|
264
305
|
bitOneIsBoolean: false,
|
|
265
306
|
typeCast
|
|
266
307
|
};
|
|
267
|
-
|
|
308
|
+
const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
309
|
+
return await this.client.query(req, values);
|
|
268
310
|
} catch (e) {
|
|
269
311
|
const error = e;
|
|
270
312
|
onError(error);
|
|
@@ -311,6 +353,10 @@ var PrismaMariaDbAdapter = class extends MariaDbQueryable {
|
|
|
311
353
|
const tag = "[js::startTransaction]";
|
|
312
354
|
debug("%s options: %O", tag, options);
|
|
313
355
|
const conn = await this.client.getConnection().catch((error) => onError(error));
|
|
356
|
+
conn.on("error", (err) => {
|
|
357
|
+
debug(`Error from connection: ${err.message} %O`, err);
|
|
358
|
+
this.options?.onConnectionError?.(err);
|
|
359
|
+
});
|
|
314
360
|
try {
|
|
315
361
|
const tx = new MariaDbTransaction(conn, options);
|
|
316
362
|
if (isolationLevel) {
|
|
@@ -335,19 +381,21 @@ var PrismaMariaDbAdapter = class extends MariaDbQueryable {
|
|
|
335
381
|
}
|
|
336
382
|
};
|
|
337
383
|
var PrismaMariaDbAdapterFactory = class {
|
|
338
|
-
constructor(config, options) {
|
|
339
|
-
this.config = config;
|
|
340
|
-
this.options = options;
|
|
341
|
-
}
|
|
342
384
|
provider = "mysql";
|
|
343
385
|
adapterName = name;
|
|
344
386
|
#capabilities;
|
|
387
|
+
#config;
|
|
388
|
+
#options;
|
|
389
|
+
constructor(config, options) {
|
|
390
|
+
this.#config = rewriteConnectionString(config);
|
|
391
|
+
this.#options = options;
|
|
392
|
+
}
|
|
345
393
|
async connect() {
|
|
346
|
-
const pool = mariadb.createPool(this
|
|
394
|
+
const pool = mariadb.createPool(this.#config);
|
|
347
395
|
if (this.#capabilities === void 0) {
|
|
348
396
|
this.#capabilities = await getCapabilities(pool);
|
|
349
397
|
}
|
|
350
|
-
return new PrismaMariaDbAdapter(pool, this.#capabilities, this
|
|
398
|
+
return new PrismaMariaDbAdapter(pool, this.#capabilities, this.#options);
|
|
351
399
|
}
|
|
352
400
|
};
|
|
353
401
|
async function getCapabilities(pool) {
|
|
@@ -377,6 +425,15 @@ function inferCapabilities(version) {
|
|
|
377
425
|
const supportsRelationJoins = !isMariaDB && (major > 8 || major === 8 && minor >= 0 && patch >= 13);
|
|
378
426
|
return { supportsRelationJoins };
|
|
379
427
|
}
|
|
428
|
+
function rewriteConnectionString(config) {
|
|
429
|
+
if (typeof config !== "string") {
|
|
430
|
+
return config;
|
|
431
|
+
}
|
|
432
|
+
if (!config.startsWith("mysql://")) {
|
|
433
|
+
return config;
|
|
434
|
+
}
|
|
435
|
+
return config.replace(/^mysql:\/\//, "mariadb://");
|
|
436
|
+
}
|
|
380
437
|
export {
|
|
381
438
|
PrismaMariaDbAdapterFactory as PrismaMariaDb
|
|
382
439
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-mariadb",
|
|
3
|
-
"version": "6.15.0-dev.
|
|
3
|
+
"version": "6.15.0-dev.30",
|
|
4
4
|
"description": "Prisma's driver adapter for \"mariadb\"",
|
|
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
|
"mariadb": "3.4.2",
|
|
35
|
-
"@prisma/driver-adapter-utils": "6.15.0-dev.
|
|
35
|
+
"@prisma/driver-adapter-utils": "6.15.0-dev.30"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"vitest": "3.0.9"
|