Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3376165
D7102.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D7102.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 10:27 PM (21 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591923
Default Alt Text
D7102.diff (1 KB)
Attached To
Mode
D7102: [web-db] implement function to get database version
Attached
Detach File
Event Timeline
Log In to Comment