Data & State
Statements that read and write data: set, find, db.update_user, derive, and merge.
set { }
The primary way to write variables. Each line is target op value. See Variables and state for the full scope and operations reference.
set {
user.balance += 10
user.name = flow.trimmed
user.todos << [{ title: "Buy milk", done: false }]
user.muted toggle true
user.profile merge { city: "NYC" }
}
The 9 operations: = (assign), += / -= (add/subtract), << / append, prepend, increment, decrement, merge, delete, toggle, ensure (set only if currently nil).
<< appends an array — wrap a single element: user.list << [item].
find
Query the user database or any collection with dynamic filters. Returns matching results and a count.
let { results, count } = find(from: "users")
send.text(`There are ${count} users.`)
find supports where/match filters and a query pipeline for filtering large collections. For in-flow array filtering, the array.* builtins (array.where, array.find, array.reject) are usually simpler — see Builtins.
db.update_user
Update a specific user's variables directly using MongoDB-style operators ($set, $inc, $push). Useful when you need to write another user's state (the current user's state is simpler with set).
db.update_user(chat_id: flow.target_uid, updates: { "$inc": { "rep": 1 } })
| Param | Type | Notes |
|---|---|---|
chat_id | Number | The user to update |
updates! | Object | MongoDB-style update document |
derive
Compute a value via a typed transform and bind it:
let { value } = derive(expr: "input * 2", input: flow.n)
In most cases a plain set { flow.x = flow.n * 2 } is clearer; derive is for when you want an explicit transform node.
merge
Collect multiple data inputs into a single aggregate value (commonly used to join the outputs of parallel work):
let { value } = merge(items: [flow.a, flow.b, flow.c])