@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.d.mts
CHANGED
|
@@ -12,14 +12,21 @@ declare class Engine {
|
|
|
12
12
|
private arguments;
|
|
13
13
|
private binary;
|
|
14
14
|
private timeout;
|
|
15
|
+
private connectionId;
|
|
16
|
+
private isConnected;
|
|
15
17
|
constructor(name: string, timeout?: number);
|
|
18
|
+
private generateConnectionId;
|
|
16
19
|
initializeBinary(): Promise<void>;
|
|
17
20
|
setArguments(): any[];
|
|
18
21
|
setConfig(name: string): {
|
|
19
22
|
[x: string]: any;
|
|
20
23
|
} | null;
|
|
21
24
|
getConfig(): any;
|
|
22
|
-
|
|
25
|
+
ensurePersistentConnection(): Promise<void>;
|
|
26
|
+
run(binary: string, args: string[]): Promise<ResponseEngine>;
|
|
27
|
+
private executeWithPersistentConnection;
|
|
28
|
+
private createProcess;
|
|
29
|
+
disconnect(): Promise<ResponseEngine>;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
interface SystemInfo {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,14 +12,21 @@ declare class Engine {
|
|
|
12
12
|
private arguments;
|
|
13
13
|
private binary;
|
|
14
14
|
private timeout;
|
|
15
|
+
private connectionId;
|
|
16
|
+
private isConnected;
|
|
15
17
|
constructor(name: string, timeout?: number);
|
|
18
|
+
private generateConnectionId;
|
|
16
19
|
initializeBinary(): Promise<void>;
|
|
17
20
|
setArguments(): any[];
|
|
18
21
|
setConfig(name: string): {
|
|
19
22
|
[x: string]: any;
|
|
20
23
|
} | null;
|
|
21
24
|
getConfig(): any;
|
|
22
|
-
|
|
25
|
+
ensurePersistentConnection(): Promise<void>;
|
|
26
|
+
run(binary: string, args: string[]): Promise<ResponseEngine>;
|
|
27
|
+
private executeWithPersistentConnection;
|
|
28
|
+
private createProcess;
|
|
29
|
+
disconnect(): Promise<ResponseEngine>;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
interface SystemInfo {
|
package/dist/index.js
CHANGED
|
@@ -556,11 +556,17 @@ var Engine = class {
|
|
|
556
556
|
arguments;
|
|
557
557
|
binary = null;
|
|
558
558
|
timeout;
|
|
559
|
+
connectionId;
|
|
560
|
+
isConnected = false;
|
|
559
561
|
constructor(name, timeout = 3e4) {
|
|
560
562
|
this.name = name;
|
|
561
563
|
this.config = this.setConfig(name);
|
|
562
564
|
this.arguments = this.setArguments();
|
|
563
565
|
this.timeout = timeout;
|
|
566
|
+
this.connectionId = this.generateConnectionId();
|
|
567
|
+
}
|
|
568
|
+
generateConnectionId() {
|
|
569
|
+
return `${this.name}_${this.config.type}_${this.config.config.DATABASE}_${this.config.config.HOST || "localhost"}`;
|
|
564
570
|
}
|
|
565
571
|
async initializeBinary() {
|
|
566
572
|
if (!this.binary) {
|
|
@@ -627,7 +633,35 @@ var Engine = class {
|
|
|
627
633
|
getConfig() {
|
|
628
634
|
return this.config;
|
|
629
635
|
}
|
|
636
|
+
async ensurePersistentConnection() {
|
|
637
|
+
if (!this.isConnected) {
|
|
638
|
+
console.log("\u{1F50C} Creating persistent connection...");
|
|
639
|
+
const response = await this.createProcess("query_engine", [
|
|
640
|
+
"--action",
|
|
641
|
+
"connect"
|
|
642
|
+
]);
|
|
643
|
+
if (response.status === 200) {
|
|
644
|
+
this.isConnected = true;
|
|
645
|
+
console.log("\u2705 Persistent connection established");
|
|
646
|
+
} else {
|
|
647
|
+
throw new Error(`Failed to create persistent connection: ${response.message}`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
630
651
|
async run(binary, args) {
|
|
652
|
+
const actionIndex = args.indexOf("--action");
|
|
653
|
+
const isExecuteAction = actionIndex !== -1 && args[actionIndex + 1] === "execute";
|
|
654
|
+
if (isExecuteAction) {
|
|
655
|
+
await this.ensurePersistentConnection();
|
|
656
|
+
return this.executeWithPersistentConnection(args);
|
|
657
|
+
} else {
|
|
658
|
+
return this.createProcess(binary, args);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
async executeWithPersistentConnection(args) {
|
|
662
|
+
return this.createProcess("query_engine", args);
|
|
663
|
+
}
|
|
664
|
+
async createProcess(binary, args) {
|
|
631
665
|
await this.initializeBinary();
|
|
632
666
|
if (!this.binary) {
|
|
633
667
|
throw new Error("Binary not initialized");
|
|
@@ -714,6 +748,25 @@ var Engine = class {
|
|
|
714
748
|
child.unref();
|
|
715
749
|
});
|
|
716
750
|
}
|
|
751
|
+
async disconnect() {
|
|
752
|
+
if (this.isConnected) {
|
|
753
|
+
console.log("\u{1F50C} Disconnecting persistent connection...");
|
|
754
|
+
const response = await this.createProcess("query_engine", [
|
|
755
|
+
"--action",
|
|
756
|
+
"disconnect"
|
|
757
|
+
]);
|
|
758
|
+
if (response.status === 200) {
|
|
759
|
+
this.isConnected = false;
|
|
760
|
+
console.log("\u2705 Persistent connection closed");
|
|
761
|
+
}
|
|
762
|
+
return response;
|
|
763
|
+
}
|
|
764
|
+
return {
|
|
765
|
+
status: 200,
|
|
766
|
+
message: "No persistent connection to disconnect",
|
|
767
|
+
data: null
|
|
768
|
+
};
|
|
769
|
+
}
|
|
717
770
|
};
|
|
718
771
|
|
|
719
772
|
// src/lib/SqliteExecutor.ts
|