@stonyx/orm 0.2.1-beta.72 → 0.2.1-beta.74

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 +4 -0
  2. package/package.json +1 -1
  3. package/src/db.js +14 -4
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![CI](https://github.com/abofs/stonyx-orm/actions/workflows/ci.yml/badge.svg)](https://github.com/abofs/stonyx-orm/actions/workflows/ci.yml)
2
+ [![npm version](https://img.shields.io/npm/v/@stonyx/orm.svg)](https://www.npmjs.com/package/@stonyx/orm)
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
+
1
5
  # @stonyx/orm
2
6
 
3
7
  A lightweight ORM for Stonyx projects, featuring model definitions, serializers, relationships, transforms, and optional REST server integration.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.2.1-beta.72",
7
+ "version": "0.2.1-beta.74",
8
8
  "description": "",
9
9
  "main": "src/main.js",
10
10
  "type": "module",
package/src/db.js CHANGED
@@ -147,15 +147,25 @@ export default class DB {
147
147
  const collectionKeys = this.getCollectionKeys();
148
148
 
149
149
  // Write each collection to its own file in parallel
150
- await Promise.all(collectionKeys.map(key =>
151
- updateFile(path.join(dirPath, `${key}.json`), jsonData[key] || [], { json: true })
152
- ));
150
+ // Use createFile for new files, updateFile for existing ones
151
+ await Promise.all(collectionKeys.map(async key => {
152
+ const filePath = path.join(dirPath, `${key}.json`);
153
+ const exists = await fileExists(filePath);
154
+ const data = jsonData[key] || [];
155
+
156
+ if (exists) await updateFile(filePath, data, { json: true });
157
+ else await createFile(filePath, data, { json: true });
158
+ }));
153
159
 
154
160
  // Write empty-array skeleton to db.json
155
161
  const skeleton = {};
156
162
  for (const key of collectionKeys) skeleton[key] = [];
157
163
 
158
- await updateFile(`${config.rootPath}/${file}`, skeleton, { json: true });
164
+ const dbFilePath = `${config.rootPath}/${file}`;
165
+ const dbFileExists = await fileExists(dbFilePath);
166
+
167
+ if (dbFileExists) await updateFile(dbFilePath, skeleton, { json: true });
168
+ else await createFile(dbFilePath, skeleton, { json: true });
159
169
 
160
170
  log.db(`DB has been successfully saved to ${config.orm.db.directory}/ directory`);
161
171
  return;