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 [email protected]:sbking/prisma-client-extensions.git
Create a .env
file and install dependencies:
cd callback-free-itx
cp .env.example .env
npm install
Run the following command to start a new Postgres database in a Docker container:
docker compose up -d
Run this command to apply migrations to the database:
npx prisma migrate deploy
Run the following command to add seed data to the database:
npx prisma db seed
To run the script.ts
file, run the following command:
npm run dev