@prisma/adapter-pg 8.1.0-dev.10 → 8.1.0-dev.12

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
@@ -29,7 +29,7 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
29
29
  * Should the query fail due to a connection error, the connection is
30
30
  * marked as unhealthy.
31
31
  */
32
- private performIO;
32
+ protected performIO(query: SqlQuery): Promise<pg.QueryArrayResult<any>>;
33
33
  protected onError(error: unknown): never;
34
34
  }
35
35
 
package/dist/index.d.ts CHANGED
@@ -29,7 +29,7 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
29
29
  * Should the query fail due to a connection error, the connection is
30
30
  * marked as unhealthy.
31
31
  */
32
- private performIO;
32
+ protected performIO(query: SqlQuery): Promise<pg.QueryArrayResult<any>>;
33
33
  protected onError(error: unknown): never;
34
34
  }
35
35
 
package/dist/index.js CHANGED
@@ -709,15 +709,50 @@ var PgTransaction = class extends PgQueryable {
709
709
  this.pgOptions = pgOptions;
710
710
  this.cleanup = cleanup;
711
711
  }
712
+ closed = false;
713
+ runningStatements = 0;
714
+ async performIO(query) {
715
+ if (this.closed) {
716
+ throw new import_driver_adapter_utils2.DriverAdapterError({
717
+ kind: "TransactionAlreadyClosed",
718
+ cause: "The transaction has already been committed or rolled back"
719
+ });
720
+ }
721
+ this.runningStatements++;
722
+ try {
723
+ return await super.performIO(query);
724
+ } finally {
725
+ this.runningStatements--;
726
+ }
727
+ }
728
+ /**
729
+ * Closes the transaction at most once. Once the pool has lent the client to
730
+ * a new owner, a second `release()` would corrupt the pool's bookkeeping, so
731
+ * it is skipped. A client with a statement still running is released with an
732
+ * error so the pool destroys it instead of lending out a busy connection.
733
+ */
734
+ close() {
735
+ if (this.closed) {
736
+ return;
737
+ }
738
+ this.closed = true;
739
+ try {
740
+ this.cleanup?.();
741
+ } finally {
742
+ if (this.runningStatements > 0) {
743
+ this.client.release(new Error("Transaction closed with a statement still running"));
744
+ } else {
745
+ this.client.release();
746
+ }
747
+ }
748
+ }
712
749
  async commit() {
713
750
  debug(`[js::commit]`);
714
- this.cleanup?.();
715
- this.client.release();
751
+ this.close();
716
752
  }
717
753
  async rollback() {
718
754
  debug(`[js::rollback]`);
719
- this.cleanup?.();
720
- this.client.release();
755
+ this.close();
721
756
  }
722
757
  async createSavepoint(name2) {
723
758
  await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
package/dist/index.mjs CHANGED
@@ -673,15 +673,50 @@ var PgTransaction = class extends PgQueryable {
673
673
  this.pgOptions = pgOptions;
674
674
  this.cleanup = cleanup;
675
675
  }
676
+ closed = false;
677
+ runningStatements = 0;
678
+ async performIO(query) {
679
+ if (this.closed) {
680
+ throw new DriverAdapterError({
681
+ kind: "TransactionAlreadyClosed",
682
+ cause: "The transaction has already been committed or rolled back"
683
+ });
684
+ }
685
+ this.runningStatements++;
686
+ try {
687
+ return await super.performIO(query);
688
+ } finally {
689
+ this.runningStatements--;
690
+ }
691
+ }
692
+ /**
693
+ * Closes the transaction at most once. Once the pool has lent the client to
694
+ * a new owner, a second `release()` would corrupt the pool's bookkeeping, so
695
+ * it is skipped. A client with a statement still running is released with an
696
+ * error so the pool destroys it instead of lending out a busy connection.
697
+ */
698
+ close() {
699
+ if (this.closed) {
700
+ return;
701
+ }
702
+ this.closed = true;
703
+ try {
704
+ this.cleanup?.();
705
+ } finally {
706
+ if (this.runningStatements > 0) {
707
+ this.client.release(new Error("Transaction closed with a statement still running"));
708
+ } else {
709
+ this.client.release();
710
+ }
711
+ }
712
+ }
676
713
  async commit() {
677
714
  debug(`[js::commit]`);
678
- this.cleanup?.();
679
- this.client.release();
715
+ this.close();
680
716
  }
681
717
  async rollback() {
682
718
  debug(`[js::rollback]`);
683
- this.cleanup?.();
684
- this.client.release();
719
+ this.close();
685
720
  }
686
721
  async createSavepoint(name2) {
687
722
  await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-pg",
3
- "version": "8.1.0-dev.10",
3
+ "version": "8.1.0-dev.12",
4
4
  "description": "Prisma's driver adapter for \"pg\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -34,10 +34,10 @@
34
34
  "pg": "^8.16.3",
35
35
  "postgres-array": "3.0.4",
36
36
  "@types/pg": "^8.16.0",
37
- "@prisma/driver-adapter-utils": "8.1.0-dev.10"
37
+ "@prisma/driver-adapter-utils": "8.1.0-dev.12"
38
38
  },
39
39
  "devDependencies": {
40
- "@prisma/debug": "8.1.0-dev.10"
40
+ "@prisma/debug": "8.1.0-dev.12"
41
41
  },
42
42
  "scripts": {
43
43
  "dev": "DEV=true tsx helpers/build.ts",