@hackthedev/dsync-sql 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/README.md +8 -8
  2. package/index.mjs +21 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  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.
4
4
 
5
- > [!IMPORTANT]
6
- >
7
- > This readme is still work in progress and examples and all will come once done.
8
-
9
5
  ------
10
6
 
11
7
  ## Connection setup
@@ -20,9 +16,9 @@ export let db = new dSyncSql({
20
16
  user: "username",
21
17
  password: "some_password",
22
18
  database: "database_name",
23
- waitForConnections: true, // optional
24
- connectionLimit: 10, // optional
25
- queueLimit: 0, // optional
19
+ waitForConnections: true, // optional
20
+ connectionLimit: 10, // optional
21
+ queueLimit: 0, // optional
26
22
  });
27
23
  ```
28
24
 
@@ -30,7 +26,11 @@ export let db = new dSyncSql({
30
26
 
31
27
  ## Defining a database
32
28
 
33
- The following is optional but dSyncSql was designed to automatically create the database structure to make deployment and updates smooth and automatic.
29
+ The following is optional but dSyncSql was designed to automatically create the database structure to make deployment and updates smooth and automatic.
30
+
31
+ > [!CAUTION]
32
+ >
33
+ > The library wont create the database itself.
34
34
 
35
35
  ```js
36
36
  const tables = [
package/index.mjs CHANGED
@@ -1,5 +1,8 @@
1
1
  import mysql from "mysql2/promise";
2
2
  import Logger from "@hackthedev/terminal-logger"
3
+ import {serverconfig} from "../../dcts/index.mjs";
4
+ import {spawn} from "node:child_process";
5
+ import fs from "fs";
3
6
 
4
7
  export default class dSyncSql {
5
8
  constructor({
@@ -36,6 +39,24 @@ export default class dSyncSql {
36
39
  });
37
40
  }
38
41
 
42
+ async exportDatabase(outFile) {
43
+ if(!outFile) throw new Error('Output File path is required');
44
+ return await new Promise((resolve, reject) => {
45
+ const dump = spawn("mariadb-dump", [
46
+ "-h", this.host,
47
+ "-u", this.user,
48
+ `-p${this.password}`,
49
+ this.database
50
+ ]);
51
+
52
+ const stream = fs.createWriteStream(outFile);
53
+
54
+ dump.stdout.pipe(stream);
55
+ dump.stderr.on("data", d => reject(d.toString()));
56
+ dump.on("close", code => code === 0 ? resolve() : reject(code));
57
+ });
58
+ }
59
+
39
60
  async waitForConnection() {
40
61
  while (true) {
41
62
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackthedev/dsync-sql",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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": {