Added type definitions for sql.js.

This commit is contained in:
George Wu
2015-12-11 21:49:53 +08:00
parent e4891332b9
commit 5c9b77c2db
2 changed files with 152 additions and 0 deletions

71
sql.js/sql.js.d.ts vendored Normal file
View File

@@ -0,0 +1,71 @@
// Type definitions for sql.js (Sep. 6 2015 snapshot)
// Project: https://github.com/kripken/sql.js
// Definitions by: George Wu <https://github.com/Hozuki/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "sql.js" {
type SQLValue = number | string | Uint8Array;
type KeyValueObject = { [key: string]: SQLValue };
type SQLValueObject = { [columnName: string]: SQLValue };
type DataRow = SQLValue[];
class Database {
constructor(data: Buffer);
constructor(data: Uint8Array);
constructor(data: number[]);
run(sql: string): Database;
run(sql: string, params: KeyValueObject): Database;
run(sql: string, params: SQLValue[]): Database;
exec(sql: string): QueryResults[];
each(sql: string, callback: (obj: SQLValueObject) => void, done: () => void): void;
each(sql: string, params: KeyValueObject, callback: (obj: SQLValueObject) => void, done: () => void): void;
each(sql: string, params: SQLValue[], callback: (obj: SQLValueObject) => void, done: () => void): void;
prepare(sql: string): Statement;
prepare(sql: string, params: KeyValueObject): Statement;
prepare(sql: string, params: SQLValue[]): Statement;
export(): Uint8Array;
close(): void;
}
class Statement {
bind(): boolean;
bind(values: KeyValueObject): boolean;
bind(values: SQLValue[]): boolean;
step(): boolean;
get(): DataRow;
get(params: KeyValueObject): DataRow;
get(params: SQLValue[]): DataRow;
getColumnNames(): string[];
getAsObject(): SQLValueObject;
getAsObject(params: KeyValueObject): SQLValueObject;
getAsObject(params: SQLValue[]): SQLValueObject;
run(): void;
run(values: KeyValueObject): void;
run(values: SQLValue[]): void;
reset(): void;
freemem(): void;
free(): boolean;
}
interface QueryResults {
columns: string[];
values: DataRow[];
}
}