···11+# Utility Globals
22+33+Global functions available in queries, procedures, and [index hooks](../../guides/index-hooks.md). These don't belong to a specific API table — they're available at the top level of any Lua script.
44+55+## now
66+77+```lua
88+local timestamp = now()
99+-- "2026-04-19T15:30:00Z"
1010+```
1111+1212+Returns the current UTC time as an ISO 8601 string. Use this for `createdAt`, `updatedAt`, and similar timestamp fields.
1313+1414+## log
1515+1616+```lua
1717+log("processing record: " .. uri)
1818+log("count: " .. tostring(n))
1919+```
2020+2121+Writes a message to the server logs at debug level. Useful for debugging scripts during development. Log output appears in HappyView's stdout — check your platform's log viewer (Railway logs, `docker logs`, terminal output) to see it.
2222+2323+## TID
2424+2525+```lua
2626+local id = TID()
2727+-- "3abc123def456"
2828+```
2929+3030+Generates a fresh atproto TID (Timestamp Identifier) — a 13-character, base32-sortable string derived from the current timestamp. TIDs are the standard record key format in atproto. Use this when creating records with a specific rkey:
3131+3232+```lua
3333+local r = Record(collection, { text = "hello" })
3434+r:set_rkey(TID())
3535+r:save()
3636+```
3737+3838+## toarray
3939+4040+```lua
4141+return { items = toarray(results) }
4242+```
4343+4444+Marks a Lua table so it serializes as a JSON array rather than a JSON object. This matters for empty tables — without `toarray`, an empty `{}` becomes a JSON object `{}` instead of an array `[]`.
4545+4646+```lua
4747+-- Without toarray:
4848+return { items = {} }
4949+-- → {"items": {}}
5050+5151+-- With toarray:
5252+return { items = toarray({}) }
5353+-- → {"items": []}
5454+```
5555+5656+You don't need `toarray()` on results from `db.query`, `db.search`, `db.backlinks`, or `db.raw` — those already return properly marked arrays. Use it when you build a table yourself with `table.insert()` or array-index assignment.