#surreal #execute #instance #delete #str #fn #execute-silent

app-db-schema

a common package for app with surreal

3 releases

0.1.2 Nov 14, 2022
0.1.1 Nov 14, 2022
0.1.0 Nov 12, 2022

#1076 in Database interfaces

31 downloads per month

MIT license

18KB
429 lines

usage

  • execute str
let v = "insert into mobile {id:123,num:123}"
        .execute_one::<Mobile>()
        .await;

or something ref to

#[async_trait]
pub trait StrDb {
        async fn execute_silent(&self) -> bool;
    async fn raw_execute_one(&self) -> Result<Vec<Value>, Error>;
    async fn execute_one<T: TryFrom<SurrealValue>>(&self) -> Vec<T>
    where
        <T as TryFrom<SurrealValue>>::Error: std::error::Error,
        <T as TryFrom<SurrealValue>>::Error: Send,
        <T as TryFrom<SurrealValue>>::Error: Sync,
        <T as TryFrom<SurrealValue>>::Error: 'static;
}
  • test sql
#[cfg(test)]
#[derive(SurrealDbObject, Debug, Clone)]
pub struct App {
    pub name: String,
}
#[cfg(test)]
mod test {
    use crate::*;
    fn instance() -> App {
        App {
            name: "adf".to_owned(),
        }
    }
    smethod!(
        format("create app CONTENT {}", instance, instance),
        App,
        create_app
    );
    // delete would return [] all ways
    // create as test would return value, so it is no need aa get_app
    smethod!(
        format("delete app where name='{}'", instance, instance.name),
        App,
        delete,
        [create_app][get_app]
    );

    smethod!(
        format(
            "select * from app where name = '{}'",
            instance,
            instance.name
        ),
        App,
        get_app
    );
}

check snapshots files to find features

  • filter set_filters!(r"[0-9a-zA-Z]{20}\b", "[UID]",);

release

cargo release publish --workspace --execute

test

cargo insta test  --review --delete-unreferenced-snapshots

Dependencies

~79MB
~1.5M SLoC