diff --git a/README.md b/README.md index e262dd1..b5adf7a 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ try { | v5.13.x | v5.13.x | \>= v0.1.0 | | v5.14.x | v5.14.x | \>= v0.1.0 | | v5.15.x | v5.15.x | \>= v0.1.0 | - +| v5.20.x | v5.20.x | \>= v0.1.0 | Here is the step to step guide for how to choose the version: 1. Choose the Prisma version: Choose the one as you need. diff --git a/package.json b/package.json index ad7a69a..1d1a4e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tidbcloud/prisma-adapter", - "version": "5.15.0", + "version": "5.20.0", "description": "Prisma's driver adapter for \"@tidbcloud/serverless\"", "main": "dist/index.js", "module": "dist/index.mjs", @@ -34,7 +34,7 @@ "license": "Apache-2.0", "sideEffects": false, "dependencies": { - "@prisma/driver-adapter-utils": "5.15.0" + "@prisma/driver-adapter-utils": "5.20.0" }, "devDependencies": { "@tidbcloud/serverless": "^0.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 044276a..623f41f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@prisma/driver-adapter-utils': - specifier: 5.15.0 - version: 5.15.0 + specifier: 5.20.0 + version: 5.20.0 devDependencies: '@tidbcloud/serverless': @@ -301,14 +301,14 @@ packages: fastq: 1.15.0 dev: true - /@prisma/debug@5.15.0: - resolution: {integrity: sha512-QpEAOjieLPc/4sMny/WrWqtpIAmBYsgqwWlWwIctqZO0AbhQ9QcT6x2Ut3ojbDo/pFRCCA1Z1+xm2MUy7fAkZA==} + /@prisma/debug@5.20.0: + resolution: {integrity: sha512-oCx79MJ4HSujokA8S1g0xgZUGybD4SyIOydoHMngFYiwEwYDQ5tBQkK5XoEHuwOYDKUOKRn/J0MEymckc4IgsQ==} dev: false - /@prisma/driver-adapter-utils@5.15.0: - resolution: {integrity: sha512-p4jxptZE3p5WCdfE+dvHTNvrtlqPllAMkbAnR9BGr48nBwl15QDMDjZdvbubgO9VH30Nc5XWHINx0dyI+RlxSw==} + /@prisma/driver-adapter-utils@5.20.0: + resolution: {integrity: sha512-xORRckszVdB8pgh8jcCsEdAniknu2RLzpHmjPQwFHoacMDF44JcbUbtNijFPiZMWRCeLxd1QZkhxgWn2xJB1tQ==} dependencies: - '@prisma/debug': 5.15.0 + '@prisma/debug': 5.20.0 dev: false /@tidbcloud/serverless@0.1.1: diff --git a/src/tidbcloud.ts b/src/tidbcloud.ts index 05282a8..2da5b6d 100644 --- a/src/tidbcloud.ts +++ b/src/tidbcloud.ts @@ -8,6 +8,7 @@ import type { Queryable, Transaction, Result, + TransactionContext, TransactionOptions, } from "@prisma/driver-adapter-utils"; import { @@ -136,6 +137,27 @@ class TiDBCloudTransaction } } +class TiDBCloudTransactionContext + extends TiDBCloudQueryable + implements TransactionContext +{ + constructor(connect: TiDBCloud.Connection) { + super(connect); + } + + async startTransaction(): Promise> { + const options: TransactionOptions = { + usePhantomQuery: true, + }; + + const tag = "[js::startTransaction]"; + debug("%s option: %O", tag, options); + + const tx = await this.client.begin(); + return ok(new TiDBCloudTransaction(tx, options)); + } +} + export class PrismaTiDBCloud extends TiDBCloudQueryable implements DriverAdapter @@ -152,15 +174,7 @@ export class PrismaTiDBCloud }); } - async startTransaction() { - const options: TransactionOptions = { - usePhantomQuery: true, - }; - - const tag = "[js::startTransaction]"; - debug(`${tag} options: %O`, options); - - const tx = await this.client.begin(); - return ok(new TiDBCloudTransaction(tx, options)); + async transactionContext(): Promise> { + return ok(new TiDBCloudTransactionContext(this.client)); } }