surreal_derive_plus-1.0.3 has been yanked.
Surreal derive
Simple library for writing SurrealQL , this is just a verythin layer on top of SurrealDb Rust SDK. You will never pay any runtime performance for what you don't do
Installation
1. Install surreal-devl: https://github.com/dev-logs/surreal-devl
Contains the core logic of the whole library, the main purpose is to act as a bridge between SurrealDb SDK and the your defined Struct, also support working with Array, ID or DateTime
cargo add sureal_devl
2. Install surreal-derive:
cargo add surreal_derive_plus
Usage
Mark your struct as surreal_derive
This will will automatically generate code that could convert your struct into surrealdb idioms
use ;
use SurrealDerive;
Implement the Intosurrealdb::value::RecordId trait
use RecordId;
use crateUser;
Write query by using surreal_derive_plus::surreal_quote! macro
Struct
use surreal_quote;
.... connect to your surreal db ...
let new_user = User ;
let created_user: = DB.query.await.unwrap.take.unwrap; => CREATE user:surreal SET name='surreal', password='000000'
Variable
let age = 2;
let query_statement = surreal_quote!;
assert_eq!
Array
let arr = vec!;
let query_statement = surreal_quote!;
assert_eq!
Struct Array
let friends = vec!;
let query_statement = surreal_quote!;
assert_eq!;
DateTime
let dateBirth: = Utc.with_ymd_and_hms.unwrap;
let query_statement = surreal_quote!;
assert_eq!;
Surreal ID
let user = User ;
let query_statement = surreal_quote!;
assert_eq!;
Customize setting
You can customize the setting inside cargo.toml it is neccessary for call cargo clean to apply all of these configuration
[]
# Will log the query command at runtime
= false
# Will log the generated code at build time
= false
# Change the naming convention of generated statement into camel case
= false
# The log namespace, apply for both build time log and runtime log
= "surrealql-derive"
# The macro name that use for info log, for example
= "println"
# The macro name that use for warning log, for example
= "println"