[PR #4554] [CLOSED] feat(db): add withTransaction helper #5445

Closed
opened 2026-03-13 12:23:03 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4554
Author: @jslno
Created: 9/10/2025
Status: Closed

Base: canaryHead: feat/with-transaction-helper


📝 Commits (10+)

  • 20a0d18 feat(internal-adapter): add withTransaction helper
  • 2a4370b chore: update init snapshot
  • 8a70767 chore: cleanup
  • b58a506 fix: shim appended to wrong parameter
  • 1e03d48 fix: preserve generics
  • d290e16 chore: remove unused import
  • 2f690d4 refactor: added createAdapterBridge and more generic approach
  • f01da78 chore: add export
  • d89f0ce chore: fix linting
  • 01ff9ba chore: fix linting

📊 Changes

7 files changed (+1256 additions, -950 deletions)

View changed files

📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+1 -0)
packages/better-auth/src/db/adapter-bridge.ts (+201 -0)
📝 packages/better-auth/src/db/index.ts (+1 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+989 -947)
📝 packages/better-auth/src/db/with-hooks.ts (+1 -2)
📝 packages/better-auth/src/init.ts (+1 -1)
📝 packages/better-auth/src/utils/shim.ts (+62 -0)

📄 Description

I guess this could be closed and put into a 3rd party library. I think it's useful for transaction heavy plugins but I also don't see a use case for this in the core library, as there aren't (at least for the current state) many transactions needed. (Maybe revert to a simpler version, like I had before).

Summary by cubic

Adds internalAdapter.withTransaction to run auth DB operations in a single transaction and reduce boilerplate. Provides a transaction-scoped internalAdapter where the transaction adapter is auto-injected.

  • New Features
    • Added internalAdapter.withTransaction(cb): executes cb within adapter.transaction.
    • cb receives { adapter, internalAdapter }; internalAdapter methods omit the trx param.
    • Introduced shimLastParam utility to auto-inject the last parameter (used for trx) when missing.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4554 **Author:** [@jslno](https://github.com/jslno) **Created:** 9/10/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/with-transaction-helper` --- ### 📝 Commits (10+) - [`20a0d18`](https://github.com/better-auth/better-auth/commit/20a0d1873b7802a339bbd9eea2e0d497b594bd7a) feat(internal-adapter): add withTransaction helper - [`2a4370b`](https://github.com/better-auth/better-auth/commit/2a4370b9349bdadbcff47e05af60ddf5813e9050) chore: update init snapshot - [`8a70767`](https://github.com/better-auth/better-auth/commit/8a70767506cf0445ec442d0d93f69e87d67a0e2c) chore: cleanup - [`b58a506`](https://github.com/better-auth/better-auth/commit/b58a506af9ffe5c3d687120f57d7c01aee4dbc45) fix: shim appended to wrong parameter - [`1e03d48`](https://github.com/better-auth/better-auth/commit/1e03d48592744f0f5aaed2ab7430da672099b1d0) fix: preserve generics - [`d290e16`](https://github.com/better-auth/better-auth/commit/d290e1613165e83e61296af7f60d0fc614a3b86a) chore: remove unused import - [`2f690d4`](https://github.com/better-auth/better-auth/commit/2f690d4fcc63835fd34f38c614a66fd3d74a03cf) refactor: added createAdapterBridge and more generic approach - [`f01da78`](https://github.com/better-auth/better-auth/commit/f01da78fc3e9a5de60175674b826f81176739f3d) chore: add export - [`d89f0ce`](https://github.com/better-auth/better-auth/commit/d89f0ce08f2ecfc0843fca882c5de54950381561) chore: fix linting - [`01ff9ba`](https://github.com/better-auth/better-auth/commit/01ff9ba95c9f93c1922cd70952b8862734e42c9b) chore: fix linting ### 📊 Changes **7 files changed** (+1256 additions, -950 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+1 -0) ➕ `packages/better-auth/src/db/adapter-bridge.ts` (+201 -0) 📝 `packages/better-auth/src/db/index.ts` (+1 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+989 -947) 📝 `packages/better-auth/src/db/with-hooks.ts` (+1 -2) 📝 `packages/better-auth/src/init.ts` (+1 -1) 📝 `packages/better-auth/src/utils/shim.ts` (+62 -0) </details> ### 📄 Description I guess this could be closed and put into a 3rd party library. I think it's useful for transaction heavy plugins but I also don't see a use case for this in the core library, as there aren't (at least for the current state) many transactions needed. (Maybe revert to a simpler version, like I had before). <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds internalAdapter.withTransaction to run auth DB operations in a single transaction and reduce boilerplate. Provides a transaction-scoped internalAdapter where the transaction adapter is auto-injected. - **New Features** - Added internalAdapter.withTransaction(cb): executes cb within adapter.transaction. - cb receives { adapter, internalAdapter }; internalAdapter methods omit the trx param. - Introduced shimLastParam utility to auto-inject the last parameter (used for trx) when missing. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:23:03 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5445