@prisma/adapter-mariadb 6.15.0-dev.3 → 6.15.0-dev.5

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 CHANGED
@@ -51,6 +51,7 @@ declare class PrismaMariaDbAdapter extends MariaDbQueryable<mariadb.Pool> implem
51
51
 
52
52
  declare type PrismaMariadbOptions = {
53
53
  database?: string;
54
+ onConnectionError?: (err: mariadb.SqlError) => void;
54
55
  };
55
56
 
56
57
  export { }
package/dist/index.d.ts CHANGED
@@ -51,6 +51,7 @@ declare class PrismaMariaDbAdapter extends MariaDbQueryable<mariadb.Pool> implem
51
51
 
52
52
  declare type PrismaMariadbOptions = {
53
53
  database?: string;
54
+ onConnectionError?: (err: mariadb.SqlError) => void;
54
55
  };
55
56
 
56
57
  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 instanceof Uint8Array) {
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;
@@ -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: values } = query;
330
+ const { sql, args } = query;
290
331
  try {
291
- const query2 = {
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
- return await this.client.query(query2, values.map(mapArg));
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) {
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 instanceof Uint8Array) {
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;
@@ -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: values } = query;
294
+ const { sql, args } = query;
254
295
  try {
255
- const query2 = {
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
- return await this.client.query(query2, values.map(mapArg));
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-mariadb",
3
- "version": "6.15.0-dev.3",
3
+ "version": "6.15.0-dev.5",
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.3"
35
+ "@prisma/driver-adapter-utils": "6.15.0-dev.5"
36
36
  },
37
37
  "devDependencies": {
38
38
  "vitest": "3.0.9"