proc-macro to help with using surrealdb's custom functions

Overview

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.

Comments
  • chore(deps): update rust crate tokio to 1.30.0

    chore(deps): update rust crate tokio to 1.30.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | tokio (source) | dev-dependencies | minor | 1.29.1 -> 1.30.0 |


    Release Notes

    tokio-rs/tokio (tokio)

    v1.30.0: Tokio v1.30.0

    Compare Source

    1.30.0 (August 9, 2023)

    This release bumps the MSRV of Tokio to 1.63. (#​5887)

    Changed
    • tokio: reduce LLVM code generation (#​5859)
    • io: support --cfg mio_unsupported_force_poll_poll flag (#​5881)
    • sync: make const_new methods always available (#​5885)
    • sync: avoid false sharing in mpsc channel (#​5829)
    • rt: pop at least one task from inject queue (#​5908)
    Added
    • sync: add broadcast::Sender::new (#​5824)
    • net: implement UCred for espidf (#​5868)
    • fs: add File::options() (#​5869)
    • time: implement extra reset variants for Interval (#​5878)
    • process: add {ChildStd*}::into_owned_{fd, handle} (#​5899)
    Removed
    • tokio: removed unused tokio_* cfgs (#​5890)
    • remove build script to speed up compilation (#​5887)
    Documented
    • sync: mention lagging in docs for broadcast::send (#​5820)
    • runtime: expand on sharing runtime docs (#​5858)
    • io: use vec in example for AsyncReadExt::read_exact (#​5863)
    • time: mark Sleep as !Unpin in docs (#​5916)
    • process: fix raw_arg not showing up in docs (#​5865)
    Unstable
    • rt: add runtime ID (#​5864)
    • rt: initial implementation of new threaded runtime (#​5823)

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • fix(deps): update rust crate quote to 1.0.32

    fix(deps): update rust crate quote to 1.0.32

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | quote | dependencies | patch | 1.0.31 -> 1.0.32 |


    Release Notes

    dtolnay/quote (quote)

    v1.0.32

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • Cargo.toml (cargo)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Show all Merge Confidence badges for pull requests.
    • Enable Renovate Dependency Dashboard creation.
    • Use semantic commit type fix for dependencies and chore for all others if semantic commits are in use.
    • Ignore node_modules, bower_components, vendor and various test/tests directories.
    • Group known monorepo packages together.
    • Use curated list of recommended non-monorepo package groupings.
    • Apply crowd-sourced package replacement rules.
    • Apply crowd-sourced workarounds for known problems with packages.

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 1 Pull Request:

    fix(deps): update rust crate quote to 1.0.32
    • Schedule: ["at any time"]
    • Branch name: renovate/quote-1.x
    • Merge into: main
    • Upgrade quote to 1.0.32

    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • fix(deps): update rust crate quote to 1.0.33

    fix(deps): update rust crate quote to 1.0.33

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | quote | dependencies | patch | 1.0.32 -> 1.0.33 |


    Release Notes

    dtolnay/quote (quote)

    v1.0.33

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • chore(deps): update rust crate tokio to 1.32.0

    chore(deps): update rust crate tokio to 1.32.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | tokio (source) | dev-dependencies | minor | 1.30.0 -> 1.32.0 |


    Release Notes

    tokio-rs/tokio (tokio)

    v1.32.0: Tokio v1.32.0

    Compare Source

    Fixed
    • sync: fix potential quadradic behavior in broadcast::Receiver (#​5925)
    Added
    • process: stabilize Command::raw_arg (#​5930)
    • io: enable awaiting error readiness (#​5781)
    Unstable
    • rt(alt): improve the scalability of alt runtime as the number of cores grows (#​5935)

    v1.31.0: Tokio v1.31.0

    Compare Source

    Fixed
    • io: delegate WriteHalf::poll_write_vectored (#​5914)
    Unstable
    • rt(unstable): fix memory leak in unstable next-gen scheduler prototype (#​5911)
    • rt: expose mean task poll time metric (#​5927)

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • fix(deps): update rust crate syn to 2.0.29

    fix(deps): update rust crate syn to 2.0.29

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | syn | dependencies | patch | 2.0.27 -> 2.0.29 |


    Release Notes

    dtolnay/syn (syn)

    v2.0.29

    Compare Source

    v2.0.28

    Compare Source

    • Fix inconsistency between full and non-full expression parse errors (#​1491)

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    Open

    These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

    Detected dependencies

    cargo
    Cargo.toml
    • nom 7.1.3
    • proc-macro-error 1.0.4
    • proc-macro2 1.0.66
    • quote 1.0.32
    • syn 2.0.27
    • chrono 0.4.26
    • tokio 1.30.0
    • uuid 1.4.1

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
  • feat: Add a warning about using unstable datastore api

    feat: Add a warning about using unstable datastore api

    On surrealdb discord it's been mentioned the API for datastore is not stable, and while it is exported, it's undocumented and shouldn't be depended on for the time being.

    This is a tracking issue for either adding a warning to the generated functions or just a note in readme.

    opened by alyti 0
  • feat: Move away from internal copy of the surrealql parser

    feat: Move away from internal copy of the surrealql parser

    Currently this crate is using a pre-beta.10, post-beta.9 nightly surrealql parser that was manually copied from official crate, the parser was also modified to allow for collection of comments so docstrings could be generated.

    In the future it would be preferable to depend on the official crate for the parsing.

    Tracking issues:

    • https://github.com/surrealdb/surrealdb/issues/2312
    opened by alyti 0
Releases(v0.0.3)
Library and proc macro to analyze memory usage of data structures in rust.

Allocative: memory profiler for Rust This crate implements a lightweight memory profiler which allows object traversal and memory size introspection.

Meta Experimental 19 Jan 6, 2023
Lightweight parsing for Rust proc macros

Lightweight parsing for Rust proc macros Venial is a WIP parser for Rust proc macros. When writing proc macros that need to parse Rust code (such as a

Olivier FAURE 148 Dec 30, 2022
A simple /proc//{mem,maps} library for Rust

Summary A very simple library that wraps around /proc/pid/mem and /proc/pid/maps to read memory out of a running process on Linux. Usage Basic usage l

null 6 Jul 27, 2022
Proc-macros for generating icons from the Iconify API

iconify-rs This crate provides a macro to embed SVGs from Iconify. For a list of icons, see Iconify Icon Sets. ?? Usage let svg = iconify::svg!("mdi:h

Matthew Taylor 5 Jul 9, 2023
probe-run is a custom Cargo runner that transparently runs Rust firmware on an embedded device

probe-run Runs embedded programs just like native ones probe-run is a custom Cargo runner that transparently runs Rust firmware on an embedded device.

Knurling 483 Jan 7, 2023
Custom deserialization for fields that can be specified as multiple types.

serde-this-or-that Custom deserialization for fields that can be specified as multiple types. This crate works with Cargo with a Cargo.toml like: [dep

Ritvik Nag 7 Aug 25, 2022
Custom formatting for Rust.

custom-format This crate extends the standard formatting syntax with custom format specifiers, by providing custom formatting macros. It uses : (a spa

null 6 Dec 14, 2022
Create custom ID types that are guaranteed to be valid `RecordID` in SurrealDB

surreal-id The surreal-id crate offers a standardized way to create and validate IDs in your application for usage with SurrealDB. Using the NewId tra

Liam Woodleigh-Hardinge 4 Oct 5, 2023
A tool & library to help you with the compiler course.

Compiler Course Helper Support: eliminate left recursion (require grammar with no cycles or ϵ-production) calculate nullable, first sets, follow, sets

水夕 4 May 2, 2022
rust database for you to use and help me make!

Welcome To Rust Database! What is this? this is a database for you to git clone and use in your project! Why should i use it? It is fast and it takes

Carghai74 2 Dec 4, 2022
A console viewer for trees – pet project to help me learn Rust.

treeviewer This is a pet project to help me learn Rust. But maybe it’ll end up being of actual use for someone? The idea is to write a program that, g

Daniel Janus 3 Jul 15, 2023
A library for extracting #[no_mangle] pub extern "C" functions (https://docs.rust-embedded.org/book/interoperability/rust-with-c.html#no_mangle)

A library for extracting #[no_mangle] pub extern "C" functions In order to expose a function with C binary interface for interoperability with other p

Dmitrii - Demenev 0 Feb 17, 2022
Functions for mapping plaintexts to a u64 while preserving sort order

ore_encoding.rs This is a companion package to ore.rs that can generate and manipulate u64 plaintexts before they are encrypted by ore.rs. Being able

CipherStash 2 Dec 14, 2022
Generate rust structs & query functions from diesel schema files

dsync A utility to generate database structs and querying code from diesel schema files. Primarily built for create-rust-app. Currently, it's more adv

Haris 20 Feb 12, 2023
A Rust crate providing utility functions and macros.

介绍 此库提供四类功能:异常处理、http post收发对象、格式转换、语法糖。 在 Cargo.toml 里添加如下依赖项 [dependencies.xuanmi_base_support] git = "https://github.com/taiyi-research-institute/x

null 17 Mar 22, 2023
A Rust macro for writing nested loop expressions

loop_chain A Rust macro for writing nested loop expressions Usage | Examples | Docs Dependencies [dependencies] loop_chain = "0.1.1" Usage For express

Takayuki Maeda 5 Jul 30, 2021
Macro assembler for Rust

Macro Assembler This crate implement JSC/SpiderMonkey like macro assembler. Macro assembler purpose is to generate machine code for different platform

playX 6 Nov 26, 2022
A procedural macro for configuring constant values across crates

toml-cfg Rough ideas: Crates can declare variables that can be overridden Anything const, e.g. usize, strings, etc. (Only) The "root crate" can overri

James Munns 43 Dec 24, 2022
A Rust attribute macro that adds memoization to a function (rhymes with Mickey)

michie (sounds like Mickey) — an attribute macro that adds memoization to a function. Table of contents Features Non-features key_expr key_type store_

Mobus Operandi 16 Dec 20, 2022