Skip to content

Commit

Permalink
adopt Prisma driver adapter 5.20 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 authored Sep 26, 2024
1 parent 0c4bbc8 commit fbd4323
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 24 additions & 10 deletions src/tidbcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
Queryable,
Transaction,
Result,
TransactionContext,
TransactionOptions,
} from "@prisma/driver-adapter-utils";
import {
Expand Down Expand Up @@ -136,6 +137,27 @@ class TiDBCloudTransaction
}
}

class TiDBCloudTransactionContext
extends TiDBCloudQueryable<TiDBCloud.Connection>
implements TransactionContext
{
constructor(connect: TiDBCloud.Connection) {
super(connect);
}

async startTransaction(): Promise<Result<Transaction>> {
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<TiDBCloud.Connection>
implements DriverAdapter
Expand All @@ -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<Result<TransactionContext>> {
return ok(new TiDBCloudTransactionContext(this.client));
}
}

0 comments on commit fbd4323

Please sign in to comment.