https://github.com/alyti/surrealdb_functions
proc-macro to help with using surrealdb's custom functions
https://github.com/alyti/surrealdb_functions
parser proc-macro rust surrealdb
Last synced: 15 days ago
JSON representation
proc-macro to help with using surrealdb's custom functions
- Host: GitHub
- URL: https://github.com/alyti/surrealdb_functions
- Owner: alyti
- License: apache-2.0
- Created: 2023-07-22T15:34:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-18T08:33:15.000Z (over 1 year ago)
- Last Synced: 2024-04-24T20:26:58.474Z (12 months ago)
- Topics: parser, proc-macro, rust, surrealdb
- Language: Rust
- Homepage: https://lib.rs/crates/surrealdb_functions
- Size: 40 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# SurrealDB Functions [](https://crates.io/crates/surrealdb_functions) [](https://docs.rs/surrealdb_functions)
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](/examples/main.rs), but in short, its main usage is as follows:
```rust
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` 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.