Page MenuHomePhabricator

D7102.id24112.diff
No OneTemporary

D7102.id24112.diff

diff --git a/web/database/queries/db-queries.js b/web/database/queries/db-queries.js
new file mode 100644
--- /dev/null
+++ b/web/database/queries/db-queries.js
@@ -0,0 +1,19 @@
+// @flow
+
+import type { SqliteDatabase } from 'sql.js';
+
+function getSQLiteDBVersion(db: SqliteDatabase): number {
+ const versionData = db.exec('PRAGMA user_version;');
+ if (!versionData.length || !versionData[0].values.length) {
+ throw new Error('Error while retrieving database version: empty result');
+ }
+ const [dbVersion] = versionData[0].values[0];
+ if (typeof dbVersion !== 'number') {
+ throw new Error(
+ 'Error while retrieving database version: invalid type returned',
+ );
+ }
+ return dbVersion;
+}
+
+export { getSQLiteDBVersion };
diff --git a/web/database/worker/db-worker.js b/web/database/worker/db-worker.js
--- a/web/database/worker/db-worker.js
+++ b/web/database/worker/db-worker.js
@@ -11,6 +11,7 @@
workerResponseMessageTypes,
type WorkerRequestProxyMessage,
} from '../../types/worker-types.js';
+import { getSQLiteDBVersion } from '../queries/db-queries.js';
import { SQLITE_CONTENT } from '../utils/constants.js';
const localforageConfig: PartialConfig = {
@@ -43,16 +44,8 @@
sqliteDb = new SQL.Database();
}
- const versionData = sqliteDb.exec('PRAGMA user_version;');
- if (!versionData.length || !versionData[0].values.length) {
- throw new Error('Error while retrieving database version');
- }
- const [dbVersion] = versionData[0].values[0];
- if (typeof dbVersion === 'number') {
- console.info(`Db version: ${dbVersion}`);
- } else {
- throw new Error('Error while retrieving database version');
- }
+ const dbVersion = getSQLiteDBVersion(sqliteDb);
+ console.info(`Db version: ${dbVersion}`);
}
async function processAppRequest(

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 4:11 AM (19 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2603621
Default Alt Text
D7102.id24112.diff (1 KB)

Event Timeline