Operations
Named, reusable OQL procedures stored server-side. Define once, execute by name from any query. Operations accept arguments and return values. Equivalent to stored procedures — but in OQL.
| Verb | Description |
|---|---|
DEFINE NEW OPERATION AS "name" OPEN NEST ... CLOSE NEST | Define and store an operation |
EXECUTE OPERATION "name" SET ?result | Execute a stored operation |
EXECUTE OPERATION "name" WITH ?args SET ?result | Execute with arguments — accessible as !REQUEST(key) inside |
LIST OPERATIONS SET ?ops | List all defined operations in the namespace |
DESCRIBE OPERATION "name" SET ?def | Get definition and metadata for an operation |
DELETE OPERATION "name" | Remove a stored operation |
Define an operation
DEFINE NEW OPERATION AS "get_top_products"
OPEN NEST
QUERY "products" FROM "shop" SORT BY "sales" LIMIT 10 SET ?rows
AFTER RETURN ?rows
CLOSE NEST
AFTER EMIT "Defined"
Execute it
EXECUTE OPERATION "get_top_products" SET ?products
AFTER EMIT ?products
Try it ›
Operation with arguments
(* Define *)
DEFINE NEW OPERATION AS "send_welcome"
OPEN NEST
EMAIL "Welcome to OQL!" TO !REQUEST(email) WITH "Welcome"
AFTER RETURN true
CLOSE NEST
(* Execute with args *)
NEW JSON OBJECT OPEN NEST SET "email" AS "new@user.com" CLOSE NEST SET ?args
AFTER EXECUTE OPERATION "send_welcome" WITH ?args SET ?ok
AFTER EMIT ?ok
List / Delete
LIST OPERATIONS SET ?ops
AFTER EMIT ?ops
DELETE OPERATION "send_welcome"
AFTER EMIT "Deleted"