Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions docs/utils-reference/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ npm install --save @raycast/utils

## Changelog

### v2.2.3

- Fixed an issue with `useSQL` on Windows where the query would refuse to be executed because the database is locked

### v2.2.2

- Fix `useCachedState` to preserve Date objects more precisely.
Expand Down
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raycast/utils",
"version": "2.2.2",
"version": "2.2.3",
"description": "Set of utilities to streamline building Raycast extensions",
"author": "Raycast Technologies Ltd.",
"homepage": "https://developers.raycast.com/utilities/getting-started",
Expand Down
28 changes: 19 additions & 9 deletions src/sql-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ export async function baseExecuteSQL<T = unknown>(

try {
db.open();

const statement = db.prepare(query);
checkAborted(abortSignal);

const result = statement.all();

db.close();

return result as T[];
} catch (error: any) {
console.log(error);
if (error.message.match("(5)") || error.message.match("(14)")) {
if (error.errcode === 5 || error.errcode === 14 || error.message.match("(5)") || error.message.match("(14)")) {
// That means that the DB is busy because of another app is locking it
// This happens when Chrome or Arc is opened: they lock the History db.
// As an ugly workaround, we duplicate the file and read that instead
Expand All @@ -69,17 +77,19 @@ export async function baseExecuteSQL<T = unknown>(
db = new sqlite3.DatabaseSync(workaroundCopiedDb, { open: false, readOnly: true });
db.open();
checkAborted(abortSignal);
}
}

const statement = db.prepare(query);
checkAborted(abortSignal);
const statement = db.prepare(query);
checkAborted(abortSignal);

const result = statement.all();

const result = statement.all();
db.close();

db.close();
return result as T[];
}

return result as T[];
throw error;
}
}

async function sqliteFallback<T = unknown>(
Expand Down
Loading
Loading