-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver-api.ts
135 lines (107 loc) · 2.97 KB
/
driver-api.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
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
export type SqliteValue = null | string | number | bigint | Uint8Array;
export type SqliteArguments =
| SqliteValue[]
| Record<string, SqliteValue>
| null
| undefined;
export type SqliteRowRaw = SqliteValue[];
export type SqliteRowObject = Record<string, SqliteValue>;
export type SqliteRow = SqliteRowRaw | SqliteRowObject;
export interface PrepareOptions {
bigint?: boolean;
rawResults?: boolean;
persist?: boolean;
}
export interface ResetOptions {
clearBindings?: 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;
getLastChanges(): Promise<SqliteChanges>;
close(): Promise<void>;
}
export type SqliteParameterBinding =
| (SqliteValue | undefined)[]
| Record<string, SqliteValue>
| null
| undefined;
export interface SqliteStepResult {
rows?: SqliteRow[];
done?: boolean;
}
export interface SqliteDriverStatement {
getColumns(): Promise<string[]>;
bind(parameters: SqliteParameterBinding): void;
step(n?: number, options?: StepOptions): Promise<SqliteStepResult>;
finalize(): void;
reset(options?: ResetOptions): void;
/**
* Similar to step, followed by reset, and returning number of changed rows.
*
* Avoids the need to use a separate statement to get changes.
*/
run(options?: StepOptions): Promise<SqliteChanges>;
[Symbol.dispose](): void;
}
export interface StepOptions {
requireTransaction?: boolean;
}
export interface SqliteDriverConnectionPool {
/**
* Reserve a connection for exclusive use.
*
* If there is no available connection, this will wait until one is available.
* @param options
*/
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;
}