Macro spacetimedb::query

source ·
query!() { /* proc-macro */ }
Expand description

Implements query!(|row| …) macro for filtering rows.

§Example

use spacetimedb::{spacetimedb, query};

#[spacetimedb(table)]
pub struct Person {
    name: String,
    age: u32,
}

for person in query!(|person: Person| person.age >= 18) {
   println!("{person:?}");
}

§Syntax

Supports Rust-like closure syntax, with the following limitations:

  • Only one argument is supported.
  • Argument must be an identifier (destructuring is not yet implemented).
  • Argument must have an explicit table type annotation.
  • Left hand side of any comparison must be a table field access.
  • Right hand side of any comparison must be a literal or a captured variable foo or a property foo.bar.baz (which will be inlined as its value). In the future field-to-field comparisons will be supported too.
  • Comparisons can be combined with && and || operators.
  • Parentheses are supported.
  • Unary ! operator is supported at the syntax level but not yet implemented by the VM so it will panic at translation phase.