Page MenuHomePhabricator

D7101.id24111.diff
No OneTemporary

D7101.id24111.diff

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
@@ -1,7 +1,7 @@
// @flow
import localforage from 'localforage';
-import initSqlJs from 'sql.js';
+import initSqlJs, { type SqliteDatabase } from 'sql.js';
import {
type SharedWorkerMessageEvent,
@@ -22,7 +22,7 @@
};
localforage.config(localforageConfig);
-let sqliteDb = null;
+let sqliteDb: ?SqliteDatabase = null;
async function initDatabase(sqljsFilePath: string, sqljsFilename: ?string) {
const content = await localforage.getItem(SQLITE_CONTENT);
@@ -44,8 +44,12 @@
}
const versionData = sqliteDb.exec('PRAGMA user_version;');
- if (versionData.length && versionData[0].values.length) {
- console.info(`Db version: ${versionData[0].values[0]}`);
+ 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');
}
diff --git a/web/flow-typed/npm/sql.js_vx.x.x.js b/web/flow-typed/npm/sql.js_vx.x.x.js
new file mode 100644
--- /dev/null
+++ b/web/flow-typed/npm/sql.js_vx.x.x.js
@@ -0,0 +1,89 @@
+// @flow
+
+// flow-typed signature: f355493becad56880bf30832260c5460
+// flow-typed version: <<STUB>>/sql.js_v1.8.0/flow_v0.182.0
+
+declare module 'sql.js' {
+ declare export type SqlValue = number | string | Uint8Array | null;
+ declare export type ParamsObject = { +[key: string]: SqlValue };
+ declare export type ParamsCallback = (obj: ParamsObject) => void;
+
+ declare export type BindParams =
+ | $ReadOnlyArray<SqlValue>
+ | ParamsObject
+ | null;
+
+ declare export type QueryExecResult = {
+ columns: string[],
+ values: SqlValue[][],
+ };
+
+ declare export type StatementIteratorResult = {
+ +done: boolean,
+ +value: SqliteStatement,
+ };
+
+ declare export type SqlJsStatic = {
+ +Database: Class<SqliteDatabase>,
+ +Statement: Class<SqliteStatement>,
+ };
+
+ declare type EmscriptenModule = {
+ +locateFile: (path: string, prefix?: string) => string,
+ ...
+ };
+
+ declare type InitSqlJsStatic = {
+ (config?: EmscriptenModule): Promise<SqlJsStatic>,
+ };
+
+ declare export class SqliteDatabase {
+ constructor(data?: Array<number> | Uint8Array | Buffer | null): this;
+ close(): void;
+
+ create_function<T, R>(
+ name: string,
+ func: (...args: $ReadOnlyArray<T>) => R,
+ ): SqliteDatabase;
+ each(
+ sql: string,
+ params: BindParams,
+ callback: ParamsCallback,
+ done: () => void,
+ ): SqliteDatabase;
+ each(
+ sql: string,
+ callback: ParamsCallback,
+ done: () => void,
+ ): SqliteDatabase;
+ exec(sql: string, params?: BindParams): QueryExecResult[];
+ export(): Uint8Array;
+ getRowsModified(): number;
+ handleError(): null | empty;
+ iterateStatements(sql: string): StatementIterator;
+ prepare(sql: string, params?: BindParams): SqliteStatement;
+ run(sql: string, params?: BindParams): SqliteDatabase;
+ }
+
+ declare export class SqliteStatement {
+ bind(values?: BindParams): boolean;
+ free(): boolean;
+ freemem(): void;
+ get(params?: BindParams): $ReadOnlyArray<SqlValue>;
+ getAsObject(params?: BindParams): ParamsObject;
+ getColumnNames(): $ReadOnlyArray<string>;
+ getNormalizedSQL(): string;
+ getSQL(): string;
+ reset(): void;
+ run(values?: BindParams): void;
+ step(): boolean;
+ }
+
+ declare export class StatementIterator implements Iterable<SqliteStatement> {
+ @@iterator: () => Iterator<SqliteStatement>;
+ getRemainingSql(): string;
+ next(): StatementIteratorResult;
+ }
+
+ declare export default InitSqlJsStatic;
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 9:37 AM (11 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2705209
Default Alt Text
D7101.id24111.diff (3 KB)

Event Timeline