[PR #1737] [CLOSED] feat: refactor database adapters #12213

Closed
opened 2026-04-13 08:14:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/1737
Author: @Netrifier
Created: 3/8/2025
Status: Closed

Base: mainHead: feat/drizzle-adapter-whereclauseconverion


📝 Commits (10+)

  • 9fa5407 feat: add all where clause conversions in drizzle adapter
  • 29f6d87 refactor: Make error messages consistent in Drizzle Adapter
  • 51d60d9 refactor: Add comments and improve typescript types
  • 37aadeb refactor: make convertWhereClause parameters consistent with other functions
  • b3aeb09 refactor: refactor convertWhereClause in PrismaAdapter and fix "ne" operator conversion
  • 7f8b80e refactor: add identifier to prisma adapter error messages
  • 163764e fix(drizzle adapter): Set the operator to "eq" if it is undefined or not provided
  • 19e1d73 feat(memory adapter): add all operator conversions
  • 16d593a fix(prisma adapter): throw error if unknown operator is passed
  • 0c61a96 feat(mongodb adapter): add missing typescript types

📊 Changes

6 files changed (+458 additions, -175 deletions)

View changed files

📝 packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts (+86 -72)
📝 packages/better-auth/src/adapters/memory-adapter/memory-adapter.ts (+56 -24)
📝 packages/better-auth/src/adapters/mongodb-adapter/adapter.mongo-db.test.ts (+62 -2)
📝 packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts (+57 -21)
📝 packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts (+54 -55)
📝 packages/better-auth/src/adapters/test.ts (+143 -1)

📄 Description

  1. Drizzle Adapter:

    • Refactored the convertWhereClause function to handle all operator conversions.
    • Changed the order of parameters convertWhereClause(model: string, where?: Where[]) to make them consistent with other adapters.
    • Add [# Drizzle Adapter] prefix to error messages.
    • Fixed count method to return count res[0].count as drizzle returns an array with the count.
  2. Memory Adapter:

    • Refactored the convertWhereClause function to handle all operator conversions.
    • Add [# Memory Adapter] prefix to error messages.
    • Fixed count method to use where clause.
  3. MongoDB Adapter:

    • Updated serializeID and deserializeID to add proper typescript types.
    • Changed the order of parameters convertWhereClause(model: string, where?: Where[]) to make them consistent with other adapters.
    • Changed the Error type to BetterAuthError instead of Error.
    • Added escapeRegex function to escape regex input to prevent regex injection.
    • Fixed regex in contains, starts_with, and ends_with operators.
    • Add [# MongoDB Adapter] prefix to error messages.
    • Fixed count method to use where clause.

    MongoDB Tests:

    • Fixed the clearDB function to delete sessions collection instead of session collection.
    • Added a test to verify proper regex input sanitization.
  4. Prisma Adapter:

    • Extracted the check if model exists logic to checkModelExistsOrThrow function.
    • Refactored the convertWhereClause function.
    • Updated the operatorToPrismaOperator function to handle all operators.
    • Add [# Prisma Adapter] prefix to error messages.
  5. Tests:

    • Added test for adapter.count() method with and without where clause.
    • Added tests for the operators ne, eq, lt, lte, gt, gte, in and undefined operator option.
      image
      image
      image
      image
      image
      image

🔄 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/1737 **Author:** [@Netrifier](https://github.com/Netrifier) **Created:** 3/8/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/drizzle-adapter-whereclauseconverion` --- ### 📝 Commits (10+) - [`9fa5407`](https://github.com/better-auth/better-auth/commit/9fa540788a0db0a87642585afeabdfc73e717687) feat: add all where clause conversions in drizzle adapter - [`29f6d87`](https://github.com/better-auth/better-auth/commit/29f6d8796d6ebc15dfd1ee78323dc752cd609016) refactor: Make error messages consistent in Drizzle Adapter - [`51d60d9`](https://github.com/better-auth/better-auth/commit/51d60d90f59ca03ad1a712e79982644eb4786b8a) refactor: Add comments and improve typescript types - [`37aadeb`](https://github.com/better-auth/better-auth/commit/37aadeb7800ed0a10c604734eb833cf1b074f868) refactor: make convertWhereClause parameters consistent with other functions - [`b3aeb09`](https://github.com/better-auth/better-auth/commit/b3aeb09bc1c61c71a50e20cdfbf98bee0d588994) refactor: refactor convertWhereClause in PrismaAdapter and fix "ne" operator conversion - [`7f8b80e`](https://github.com/better-auth/better-auth/commit/7f8b80e78cf67a0350660e61ca7ebd20df2f53f6) refactor: add identifier to prisma adapter error messages - [`163764e`](https://github.com/better-auth/better-auth/commit/163764e4153fe572a4463a16cd1cb76d200461ad) fix(drizzle adapter): Set the operator to "eq" if it is undefined or not provided - [`19e1d73`](https://github.com/better-auth/better-auth/commit/19e1d7394bc77c947fd5343df5476ce2bb5ffec7) feat(memory adapter): add all operator conversions - [`16d593a`](https://github.com/better-auth/better-auth/commit/16d593a1c1d386d29d8b9d8cb5a05e8cd0494798) fix(prisma adapter): throw error if unknown operator is passed - [`0c61a96`](https://github.com/better-auth/better-auth/commit/0c61a968558d93d67bea4c2e8b99de9eabc9ee29) feat(mongodb adapter): add missing typescript types ### 📊 Changes **6 files changed** (+458 additions, -175 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts` (+86 -72) 📝 `packages/better-auth/src/adapters/memory-adapter/memory-adapter.ts` (+56 -24) 📝 `packages/better-auth/src/adapters/mongodb-adapter/adapter.mongo-db.test.ts` (+62 -2) 📝 `packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts` (+57 -21) 📝 `packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts` (+54 -55) 📝 `packages/better-auth/src/adapters/test.ts` (+143 -1) </details> ### 📄 Description 1. **Drizzle Adapter:** - Refactored the `convertWhereClause` function to handle all operator conversions. - Changed the order of parameters `convertWhereClause(model: string, where?: Where[])` to make them consistent with other adapters. - Add `[# Drizzle Adapter]` prefix to error messages. - Fixed count method to return count `res[0].count` as drizzle returns an array with the count. 2. **Memory Adapter:** - Refactored the `convertWhereClause` function to handle all operator conversions. - Add `[# Memory Adapter]` prefix to error messages. - Fixed count method to use where clause. 3. **MongoDB Adapter:** - Updated `serializeID` and `deserializeID` to add proper typescript types. - Changed the order of parameters `convertWhereClause(model: string, where?: Where[])` to make them consistent with other adapters. - Changed the Error type to `BetterAuthError` instead of `Error`. - Added `escapeRegex` function to escape regex input to prevent regex injection. - Fixed regex in `contains`, `starts_with`, and `ends_with` operators. - Add `[# MongoDB Adapter]` prefix to error messages. - Fixed count method to use where clause. **MongoDB Tests:** - Fixed the `clearDB` function to delete `sessions` collection instead of `session` collection. - Added a test to verify proper regex input sanitization. 4. **Prisma Adapter:** - Extracted the check if model exists logic to `checkModelExistsOrThrow` function. - Refactored the `convertWhereClause` function. - Updated the `operatorToPrismaOperator` function to handle all operators. - Add `[# Prisma Adapter]` prefix to error messages. 5. **Tests:** - Added test for `adapter.count()` method with and without where clause. - Added tests for the operators `ne`, `eq`, `lt`, `lte`, `gt`, `gte`, `in` and undefined operator option. ![image](https://github.com/user-attachments/assets/b1954e1d-1602-4546-8182-3d07867cfeb8) ![image](https://github.com/user-attachments/assets/766da057-8af7-4b35-b34f-b22eb0802d28) ![image](https://github.com/user-attachments/assets/a6dccfbe-b555-4869-a02d-5331ee2b7f25) ![image](https://github.com/user-attachments/assets/f62fc196-410d-4da5-b67e-2f73eceb7a7d) ![image](https://github.com/user-attachments/assets/dcbd5ec9-bfeb-44d1-a4e6-8fa20f77be4e) ![image](https://github.com/user-attachments/assets/fe22e3d3-5eac-4d45-a717-5d9847c7da03) --- <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-04-13 08:14:10 -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#12213