stonyx 0.2.3-beta.10 → 0.2.3-beta.11
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/docs/conventions/orm-conventions.md +32 -0
- package/package.json +1 -1
- package/src/cli.js +1 -1
|
@@ -156,3 +156,35 @@ export default class DBModel extends Model {
|
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Located at `config/db-schema.js`, referenced from `config/environment.js`.
|
|
159
|
+
|
|
160
|
+
## Store
|
|
161
|
+
|
|
162
|
+
The store is the in-memory data layer. Use it for internal app logic (not REST API consumers).
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
import Orm, { store, createRecord, updateRecord } from '@stonyx/orm';
|
|
166
|
+
|
|
167
|
+
// Read — sync, from memory (requires memory: true on model, which is the default)
|
|
168
|
+
const record = store.get('animal', 1);
|
|
169
|
+
const allAnimals = store.data.get('animals');
|
|
170
|
+
|
|
171
|
+
// Read — async, queries DB if memory: false
|
|
172
|
+
const record = await store.find('animal', 1);
|
|
173
|
+
const all = await store.findAll('animal');
|
|
174
|
+
|
|
175
|
+
// Create — adds to store and returns the record
|
|
176
|
+
const animal = createRecord('animal', { type: 'dog', age: 3, owner: 'angela' });
|
|
177
|
+
|
|
178
|
+
// Update — patches fields on an existing record
|
|
179
|
+
updateRecord(animal, { age: 4 });
|
|
180
|
+
|
|
181
|
+
// Delete
|
|
182
|
+
store.remove('animal', 1);
|
|
183
|
+
|
|
184
|
+
// Persist to disk — required when not using REST-triggered autosave
|
|
185
|
+
await Orm.db.save();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**When to use `Orm.db.save()`**: The `autosave: 'onUpdate'` config only triggers on REST POST/PATCH/DELETE. When modifying data directly via `createRecord` / `updateRecord` in app code (not through REST), call `Orm.db.save()` explicitly to persist.
|
|
189
|
+
|
|
190
|
+
**Store vs REST**: Use `store` for internal app logic (session tracking, state management). Use REST request handlers for external API consumers. Both operate on the same in-memory data.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED