nenu-lang / reading-data
Stable

Reading Data

  • need declares durable reads before ordinary runnable logic.
  • The entity suffix chooses one, optional, array, or map result shape.
  • A need block is declarative: references determine dependency order, not written order.

Inline And Block Need

code
1need room = Room(request.room_id)

Use inline form for one read and block form for related reads. Backend needs appear at runnable top level before ordinary branches, loops, and effects.

Fetch Result Shapes

FormResultMeaning
Expense(id)ExpenseOne required record.
Expense?(id)Expense?One optional record.
Expense[](ids)Expense[]Requested IDs as an array.
Expense{}(ids)Expense{}Requested IDs as a map keyed by requested ID.
Room.name(value)RoomOne record by a unique named field.
Expense(request.id).shares(key)Expense.sharesOne exact child record.

The optional marker appears before the parentheses. The array or map marker appears on the entity name. Parentheses contain the exact fetch input.

Declarative Dependency Ordering

code
1need {2  expenses = Expense[]({ room_id == room.id })3  room = Room(request.room_id)4}

room is fetched first even though it is written second because expenses depends on room.id. The compiler builds a dependency graph from fetch inputs and ordinary query filter values.

  • Bindings may reference another binding declared anywhere in the same need block.
  • Use the bare binding name. needs.room.id is invalid.
  • Unknown references are compile-time errors.
  • Dependency cycles such as a → b → a are compile-time errors.
  • Independent reads have deterministic lowering order but must remain semantically independent.

Required And Optional Reads

code
1need expense = Expense(request.expense_id)2return Response { expense }

Choose a required fetch when absence is itself a hard failure. Choose an optional fetch when the runnable has meaningful control flow for the missing case.

Child Reads

code
1need share = Expense(request.expense_id).shares(request.member_id)

A child read begins with one exact parent, then names the declared lower-camel child segment. The separate Room.name(...) tab demonstrates a named lookup against the canonical unique Room.name field. Child array queries may use the same supported filters and modifiers as other needs.

Reserved Need Bindings

Need binding names request, req, auth, and needs are reserved runtime source roots. Choose domain names such as room, expense, or payer.

Common Mistakes

WrongCorrect
needs { ... }need { ... }
Expense(id)?Expense?(id)
Array<Expense>(ids)Expense[](ids)
needs.room.idroom.id
Put need inside an if branchDeclare backend needs at runnable top level.

Continue Learning