This example shows a Prisma Client extension which adds a new API for starting interactive transactions without callbacks.
This gives you the full power of interactive transactions (such as read–modify–write cycles), but in a more imperative API. This may be more convenient than the normal callback-style API for interactive transactions in some scenarios:
const tx = await prisma.$begin();
const user = await tx.user.findFirstOrThrow();
await tx.user.update(/* ... */);
await tx.$commit(); // Or: await tx.$rollback();This extension is provided as an example only. It is not intended to be used in production environments.
Please read the documentation on client extensions for more information.
Clone this repository:
git clone git@github.com:sbking/prisma-client-extensions.gitCreate a .env file and install dependencies:
cd callback-free-itx
cp .env.example .env
npm installRun the following command to start a new Postgres database in a Docker container:
docker compose up -dRun this command to apply migrations to the database:
npx prisma migrate deployRun the following command to add seed data to the database:
npx prisma db seedTo run the script.ts file, run the following command:
npm run dev