node-firebird 2.9.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +211 -6
- package/lib/index.d.ts +5 -0
- package/lib/index.js +32 -1
- package/lib/pool.js +1 -1
- package/lib/srp.d.ts +3 -3
- package/lib/types.d.ts +165 -5
- package/lib/uri.js +2 -2
- package/lib/wire/connection.d.ts +92 -59
- package/lib/wire/connection.js +279 -58
- package/lib/wire/const.d.ts +9 -1
- package/lib/wire/const.js +23 -9
- package/lib/wire/database.d.ts +51 -26
- package/lib/wire/database.js +53 -20
- package/lib/wire/eventConnection.js +5 -3
- package/lib/wire/query-stream.d.ts +18 -0
- package/lib/wire/query-stream.js +73 -0
- package/lib/wire/serialize.d.ts +20 -2
- package/lib/wire/serialize.js +7 -0
- package/lib/wire/service.d.ts +42 -0
- package/lib/wire/service.js +145 -0
- package/lib/wire/socket.d.ts +3 -1
- package/lib/wire/socket.js +5 -2
- package/lib/wire/statement.d.ts +31 -19
- package/lib/wire/statement.js +1 -5
- package/lib/wire/transaction.d.ts +30 -18
- package/lib/wire/transaction.js +23 -4
- package/lib/wire/wire-types.d.ts +116 -0
- package/lib/wire/wire-types.js +10 -0
- package/lib/wire/xsqlvar.d.ts +57 -18
- package/lib/wire/xsqlvar.js +59 -0
- package/package.json +1 -1
- package/src/index.ts +36 -4
- package/src/messages.ts +1 -1
- package/src/pool.ts +1 -1
- package/src/srp.ts +6 -6
- package/src/types.ts +162 -5
- package/src/unix-crypt.ts +9 -9
- package/src/uri.ts +2 -2
- package/src/wire/connection.ts +475 -234
- package/src/wire/const.ts +23 -9
- package/src/wire/database.ts +101 -54
- package/src/wire/eventConnection.ts +8 -5
- package/src/wire/query-stream.ts +80 -0
- package/src/wire/serialize.ts +31 -0
- package/src/wire/service.ts +188 -6
- package/src/wire/socket.ts +17 -8
- package/src/wire/statement.ts +37 -29
- package/src/wire/transaction.ts +57 -32
- package/src/wire/wire-types.ts +127 -0
- package/src/wire/xsqlvar.ts +85 -7
package/lib/wire/service.js
CHANGED
|
@@ -1027,5 +1027,150 @@ class ServiceManager extends events_1.default.EventEmitter {
|
|
|
1027
1027
|
self._processquery(data.buffer, callback);
|
|
1028
1028
|
});
|
|
1029
1029
|
}
|
|
1030
|
+
/* Promise / async-await API — wrappers over the callback methods above. */
|
|
1031
|
+
detachAsync(force) {
|
|
1032
|
+
var self = this;
|
|
1033
|
+
return (0, callback_1.fromCallback)(function (cb) { self.detach(cb, force); });
|
|
1034
|
+
}
|
|
1035
|
+
backupAsync(options) {
|
|
1036
|
+
var self = this;
|
|
1037
|
+
return (0, callback_1.fromCallback)(function (cb) { self.backup(options, cb); });
|
|
1038
|
+
}
|
|
1039
|
+
nbackupAsync(options) {
|
|
1040
|
+
var self = this;
|
|
1041
|
+
return (0, callback_1.fromCallback)(function (cb) { self.nbackup(options, cb); });
|
|
1042
|
+
}
|
|
1043
|
+
restoreAsync(options) {
|
|
1044
|
+
var self = this;
|
|
1045
|
+
return (0, callback_1.fromCallback)(function (cb) { self.restore(options, cb); });
|
|
1046
|
+
}
|
|
1047
|
+
nrestoreAsync(options) {
|
|
1048
|
+
var self = this;
|
|
1049
|
+
return (0, callback_1.fromCallback)(function (cb) { self.nrestore(options, cb); });
|
|
1050
|
+
}
|
|
1051
|
+
setDialectAsync(db, dialect) {
|
|
1052
|
+
var self = this;
|
|
1053
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setDialect(db, dialect, cb); });
|
|
1054
|
+
}
|
|
1055
|
+
setSweepintervalAsync(db, sweepinterval) {
|
|
1056
|
+
var self = this;
|
|
1057
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setSweepinterval(db, sweepinterval, cb); });
|
|
1058
|
+
}
|
|
1059
|
+
setCachebufferAsync(db, nbpages) {
|
|
1060
|
+
var self = this;
|
|
1061
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setCachebuffer(db, nbpages, cb); });
|
|
1062
|
+
}
|
|
1063
|
+
BringOnlineAsync(db) {
|
|
1064
|
+
var self = this;
|
|
1065
|
+
return (0, callback_1.fromCallback)(function (cb) { self.BringOnline(db, cb); });
|
|
1066
|
+
}
|
|
1067
|
+
ShutdownAsync(db, kind, delay, mode) {
|
|
1068
|
+
var self = this;
|
|
1069
|
+
return (0, callback_1.fromCallback)(function (cb) { self.Shutdown(db, kind, delay, mode, cb); });
|
|
1070
|
+
}
|
|
1071
|
+
setShadowAsync(db, val) {
|
|
1072
|
+
var self = this;
|
|
1073
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setShadow(db, val, cb); });
|
|
1074
|
+
}
|
|
1075
|
+
setForcewriteAsync(db, val) {
|
|
1076
|
+
var self = this;
|
|
1077
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setForcewrite(db, val, cb); });
|
|
1078
|
+
}
|
|
1079
|
+
setReservespaceAsync(db, val) {
|
|
1080
|
+
var self = this;
|
|
1081
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setReservespace(db, val, cb); });
|
|
1082
|
+
}
|
|
1083
|
+
setReadonlyModeAsync(db) {
|
|
1084
|
+
var self = this;
|
|
1085
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setReadonlyMode(db, cb); });
|
|
1086
|
+
}
|
|
1087
|
+
setReadwriteModeAsync(db) {
|
|
1088
|
+
var self = this;
|
|
1089
|
+
return (0, callback_1.fromCallback)(function (cb) { self.setReadwriteMode(db, cb); });
|
|
1090
|
+
}
|
|
1091
|
+
validateAsync(options) {
|
|
1092
|
+
var self = this;
|
|
1093
|
+
return (0, callback_1.fromCallback)(function (cb) { self.validate(options, cb); });
|
|
1094
|
+
}
|
|
1095
|
+
commitAsync(db, transactid) {
|
|
1096
|
+
var self = this;
|
|
1097
|
+
return (0, callback_1.fromCallback)(function (cb) { self.commit(db, transactid, cb); });
|
|
1098
|
+
}
|
|
1099
|
+
rollbackAsync(db, transactid) {
|
|
1100
|
+
var self = this;
|
|
1101
|
+
return (0, callback_1.fromCallback)(function (cb) { self.rollback(db, transactid, cb); });
|
|
1102
|
+
}
|
|
1103
|
+
recoverAsync(db, transactid) {
|
|
1104
|
+
var self = this;
|
|
1105
|
+
return (0, callback_1.fromCallback)(function (cb) { self.recover(db, transactid, cb); });
|
|
1106
|
+
}
|
|
1107
|
+
getStatsAsync(options) {
|
|
1108
|
+
var self = this;
|
|
1109
|
+
return (0, callback_1.fromCallback)(function (cb) { self.getStats(options, cb); });
|
|
1110
|
+
}
|
|
1111
|
+
getLogAsync(options) {
|
|
1112
|
+
var self = this;
|
|
1113
|
+
return (0, callback_1.fromCallback)(function (cb) { self.getLog(options, cb); });
|
|
1114
|
+
}
|
|
1115
|
+
getUsersAsync(username) {
|
|
1116
|
+
var self = this;
|
|
1117
|
+
return (0, callback_1.fromCallback)(function (cb) { self.getUsers(username === undefined ? null : username, cb); });
|
|
1118
|
+
}
|
|
1119
|
+
addUserAsync(username, password, options) {
|
|
1120
|
+
var self = this;
|
|
1121
|
+
return (0, callback_1.fromCallback)(function (cb) { self.addUser(username, password, options, cb); });
|
|
1122
|
+
}
|
|
1123
|
+
editUserAsync(username, options) {
|
|
1124
|
+
var self = this;
|
|
1125
|
+
return (0, callback_1.fromCallback)(function (cb) { self.editUser(username, options, cb); });
|
|
1126
|
+
}
|
|
1127
|
+
removeUserAsync(username, rolename) {
|
|
1128
|
+
var self = this;
|
|
1129
|
+
return (0, callback_1.fromCallback)(function (cb) { self.removeUser(username, rolename === undefined ? null : rolename, cb); });
|
|
1130
|
+
}
|
|
1131
|
+
getFbserverInfosAsync(infos, options) {
|
|
1132
|
+
var self = this;
|
|
1133
|
+
return (0, callback_1.fromCallback)(function (cb) { self.getFbserverInfos(infos || {}, options || {}, cb); });
|
|
1134
|
+
}
|
|
1135
|
+
startTraceAsync(options) {
|
|
1136
|
+
var self = this;
|
|
1137
|
+
return (0, callback_1.fromCallback)(function (cb) { self.startTrace(options, cb); });
|
|
1138
|
+
}
|
|
1139
|
+
suspendTraceAsync(options) {
|
|
1140
|
+
var self = this;
|
|
1141
|
+
return (0, callback_1.fromCallback)(function (cb) { self.suspendTrace(options, cb); });
|
|
1142
|
+
}
|
|
1143
|
+
resumeTraceAsync(options) {
|
|
1144
|
+
var self = this;
|
|
1145
|
+
return (0, callback_1.fromCallback)(function (cb) { self.resumeTrace(options, cb); });
|
|
1146
|
+
}
|
|
1147
|
+
stopTraceAsync(options) {
|
|
1148
|
+
var self = this;
|
|
1149
|
+
return (0, callback_1.fromCallback)(function (cb) { self.stopTrace(options, cb); });
|
|
1150
|
+
}
|
|
1151
|
+
getTraceListAsync(options) {
|
|
1152
|
+
var self = this;
|
|
1153
|
+
return (0, callback_1.fromCallback)(function (cb) { self.getTraceList(options || {}, cb); });
|
|
1154
|
+
}
|
|
1155
|
+
readlineAsync(options) {
|
|
1156
|
+
var self = this;
|
|
1157
|
+
return (0, callback_1.fromCallback)(function (cb) { self.readline(options || {}, cb); });
|
|
1158
|
+
}
|
|
1159
|
+
readeofAsync(options) {
|
|
1160
|
+
var self = this;
|
|
1161
|
+
return (0, callback_1.fromCallback)(function (cb) { self.readeof(options || {}, cb); });
|
|
1162
|
+
}
|
|
1163
|
+
hasRunningActionAsync(options) {
|
|
1164
|
+
var self = this;
|
|
1165
|
+
return (0, callback_1.fromCallback)(function (cb) { self.hasRunningAction(options || {}, cb); });
|
|
1166
|
+
}
|
|
1167
|
+
readusersAsync(options) {
|
|
1168
|
+
var self = this;
|
|
1169
|
+
return (0, callback_1.fromCallback)(function (cb) { self.readusers(options || {}, cb); });
|
|
1170
|
+
}
|
|
1171
|
+
readlimboAsync(options) {
|
|
1172
|
+
var self = this;
|
|
1173
|
+
return (0, callback_1.fromCallback)(function (cb) { self.readlimbo(options || {}, cb); });
|
|
1174
|
+
}
|
|
1030
1175
|
}
|
|
1031
1176
|
module.exports = ServiceManager;
|
package/lib/wire/socket.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ declare class Arc4 {
|
|
|
20
20
|
*/
|
|
21
21
|
declare class Socket {
|
|
22
22
|
static Arc4: typeof Arc4;
|
|
23
|
+
end: net.Socket['end'];
|
|
24
|
+
removeAllListeners: net.Socket['removeAllListeners'];
|
|
23
25
|
_socket: net.Socket;
|
|
24
26
|
compress: boolean;
|
|
25
27
|
compressor: zlib.Deflate | null;
|
|
@@ -30,7 +32,7 @@ declare class Socket {
|
|
|
30
32
|
encrypt: boolean;
|
|
31
33
|
encryptCipher: any;
|
|
32
34
|
decryptCipher: any;
|
|
33
|
-
constructor(port: number, host: string);
|
|
35
|
+
constructor(port: number, host: string, enableKeepAlive?: boolean, keepAliveInitialDelay?: number);
|
|
34
36
|
/**
|
|
35
37
|
* Decompress and/or decrypt data when received.
|
|
36
38
|
* Override on data event.
|
package/lib/wire/socket.js
CHANGED
|
@@ -82,10 +82,13 @@ class ChaChaCipher {
|
|
|
82
82
|
*/
|
|
83
83
|
class Socket {
|
|
84
84
|
static { this.Arc4 = Arc4; }
|
|
85
|
-
constructor(port, host) {
|
|
85
|
+
constructor(port, host, enableKeepAlive = true, keepAliveInitialDelay = 60000) {
|
|
86
|
+
this.compress = false;
|
|
86
87
|
this._socket = net_1.default.createConnection(port, host);
|
|
87
88
|
this._socket.setNoDelay(true);
|
|
88
|
-
|
|
89
|
+
// TCP keepalive probing detects dead/stale connections; the delay is
|
|
90
|
+
// how long the socket must be idle before the first probe.
|
|
91
|
+
this._socket.setKeepAlive(enableKeepAlive, keepAliveInitialDelay);
|
|
89
92
|
this.compressor = null;
|
|
90
93
|
this.compressorBuffer = [];
|
|
91
94
|
this.decompressor = null;
|
package/lib/wire/statement.d.ts
CHANGED
|
@@ -3,13 +3,21 @@
|
|
|
3
3
|
* Statement
|
|
4
4
|
*
|
|
5
5
|
***************************************/
|
|
6
|
+
import { type Callback, type SimpleCallback } from '../callback';
|
|
7
|
+
import type Connection from './connection';
|
|
8
|
+
import type Transaction from './transaction';
|
|
9
|
+
import type { SQLVarBase } from './xsqlvar';
|
|
10
|
+
import type { QueryOptions, QueryParams } from '../types';
|
|
6
11
|
declare class Statement {
|
|
7
|
-
connection:
|
|
12
|
+
connection: Connection;
|
|
8
13
|
query: string;
|
|
9
14
|
type: number;
|
|
10
|
-
output:
|
|
11
|
-
input:
|
|
12
|
-
options
|
|
15
|
+
output: SQLVarBase[];
|
|
16
|
+
input: SQLVarBase[];
|
|
17
|
+
/** per-execute query options (asObject/asStream/timeout/...) */
|
|
18
|
+
options: (QueryOptions & {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}) | undefined;
|
|
13
21
|
handle: number;
|
|
14
22
|
plan: string;
|
|
15
23
|
/**
|
|
@@ -18,27 +26,31 @@ declare class Statement {
|
|
|
18
26
|
* null/undefined otherwise. Set by Transaction.newStatement.
|
|
19
27
|
*/
|
|
20
28
|
namedParams?: string[] | null;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
/** set when an execute/fetch on this statement errored — the statement
|
|
30
|
+
* is dropped on release instead of going back into the cache */
|
|
31
|
+
_failed?: boolean;
|
|
32
|
+
/** rows fetched so far by the current cursor (decodeResponse) */
|
|
33
|
+
nbrowsfetched?: number;
|
|
34
|
+
constructor(connection: Connection);
|
|
35
|
+
close(callback?: SimpleCallback): void;
|
|
36
|
+
drop(callback?: SimpleCallback): void;
|
|
37
|
+
release(callback?: SimpleCallback): void;
|
|
38
|
+
execute(transaction: Transaction, params?: any, callback?: any, options?: any): void;
|
|
39
|
+
fetch(transaction: Transaction, count: number | string, callback: Callback): void;
|
|
40
|
+
fetchScroll(transaction: Transaction, direction: string | number, offset?: any, count?: any, callback?: any): void;
|
|
41
|
+
fetchAll(transaction: Transaction, callback: Callback): void;
|
|
30
42
|
/**
|
|
31
43
|
* Execute this statement once per row via the Firebird 4 batch API
|
|
32
44
|
* (protocol 16+). `rows` is an array of parameter arrays — or, when the
|
|
33
45
|
* statement was prepared with named placeholders, of values-by-name
|
|
34
46
|
* objects (the two forms can be mixed).
|
|
35
47
|
*/
|
|
36
|
-
executeBatch(transaction:
|
|
37
|
-
executeAsync(transaction:
|
|
38
|
-
executeBatchAsync(transaction:
|
|
39
|
-
fetchAsync(transaction:
|
|
40
|
-
fetchScrollAsync(transaction:
|
|
41
|
-
fetchAllAsync(transaction:
|
|
48
|
+
executeBatch(transaction: Transaction, rows: QueryParams[], callback?: any, options?: any): void;
|
|
49
|
+
executeAsync(transaction: Transaction, params?: any, options?: any): Promise<any>;
|
|
50
|
+
executeBatchAsync(transaction: Transaction, rows: QueryParams[], options?: any): Promise<any>;
|
|
51
|
+
fetchAsync(transaction: Transaction, count: number | string): Promise<any>;
|
|
52
|
+
fetchScrollAsync(transaction: Transaction, direction: string | number, offset?: any, count?: any): Promise<any>;
|
|
53
|
+
fetchAllAsync(transaction: Transaction): Promise<any>;
|
|
42
54
|
closeAsync(): Promise<void>;
|
|
43
55
|
dropAsync(): Promise<void>;
|
|
44
56
|
releaseAsync(): Promise<void>;
|
package/lib/wire/statement.js
CHANGED
|
@@ -17,11 +17,7 @@ class Statement {
|
|
|
17
17
|
this.connection.dropStatement(this, callback);
|
|
18
18
|
}
|
|
19
19
|
release(callback) {
|
|
20
|
-
|
|
21
|
-
if (cache_query)
|
|
22
|
-
this.connection.closeStatement(this, callback);
|
|
23
|
-
else
|
|
24
|
-
this.connection.dropStatement(this, callback);
|
|
20
|
+
this.connection.releaseStatement(this, callback);
|
|
25
21
|
}
|
|
26
22
|
execute(transaction, params, callback, options) {
|
|
27
23
|
if (params instanceof Function) {
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import { type Callback, type SimpleCallback } from '../callback';
|
|
2
|
+
import type Connection from './connection';
|
|
3
|
+
import type Database from './database';
|
|
4
|
+
import type Statement from './statement';
|
|
5
|
+
import type { BatchCb, StatementCb, InternalQueryOptions } from './wire-types';
|
|
6
|
+
import type { BatchOptions, BatchResult, QueryOptions, QueryParams, QueryStreamOptions, SequentialCallback } from '../types';
|
|
1
7
|
declare class Transaction {
|
|
2
|
-
connection:
|
|
3
|
-
db:
|
|
8
|
+
connection: Connection;
|
|
9
|
+
db: Database;
|
|
4
10
|
handle: number;
|
|
5
|
-
|
|
6
|
-
constructor(connection: any);
|
|
11
|
+
constructor(connection: Connection);
|
|
7
12
|
/** Per-call options.namedPlaceholders overrides the connection option. */
|
|
8
13
|
private namedPlaceholdersEnabled;
|
|
9
|
-
newStatement(query: string, callback:
|
|
10
|
-
execute(query: string, params?:
|
|
11
|
-
sequentially(query: string, params?: any, on?: any, callback?: any, options?:
|
|
12
|
-
|
|
14
|
+
newStatement(query: string, callback: StatementCb, options?: InternalQueryOptions): void;
|
|
15
|
+
execute(query: string, params?: QueryParams | Callback, callback?: any, options?: InternalQueryOptions): void;
|
|
16
|
+
sequentially(query: string, params?: any, on?: any, callback?: any, options?: InternalQueryOptions | boolean): this;
|
|
17
|
+
/**
|
|
18
|
+
* Run `query` inside this transaction and return an object-mode
|
|
19
|
+
* Readable emitting one row per chunk, with real backpressure (see
|
|
20
|
+
* Database.queryStream). The transaction is NOT committed when the
|
|
21
|
+
* stream ends — commit or roll back yourself.
|
|
22
|
+
*/
|
|
23
|
+
queryStream(query: string, params?: QueryParams, options?: QueryStreamOptions): import("node:stream").Readable;
|
|
24
|
+
query(query: string, params?: QueryParams | Callback, callback?: any, options?: InternalQueryOptions): void;
|
|
13
25
|
/**
|
|
14
26
|
* Execute `query` once per row in `rows` using the Firebird 4 batch API
|
|
15
27
|
* (protocol 16+, single network flush). The callback receives a
|
|
@@ -19,16 +31,16 @@ declare class Transaction {
|
|
|
19
31
|
* commit or roll back yourself (or use db.executeBatch for
|
|
20
32
|
* all-or-nothing semantics).
|
|
21
33
|
*/
|
|
22
|
-
executeBatch(query: string, rows:
|
|
23
|
-
executeBatchAsync(query: string, rows:
|
|
24
|
-
commit(callback?:
|
|
25
|
-
rollback(callback?:
|
|
26
|
-
commitRetaining(callback?:
|
|
27
|
-
rollbackRetaining(callback?:
|
|
28
|
-
queryAsync(query: string, params?:
|
|
29
|
-
executeAsync(query: string, params?:
|
|
30
|
-
sequentiallyAsync(query: string, params?: any, on?:
|
|
31
|
-
newStatementAsync(query: string): Promise<
|
|
34
|
+
executeBatch(query: string, rows: QueryParams[], callback?: BatchCb, options?: BatchOptions & QueryOptions): void;
|
|
35
|
+
executeBatchAsync(query: string, rows: QueryParams[], options?: BatchOptions & QueryOptions): Promise<BatchResult>;
|
|
36
|
+
commit(callback?: SimpleCallback): void;
|
|
37
|
+
rollback(callback?: SimpleCallback): void;
|
|
38
|
+
commitRetaining(callback?: SimpleCallback): void;
|
|
39
|
+
rollbackRetaining(callback?: SimpleCallback): void;
|
|
40
|
+
queryAsync(query: string, params?: QueryParams, options?: InternalQueryOptions): Promise<any[]>;
|
|
41
|
+
executeAsync(query: string, params?: QueryParams, options?: InternalQueryOptions): Promise<any[]>;
|
|
42
|
+
sequentiallyAsync(query: string, params?: any, on?: SequentialCallback, options?: InternalQueryOptions | boolean): Promise<void>;
|
|
43
|
+
newStatementAsync(query: string): Promise<Statement>;
|
|
32
44
|
commitAsync(): Promise<void>;
|
|
33
45
|
rollbackAsync(): Promise<void>;
|
|
34
46
|
commitRetainingAsync(): Promise<void>;
|
package/lib/wire/transaction.js
CHANGED
|
@@ -6,6 +6,7 @@ const callback_1 = require("../callback");
|
|
|
6
6
|
const named_params_1 = require("../named-params");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const const_1 = __importDefault(require("./const"));
|
|
9
|
+
const query_stream_1 = __importDefault(require("./query-stream"));
|
|
9
10
|
/***************************************
|
|
10
11
|
*
|
|
11
12
|
* Transaction
|
|
@@ -55,6 +56,9 @@ class Transaction {
|
|
|
55
56
|
newStatement(query, callback, options) {
|
|
56
57
|
var cnx = this.connection;
|
|
57
58
|
var self = this;
|
|
59
|
+
// the public strict callback shape and the internal optional-args
|
|
60
|
+
// shape only differ in optionality; treat it as the internal one
|
|
61
|
+
var cb = callback;
|
|
58
62
|
// With namedPlaceholders on, prepare the positional rewrite and
|
|
59
63
|
// remember the name order on the statement so statement.execute can
|
|
60
64
|
// accept a values-by-name object. The rewritten SQL is the cache key.
|
|
@@ -69,9 +73,9 @@ class Transaction {
|
|
|
69
73
|
var deliver = function (err, statement) {
|
|
70
74
|
if (statement)
|
|
71
75
|
statement.namedParams = names;
|
|
72
|
-
|
|
76
|
+
cb(err, statement);
|
|
73
77
|
};
|
|
74
|
-
var query_cache = cnx.
|
|
78
|
+
var query_cache = cnx.takeCachedStatement(query);
|
|
75
79
|
if (query_cache) {
|
|
76
80
|
deliver(null, query_cache);
|
|
77
81
|
}
|
|
@@ -95,11 +99,15 @@ class Transaction {
|
|
|
95
99
|
}
|
|
96
100
|
var self = this;
|
|
97
101
|
this.newStatement(query, function (err, statement) {
|
|
98
|
-
if (err) {
|
|
102
|
+
if (err || !statement) {
|
|
99
103
|
(0, callback_1.doError)(err, callback);
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
102
106
|
function dropError(err) {
|
|
107
|
+
// do not put a statement that just failed back into the cache
|
|
108
|
+
// (statement is guaranteed by the guard above; hoisting keeps
|
|
109
|
+
// the narrowing from reaching this function declaration)
|
|
110
|
+
statement._failed = true;
|
|
103
111
|
statement.release();
|
|
104
112
|
(0, callback_1.doCallback)(err, callback);
|
|
105
113
|
}
|
|
@@ -209,6 +217,15 @@ class Transaction {
|
|
|
209
217
|
self.execute(query, params, callback, options);
|
|
210
218
|
return self;
|
|
211
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Run `query` inside this transaction and return an object-mode
|
|
222
|
+
* Readable emitting one row per chunk, with real backpressure (see
|
|
223
|
+
* Database.queryStream). The transaction is NOT committed when the
|
|
224
|
+
* stream ends — commit or roll back yourself.
|
|
225
|
+
*/
|
|
226
|
+
queryStream(query, params, options) {
|
|
227
|
+
return (0, query_stream_1.default)(this, query, params, options);
|
|
228
|
+
}
|
|
212
229
|
query(query, params, callback, options = {}) {
|
|
213
230
|
if (params instanceof Function) {
|
|
214
231
|
callback = params;
|
|
@@ -235,11 +252,13 @@ class Transaction {
|
|
|
235
252
|
executeBatch(query, rows, callback, options) {
|
|
236
253
|
var self = this;
|
|
237
254
|
this.newStatement(query, function (err, statement) {
|
|
238
|
-
if (err) {
|
|
255
|
+
if (err || !statement) {
|
|
239
256
|
(0, callback_1.doError)(err, callback);
|
|
240
257
|
return;
|
|
241
258
|
}
|
|
242
259
|
statement.executeBatch(self, rows, function (err, result) {
|
|
260
|
+
if (err)
|
|
261
|
+
statement._failed = true;
|
|
243
262
|
statement.release();
|
|
244
263
|
if (callback)
|
|
245
264
|
callback(err, result);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/***************************************
|
|
2
|
+
*
|
|
3
|
+
* Internal wire-protocol types (type-only module)
|
|
4
|
+
*
|
|
5
|
+
* Shared vocabulary for the wire core (connection/statement/transaction/
|
|
6
|
+
* database). Nothing here exists at runtime.
|
|
7
|
+
*
|
|
8
|
+
***************************************/
|
|
9
|
+
import type { Callback, FbStatusItem } from '../callback';
|
|
10
|
+
import type Statement from './statement';
|
|
11
|
+
import type { BatchResult, Options, QueryOptions, Statement as PublicStatement } from '../types';
|
|
12
|
+
/**
|
|
13
|
+
* One entry of the connection's response queue (`connection._queue`).
|
|
14
|
+
* The function itself is the user/driver callback; the extra properties
|
|
15
|
+
* steer decodeResponse:
|
|
16
|
+
*
|
|
17
|
+
* - `response` — pre-allocated object the op_response decode fills in
|
|
18
|
+
* (a Statement, Transaction, or plain response object).
|
|
19
|
+
* - `statement` — statement whose `output` describes the rows of an
|
|
20
|
+
* op_fetch_response / op_sql_response.
|
|
21
|
+
* - `lazy_count`— number of chained lazy op_responses this entry consumes
|
|
22
|
+
* (ptype_lazy_send batches e.g. allocate+prepare).
|
|
23
|
+
*
|
|
24
|
+
* Deferred ops (op_free_statement, op_close_blob, ...) push `undefined`
|
|
25
|
+
* placeholders so every server response still pairs with one entry.
|
|
26
|
+
*/
|
|
27
|
+
export interface QueueCallback {
|
|
28
|
+
(err?: any, obj?: any): void;
|
|
29
|
+
response?: any;
|
|
30
|
+
statement?: Statement;
|
|
31
|
+
lazy_count?: number;
|
|
32
|
+
}
|
|
33
|
+
/** A queue entry: a callback, or a placeholder for a deferred op. */
|
|
34
|
+
export type QueueEntry = QueueCallback | undefined;
|
|
35
|
+
/** XDR quad — 64-bit value as two 32-bit halves (blob ids, object ids). */
|
|
36
|
+
export interface Quad {
|
|
37
|
+
high: number;
|
|
38
|
+
low: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Decoded op_response packet (see parseOpResponse): object handle, object
|
|
42
|
+
* id, optional info buffer and, on failure, the status vector. Statement /
|
|
43
|
+
* Transaction responses are these fields merged onto the pre-allocated
|
|
44
|
+
* object from QueueCallback.response.
|
|
45
|
+
*/
|
|
46
|
+
export interface WireResponse {
|
|
47
|
+
handle?: number;
|
|
48
|
+
oid?: Quad;
|
|
49
|
+
buffer?: Buffer;
|
|
50
|
+
status?: FbStatusItem[];
|
|
51
|
+
/** isc_arg_warning entries — attached to a SUCCESSFUL response */
|
|
52
|
+
warnings?: FbStatusItem[];
|
|
53
|
+
sqlcode?: number;
|
|
54
|
+
message?: string;
|
|
55
|
+
}
|
|
56
|
+
/** Result of decoding op_fetch_response / op_sql_response row data. */
|
|
57
|
+
export interface FetchResult {
|
|
58
|
+
data: any[];
|
|
59
|
+
/** true when the cursor is exhausted (fetch status 100 / singleton). */
|
|
60
|
+
fetched: boolean;
|
|
61
|
+
/** pending blobAsText fetches to resolve before delivering rows. */
|
|
62
|
+
arrBlob?: any[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Protocol negotiation result decoded from op_accept / op_cond_accept /
|
|
66
|
+
* op_accept_data, plus the auth/crypt state accumulated during the
|
|
67
|
+
* handshake (op_cont_auth rounds, wire-crypt keys).
|
|
68
|
+
*/
|
|
69
|
+
export interface AcceptPacket {
|
|
70
|
+
protocolVersion: number;
|
|
71
|
+
protocolArchitecture: number;
|
|
72
|
+
protocolMinimumType: number;
|
|
73
|
+
compress: boolean;
|
|
74
|
+
pluginName: string;
|
|
75
|
+
authData: any;
|
|
76
|
+
sessionKey?: any;
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Query options as the wire core sees them: the public QueryOptions plus
|
|
81
|
+
* the internal row-delivery flags set by the Database/Transaction helpers
|
|
82
|
+
* (query / sequentially / queryStream).
|
|
83
|
+
*/
|
|
84
|
+
export type InternalQueryOptions = QueryOptions & {
|
|
85
|
+
/** deliver rows as objects keyed by column alias */
|
|
86
|
+
asObject?: boolean;
|
|
87
|
+
/** deliver rows one by one (row events / `on` delegate) instead of accumulating */
|
|
88
|
+
asStream?: boolean;
|
|
89
|
+
/** per-row delegate installed by sequentially() */
|
|
90
|
+
on?: (row: any, index: number, meta: any[], next: (err?: any) => void) => void;
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* newStatement callback: the internal optional-args shape, or the public
|
|
95
|
+
* strict shape (non-optional statement) declared in types.ts.
|
|
96
|
+
*/
|
|
97
|
+
export type StatementCb = Callback<Statement> | ((err: Error | null, statement: PublicStatement) => void);
|
|
98
|
+
/**
|
|
99
|
+
* executeBatch callback: the internal optional-args shape, or the public
|
|
100
|
+
* strict shape (non-optional result) declared in types.ts.
|
|
101
|
+
*/
|
|
102
|
+
export type BatchCb = Callback<BatchResult> | ((err: any, result: BatchResult) => void);
|
|
103
|
+
/**
|
|
104
|
+
* Connection options as the wire core sees them: the public Options plus
|
|
105
|
+
* internal flags set by the driver itself.
|
|
106
|
+
*/
|
|
107
|
+
export type InternalOptions = Options & {
|
|
108
|
+
/** set by the pool so detach() returns the connection instead */
|
|
109
|
+
isPool?: boolean;
|
|
110
|
+
/** override path of the firebird.msg error-message file */
|
|
111
|
+
messageFile?: string;
|
|
112
|
+
/** legacy statement-cache flags (mapped onto statementCacheSize) */
|
|
113
|
+
cacheQuery?: boolean;
|
|
114
|
+
maxCachedQuery?: number;
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/***************************************
|
|
3
|
+
*
|
|
4
|
+
* Internal wire-protocol types (type-only module)
|
|
5
|
+
*
|
|
6
|
+
* Shared vocabulary for the wire core (connection/statement/transaction/
|
|
7
|
+
* database). Nothing here exists at runtime.
|
|
8
|
+
*
|
|
9
|
+
***************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|