Changeset View
Standalone View
web/flow-typed/npm/sql.js_vx.x.x.js
- This file was added.
// @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[][], | |||||
ashoat: You set these properties to be read-only, but the values are not. In general we usually want… | |||||
kamilAuthorUnsubmitted Done Inline ActionsAccording to this comment: https://phab.comm.dev/D7118?id=23917#inline-46618 I wanted to make this non-read-only, I just forgot to update properties. kamil: According to this comment: https://phab.comm.dev/D7118?id=23917#inline-46618 I wanted to make… | |||||
}; | |||||
declare export type StatementIteratorResult = { | |||||
+done: boolean, | |||||
+value: SqliteStatement, | |||||
}; | |||||
declare export type SqlJsStatic = { | |||||
+Database: typeof SqliteDatabase, | |||||
+Statement: typeof SqliteStatement, | |||||
ashoatUnsubmitted Not Done Inline ActionsI think you can also use Class<> instead of typeof, which is slightly more Flow-like but it honestly doesn't really matter ashoat: I think you can also use `Class<>` instead of `typeof`, which is slightly more Flow-like but it… | |||||
}; | |||||
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>( | |||||
ashoatUnsubmitted Not Done Inline ActionsWhy is this create_function instead of createFunction? I guess it's sql.js being inconsistent with naming? ashoat: Why is this `create_function` instead of `createFunction`? I guess it's sql.js being… | |||||
kamilAuthorUnsubmitted Done Inline ActionsYeah, that's the case, example inconsistency: kamil: Yeah, that's the case, example inconsistency:
- [create_function](https://sql.js. | |||||
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[]; | |||||
ashoatUnsubmitted Not Done Inline ActionsWhy is this synchronous? I would've expected an async call that returns a Promise, but I guess the call basically just calls the underlying SQLite function, and it's all in a web worker so it's okay? ashoat: Why is this synchronous? I would've expected an async call that returns a `Promise`, but I… | |||||
kamilAuthorUnsubmitted Done Inline Actionssql.js API is synchronous because it’s based on the C API (basically SQLite engine compiled to WebAssymbly). Only worker uses this API and I've implemented app<->worker connection using Promises so it will not be a problem kamil: `sql.js` API is synchronous because it’s based on the C API (basically SQLite engine compiled… | |||||
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; | |||||
} |
You set these properties to be read-only, but the values are not. In general we usually want read-only values if we're using a read-only property
On the other hand, if this is only used as a return type, and we don't care about passing it around, AND we know that all of the objects returned here are created fresh every single time, then we could make this type non-readonly