[PR #5319] [CLOSED] fix(drizzle-adapter): correctly handle all operators in AND clause for combined filter and search #22825

Closed
opened 2026-04-15 21:18:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5319
Author: @biniam0
Created: 10/15/2025
Status: Closed

Base: canaryHead: fix/drizzle-adapter-and-operator-handling


📝 Commits (1)

  • 5cd6b45 fix(drizzle-adapter): handle all operators in AND clause for multi-condition queries

📊 Changes

12 files changed (+645 additions, -22 deletions)

View changed files

examples/svelte-kit-example/.svelte-kit/ambient.d.ts (+357 -0)
examples/svelte-kit-example/.svelte-kit/non-ambient.d.ts (+47 -0)
examples/svelte-kit-example/.svelte-kit/tsconfig.json (+52 -0)
examples/svelte-kit-example/.svelte-kit/types/route_meta_data.json (+8 -0)
examples/svelte-kit-example/.svelte-kit/types/src/routes/$types.d.ts (+24 -0)
examples/svelte-kit-example/.svelte-kit/types/src/routes/(protected)/dashboard/$types.d.ts (+18 -0)
examples/svelte-kit-example/.svelte-kit/types/src/routes/forget-password/$types.d.ts (+18 -0)
examples/svelte-kit-example/.svelte-kit/types/src/routes/reset-password/$types.d.ts (+18 -0)
examples/svelte-kit-example/.svelte-kit/types/src/routes/sign-in/$types.d.ts (+18 -0)
examples/svelte-kit-example/.svelte-kit/types/src/routes/sign-up/$types.d.ts (+18 -0)
📝 packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts (+47 -22)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+20 -0)

📄 Description

This PR fixes an issue in the Drizzle adapter where combining filter and search parameters in the /admin/list-users endpoint returned zero results, even when matching records existed.

Root Cause

The convertWhereClause function in
packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts
only handled a limited subset of operators (eq, in, not_in) when multiple AND conditions were present.

As a result, operators like contains, starts_with, and ends_with (used for search queries) were incorrectly treated as equality checks, causing the generated SQL to fail to match expected results.

Fix

  • Extended the andGroup.map() logic in convertWhereClause() to handle all supported operators:

    • contains, starts_with, ends_with
    • lt, lte, ne, gt, gte
  • Ensured multi-condition queries now behave consistently with single-condition logic.

Example (Before vs After)

Before (bug):

GET /admin/list-users?filterField=role&filterValue=admin&searchField=email&searchValue=mark
// ❌ Returned 0 results

After (fixed):

// working on test cases, cuz I'm having a problem while testing with plugins (serialized error) and adapters errors and not passing

Summary by cubic

Fixes the Drizzle adapter so all operators in AND groups are handled correctly, restoring expected results when combining filter and search in /admin/list-users. Multi-condition queries no longer return zero results.

  • Bug Fixes
    • Updated convertWhereClause to support contains, starts_with, ends_with, lt, lte, ne, gt, gte alongside in/not_in, mapping to the correct SQL (like, lt/lte, ne, gt/gte).
    • Added a test for admin.listUsers to verify filter + search works together.

🔄 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/5319 **Author:** [@biniam0](https://github.com/biniam0) **Created:** 10/15/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/drizzle-adapter-and-operator-handling` --- ### 📝 Commits (1) - [`5cd6b45`](https://github.com/better-auth/better-auth/commit/5cd6b4582fedeceb7c2e5791b4b021718d93dec8) fix(drizzle-adapter): handle all operators in AND clause for multi-condition queries ### 📊 Changes **12 files changed** (+645 additions, -22 deletions) <details> <summary>View changed files</summary> ➕ `examples/svelte-kit-example/.svelte-kit/ambient.d.ts` (+357 -0) ➕ `examples/svelte-kit-example/.svelte-kit/non-ambient.d.ts` (+47 -0) ➕ `examples/svelte-kit-example/.svelte-kit/tsconfig.json` (+52 -0) ➕ `examples/svelte-kit-example/.svelte-kit/types/route_meta_data.json` (+8 -0) ➕ `examples/svelte-kit-example/.svelte-kit/types/src/routes/$types.d.ts` (+24 -0) ➕ `examples/svelte-kit-example/.svelte-kit/types/src/routes/(protected)/dashboard/$types.d.ts` (+18 -0) ➕ `examples/svelte-kit-example/.svelte-kit/types/src/routes/forget-password/$types.d.ts` (+18 -0) ➕ `examples/svelte-kit-example/.svelte-kit/types/src/routes/reset-password/$types.d.ts` (+18 -0) ➕ `examples/svelte-kit-example/.svelte-kit/types/src/routes/sign-in/$types.d.ts` (+18 -0) ➕ `examples/svelte-kit-example/.svelte-kit/types/src/routes/sign-up/$types.d.ts` (+18 -0) 📝 `packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts` (+47 -22) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+20 -0) </details> ### 📄 Description This PR fixes an issue in the Drizzle adapter where combining **filter** and **search** parameters in the `/admin/list-users` endpoint returned **zero results**, even when matching records existed. #### **Root Cause** The `convertWhereClause` function in `packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts` only handled a limited subset of operators (`eq`, `in`, `not_in`) when multiple `AND` conditions were present. As a result, operators like `contains`, `starts_with`, and `ends_with` (used for search queries) were incorrectly treated as equality checks, causing the generated SQL to fail to match expected results. #### **Fix** * Extended the `andGroup.map()` logic in `convertWhereClause()` to handle **all supported operators**: * `contains`, `starts_with`, `ends_with` * `lt`, `lte`, `ne`, `gt`, `gte` * Ensured multi-condition queries now behave consistently with single-condition logic. #### **Example (Before vs After)** **Before (bug):** ```ts GET /admin/list-users?filterField=role&filterValue=admin&searchField=email&searchValue=mark // ❌ Returned 0 results ``` **After (fixed):** ```ts // working on test cases, cuz I'm having a problem while testing with plugins (serialized error) and adapters errors and not passing ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes the Drizzle adapter so all operators in AND groups are handled correctly, restoring expected results when combining filter and search in /admin/list-users. Multi-condition queries no longer return zero results. - **Bug Fixes** - Updated convertWhereClause to support contains, starts_with, ends_with, lt, lte, ne, gt, gte alongside in/not_in, mapping to the correct SQL (like, lt/lte, ne, gt/gte). - Added a test for admin.listUsers to verify filter + search works together. <!-- 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-04-15 21:18:28 -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#22825