[PR #7895] [CLOSED] fix(drizzle-adapter): handle sqlite json-mode arrays #24518

Closed
opened 2026-04-15 22:24:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7895
Author: @jayy-77
Created: 2/10/2026
Status: Closed

Base: canaryHead: fix/drizzle-sqlite-json-arrays-7440


📝 Commits (1)

  • 8c0bd1b fix(drizzle-adapter): handle sqlite json-mode arrays

📊 Changes

5 files changed (+272 additions, -2 deletions)

View changed files

📝 docs/content/docs/adapters/drizzle.mdx (+7 -0)
📝 packages/drizzle-adapter/src/drizzle-adapter.test.ts (+191 -0)
📝 packages/drizzle-adapter/src/drizzle-adapter.ts (+28 -2)
packages/drizzle-adapter/src/json.test.ts (+29 -0)
packages/drizzle-adapter/src/json.ts (+17 -0)

📄 Description

Problem

With the Drizzle adapter on SQLite, Better Auth could pre-JSON.stringify values for json, string[], and number[] fields. When those fields use Drizzle mode: \"json\" columns (as generated by the CLI), this results in JSON being stored as a string (and can lead to double-stringification).

This shows up as string[] additional fields being returned as a stringified JSON array when querying the database directly via Drizzle.

Changes

  • Treat SQLite as supporting JSON + array values for the adapter factory (so native objects/arrays are passed to Drizzle).
  • Add lightweight parsing for legacy JSON-string values on both input and output for SQLite.
  • Add regression tests for:
    • native array/object inputs
    • legacy JSON-string outputs
    • JSON-string inputs for smoother upgrades
  • Document JSON-mode columns behavior in the Drizzle adapter docs.

Test plan

  • pnpm typecheck
  • pnpm -F @better-auth/drizzle-adapter test

Fixes #7440


Summary by cubic

Fixes SQLite handling in the Drizzle adapter so json and array fields using Drizzle mode: "json" store native objects/arrays instead of stringified JSON. Also parses legacy JSON-string values on input/output to avoid breakage during upgrades.

  • Bug Fixes

    • Treat SQLite as supporting JSON and arrays; pass native values to Drizzle.
    • Parse legacy JSON strings for json/string[]/number[] on read and write.
    • Prevent double-stringification and string[] being returned as JSON strings.
  • Migration

    • For JSON-mode columns, send native objects/arrays (do not JSON.stringify).
    • If older rows stored JSON as strings, consider a one-time data migration.

Written for commit 8c0bd1bda6. Summary will update on new commits.


🔄 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/7895 **Author:** [@jayy-77](https://github.com/jayy-77) **Created:** 2/10/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/drizzle-sqlite-json-arrays-7440` --- ### 📝 Commits (1) - [`8c0bd1b`](https://github.com/better-auth/better-auth/commit/8c0bd1bda6c2eb6990b713545bf88496563046de) fix(drizzle-adapter): handle sqlite json-mode arrays ### 📊 Changes **5 files changed** (+272 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/adapters/drizzle.mdx` (+7 -0) 📝 `packages/drizzle-adapter/src/drizzle-adapter.test.ts` (+191 -0) 📝 `packages/drizzle-adapter/src/drizzle-adapter.ts` (+28 -2) ➕ `packages/drizzle-adapter/src/json.test.ts` (+29 -0) ➕ `packages/drizzle-adapter/src/json.ts` (+17 -0) </details> ### 📄 Description ## Problem With the Drizzle adapter on SQLite, Better Auth could pre-`JSON.stringify` values for `json`, `string[]`, and `number[]` fields. When those fields use Drizzle `mode: \"json\"` columns (as generated by the CLI), this results in JSON being stored as a *string* (and can lead to double-stringification). This shows up as `string[]` additional fields being returned as a stringified JSON array when querying the database directly via Drizzle. ## Changes - Treat SQLite as supporting JSON + array values for the adapter factory (so native objects/arrays are passed to Drizzle). - Add lightweight parsing for legacy JSON-string values on both input and output for SQLite. - Add regression tests for: - native array/object inputs - legacy JSON-string outputs - JSON-string inputs for smoother upgrades - Document JSON-mode columns behavior in the Drizzle adapter docs. ## Test plan - `pnpm typecheck` - `pnpm -F @better-auth/drizzle-adapter test` Fixes #7440 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes SQLite handling in the Drizzle adapter so json and array fields using Drizzle mode: "json" store native objects/arrays instead of stringified JSON. Also parses legacy JSON-string values on input/output to avoid breakage during upgrades. - **Bug Fixes** - Treat SQLite as supporting JSON and arrays; pass native values to Drizzle. - Parse legacy JSON strings for json/string[]/number[] on read and write. - Prevent double-stringification and string[] being returned as JSON strings. - **Migration** - For JSON-mode columns, send native objects/arrays (do not JSON.stringify). - If older rows stored JSON as strings, consider a one-time data migration. <sup>Written for commit 8c0bd1bda6c2eb6990b713545bf88496563046de. Summary will update on new commits.</sup> <!-- 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 22:24:33 -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#24518