feat: database transaction support (#4414)

Co-authored-by: Joel Solano <solano.joel@gmx.de>
This commit is contained in:
Alex Yang
2025-09-09 17:10:27 -07:00
committed by GitHub
parent 61b6a87435
commit 22c39b92be
16 changed files with 647 additions and 228 deletions

View File

@@ -20,7 +20,7 @@ const client = new MongoClient("mongodb://localhost:27017/database");
const db = client.db();
export const auth = betterAuth({
database: mongodbAdapter(db),
database: mongodbAdapter(db, { client }),
});
```

View File

@@ -452,6 +452,16 @@ const adapter = myAdapter({
});
```
### `transaction`
Whether the adapter supports transactions. If `false`, operations run sequentially; otherwise provide a function that executes a callback with a `TransactionAdapter`.
<Callout type="warn">
If your database does not support transactions, the error handling and rollback
will not be as robust. We recommend using a database that supports transactions
for better data integrity.
</Callout>
### `debugLogs`
Used to enable debug logs for the adapter. You can pass in a boolean, or an object with the following keys: `create`, `update`, `updateMany`, `findOne`, `findMany`, `delete`, `deleteMany`, `count`.