Changeset View
Standalone View
web/flow-typed/SQLiteJS.js
- This file was added.
// @flow | |||||
ashoat: You are taking a very non-standard approach here. Can you please make this file look like the… | |||||
kamilAuthorUnsubmitted Done Inline ActionsYeah, I did an awful job here, I put up this diff too chaotically without checking what will be best. Creating stub and wrapping everything in declare module as you suggested kamil: Yeah, I did an awful job here, I put up this diff too chaotically without checking what will be… | |||||
declare type SqlValue = number | string | Uint8Array | null; | |||||
declare type ParamsObject = { +[key: string]: SqlValue, ... }; | |||||
michalUnsubmitted Not Done Inline ActionsDoes this need to be inexact? michal: Does this need to be inexact? | |||||
kamilAuthorUnsubmitted Done Inline ActionsHmm... that's how it is typed in typescript, but inexact it's not needed in a way we will use it so I'll update this to exact for now. kamil: Hmm... that's how it is typed in typescript, but inexact it's not needed in a way we will use… | |||||
declare type ParamsCallback = (obj: ParamsObject) => void; | |||||
declare type BindParams = $ReadOnlyArray<SqlValue> | ParamsObject | null; | |||||
declare type QueryExecResult = { | |||||
+columns: $ReadOnlyArray<string>, | |||||
+values: $ReadOnlyArray<$ReadOnlyArray<SqlValue>>, | |||||
}; | |||||
declare type StatementIteratorResult = { | |||||
+done: boolean, | |||||
+value: SqliteStatement, | |||||
}; | |||||
declare type SqlJsStatic = { | |||||
+Database: SqliteDatabase, | |||||
+Statement: SqliteStatement, | |||||
michalUnsubmitted Not Done Inline ActionsTypescript uses typeof keyword for typing these fields. I think they are supposed to hold classes themselves and not instances so we will also need to use typeof but please correct me if I'm wrong. michal: Typescript uses `typeof` keyword for typing these fields. I think they are supposed to hold… | |||||
kamilAuthorUnsubmitted Done Inline Actionsgood catch! kamil: good catch! | |||||
}; | |||||
declare type InitSqlJsStatic = { | |||||
(config?: Object): Promise<SqlJsStatic>, | |||||
michalUnsubmitted Not Done Inline ActionsCan we type the config better? In the sql.js documentation, there's locateFile specified (and in the emscripten documentation there are even more fields but we probably don't need to add the all) michal: Can we type the `config` better? In the [sql.js documentation](https://sql.js. | |||||
kamilAuthorUnsubmitted Done Inline ActionsMaking this inexact type with locateFile funciton kamil: Making this inexact type with `locateFile` funciton | |||||
}; | |||||
declare class SqliteDatabase { | |||||
constructor(data?: Array<number> | 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): $ReadOnlyArray<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 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 class StatementIterator implements Iterable<SqliteStatement> { | |||||
michalUnsubmitted Not Done Inline ActionsIn typescript, it's typed as both Iterable and Iterator. Can we do the same? michal: In typescript, it's typed as both `Iterable` and `Iterator`. Can we do the same? | |||||
kamilAuthorUnsubmitted Done Inline ActionsI'm not sure if there is a need for this. { +done: boolean, +value: ..., }; while for Iterator it is: | { +done: true, +value: ..., } | { +done: false, +value: ..., }; kamil: I'm not sure if there is a need for this.
Also there will be a problem because for `Iterable`… | |||||
@@iterator: () => Iterator<SqliteStatement>; | |||||
getRemainingSql(): string; | |||||
next(): StatementIteratorResult; | |||||
} | |||||
declare var initSqlJs: InitSqlJsStatic; |
You are taking a very non-standard approach here. Can you please make this file look like the rest, instead of polluting the global namespace with type declarations?
Start with flow-typed stub. Pay attention to where the file is created and what the naming convention is. Note that all declarations are wrapped in a declare module.