[SQLite]: fix libsql cache JSON roundtrip regression#5563
Open
muhammadosama984 wants to merge 1 commit intodrizzle-team:mainfrom
Open
[SQLite]: fix libsql cache JSON roundtrip regression#5563muhammadosama984 wants to merge 1 commit intodrizzle-team:mainfrom
muhammadosama984 wants to merge 1 commit intodrizzle-team:mainfrom
Conversation
Convert libSQL values rows to plain arrays before caching so JSON-based caches keep positional data and avoid decode failures on cache hits. Add regression coverage in both drizzle-orm unit tests and libsql integration tests. Made-with: Cursor
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5561
Summary
values()rows to plain arrays before storing them in cache so JSON roundtrips preserve positional data used by result mappingdrizzle-ormunit regression test that mocks libSQL row shape and reproduces the cache-hit JSON-roundtrip scenariolibsqlintegration regression test that validates cached query results with JSON columns on subsequent readsRoot Cause
LibSQL
Rowobjects are plain objects with both named keys and non-enumerable numeric indices +length.JSON.stringifyonly serializes enumerable own properties, so numeric indices are lost during the cache roundtrip. On cache hit,Array.prototype.slice.call(row)returns an empty array, causingmapResultRowto readundefinedand crash withSyntaxError: "undefined" is not valid JSON.Fix
In
drizzle-orm/src/libsql/session.ts, thevalues()method now converts eachRowto a plainArrayviaArray.prototype.slice.call(row)before passing it toqueryWithCache. This ensures the data survives any JSON-based serialization (Upstash Redis, custom caches, etc.).Test plan
pnpm testindrizzle-orm— all unit tests pass, including new regression testpnpm test:typesindrizzle-orm— type checks passLIBSQL_URL='file:./tmp-libsql.db' pnpm exec vitest run tests/sqlite/libsql.test.tsinintegration-tests— integration regression test passes