Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3532728
D7101.id24078.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D7101.id24078.diff
View Options
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,
@@ -23,7 +23,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);
@@ -45,8 +45,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
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 9:40 AM (11 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2705221
Default Alt Text
D7101.id24078.diff (3 KB)
Attached To
Mode
D7101: [web-db] add `sql.js` types
Attached
Detach File
Event Timeline
Log In to Comment