nenu-lang / writing-data
Stable

Writing Data

  • Construction and assignment change in-memory values; save publishes durable writes.
  • save.transaction groups several saves under one transactional operation.
  • delete accepts a resolved entity variable or an entity fetch expression.

Create And Save

code
1Expense expense = Expense {2  room_id: room.id3  payer4  title: request.title5  amount: request.amount6  note: request.note7  receipt: ?8  status: ExpenseStatus.Draft9}1011save(expense)

Construction creates the entity value. Save persists it. Use parentheses even for one record, and pass the resolved variable rather than inventing bracket or bare save syntax.

Update An Existing Record

code
1need expense = Expense(request.expense_id)23expense.title = request.title4expense.amount = request.amount5expense.status = ExpenseStatus.Submitted67save(expense)8return Response { expense }

Fetching does not lock a record for the rest of the runnable. Keep the workflow’s conflict and authorization semantics explicit in the owning API contract.

Save Several Records

code
1save(expense, settlement)

Use ordinary multi-value save when the workflow does not require an all-or-nothing group. Use save.transaction when the active backend contract requires the participating writes to succeed together.

Create A Missing Exact Record

code
1need {2  member = User(request.member_id)3  share = Expense(request.expense_id).shares(request.member_id) | default4}56share.member = member7share.amount = request.amount8save(share)

| default is valid when an exact fetch supplies stable identity for a record that may not exist. It does not turn an arbitrary filtered query into a safe creation target.

Delete Records

code
1need settlement = Settlement(request.settlement_id)2delete settlement

A variable delete uses the resolved record identity. An entity expression identifies the target directly. Return a typed acknowledgement or useful result according to the API’s Response contract.

Room Settlement Workflow

code
1need {2  sender = User(request.sender_id)3  recipient = User(request.recipient_id)4}56if request.amount <= 0 {7  throw BadRequest("Settlement amount must be positive")8}910Settlement settlement = Settlement {11  room_id: request.room_id12  sender13  recipient14  amount: request.amount15  settled_at: time.now()16}1718save(settlement)19return Response { settlement }

The validation branch stops invalid work. Construction stays visible, durable mutation stays explicit, and the typed return confirms what was saved.

Clone Boundary

code
1Expense copied_expense = Expense {2  room_id: expense.room_id3  payer: expense.payer4  title: expense.title + " (copy)"5  amount: expense.amount6  note: expense.note7  receipt: expense.receipt8  status: ExpenseStatus.Draft9}1011save(copied_expense)

When portable authored source matters, construct the new entity explicitly and save it. The fields being copied, the new status, and the durable write remain visible instead of depending on an unavailable clone lowering.

Common Mistakes

WrongCorrect
save expensesave(expense)
save [expense]save(expense)
Assume assignment persistsCall save explicitly.
Use backend save in Page ScriptCall a typed backend API alias.
Return nothing from a typed mutation APIReturn the metadata-defined Response value.
clone(expense)Construct a new entity explicitly, or use an explicitly supported host clone workflow.

Continue Learning