/
SQLite.types.ts
110 lines (91 loc) · 2.44 KB
/
SQLite.types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Definitions copied from `@types/websql` as we want
// to expose a custom version of the API that:
// - uses primitive `string` instead of `String`
// - excludes some methods that are not exposed by our API.
//
// Original definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>
export interface Window {
openDatabase?: (
name: string,
version: string,
displayName: string,
estimatedSize: number,
creationCallback?: DatabaseCallback
) => Database;
}
export interface DatabaseCallback {
(database: Database): void;
}
export interface Database {
version: string;
transaction(
callback: SQLTransactionCallback,
errorCallback?: SQLTransactionErrorCallback,
successCallback?: SQLVoidCallback
): void;
readTransaction(
callback: SQLTransactionCallback,
errorCallback?: SQLTransactionErrorCallback,
successCallback?: SQLVoidCallback
): void;
}
export interface SQLVoidCallback {
(): void;
}
export interface SQLTransactionCallback {
(transaction: SQLTransaction): void;
}
export interface SQLTransactionErrorCallback {
(error: SQLError): void;
}
export interface SQLTransaction {
executeSql(
sqlStatement: string,
args?: any[],
callback?: SQLStatementCallback,
errorCallback?: SQLStatementErrorCallback
): void;
}
export interface SQLStatementCallback {
(transaction: SQLTransaction, resultSet: SQLResultSet): void;
}
export interface SQLStatementErrorCallback {
(transaction: SQLTransaction, error: SQLError): boolean;
}
export interface SQLResultSet {
insertId: number;
rowsAffected: number;
rows: SQLResultSetRowList;
}
export interface SQLResultSetRowList {
length: number;
item(index: number): any;
}
export declare class SQLError {
static UNKNOWN_ERR: number;
static DATABASE_ERR: number;
static VERSION_ERR: number;
static TOO_LARGE_ERR: number;
static QUOTA_ERR: number;
static SYNTAX_ERR: number;
static CONSTRAINT_ERR: number;
static TIMEOUT_ERR: number;
code: number;
message: string;
}
export interface WebSQLDatabase extends Database {
exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;
}
export type Query = { sql: string; args: unknown[] };
export interface ResultSetError {
error: Error;
}
export interface ResultSet {
insertId?: number;
rowsAffected: number;
rows: { [column: string]: any }[];
}
export type SQLiteCallback = (
error?: Error | null,
resultSet?: (ResultSetError | ResultSet)[]
) => void;