tiki/.doc/doki/doc/ruki/examples.md
2026-04-14 23:31:32 -04:00

5.3 KiB

Examples

Table of contents

Overview

The examples show common patterns, useful combinations, and a few edge cases.

Simple statements

Select all tikis:

select

Select with a basic filter:

select where status = "done" and priority <= 2

Select specific fields:

select title, status
select id, title where status = "done"
select * where priority <= 2
select title, status where "bug" in tags order by priority

Select with ordering:

select order by priority
select where status = "done" order by updatedAt desc
select where "bug" in tags order by priority asc, createdAt desc

Select with limit:

select order by priority limit 3
select where "bug" in tags order by priority limit 5
select id, title order by priority limit 2 | clipboard()

Create a tiki:

create title="Fix login" priority=2 status="ready" tags=["bug"]

Update matching tikis:

update where status = "ready" and "sprint-3" in tags set status="cancelled"

Delete matching tikis:

delete where status = "cancelled" and "old" in tags

Conditions and lists

Check whether a tag is present:

select where "bug" in tags

Check whether one tiki depends on another:

select where id in dependsOn

Check whether status is one of several values:

select where status in ["done", "cancelled"]

Check whether dependencies match a condition:

select where dependsOn any status != "done"
select where dependsOn all status = "done"

Boolean grouping:

select where not (status = "done" or priority = 1)

Functions and dates

Count matching tikis:

select where count(select where status = "done") >= 1

Current user:

select where assignee = user()

Compare timestamps:

select where updatedAt < now()
select where updatedAt - createdAt > 1day

Calculate a date from recurrence:

create title="x" due=next_date(recurrence)

Add to or remove from a list:

create title="x" tags=tags + ["needs-triage"]
create title="x" dependsOn=dependsOn - ["TIKI-ABC123"]

Use call(...) in a value:

create title=call("echo hi")

Pipe select results to a shell command or clipboard:

select id, title where status = "done" | run("myscript $1 $2")
select id where id = id() | clipboard()
select description where id = id() | clipboard()

Before triggers

Block completion when dependencies remain open:

before update where new.status = "done" and dependsOn any status != "done" deny "cannot complete tiki with open dependencies"

Require a description for high-priority work:

before update where new.priority <= 2 and new.description is empty deny "high priority tikis need a description"

Limit how many in-progress tikis someone can have:

before update where new.status = "in progress" and count(select where assignee = new.assignee and status = "in progress") >= 3 deny "WIP limit reached for this assignee"

After triggers

Auto-assign urgent new work:

after create where new.priority <= 2 and new.assignee is empty update where id = new.id set assignee="booleanmaybe"

Create the next recurring tiki:

after update where new.status = "done" and old.recurrence is not empty create title=old.title priority=old.priority tags=old.tags recurrence=old.recurrence due=next_date(old.recurrence) status="ready"

Clear recurrence on the completed source tiki:

after update where new.status = "done" and old.recurrence is not empty update where id = old.id set recurrence=empty

Clean up reverse dependencies on delete:

after delete update where old.id in dependsOn set dependsOn=dependsOn - [old.id]

Run a command after an update:

after update where new.status = "in progress" and "claude" in new.tags run("claude -p 'implement tiki " + old.id + "'")

Time triggers

Move stale in-progress tasks back to backlog:

every 1hour update where status = "in_progress" and updatedAt < now() - 7day set status="backlog"

Delete expired done tasks:

every 1day delete where status = "done" and updatedAt < now() - 30day

Create a weekly review task:

every 1week create title="weekly review" status="ready" priority=3

Invalid examples

Unknown field:

select where foo = "bar"

Wrong field value type:

create title="x" priority="high"

Using the wrong operator with status:

select where status < "done"

Using any on the wrong kind of field:

select where tags any status = "done"

Using old. where it is not allowed:

select where old.status = "done"

A list with mixed value types:

select where status in ["done", 1]

Trigger is missing the right action:

after update where new.status = "done" deny "no"

Non-string run(...) command:

after update run(1 + 2)

Ordering by a non-orderable field:

select order by tags
select order by dependsOn

Order by inside a subquery:

select where count(select where status = "done" order by priority) >= 1