Skip to content

Commit

Permalink
Fix #1 - Fallback to empty array when no output is present
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Feb 2, 2022
1 parent b761703 commit 7387b62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const exec = (res, rej, type, bin, args, opts) => {
if (type === 'query')
res(result);
else {
const json = parse(result);
const json = parse(result || '[]');
res(type === 'get' && isArray(json) ? json.shift() : json);
}
}
Expand Down
2 changes: 1 addition & 1 deletion esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const exec = (res, rej, type, bin, args, opts) => {
if (type === 'query')
res(result);
else {
const json = parse(result);
const json = parse(result || '[]');
res(type === 'get' && isArray(json) ? json.shift() : json);
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const {all, get, query, raw, transaction} = SQLiteTag('./test/sqlite.db');
await query`CREATE TABLE IF NOT EXISTS ${raw`lorem`} (info TEXT)`;
await query`DELETE FROM lorem`;

console.log('✔', 'getting nothing from DB');
console.log(
' ',
await get`SELECT * FROM lorem WHERE info=${'test'}` === void 0,
(await all`SELECT * FROM lorem WHERE info=${'test'}`).length === 0
);

console.log('✔', 'transaction');
const insert = transaction();
for (let i = 0; i < 9; i++)
Expand Down

0 comments on commit 7387b62

Please sign in to comment.