@stonyx/orm 0.0.5 → 0.0.7

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.
@@ -9,10 +9,12 @@ const {
9
9
  } = process;
10
10
 
11
11
  export default {
12
+ logColor: 'white',
13
+ logMethod: 'db',
14
+
12
15
  db: {
13
16
  autosave: DB_AUTO_SAVE ?? 'false',
14
17
  file: DB_FILE ?? 'db.json',
15
- logColor: 'white',
16
18
  saveInterval: DB_SAVE_INTERVAL ?? 60 * 60, // 1 hour
17
19
  schema: DB_SCHEMA_PATH ?? './config/db-schema.js'
18
20
  },
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.0.5",
7
+ "version": "0.0.7",
8
8
  "description": "",
9
9
  "main": "src/main.js",
10
10
  "type": "module",
@@ -30,11 +30,11 @@
30
30
  },
31
31
  "homepage": "https://github.com/abofs/stonyx-orm#readme",
32
32
  "dependencies": {
33
- "stonyx": "^0.0.6"
33
+ "stonyx": "^0.0.7"
34
34
  },
35
35
  "devDependencies": {
36
- "@stonyx/cron": "^0.0.5",
37
- "@stonyx/utils": "^0.0.3",
36
+ "@stonyx/cron": "^0.0.6",
37
+ "@stonyx/utils": "^0.0.4",
38
38
  "qunit": "^2.24.1"
39
39
  }
40
40
  }
package/src/db.js CHANGED
@@ -31,10 +31,6 @@ export default class DB {
31
31
  new Cron().register('save', this.save.bind(this), saveInterval);
32
32
  }
33
33
 
34
- get rawData() {
35
- return JSON.stringify(this.data, null, "\t");
36
- }
37
-
38
34
  async create() {
39
35
  const { rootPath } = config;
40
36
  const { file, schema } = config.orm.db;
@@ -49,16 +45,18 @@ export default class DB {
49
45
  dbSchema = {};
50
46
  log.db('Unable to load DB schema from file, using empty schema instead');
51
47
  }
48
+
49
+ const data = deepCopy(dbSchema);
52
50
 
53
- this.data = deepCopy(dbSchema);
54
-
55
- createFile(`${rootPath}/${file}`, this.rawData);
51
+ createFile(`${rootPath}/${file}`, data, { json: true });
52
+
53
+ return data;
56
54
  }
57
55
 
58
56
  async save() {
59
57
  const { file } = config.orm.db;
60
58
 
61
- await updateFile(file, this.rawData);
59
+ await updateFile(file, this.data, { json: true });
62
60
 
63
61
  log.db(`DB has been successfully saved to ${file}`);
64
62
  }
@@ -66,9 +64,7 @@ export default class DB {
66
64
  async retrieve() {
67
65
  const { file } = config.orm.db;
68
66
 
69
- const data = await readFile(file, { json: true, missingFileCallback: this.create.bind(this) });
70
-
71
- if (data) this.data = data;
67
+ this.data = await readFile(file, { json: true, missingFileCallback: this.create.bind(this) });
72
68
  }
73
69
 
74
70
  /** TODO: We need ORM specific reload logic that replaces models attributes when loading from DB */