Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: SQLite causes crash when trying to merge undefined #334

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/storage/providers/SQLiteStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,27 @@ const provider = {
ON CONFLICT DO UPDATE
SET valueJSON = JSON_PATCH(valueJSON, JSON(:value));
`;
const queryArguments = _.map(pairs, (pair) => {

const queryArguments = [];
const keysToDelete = [];
_.forEach(pairs, (pair) => {
if (pair[1] == null) {
chrispader marked this conversation as resolved.
Show resolved Hide resolved
keysToDelete.push(pair[0]);
return;
}

const value = JSON.stringify(pair[1]);
return [pair[0], value];

queryArguments.push([pair[0], value]);
});
return db.executeBatchAsync([[query, queryArguments]]);

const deletePromise = this.removeItems(keysToDelete);
chrispader marked this conversation as resolved.
Show resolved Hide resolved
const mergePromise = queryArguments.length !== 0 ? db.executeBatchAsync([[query, queryArguments]]) : Promise.resolve();

return Promise.all([
mergePromise,
deletePromise,
]).then(() => mergePromise);
},

/**
Expand Down
Loading