[PR #5158] [MERGED] fix(adapter): missing data type transformation on where clauses #14061

Closed
opened 2026-04-13 09:17:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5158
Author: @ping-maxwell
Created: 10/8/2025
Status: Merged
Merged: 10/12/2025
Merged by: @Bekacru

Base: canaryHead: fix/adpater-missing-where-transformation


📝 Commits (10+)

📊 Changes

13 files changed (+181 additions, -105 deletions)

View changed files

📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+38 -13)
📝 packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts (+13 -64)
📝 packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.sqlite.test.ts (+1 -1)
📝 packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts (+4 -1)
📝 packages/better-auth/src/adapters/prisma-adapter/test/prisma.sqlite.test.ts (+2 -2)
📝 packages/better-auth/src/adapters/tests/normal.ts (+102 -1)
📝 packages/cli/src/generators/drizzle.ts (+5 -1)
📝 packages/cli/src/generators/prisma.ts (+6 -12)
📝 packages/cli/test/__snapshots__/schema-mongodb.prisma (+2 -2)
📝 packages/cli/test/__snapshots__/schema-mysql-custom.prisma (+2 -2)
📝 packages/cli/test/__snapshots__/schema-mysql.prisma (+2 -2)
📝 packages/cli/test/__snapshots__/schema-numberid.prisma (+2 -2)
📝 packages/cli/test/__snapshots__/schema.prisma (+2 -2)

📄 Description

kysely breaks with DBs that have lack of support for specific field types like dates or booleans during where clause transformation.
Also removed default and onUpdate to drizzle & prisma schema generation since this should be handled by adapter factory. Also sometimes the default functions are too complex of logic that couldn't just be passed to certain schemas like Prisma schemas - it just makes sense that the adapter factory is to handle this.

closes https://github.com/better-auth/better-auth/issues/3683 & https://github.com/better-auth/better-auth/issues/4805


Summary by cubic

Fixes where-clause value normalization across adapters to support DBs without native dates/booleans/JSON and prevents accidental multi-row deletes by enforcing limit(1) on single deletes. Also makes Prisma delete resilient when the record doesn’t exist.

  • Bug Fixes

    • Normalize where values in adapter factory: number IDs, Date → ISO when dates unsupported, boolean → 1/0, JSON → string when JSON unsupported.
    • Kysely: validate fields via schema, build safer where expressions, remove post-read transforms
    • Prisma: ignore “Record to delete does not exist.” errors; log unknown errors.
    • Tests: add coverage for date filters and deleteMany with numeric/boolean fields.
  • Refactors

    • Simplified CLI schema generators by removing default timestamp and onUpdate automation for Drizzle and Prisma.

🔄 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/5158 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/8/2025 **Status:** ✅ Merged **Merged:** 10/12/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/adpater-missing-where-transformation` --- ### 📝 Commits (10+) - [`585dc2c`](https://github.com/better-auth/better-auth/commit/585dc2cb08c11b12e4ec79182af3e89362eda35e) fix(adapter): missing where transformation - [`038f888`](https://github.com/better-auth/better-auth/commit/038f888d76c07fa1b81124d0a802495213fe026d) Merge branch 'canary' into fix/adpater-missing-where-transformation - [`ce6ce75`](https://github.com/better-auth/better-auth/commit/ce6ce75197471911183fd597850b381c2f405295) chore: cleanup - [`fd9afd3`](https://github.com/better-auth/better-auth/commit/fd9afd341ffa7e8102458fa3796fd67146c173f7) Merge branch 'fix/adpater-missing-where-transformation' of https://github.com/ping-maxwell/better-auth into fix/adpater-missing-where-transformation - [`60e23ed`](https://github.com/better-auth/better-auth/commit/60e23ede1958c798e36e0f0616f54d7cb8ff425e) fix: pg breaking - [`5b30b10`](https://github.com/better-auth/better-auth/commit/5b30b10b8cbcc703525c3e72fd2f11950c6ab145) chore: cleanup - [`438fcf0`](https://github.com/better-auth/better-auth/commit/438fcf02f1157f409499580b4d765e8807aacbb1) fix: revert schema gen, but not generate custom defaultValue functions - [`cceb2fd`](https://github.com/better-auth/better-auth/commit/cceb2fd33292e5fc12272fe77a5f750801f69b73) Merge branch 'canary' into fix/adpater-missing-where-transformation - [`c3b048a`](https://github.com/better-auth/better-auth/commit/c3b048a16b3a43611cd6cd44e252636917069d66) fix: ci - [`61ba3ba`](https://github.com/better-auth/better-auth/commit/61ba3ba212864497bfe3b00553a3987e8aace34d) fix: ci ### 📊 Changes **13 files changed** (+181 additions, -105 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+38 -13) 📝 `packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts` (+13 -64) 📝 `packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.sqlite.test.ts` (+1 -1) 📝 `packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts` (+4 -1) 📝 `packages/better-auth/src/adapters/prisma-adapter/test/prisma.sqlite.test.ts` (+2 -2) 📝 `packages/better-auth/src/adapters/tests/normal.ts` (+102 -1) 📝 `packages/cli/src/generators/drizzle.ts` (+5 -1) 📝 `packages/cli/src/generators/prisma.ts` (+6 -12) 📝 `packages/cli/test/__snapshots__/schema-mongodb.prisma` (+2 -2) 📝 `packages/cli/test/__snapshots__/schema-mysql-custom.prisma` (+2 -2) 📝 `packages/cli/test/__snapshots__/schema-mysql.prisma` (+2 -2) 📝 `packages/cli/test/__snapshots__/schema-numberid.prisma` (+2 -2) 📝 `packages/cli/test/__snapshots__/schema.prisma` (+2 -2) </details> ### 📄 Description kysely breaks with DBs that have lack of support for specific field types like dates or booleans during where clause transformation. Also removed `default` and `onUpdate` to drizzle & prisma schema generation since this should be handled by adapter factory. Also sometimes the `default` functions are too complex of logic that couldn't just be passed to certain schemas like Prisma schemas - it just makes sense that the adapter factory is to handle this. closes https://github.com/better-auth/better-auth/issues/3683 & https://github.com/better-auth/better-auth/issues/4805 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes where-clause value normalization across adapters to support DBs without native dates/booleans/JSON and prevents accidental multi-row deletes by enforcing limit(1) on single deletes. Also makes Prisma delete resilient when the record doesn’t exist. - **Bug Fixes** - Normalize where values in adapter factory: number IDs, Date → ISO when dates unsupported, boolean → 1/0, JSON → string when JSON unsupported. - Kysely: validate fields via schema, build safer where expressions, remove post-read transforms - Prisma: ignore “Record to delete does not exist.” errors; log unknown errors. - Tests: add coverage for date filters and deleteMany with numeric/boolean fields. - **Refactors** - Simplified CLI schema generators by removing default timestamp and onUpdate automation for Drizzle and Prisma. - <!-- 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-13 09:17:41 -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#14061