-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver-api.ts
More file actions
168 lines (139 loc) · 3.87 KB
/
driver-api.ts
File metadata and controls
168 lines (139 loc) · 3.87 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
export type SqliteValue = null | string | number | bigint | Uint8Array;
export type SqliteArguments =
| SqliteValue[]
| Record<string, SqliteValue>
| null
| undefined;
export type SqliteArrayRow = SqliteValue[];
export type SqliteObjectRow = Record<string, SqliteValue>;
export interface PrepareOptions {
autoFinalize?: boolean;
}
export interface SqliteDriverConnection {
/**
* Prepare a statement.
*
* Does not return any errors.
*/
prepare(sql: string, options?: PrepareOptions): SqliteDriverStatement;
onUpdate(
listener: UpdateListener,
options?: { tables?: string[]; batchLimit?: number }
): () => void;
close(): Promise<void>;
}
export type SqliteParameterBinding =
| SqliteValue[]
| Record<string, SqliteValue>
| null
| undefined;
export interface QueryOptions {
requireTransaction?: boolean;
bigint?: boolean;
}
export interface StreamQueryOptions extends QueryOptions {
chunkMaxRows?: number;
chunkMaxSize?: number;
}
export interface SqliteDriverStatement {
/**
* Run a query, and return results as an array of row objects.
*
* If the query does not return results, an empty array is returned.
*/
all(
parameters?: SqliteParameterBinding,
options?: QueryOptions
): Promise<SqliteObjectRow[]>;
/**
* Run a query, and return results as an array of row arrays.
*
* If the query does not return results, an empty array is returned.
*/
allArray(
parameters?: SqliteParameterBinding,
options?: QueryOptions
): Promise<SqliteArrayRow[]>;
/**
* Run a query, and return as an iterator of array of row object chunks.
*
* It is an error to call any other query methods on the same statement
* before the iterator has returned.
*/
stream(
parameters?: SqliteParameterBinding,
options?: StreamQueryOptions
): AsyncIterableIterator<SqliteObjectRow[]>;
/**
* Run a query, and return as an iterator of array of row array chunks.
*
* It is an error to call any other query methods on the same statement
* before the iterator has returned.
*/
streamArray(
parameters?: SqliteParameterBinding,
options?: StreamQueryOptions
): AsyncIterableIterator<SqliteArrayRow[]>;
/**
* Run a query, and return the number of changed rows, and last insert id.
*/
run(
parameters?: SqliteParameterBinding,
options?: QueryOptions
): Promise<SqliteChanges>;
/**
* Get the column names of the data returned by the query.
*/
getColumns(): Promise<string[]>;
finalize(): void;
[Symbol.dispose](): void;
}
export interface SqliteDriverConnectionPool {
/**
* Reserve a connection for exclusive use.
*
* If there is no available connection, this will wait until one is available.
*/
reserveConnection(
options?: ReserveConnectionOptions
): Promise<ReservedConnection>;
close(): Promise<void>;
[Symbol.asyncDispose](): Promise<void>;
onUpdate(
listener: UpdateListener,
options?: { tables?: string[]; batchLimit?: number }
): () => void;
}
export type UpdateListener = (event: BatchedUpdateEvent) => void;
export interface BatchedUpdateEvent {
events: UpdateEvent[];
}
export interface UpdateEvent {
table: string;
type: 'insert' | 'update' | 'delete';
rowId: bigint;
}
export interface ReservedConnection {
/** Direct handle to the underlying connection. */
connection: SqliteDriverConnection;
/** Proxied to the underlying connection */
prepare(sql: string, options?: PrepareOptions): SqliteDriverStatement;
release(): Promise<void>;
[Symbol.asyncDispose](): Promise<void>;
}
export interface ReserveConnectionOptions {
readonly?: boolean;
signal?: AbortSignal;
}
export interface SqliteChanges {
changes: number;
lastInsertRowId: bigint;
}
export interface ResultSet {
columns: string[];
rows: SqliteValue[][];
}
export interface ExecuteOptions {
chunkSize?: number;
bigint?: boolean;
}