@prisma/adapter-mariadb 7.10.0 → 7.11.0-dev.1

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.js CHANGED
@@ -85,7 +85,7 @@ function mapColumnType(field) {
85
85
  case "TINY_BLOB" /* TINY_BLOB */:
86
86
  case "MEDIUM_BLOB" /* MEDIUM_BLOB */:
87
87
  case "LONG_BLOB" /* LONG_BLOB */:
88
- if (field["dataTypeFormat"] === "json") {
88
+ if (field.isDataTypeFormatJson()) {
89
89
  return import_driver_adapter_utils.ColumnTypeEnum.Json;
90
90
  } else if (field.collation.index === BINARY_COLLATION_INDEX) {
91
91
  return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
@@ -367,36 +367,62 @@ var MariaDbTransaction = class extends MariaDbQueryable {
367
367
  this.options = options;
368
368
  this.cleanup = cleanup;
369
369
  }
370
+ /**
371
+ * Set on entry to `commit()` or `rollback()`, before either sends SQL. Once the pool has lent the
372
+ * connection to a new owner, a second close would send `COMMIT` or `ROLLBACK` into that owner's
373
+ * session and release the connection twice, so the transaction closes at most once and sends
374
+ * nothing afterwards.
375
+ */
376
+ closed = false;
377
+ async performIO(query) {
378
+ this.assertOpen();
379
+ return await super.performIO(query);
380
+ }
370
381
  async commit() {
371
382
  debug(`[js::commit]`);
372
- try {
373
- await this.client.query({ sql: "COMMIT" });
374
- } catch (err) {
375
- this.onError(err);
376
- } finally {
377
- this.cleanup?.();
378
- await releaseConnection(this.client);
379
- }
383
+ await this.close("COMMIT");
380
384
  }
381
385
  async rollback() {
382
386
  debug(`[js::rollback]`);
387
+ await this.close("ROLLBACK");
388
+ }
389
+ async createSavepoint(name2) {
390
+ await this.sendTransactionControl(`SAVEPOINT ${name2}`);
391
+ }
392
+ async rollbackToSavepoint(name2) {
393
+ await this.sendTransactionControl(`ROLLBACK TO ${name2}`);
394
+ }
395
+ async releaseSavepoint(name2) {
396
+ await this.sendTransactionControl(`RELEASE SAVEPOINT ${name2}`);
397
+ }
398
+ async close(sql) {
399
+ if (this.closed) {
400
+ return;
401
+ }
402
+ this.closed = true;
383
403
  try {
384
- await this.client.query({ sql: "ROLLBACK" });
404
+ await this.client.query({ sql });
385
405
  } catch (err) {
386
406
  this.onError(err);
387
407
  } finally {
388
- this.cleanup?.();
389
- await releaseConnection(this.client);
408
+ try {
409
+ this.cleanup?.();
410
+ } finally {
411
+ await releaseConnection(this.client);
412
+ }
390
413
  }
391
414
  }
392
- async createSavepoint(name2) {
393
- await this.client.query({ sql: `SAVEPOINT ${name2}` }).catch(this.onError.bind(this));
394
- }
395
- async rollbackToSavepoint(name2) {
396
- await this.client.query({ sql: `ROLLBACK TO ${name2}` }).catch(this.onError.bind(this));
415
+ async sendTransactionControl(sql) {
416
+ this.assertOpen();
417
+ await this.client.query({ sql }).catch(this.onError.bind(this));
397
418
  }
398
- async releaseSavepoint(name2) {
399
- await this.client.query({ sql: `RELEASE SAVEPOINT ${name2}` }).catch(this.onError.bind(this));
419
+ assertOpen() {
420
+ if (this.closed) {
421
+ throw new import_driver_adapter_utils2.DriverAdapterError({
422
+ kind: "TransactionAlreadyClosed",
423
+ cause: "The transaction has already been committed or rolled back"
424
+ });
425
+ }
400
426
  }
401
427
  };
402
428
  var PrismaMariaDbAdapter = class extends MariaDbQueryable {
@@ -559,9 +585,6 @@ function rewriteConnectionString(url) {
559
585
  if (url.protocol === "mysql:") {
560
586
  url.protocol = "mariadb:";
561
587
  }
562
- if (url.hostname.startsWith("[") && url.hostname.endsWith("]")) {
563
- url.hostname = encodeURIComponent(url.hostname.slice(1, -1));
564
- }
565
588
  return url;
566
589
  }
567
590
  async function releaseConnection(conn) {
package/dist/index.mjs CHANGED
@@ -49,7 +49,7 @@ function mapColumnType(field) {
49
49
  case "TINY_BLOB" /* TINY_BLOB */:
50
50
  case "MEDIUM_BLOB" /* MEDIUM_BLOB */:
51
51
  case "LONG_BLOB" /* LONG_BLOB */:
52
- if (field["dataTypeFormat"] === "json") {
52
+ if (field.isDataTypeFormatJson()) {
53
53
  return ColumnTypeEnum.Json;
54
54
  } else if (field.collation.index === BINARY_COLLATION_INDEX) {
55
55
  return ColumnTypeEnum.Bytes;
@@ -331,36 +331,62 @@ var MariaDbTransaction = class extends MariaDbQueryable {
331
331
  this.options = options;
332
332
  this.cleanup = cleanup;
333
333
  }
334
+ /**
335
+ * Set on entry to `commit()` or `rollback()`, before either sends SQL. Once the pool has lent the
336
+ * connection to a new owner, a second close would send `COMMIT` or `ROLLBACK` into that owner's
337
+ * session and release the connection twice, so the transaction closes at most once and sends
338
+ * nothing afterwards.
339
+ */
340
+ closed = false;
341
+ async performIO(query) {
342
+ this.assertOpen();
343
+ return await super.performIO(query);
344
+ }
334
345
  async commit() {
335
346
  debug(`[js::commit]`);
336
- try {
337
- await this.client.query({ sql: "COMMIT" });
338
- } catch (err) {
339
- this.onError(err);
340
- } finally {
341
- this.cleanup?.();
342
- await releaseConnection(this.client);
343
- }
347
+ await this.close("COMMIT");
344
348
  }
345
349
  async rollback() {
346
350
  debug(`[js::rollback]`);
351
+ await this.close("ROLLBACK");
352
+ }
353
+ async createSavepoint(name2) {
354
+ await this.sendTransactionControl(`SAVEPOINT ${name2}`);
355
+ }
356
+ async rollbackToSavepoint(name2) {
357
+ await this.sendTransactionControl(`ROLLBACK TO ${name2}`);
358
+ }
359
+ async releaseSavepoint(name2) {
360
+ await this.sendTransactionControl(`RELEASE SAVEPOINT ${name2}`);
361
+ }
362
+ async close(sql) {
363
+ if (this.closed) {
364
+ return;
365
+ }
366
+ this.closed = true;
347
367
  try {
348
- await this.client.query({ sql: "ROLLBACK" });
368
+ await this.client.query({ sql });
349
369
  } catch (err) {
350
370
  this.onError(err);
351
371
  } finally {
352
- this.cleanup?.();
353
- await releaseConnection(this.client);
372
+ try {
373
+ this.cleanup?.();
374
+ } finally {
375
+ await releaseConnection(this.client);
376
+ }
354
377
  }
355
378
  }
356
- async createSavepoint(name2) {
357
- await this.client.query({ sql: `SAVEPOINT ${name2}` }).catch(this.onError.bind(this));
358
- }
359
- async rollbackToSavepoint(name2) {
360
- await this.client.query({ sql: `ROLLBACK TO ${name2}` }).catch(this.onError.bind(this));
379
+ async sendTransactionControl(sql) {
380
+ this.assertOpen();
381
+ await this.client.query({ sql }).catch(this.onError.bind(this));
361
382
  }
362
- async releaseSavepoint(name2) {
363
- await this.client.query({ sql: `RELEASE SAVEPOINT ${name2}` }).catch(this.onError.bind(this));
383
+ assertOpen() {
384
+ if (this.closed) {
385
+ throw new DriverAdapterError({
386
+ kind: "TransactionAlreadyClosed",
387
+ cause: "The transaction has already been committed or rolled back"
388
+ });
389
+ }
364
390
  }
365
391
  };
366
392
  var PrismaMariaDbAdapter = class extends MariaDbQueryable {
@@ -523,9 +549,6 @@ function rewriteConnectionString(url) {
523
549
  if (url.protocol === "mysql:") {
524
550
  url.protocol = "mariadb:";
525
551
  }
526
- if (url.hostname.startsWith("[") && url.hostname.endsWith("]")) {
527
- url.hostname = encodeURIComponent(url.hostname.slice(1, -1));
528
- }
529
552
  return url;
530
553
  }
531
554
  async function releaseConnection(conn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-mariadb",
3
- "version": "7.10.0",
3
+ "version": "7.11.0-dev.1",
4
4
  "description": "Prisma's driver adapter for \"mariadb\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "https://github.com/prisma/prisma.git",
22
+ "url": "https://github.com/prisma/orm.git",
23
23
  "directory": "packages/adapter-planetscale"
24
24
  },
25
25
  "files": [
@@ -31,15 +31,14 @@
31
31
  "license": "Apache-2.0",
32
32
  "sideEffects": false,
33
33
  "dependencies": {
34
- "mariadb": "3.4.5",
35
- "@prisma/driver-adapter-utils": "7.10.0"
34
+ "mariadb": "3.5.4",
35
+ "@prisma/driver-adapter-utils": "7.11.0-dev.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@prisma/debug": "7.10.0"
38
+ "@prisma/debug": "7.11.0-dev.1"
39
39
  },
40
40
  "scripts": {
41
41
  "dev": "DEV=true tsx helpers/build.ts",
42
- "build": "tsx helpers/build.ts",
43
- "test": "vitest run"
42
+ "build": "tsx helpers/build.ts"
44
43
  }
45
44
  }