-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
195 lines (192 loc) · 7.02 KB
/
index.d.ts
File metadata and controls
195 lines (192 loc) · 7.02 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
export interface RunResult {
changes: number;
}
export declare class Database {
/**
* Open a database asynchronously. Returns a Promise that resolves to a Database instance.
*
* Accepts:
* - `:memory:` or empty string for in-memory database
* - `memory://` for in-memory database
* - `file:///path/to/db` for file-based database
* - Bare path like `./mydb` for file-based database
*/
static open(path: string): Promise<Database>;
/**
* Open a database synchronously.
*/
static openSync(path: string): Database;
/**
* Clone this database handle. The clone shares the same underlying engine
* (data, indexes, transactions) but has its own executor and error state.
* Each clone must be closed independently.
*/
clone(): Database;
/**
* Execute a DDL/DML statement. Returns Promise<{ changes: number }>.
*
* @param sql - SQL statement
* @param params - Optional: Array for positional ($1, $2) or Object for named (:key)
*/
execute(
sql: string,
params?: any[] | Record<string, any>,
): Promise<RunResult>;
/**
* Execute a DDL statement. Returns Promise<void>.
*/
exec(sql: string): Promise<void>;
/**
* Query rows. Returns Promise<Array<Object>>.
*
* Each row is an object with column names as keys.
*/
query(
sql: string,
params?: any[] | Record<string, any>,
): Promise<Record<string, any>[]>;
/** Query a single row. Returns Promise<Object | null>. */
queryOne(
sql: string,
params?: any[] | Record<string, any>,
): Promise<Record<string, any> | null>;
/**
* Query rows in raw format. Returns Promise<{ columns: string[], rows: any[][] }>.
*
* Faster than query(). Skips per-row object creation.
*/
queryRaw(
sql: string,
params?: any[] | Record<string, any>,
): Promise<{ columns: string[]; rows: any[][] }>;
/**
* Execute a DML statement synchronously. Returns { changes: number }.
*
* Faster than execute() for simple operations. No async overhead.
*/
executeSync(sql: string, params?: any[] | Record<string, any>): RunResult;
/** Execute a DDL statement synchronously. */
execSync(sql: string): void;
/** Query rows synchronously. Returns Array<Object>. */
querySync(
sql: string,
params?: any[] | Record<string, any>,
): Record<string, any>[];
/** Query a single row synchronously. Returns Object | null. */
queryOneSync(
sql: string,
params?: any[] | Record<string, any>,
): Record<string, any> | null;
/** Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }. */
queryRawSync(
sql: string,
params?: any[] | Record<string, any>,
): { columns: string[]; rows: any[][] };
/**
* Execute the same SQL with multiple param sets in a single call.
* Auto-wraps in a transaction: begin, execute all, commit.
* Returns { changes: total_rows_affected }.
*/
executeBatchSync(sql: string, paramsArray: any[][]): RunResult;
/** Create a prepared statement (synchronous). */
prepare(sql: string): PreparedStatement;
/** Begin a transaction. Returns Promise<Transaction>. */
begin(): Promise<Transaction>;
/** Begin a transaction synchronously. Returns Transaction. */
beginSync(): Transaction;
/** Close the database. Returns Promise<void>. */
close(): Promise<void>;
/** Close the database synchronously. */
closeSync(): void;
}
export type JsDatabase = Database;
export declare class PreparedStatement {
/** Execute the statement (DML). Returns Promise<{ changes: number }>. */
execute(params?: any[] | Record<string, any>): Promise<RunResult>;
/** Query rows. Returns Promise<Array<Object>>. */
query(params?: any[] | Record<string, any>): Promise<Record<string, any>[]>;
/** Query single row. Returns Promise<Object | null>. */
queryOne(
params?: any[] | Record<string, any>,
): Promise<Record<string, any> | null>;
/** Query rows in raw format. Returns Promise<{ columns: string[], rows: any[][] }>. */
queryRaw(
params?: any[] | Record<string, any>,
): Promise<{ columns: string[]; rows: any[][] }>;
/** Execute synchronously. Returns { changes: number }. */
executeSync(params?: any[] | Record<string, any>): RunResult;
/** Query rows synchronously. Returns Array<Object>. */
querySync(params?: any[] | Record<string, any>): Record<string, any>[];
/** Query single row synchronously. Returns Object | null. */
queryOneSync(
params?: any[] | Record<string, any>,
): Record<string, any> | null;
/** Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }. */
queryRawSync(params?: any[] | Record<string, any>): {
columns: string[];
rows: any[][];
};
/**
* Execute the prepared SQL with multiple param sets in a single call.
* Returns { changes: total_rows_affected }.
*/
executeBatchSync(paramsArray: any[][]): RunResult;
/** Get the SQL text of this prepared statement. */
get sql(): string;
/** Release the prepared statement. */
finalize(): void;
}
export type JsPreparedStatement = PreparedStatement;
export declare class Transaction {
/** Execute a DML statement within the transaction. Returns Promise<{ changes: number }>. */
execute(
sql: string,
params?: any[] | Record<string, any>,
): Promise<RunResult>;
/** Query rows within the transaction. Returns Promise<Array<Object>>. */
query(
sql: string,
params?: any[] | Record<string, any>,
): Promise<Record<string, any>[]>;
/** Query a single row within the transaction. Returns Promise<Object | null>. */
queryOne(
sql: string,
params?: any[] | Record<string, any>,
): Promise<Record<string, any> | null>;
/** Query rows in raw format within the transaction. Returns Promise<{ columns: string[], rows: any[][] }>. */
queryRaw(
sql: string,
params?: any[] | Record<string, any>,
): Promise<{ columns: string[]; rows: any[][] }>;
/** Commit the transaction. Returns Promise<void>. */
commit(): Promise<void>;
/** Rollback the transaction. Returns Promise<void>. */
rollback(): Promise<void>;
/** Execute a DML statement synchronously. Returns { changes: number }. */
executeSync(sql: string, params?: any[] | Record<string, any>): RunResult;
/** Query rows synchronously. Returns Array<Object>. */
querySync(
sql: string,
params?: any[] | Record<string, any>,
): Record<string, any>[];
/** Query a single row synchronously. Returns Object | null. */
queryOneSync(
sql: string,
params?: any[] | Record<string, any>,
): Record<string, any> | null;
/** Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }. */
queryRawSync(
sql: string,
params?: any[] | Record<string, any>,
): { columns: string[]; rows: any[][] };
/** Commit the transaction synchronously. */
commitSync(): void;
/**
* Execute the same SQL with multiple param sets in a single call.
* Returns { changes: total_rows_affected }.
*/
executeBatchSync(sql: string, paramsArray: any[][]): RunResult;
/** Rollback the transaction synchronously. */
rollbackSync(): void;
}
export type JsTransaction = Transaction;