surrealdb_functions

Crates.iosurrealdb_functions
lib.rssurrealdb_functions
version0.0.4
sourcesrc
created_at2023-07-22 15:29:20.342396
updated_at2023-07-23 17:57:00.367462
descriptionprocmacro for surrealdb functions (fn::*)
homepage
repositoryhttps://github.com/alyti/surrealdb_functions
max_upload_size
id923277
size104,449
Aly (alyti)

documentation

https://docs.rs/surrealdb_functions

README

SurrealDB Functions Crates.io Docs.rs

This is a proc-macro crate that given a path to a .surql file or a folder of .surql files, will parse DEFINE FUNCTION fn::s inside them and output rust fns that wrap around them. It will also generate a bootstrap function that stores the defined functions to db, and finally if a function is nested (fn::a::nested::function) it will be put in a nested module.

Usage

Example usage can be found in examples/main.rs, but in short, its main usage is as follows:

include_fn!{
    driver as is;
    datastore as ds_$;
    "$CARGO_MANIFEST_DIR/tests/main.surql"
}

When calling the macro you need to provide what naming the bindings should use: driver/datastore as is/prefix_$/$_suffix

  • is will not apply any changes to the method names.
  • prefix_$/$_suffix will replace $ with function name, effectively prefixing/suffixing it (ex. prefix_greet / greet_suffix)

At least one of driver/datastore must be defined.

  • driver will generate regular Surreal<C> bindings.
  • datastore will generate bindings for the more low-level locally-available-only surrealdb::kvs::Datastore

If both are defined, the parser will validate they don't conflict. (ex. you can't have both be as is)

Finally the last argument type is a file/directory path, if a directory is provided, it will be recursively resolved.

At least one valid path argument is expected, but more can be supplied. All resolved are stored in a hashset internally so path duplication should be a non-issue.

The docs.rs content is coming later, for now either read the source or ask me in surrealdb discord (same handle as on github). I am open to new feature/pull requests.

Crate notes

This is a utility proc-macro for surrealdb, as such it expects presence of surrealdb in user's dependencies. However, this crate by itself, does not depend on surrealdb.

Parser notes

Currently this macro only has the minimal surrealql parser for resolving the custom function definitions, sans their body.

Commit count: 15

cargo fmt