@dbcube/core 3.0.12 → 3.0.15
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/dist/index.cjs +15 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +0 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.js +15 -146
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -45,14 +45,10 @@ declare class QueryEngine {
|
|
|
45
45
|
private waitForServerReady;
|
|
46
46
|
private isServerResponding;
|
|
47
47
|
private sleep;
|
|
48
|
-
private initializeConnectionPool;
|
|
49
48
|
private getCachedDML;
|
|
50
49
|
private startTcpServer;
|
|
51
50
|
private sendTcpRequest;
|
|
52
51
|
private sendTcpRequestFast;
|
|
53
|
-
private sendUltraFast;
|
|
54
|
-
private createAndPoolConnection;
|
|
55
|
-
private createPooledConnection;
|
|
56
52
|
private sendOnExistingConnection;
|
|
57
53
|
private createPersistentConnection;
|
|
58
54
|
private createProcess;
|
package/dist/index.d.ts
CHANGED
|
@@ -45,14 +45,10 @@ declare class QueryEngine {
|
|
|
45
45
|
private waitForServerReady;
|
|
46
46
|
private isServerResponding;
|
|
47
47
|
private sleep;
|
|
48
|
-
private initializeConnectionPool;
|
|
49
48
|
private getCachedDML;
|
|
50
49
|
private startTcpServer;
|
|
51
50
|
private sendTcpRequest;
|
|
52
51
|
private sendTcpRequestFast;
|
|
53
|
-
private sendUltraFast;
|
|
54
|
-
private createAndPoolConnection;
|
|
55
|
-
private createPooledConnection;
|
|
56
52
|
private sendOnExistingConnection;
|
|
57
53
|
private createPersistentConnection;
|
|
58
54
|
private createProcess;
|
package/dist/index.js
CHANGED
|
@@ -730,39 +730,9 @@ import * as net from "net";
|
|
|
730
730
|
import { spawn as spawn2 } from "child_process";
|
|
731
731
|
var globalTcpServers = /* @__PURE__ */ new Map();
|
|
732
732
|
var globalTcpConnections = /* @__PURE__ */ new Map();
|
|
733
|
-
var
|
|
734
|
-
var
|
|
735
|
-
var
|
|
736
|
-
cache = /* @__PURE__ */ new Map();
|
|
737
|
-
maxSize;
|
|
738
|
-
constructor(maxSize) {
|
|
739
|
-
this.maxSize = maxSize;
|
|
740
|
-
}
|
|
741
|
-
get(key) {
|
|
742
|
-
if (this.cache.has(key)) {
|
|
743
|
-
const value = this.cache.get(key);
|
|
744
|
-
this.cache.delete(key);
|
|
745
|
-
this.cache.set(key, value);
|
|
746
|
-
return value;
|
|
747
|
-
}
|
|
748
|
-
return void 0;
|
|
749
|
-
}
|
|
750
|
-
set(key, value) {
|
|
751
|
-
if (this.cache.has(key)) {
|
|
752
|
-
this.cache.delete(key);
|
|
753
|
-
} else if (this.cache.size >= this.maxSize) {
|
|
754
|
-
const firstKey = this.cache.keys().next().value;
|
|
755
|
-
if (firstKey !== void 0) {
|
|
756
|
-
this.cache.delete(firstKey);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
this.cache.set(key, value);
|
|
760
|
-
}
|
|
761
|
-
size() {
|
|
762
|
-
return this.cache.size;
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
var queryCache = new LRUCache(500);
|
|
733
|
+
var queryCache = /* @__PURE__ */ new Map();
|
|
734
|
+
var cacheSize = 0;
|
|
735
|
+
var MAX_CACHE_SIZE = 500;
|
|
766
736
|
var QueryEngine = class {
|
|
767
737
|
name;
|
|
768
738
|
config;
|
|
@@ -881,7 +851,6 @@ var QueryEngine = class {
|
|
|
881
851
|
if (!serverInfo || !serverInfo.process || serverInfo.process.killed) {
|
|
882
852
|
await this.startTcpServer();
|
|
883
853
|
await this.waitForServerReady();
|
|
884
|
-
await this.initializeConnectionPool();
|
|
885
854
|
}
|
|
886
855
|
return this.sendTcpRequestFast(args);
|
|
887
856
|
}
|
|
@@ -917,30 +886,15 @@ var QueryEngine = class {
|
|
|
917
886
|
sleep(ms) {
|
|
918
887
|
return new Promise((resolve5) => setTimeout(resolve5, ms));
|
|
919
888
|
}
|
|
920
|
-
async initializeConnectionPool() {
|
|
921
|
-
console.log("\u{1F3CA} Initializing connection pool...");
|
|
922
|
-
if (!connectionPools.has(this.connectionId)) {
|
|
923
|
-
connectionPools.set(this.connectionId, []);
|
|
924
|
-
}
|
|
925
|
-
const pool = connectionPools.get(this.connectionId);
|
|
926
|
-
for (let i = 0; i < MAX_POOL_SIZE; i++) {
|
|
927
|
-
try {
|
|
928
|
-
const connection = await this.createPooledConnection();
|
|
929
|
-
pool.push(connection);
|
|
930
|
-
console.log(`\u2705 Pool connection ${i + 1}/${MAX_POOL_SIZE} created`);
|
|
931
|
-
} catch (error) {
|
|
932
|
-
console.error(`\u274C Failed to create pool connection ${i + 1}:`, error);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
console.log(`\u{1F680} Connection pool ready with ${pool.length} connections`);
|
|
936
|
-
}
|
|
937
889
|
getCachedDML(dmlJson) {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
return cached;
|
|
890
|
+
if (queryCache.has(dmlJson)) {
|
|
891
|
+
return queryCache.get(dmlJson);
|
|
941
892
|
}
|
|
942
893
|
const parsed = JSON.parse(dmlJson);
|
|
943
|
-
|
|
894
|
+
if (cacheSize < MAX_CACHE_SIZE) {
|
|
895
|
+
queryCache.set(dmlJson, parsed);
|
|
896
|
+
cacheSize++;
|
|
897
|
+
}
|
|
944
898
|
return parsed;
|
|
945
899
|
}
|
|
946
900
|
async startTcpServer() {
|
|
@@ -1054,100 +1008,16 @@ var QueryEngine = class {
|
|
|
1054
1008
|
});
|
|
1055
1009
|
}
|
|
1056
1010
|
async sendTcpRequestFast(args) {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
}
|
|
1060
|
-
const pool = connectionPools.get(this.connectionId);
|
|
1061
|
-
if (pool.length > 0) {
|
|
1062
|
-
const connection = pool.pop();
|
|
1011
|
+
const existingConnection = globalTcpConnections.get(this.connectionId);
|
|
1012
|
+
if (existingConnection && existingConnection.readyState === "open") {
|
|
1063
1013
|
try {
|
|
1064
|
-
|
|
1065
|
-
pool.push(connection);
|
|
1066
|
-
return result;
|
|
1014
|
+
return await this.sendOnExistingConnection(existingConnection, args);
|
|
1067
1015
|
} catch (error) {
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
return await this.createAndPoolConnection(args);
|
|
1073
|
-
}
|
|
1074
|
-
async sendUltraFast(connection, args) {
|
|
1075
|
-
return new Promise((resolve5, reject) => {
|
|
1076
|
-
const dmlIndex = args.findIndex((arg) => arg === "--dml");
|
|
1077
|
-
const dmlJson = dmlIndex !== -1 ? args[dmlIndex + 1] : null;
|
|
1078
|
-
if (!dmlJson) {
|
|
1079
|
-
reject(new Error("No DML found in arguments"));
|
|
1080
|
-
return;
|
|
1016
|
+
globalTcpConnections.delete(this.connectionId);
|
|
1017
|
+
existingConnection.destroy();
|
|
1081
1018
|
}
|
|
1082
|
-
let responseBuffer = "";
|
|
1083
|
-
let isResolved = false;
|
|
1084
|
-
const timeout = setTimeout(() => {
|
|
1085
|
-
if (!isResolved) {
|
|
1086
|
-
isResolved = true;
|
|
1087
|
-
connection.off("data", onData);
|
|
1088
|
-
connection.off("error", onError);
|
|
1089
|
-
reject(new Error("Ultra-fast timeout"));
|
|
1090
|
-
}
|
|
1091
|
-
}, 50);
|
|
1092
|
-
const onData = (data) => {
|
|
1093
|
-
responseBuffer += data.toString();
|
|
1094
|
-
const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
1095
|
-
if (match && !isResolved) {
|
|
1096
|
-
isResolved = true;
|
|
1097
|
-
clearTimeout(timeout);
|
|
1098
|
-
connection.off("data", onData);
|
|
1099
|
-
connection.off("error", onError);
|
|
1100
|
-
try {
|
|
1101
|
-
const response = JSON.parse(match[1]);
|
|
1102
|
-
resolve5({
|
|
1103
|
-
status: response.status,
|
|
1104
|
-
message: response.message,
|
|
1105
|
-
data: response.data
|
|
1106
|
-
});
|
|
1107
|
-
} catch (error) {
|
|
1108
|
-
reject(new Error("Failed to parse TCP response"));
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
};
|
|
1112
|
-
const onError = (error) => {
|
|
1113
|
-
if (!isResolved) {
|
|
1114
|
-
isResolved = true;
|
|
1115
|
-
clearTimeout(timeout);
|
|
1116
|
-
connection.off("data", onData);
|
|
1117
|
-
connection.off("error", onError);
|
|
1118
|
-
reject(error);
|
|
1119
|
-
}
|
|
1120
|
-
};
|
|
1121
|
-
connection.on("data", onData);
|
|
1122
|
-
connection.on("error", onError);
|
|
1123
|
-
const command = `{"action":"execute","dml":${dmlJson}}`;
|
|
1124
|
-
connection.write(command);
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
async createAndPoolConnection(args) {
|
|
1128
|
-
const connection = await this.createPooledConnection();
|
|
1129
|
-
if (!connectionPools.has(this.connectionId)) {
|
|
1130
|
-
connectionPools.set(this.connectionId, []);
|
|
1131
1019
|
}
|
|
1132
|
-
|
|
1133
|
-
const pool = connectionPools.get(this.connectionId);
|
|
1134
|
-
if (pool.length < MAX_POOL_SIZE) {
|
|
1135
|
-
pool.push(connection);
|
|
1136
|
-
} else {
|
|
1137
|
-
connection.destroy();
|
|
1138
|
-
}
|
|
1139
|
-
return result;
|
|
1140
|
-
}
|
|
1141
|
-
async createPooledConnection() {
|
|
1142
|
-
return new Promise((resolve5, reject) => {
|
|
1143
|
-
const client = new net.Socket();
|
|
1144
|
-
client.setNoDelay(true);
|
|
1145
|
-
client.setKeepAlive(true, 0);
|
|
1146
|
-
client.connect(this.tcpPort, "127.0.0.1", () => {
|
|
1147
|
-
resolve5(client);
|
|
1148
|
-
});
|
|
1149
|
-
client.on("error", reject);
|
|
1150
|
-
});
|
|
1020
|
+
return await this.createPersistentConnection(args);
|
|
1151
1021
|
}
|
|
1152
1022
|
async sendOnExistingConnection(connection, args) {
|
|
1153
1023
|
return new Promise((resolve5, reject) => {
|
|
@@ -1157,7 +1027,6 @@ var QueryEngine = class {
|
|
|
1157
1027
|
reject(new Error("No DML found in arguments"));
|
|
1158
1028
|
return;
|
|
1159
1029
|
}
|
|
1160
|
-
const dmlParsed = this.getCachedDML(dmlJson);
|
|
1161
1030
|
let responseBuffer = "";
|
|
1162
1031
|
let isResolved = false;
|
|
1163
1032
|
const timeout = setTimeout(() => {
|