@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.
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/db.js +14 -4
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
[](https://github.com/abofs/stonyx-orm/actions/workflows/ci.yml)
|
|
2
|
+
[](https://www.npmjs.com/package/@stonyx/orm)
|
|
3
|
+
[](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
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
|
-
|
|
151
|
-
|
|
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
|
-
|
|
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;
|