@hackthedev/dsync-sql 1.0.1 → 1.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/index.mjs +20 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import mysql from "mysql2/promise";
|
|
2
2
|
import Logger from "@hackthedev/terminal-logger"
|
|
3
|
+
import {spawn} from "node:child_process";
|
|
4
|
+
import fs from "fs";
|
|
3
5
|
|
|
4
6
|
export default class dSyncSql {
|
|
5
7
|
constructor({
|
|
@@ -36,6 +38,24 @@ export default class dSyncSql {
|
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
async exportDatabase(outFile) {
|
|
42
|
+
if(!outFile) throw new Error('Output File path is required');
|
|
43
|
+
return await new Promise((resolve, reject) => {
|
|
44
|
+
const dump = spawn("mariadb-dump", [
|
|
45
|
+
"-h", this.host,
|
|
46
|
+
"-u", this.user,
|
|
47
|
+
`-p${this.password}`,
|
|
48
|
+
this.database
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const stream = fs.createWriteStream(outFile);
|
|
52
|
+
|
|
53
|
+
dump.stdout.pipe(stream);
|
|
54
|
+
dump.stderr.on("data", d => reject(d.toString()));
|
|
55
|
+
dump.on("close", code => code === 0 ? resolve() : reject(code));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
39
59
|
async waitForConnection() {
|
|
40
60
|
while (true) {
|
|
41
61
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackthedev/dsync-sql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "dSyncSql is supposed to be a helper for handling MySQL / MariaDB connections and executing queries. In addition it will also allow you to automatically create a database's structure like tables, column and such and will automatically create missing columns and tables based off a json Object.",
|
|
5
5
|
"homepage": "https://github.com/NETWORK-Z-Dev/dSyncSql#readme",
|
|
6
6
|
"bugs": {
|