@mindstudio-ai/remy 0.1.3 → 0.1.4
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/dist/compiled/tables.md +23 -4
- package/package.json +1 -1
package/dist/compiled/tables.md
CHANGED
|
@@ -143,7 +143,9 @@ const minAmount = 10000;
|
|
|
143
143
|
Vendors.filter(v => v.totalCents > minAmount) // captured variables
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
**What compiles to SQL** (efficient): equality, comparisons, `&&`/`||`, `.includes()` for arrays and strings, null checks, boolean negation, captured variables.
|
|
147
|
+
|
|
148
|
+
**What falls back to JS** (fetches all rows, filters in memory): `.startsWith()`, regex, computed expressions like `o.a + o.b > 100`, complex closures. A warning is logged when this happens. Avoid these patterns on large tables.
|
|
147
149
|
|
|
148
150
|
### Time Helpers
|
|
149
151
|
|
|
@@ -160,17 +162,34 @@ db.ago(db.days(7) + db.hours(12)) // composable — 7.5 days ago
|
|
|
160
162
|
Invoices.filter(i => i.dueDate < db.ago(db.days(30)))
|
|
161
163
|
```
|
|
162
164
|
|
|
163
|
-
###
|
|
165
|
+
### Batching
|
|
164
166
|
|
|
165
|
-
|
|
167
|
+
`db.batch()` combines multiple operations into a single HTTP round-trip. Every `await` on a table operation is a network call, so batching is critical for performance. Use it whenever you have multiple reads, writes, or a mix of both:
|
|
166
168
|
|
|
167
169
|
```typescript
|
|
168
|
-
|
|
170
|
+
// Reads: fetch related data in one call instead of sequential awaits
|
|
171
|
+
const [vendors, orders, invoiceCount] = await db.batch(
|
|
169
172
|
Vendors.filter(v => v.status === 'approved'),
|
|
170
173
|
PurchaseOrders.filter(po => po.vendorId === vendorId),
|
|
174
|
+
Invoices.count(i => i.status === 'pending'),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// Writes: batch multiple updates instead of awaiting each one in a loop
|
|
178
|
+
const mutations = items.map(item =>
|
|
179
|
+
Orders.update(item.id, { status: 'approved' })
|
|
180
|
+
);
|
|
181
|
+
await db.batch(...mutations);
|
|
182
|
+
|
|
183
|
+
// Mixed: writes execute in order, reads observe prior writes
|
|
184
|
+
const [_, newOrder, pending] = await db.batch(
|
|
185
|
+
Orders.update(id, { status: 'approved' }),
|
|
186
|
+
Orders.push({ item: 'Laptop', amount: 999, status: 'pending', requestedBy: userId }),
|
|
187
|
+
Orders.filter(o => o.status === 'pending').take(10),
|
|
171
188
|
);
|
|
172
189
|
```
|
|
173
190
|
|
|
191
|
+
**Always batch instead of sequential awaits.** A loop with `await Table.update()` inside makes N separate HTTP calls. Mapping to mutations and passing them to `db.batch()` makes one.
|
|
192
|
+
|
|
174
193
|
## Migrations
|
|
175
194
|
|
|
176
195
|
No migration files. Migrations are automatic:
|