-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatement.js
More file actions
64 lines (57 loc) · 1.48 KB
/
Statement.js
File metadata and controls
64 lines (57 loc) · 1.48 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
/**
* Statement — Executes SQL against a connection.
*
* Abstract base class. Driver implementations override the protected
* _executeQuery and _executeUpdate methods.
*/
export default class Statement {
/**
* @param {Connection} connection
*/
constructor(connection) {
this._connection = connection;
this._closed = false;
}
/**
* Execute a query that returns a ResultSet.
* @param {string} sql
* @returns {Promise<ResultSet>}
*/
async executeQuery(sql) {
this._checkClosed();
return this._executeQuery(sql);
}
/**
* Execute an INSERT, UPDATE, DELETE, or DDL statement.
* @param {string} sql
* @returns {Promise<number>} affected row count
*/
async executeUpdate(sql) {
this._checkClosed();
return this._executeUpdate(sql);
}
/**
* Execute any SQL. Returns true if the result is a ResultSet.
* @param {string} sql
* @returns {Promise<boolean>}
*/
async execute(sql) {
this._checkClosed();
return this._execute(sql);
}
/** Close and release resources. */
async close() {
this._closed = true;
}
/** @returns {boolean} */
isClosed() {
return this._closed;
}
_checkClosed() {
if (this._closed) throw new Error('Statement is closed');
}
// Override in driver implementations
async _executeQuery(sql) { throw new Error('Not implemented'); }
async _executeUpdate(sql) { throw new Error('Not implemented'); }
async _execute(sql) { throw new Error('Not implemented'); }
}