NoteThe
surrealismexperimental feature must be enabled before you can use aDEFINE MODULEstatement.
Available since: v3.0.0-alpha.12
DEFINE MODULE statementA DEFINE MODULE statement is used to define a module via which Surrealism functions can be called.
SurrealQL SyntaxDEFINE MODULE [ OVERWRITE | IF NOT EXISTS ] @mod::@sub AS @file_name
A module includes a module and a sub, followed by AS and a pointer to the .surli file containing the Rust code compiled to WASM through the Surrealism CLI.
DEFINE MODULE mod::test AS f"test:/demo.surli";
Once the module is defined, functions can be accessed through this path.
Assuming these two functions in the Rust code before compilation to WASM via the Surrealism CLI:
fn returns_true() -> bool { true }; fn check_num_size(num: i32) -> Result<i32, &'static str> { if num >= 500 { Err("Number is too big!") } else { Ok(num) } }
They will then be accessible using the following paths.
RETURN mod::test::returns_true(); -- true RETURN mod::test::check_num_size(100); -- 100