Skip to content

Commit 04ac56d

Browse files
committed
Restore JSON() wrapper in merge replace query
1 parent a9f31c1 commit 04ac56d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/storage/providers/SQLiteProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ const provider: StorageProvider<NitroSQLiteConnection | undefined> = {
150150
const patchQueryArguments: string[][] = [];
151151

152152
// Query to fully replace the nested objects of the DB value.
153+
// NOTE: The JSON() wrapper around the replacement value is required here. Unlike JSON_PATCH (which
154+
// parses both arguments as JSON internally), JSON_REPLACE treats a plain TEXT binding as a quoted
155+
// JSON string. Without JSON(), objects would be stored as string values (e.g. "{...}") instead of
156+
// actual JSON objects, corrupting the stored data.
153157
const replaceQuery = `UPDATE keyvaluepairs
154-
SET valueJSON = JSON_REPLACE(valueJSON, ?, ?)
158+
SET valueJSON = JSON_REPLACE(valueJSON, ?, JSON(?))
155159
WHERE record_key = ?;
156160
`;
157161
const replaceQueryArguments: string[][] = [];

0 commit comments

Comments
 (0)