-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.d.ts
321 lines (278 loc) · 8.73 KB
/
index.d.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
declare namespace databasejs {
interface ConnectionStruct {
driverName?: string;
DriverName?: string;
username?:string;
Username?:string;
password?:string;
Password?:string;
hostname?:string;
Hostname?:string;
port?:string;
Port?:string;
database?:string;
Database?:string;
parameters?:string;
Parameters?:string;
}
class ConnectionObject {
constructor(driverName: string, username: string, password: string, hostname: string, port: string, database: string, driver?: any);
/** Splits the parameter string into an object of key/value pairs */
parseParameters() : Object;
/** Makes a URL from this ConnectionObject */
makeURL() : string;
/** Allows plain object to be used to construct a ConnectionObject */
static fromPlain(obj: ConnectionStruct, driver?: any): ConnectionObject;
}
class Statement {
/**
* Executes the SQL query. If any parameters are required, they
* will be passed to the query here.
*
* @param {any[]} args arguments to replace into the prepared SQL string
* @returns {Promise<Array<any>}
* @memberof Statement
*/
query(... args: any[]) : Promise<Array<any>>;
/**
* Prepares the statement for use with parameters.
*
* @memberof Statement
*/
prepare() : void;
/**
* Executes the SQL statement. If any parameters are required, they
* will be passed in here.
*
* @param {any[]} args arguments to replace into the prepared SQL string
* @returns {Promise<any>}
* @memberof Statement
*/
execute(... args: any[]) : Promise<void | Array<any>>;
}
class PreparedStatement extends Statement {}
class Connection {
constructor(url: string | ConnectionStruct, driver?: any);
readonly URL: string;
readonly Driver: Object;
/**
* Creates a statement with the passed SQL.
*
* @param {string} sql the SQL string to use for the statement
* @returns {Statement} a Statement object
* @memberof Connection
*/
createStatement(sql: string) : Statement;
/**
* Creates and prepares a statement with the passed SQL.
*
* @param {string} sql the SQL string to use for the statement
* @returns {PreparedStatement} a PreparedStatement object
* @memberof Connection
*/
prepareStatement(sql: string) : PreparedStatement;
/**
* Closes the underlying connection.
*
* @returns {Promise<boolean>}
* @memberof Connection
*/
close() : Promise<boolean>;
/**
* Indicates whether the underlying driver can support transactions;
*
* @returns {boolean}
* @memberof Connection
*/
isTransactionSupported() : boolean;
/**
* Returns true if the underlying driver is in a transaction, false
* if it does not support transactions or is not in a transaction.
*
* @returns {boolean}
* @memberof Connection
*/
inTransaction() : boolean;
/**
* Returns a boolean promise: true if a transaction was started and
* false if it was not started. Transactions can fail to start if
* another transaction is already running or if the driver does
* not support transactions.
*
* @returns {Promise<boolean>}
* @memberof Connection
*/
beginTransaction() : Promise<boolean>;
/**
* Returns a boolean promise: true if a transaction was committed and
* false if one was not committed. Transactions can fail to commit if
* no transaction was started, or if the driver does not support
* transactions.
*
* @returns {Promise<boolean>}
* @memberof Connection
*/
commit() : Promise<boolean>;
/**
* Returns a boolean promise: true if a transaction was rolled back and
* false if one was not rolled back. Transactions can fail to roll back if
* no transaction was started, or if the driver does not support
* transactions.
*
* @returns {Promise<boolean>}
* @memberof Connection
*/
rollback() : Promise<boolean>;
}
class PooledConnection extends Connection {
/**
* Closes the connection completely
*
* @returns {Promise<boolean>}
* @memberof PooledConnection
*/
kill() : Promise<boolean>;
/**
* Frees this connection for the pool
*
* @returns {Promise<boolean>}
* @memberof PooledConnection
*/
close() : Promise<boolean>;
}
interface Pool {
/**
* The number of used connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Available : number;
/**
* The number of used connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly InUse : number;
/**
* The total number of connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Count : number;
/**
* The prefered number of connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Size : number;
/**
* Grabs an available connection from the pool
*
* @returns {PooledConnection}
* @memberof Pool
*/
getConnection() : PooledConnection;
/**
* Closes the underlying connections and empties the pool
*
* @returns {Promise<Array<boolean>>}
* @memberof Pool
*/
close() : Promise<Array<boolean>>
}
class StaticPool implements Pool {
constructor(url: string | ConnectionObject, poolSize: number, driver?: any);
/**
* The number of used connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Available : number;
/**
* The number of used connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly InUse : number;
/**
* The total number of connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Count : number;
/**
* The prefered number of connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Size : number;
/**
* Grabs an available connection from the pool
*
* @returns {PooledConnection}
* @memberof Pool
*/
getConnection() : PooledConnection;
/**
* Closes the underlying connections and empties the pool
*
* @returns {Promise<Array<boolean>>}
* @memberof Pool
*/
close() : Promise<Array<boolean>>
}
class DynamicPool implements Pool {
constructor(url: string | ConnectionObject, poolSize: number, driver?: any);
/**
* The number of used connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Available : number;
/**
* The number of used connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly InUse : number;
/**
* The total number of connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Count : number;
/**
* The prefered number of connections in the pool
* @returns {number}
* @readonly
* @memberof Pool
*/
readonly Size : number;
/**
* Grabs an available connection from the pool
*
* @returns {PooledConnection}
* @memberof Pool
*/
getConnection() : PooledConnection;
/**
* Closes the underlying connections and empties the pool
*
* @returns {Promise<Array<boolean>>}
* @memberof Pool
*/
close() : Promise<Array<boolean>>
}
}
export = databasejs;