@dbcube/core 3.0.1 → 3.0.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/dist/index.cjs +53 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -600,11 +600,17 @@ var Engine = class {
|
|
|
600
600
|
arguments;
|
|
601
601
|
binary = null;
|
|
602
602
|
timeout;
|
|
603
|
+
connectionId;
|
|
604
|
+
isConnected = false;
|
|
603
605
|
constructor(name, timeout = 3e4) {
|
|
604
606
|
this.name = name;
|
|
605
607
|
this.config = this.setConfig(name);
|
|
606
608
|
this.arguments = this.setArguments();
|
|
607
609
|
this.timeout = timeout;
|
|
610
|
+
this.connectionId = this.generateConnectionId();
|
|
611
|
+
}
|
|
612
|
+
generateConnectionId() {
|
|
613
|
+
return `${this.name}_${this.config.type}_${this.config.config.DATABASE}_${this.config.config.HOST || "localhost"}`;
|
|
608
614
|
}
|
|
609
615
|
async initializeBinary() {
|
|
610
616
|
if (!this.binary) {
|
|
@@ -671,7 +677,35 @@ var Engine = class {
|
|
|
671
677
|
getConfig() {
|
|
672
678
|
return this.config;
|
|
673
679
|
}
|
|
680
|
+
async ensurePersistentConnection() {
|
|
681
|
+
if (!this.isConnected) {
|
|
682
|
+
console.log("\u{1F50C} Creating persistent connection...");
|
|
683
|
+
const response = await this.createProcess("query_engine", [
|
|
684
|
+
"--action",
|
|
685
|
+
"connect"
|
|
686
|
+
]);
|
|
687
|
+
if (response.status === 200) {
|
|
688
|
+
this.isConnected = true;
|
|
689
|
+
console.log("\u2705 Persistent connection established");
|
|
690
|
+
} else {
|
|
691
|
+
throw new Error(`Failed to create persistent connection: ${response.message}`);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
674
695
|
async run(binary, args) {
|
|
696
|
+
const actionIndex = args.indexOf("--action");
|
|
697
|
+
const isExecuteAction = actionIndex !== -1 && args[actionIndex + 1] === "execute";
|
|
698
|
+
if (isExecuteAction) {
|
|
699
|
+
await this.ensurePersistentConnection();
|
|
700
|
+
return this.executeWithPersistentConnection(args);
|
|
701
|
+
} else {
|
|
702
|
+
return this.createProcess(binary, args);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
async executeWithPersistentConnection(args) {
|
|
706
|
+
return this.createProcess("query_engine", args);
|
|
707
|
+
}
|
|
708
|
+
async createProcess(binary, args) {
|
|
675
709
|
await this.initializeBinary();
|
|
676
710
|
if (!this.binary) {
|
|
677
711
|
throw new Error("Binary not initialized");
|
|
@@ -758,6 +792,25 @@ var Engine = class {
|
|
|
758
792
|
child.unref();
|
|
759
793
|
});
|
|
760
794
|
}
|
|
795
|
+
async disconnect() {
|
|
796
|
+
if (this.isConnected) {
|
|
797
|
+
console.log("\u{1F50C} Disconnecting persistent connection...");
|
|
798
|
+
const response = await this.createProcess("query_engine", [
|
|
799
|
+
"--action",
|
|
800
|
+
"disconnect"
|
|
801
|
+
]);
|
|
802
|
+
if (response.status === 200) {
|
|
803
|
+
this.isConnected = false;
|
|
804
|
+
console.log("\u2705 Persistent connection closed");
|
|
805
|
+
}
|
|
806
|
+
return response;
|
|
807
|
+
}
|
|
808
|
+
return {
|
|
809
|
+
status: 200,
|
|
810
|
+
message: "No persistent connection to disconnect",
|
|
811
|
+
data: null
|
|
812
|
+
};
|
|
813
|
+
}
|
|
761
814
|
};
|
|
762
815
|
|
|
763
816
|
// src/lib/SqliteExecutor.ts
|