Queries
Helper functions for building Roam API queries. Available at roam_sdk::queries.
Daily notes
daily_note_uid_for_date
Generate the UID for a daily note from a date.
pub fn daily_note_uid_for_date(month: u32, day: u32, year: i32) -> Stringlet uid = queries::daily_note_uid_for_date(2, 21, 2026);
assert_eq!(uid, "02-21-2026");pull_daily_note
Build a pull request for a daily note by its UID.
pub fn pull_daily_note(uid: &str) -> (serde_json::Value, String)Returns (eid, selector) ready to pass to client.pull().
let uid = queries::daily_note_uid_for_date(2, 21, 2026);
let (eid, selector) = queries::pull_daily_note(&uid);
let resp = client.pull(eid, &selector).await?;The selector includes: :block/uid, :node/title, :block/string, :block/children (recursive), :block/order, :block/open, :block/refs.
Pages
pull_page_by_title
Build a pull request for any page by title.
Uses [:node/title "..."] as the entity lookup. Same selector as daily notes.
all_page_titles_query
Build a Datalog query to fetch all page titles and UIDs.
Returns rows of [title, uid].
search_blocks_query
Build a Datalog query to fetch all blocks with their text and parent page title.
Returns rows of [uid, block_string, page_title]. Useful for full-text search when combined with client-side filtering.
Graph statistics
graph_page_count_query
Count total pages in the graph.
Returns [[count]].
graph_block_count_query
Count total blocks in the graph.
Returns [[count]].
Linked references
linked_refs_query
Build a Datalog query that finds all blocks referencing a page.
Returns a query string for client.query(). Double quotes in the title are escaped.
The query returns rows of [uid, block_string, source_page_title]. Parse the results with types::parse_linked_refs():
Writing your own queries
You can pass any Datalog query string directly to client.query():
Query format notes:
Use
:findwith simple variable bindings (not pull expressions):whereclauses use Datomic-style pattern matchingargsmust always be provided (usevec![]for no arguments)Results are
Vec<Vec<serde_json::Value>>with values in:findvariable order
Last updated
Was this helpful?