DefinitelyTyped/types/sql.js/module.d.ts
Louis DeScioli 32b5dfe149
Updates Emscripten types with new MODULARIZE API (#44590)
* Updates Emscripten types with new `MODULARIZE` API

This corresponds with the changes to Emscripten in emscripten-core/emscripten#10697,
creating a type for the new Promise-based API of the factory function
generated when using `MODULARIZE`.

Removes the obsolete `then` method from EmscriptenModule and separates
the type for the factory function generated when using the `MODULARIZE`
build option from the rest of the `EmscriptenModule` interface. This
will make it easier to extend the interface.

Also removes the global `Module` variable declaration as this is not
applicable for every application. This was not ideal as it left a very
generic variable name in the global scope for any application that used
Emscripten, regardless of whether there was actually a global variable.
This now leaves it up to the user to declare their module instance as
appropriate for them.

Fixes the reference in sql.js, using the EmscriptenModule interface
directly.

* Runs prettier on the emscripten types
2020-05-15 10:25:10 -07:00

86 lines
2.3 KiB
TypeScript

/// <reference types="node" />
/// <reference types="emscripten" />
export namespace SqlJs {
type ValueType = number | string | Uint8Array | null;
type ParamsObject = Record<string, ValueType>;
type ParamsCallback = (obj: ParamsObject) => void;
type Config = Partial<EmscriptenModule>;
interface QueryResults {
columns: string[];
values: ValueType[][];
}
class Database {
constructor();
constructor(data?: Buffer | null);
constructor(data?: Uint8Array | null);
constructor(data?: number[] | null);
run(sql: string): Database;
run(sql: string, params: ParamsObject): Database;
run(sql: string, params: ValueType[]): Database;
exec(sql: string): QueryResults[];
each(sql: string, callback: ParamsCallback, done: () => void): void;
each(sql: string, params: ParamsObject, callback: ParamsCallback, done: () => void): void;
each(sql: string, params: ValueType[], callback: ParamsCallback, done: () => void): void;
prepare(sql: string): Statement;
prepare(sql: string, params: ParamsObject): Statement;
prepare(sql: string, params: ValueType[]): Statement;
export(): Uint8Array;
close(): void;
getRowsModified(): number;
create_function(name: string, func: Function): void;
}
class Statement {
bind(): boolean;
bind(values: ParamsObject): boolean;
bind(values: ValueType[]): boolean;
step(): boolean;
get(): ValueType[];
get(params: ParamsObject): ValueType[];
get(params: ValueType[]): ValueType[];
getColumnNames(): string[];
getAsObject(): ParamsObject;
getAsObject(params: ParamsObject): ParamsObject;
getAsObject(params: ValueType[]): ParamsObject;
run(): void;
run(values: ParamsObject): void;
run(values: ValueType[]): void;
reset(): void;
freemem(): void;
free(): boolean;
}
export interface SqlJsStatic {
Database: typeof Database;
Statement: typeof Statement;
}
interface InitSqlJsStatic extends Function {
(config?: Config): Promise<SqlJsStatic>;
readonly default: this;
}
}
declare global {
let initSqlJs: SqlJs.InitSqlJsStatic;
}