@tdxvolt/volt-client-grpc 0.11.1 → 0.11.3
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/lib/index.cjs +64 -3
- package/package.json +1 -1
- package/src/grpc-call.js +2 -1
- package/src/volt-client.js +62 -2
package/lib/index.cjs
CHANGED
|
@@ -1026,7 +1026,8 @@ class GRPCCall extends EventEmitter__default["default"] {
|
|
|
1026
1026
|
});
|
|
1027
1027
|
|
|
1028
1028
|
if (this._initialRequest.request) {
|
|
1029
|
-
|
|
1029
|
+
// Allow callee to attach event handlers before we actually send the initial payload.
|
|
1030
|
+
process.nextTick(() => this._call.write(this._initialRequest.request));
|
|
1030
1031
|
}
|
|
1031
1032
|
|
|
1032
1033
|
return this;
|
|
@@ -2088,8 +2089,68 @@ class VoltClient extends EventEmitter__default["default"] {
|
|
|
2088
2089
|
SqlExecute(request) {
|
|
2089
2090
|
const grpcClient = this.getVoltAPIClient();
|
|
2090
2091
|
|
|
2091
|
-
const
|
|
2092
|
-
return
|
|
2092
|
+
const call = new GRPCCall(this, "Execute", "METHOD_TYPE_BIDI");
|
|
2093
|
+
return call.start(grpcClient, request);
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
/**
|
|
2097
|
+
* A synchronous version of SqlExecute that returns the result as an array of JSON objects.
|
|
2098
|
+
*/
|
|
2099
|
+
SqlExecuteJSON(request) {
|
|
2100
|
+
return new Promise((resolve, reject) => {
|
|
2101
|
+
const call = this.SqlExecute(request);
|
|
2102
|
+
|
|
2103
|
+
let header;
|
|
2104
|
+
const rows = [];
|
|
2105
|
+
|
|
2106
|
+
call.on("error", reject);
|
|
2107
|
+
call.on("end", () => {
|
|
2108
|
+
resolve(rows);
|
|
2109
|
+
});
|
|
2110
|
+
|
|
2111
|
+
call.on("data", (response) => {
|
|
2112
|
+
if (response.header) {
|
|
2113
|
+
header = response.header;
|
|
2114
|
+
} else if (response.row) {
|
|
2115
|
+
const row = response.row;
|
|
2116
|
+
const obj = {};
|
|
2117
|
+
|
|
2118
|
+
for (let idx = 0; idx < header.column.length; idx++) {
|
|
2119
|
+
const column = header.column[idx];
|
|
2120
|
+
|
|
2121
|
+
if (row.column[idx].data === "null") {
|
|
2122
|
+
obj[column.name] = null;
|
|
2123
|
+
continue;
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
switch (column.type) {
|
|
2127
|
+
case "DATA_TYPE_TEXT": {
|
|
2128
|
+
obj[column.name] = row.column[idx].text;
|
|
2129
|
+
break;
|
|
2130
|
+
}
|
|
2131
|
+
case "DATA_TYPE_INTEGER": {
|
|
2132
|
+
obj[column.name] = parseInt(row.column[idx].integer);
|
|
2133
|
+
break;
|
|
2134
|
+
}
|
|
2135
|
+
case "DATA_TYPE_REAL": {
|
|
2136
|
+
obj[column.name] = parseFloat(row.column[idx].real);
|
|
2137
|
+
break;
|
|
2138
|
+
}
|
|
2139
|
+
case "DATA_TYPE_BLOB": {
|
|
2140
|
+
obj[column.name] = row.column[idx].blob;
|
|
2141
|
+
break;
|
|
2142
|
+
}
|
|
2143
|
+
default: {
|
|
2144
|
+
obj[column.name] = `unrecognised data type: ${column.type}`;
|
|
2145
|
+
break;
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
rows.push(obj);
|
|
2151
|
+
}
|
|
2152
|
+
});
|
|
2153
|
+
});
|
|
2093
2154
|
}
|
|
2094
2155
|
|
|
2095
2156
|
/**
|
package/package.json
CHANGED
package/src/grpc-call.js
CHANGED
|
@@ -242,7 +242,8 @@ export default class GRPCCall extends EventEmitter {
|
|
|
242
242
|
});
|
|
243
243
|
|
|
244
244
|
if (this._initialRequest.request) {
|
|
245
|
-
|
|
245
|
+
// Allow callee to attach event handlers before we actually send the initial payload.
|
|
246
|
+
process.nextTick(() => this._call.write(this._initialRequest.request));
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
return this;
|
package/src/volt-client.js
CHANGED
|
@@ -530,8 +530,68 @@ export class VoltClient extends EventEmitter {
|
|
|
530
530
|
SqlExecute(request) {
|
|
531
531
|
const grpcClient = this.getVoltAPIClient();
|
|
532
532
|
|
|
533
|
-
const
|
|
534
|
-
return
|
|
533
|
+
const call = new GRPCCall(this, "Execute", "METHOD_TYPE_BIDI");
|
|
534
|
+
return call.start(grpcClient, request);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* A synchronous version of SqlExecute that returns the result as an array of JSON objects.
|
|
539
|
+
*/
|
|
540
|
+
SqlExecuteJSON(request) {
|
|
541
|
+
return new Promise((resolve, reject) => {
|
|
542
|
+
const call = this.SqlExecute(request);
|
|
543
|
+
|
|
544
|
+
let header;
|
|
545
|
+
const rows = [];
|
|
546
|
+
|
|
547
|
+
call.on("error", reject);
|
|
548
|
+
call.on("end", () => {
|
|
549
|
+
resolve(rows);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
call.on("data", (response) => {
|
|
553
|
+
if (response.header) {
|
|
554
|
+
header = response.header;
|
|
555
|
+
} else if (response.row) {
|
|
556
|
+
const row = response.row;
|
|
557
|
+
const obj = {};
|
|
558
|
+
|
|
559
|
+
for (let idx = 0; idx < header.column.length; idx++) {
|
|
560
|
+
const column = header.column[idx];
|
|
561
|
+
|
|
562
|
+
if (row.column[idx].data === "null") {
|
|
563
|
+
obj[column.name] = null;
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
switch (column.type) {
|
|
568
|
+
case "DATA_TYPE_TEXT": {
|
|
569
|
+
obj[column.name] = row.column[idx].text;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
case "DATA_TYPE_INTEGER": {
|
|
573
|
+
obj[column.name] = parseInt(row.column[idx].integer);
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
case "DATA_TYPE_REAL": {
|
|
577
|
+
obj[column.name] = parseFloat(row.column[idx].real);
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
case "DATA_TYPE_BLOB": {
|
|
581
|
+
obj[column.name] = row.column[idx].blob;
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
default: {
|
|
585
|
+
obj[column.name] = `unrecognised data type: ${column.type}`;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
rows.push(obj);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
});
|
|
535
595
|
}
|
|
536
596
|
|
|
537
597
|
/**
|