Crate surreal_use

Source
Expand description

§surreal_use

An extension library based on the Surrealdb library to help users develop more conveniently


|\ |\ |\ |\ __ |\ __ |\ ___ \ |\ __ |\ \ |\ |\ |\ |\ ___
\ \ ___|\ \ \\ \ \ |\ \ \ |\ \ \ /|\ \ |\ \ \ \ \ \ \\ \ \ _|\ \ /| \ _
\ \ \\ \ \ _ \ \ _ \ \ _|/\ \ __ \ \ \ \ \ \\ \ _
\ \ _|/
|
|\ \ \ \\ \ \ \ \ \ \ \ \ _|\ \ \ \ \ \ \ _ \ \ \\ ||\ \ \ _|\
_\ \ _
\ _
\ \ _\ \ _
\ _\ _\ _\ ___\ \ _
|_
|_______||||||||||_______||||||| ||_|| || |____|

  • author:syf20020816@outlook.com
  • createDate:20240115
  • updateDate:20240125
  • version:0.0.1
  • email:syf20020816@outlook.com

§QuickStart

§write surrealdb.config.json

{
  "endpoint":"127.0.0.1",
  "port":10086,
  "auth":{
    "user":"root",
    "pass":"root"
  }
}

§use surreal_use

use lazy_static::lazy_static;
use surreal_use::{
    config::{auth::Root, parser::Parsers, AuthBridger},
    core::Stmt,
};
use surrealdb::{
    engine::remote::ws::{Client, Ws},
    Surreal,
};

// use lazy static macro
lazy_static! {
    static ref DB: Surreal<Client> = Surreal::init();
}

#[tokio::main]
async fn main() -> surrealdb::Result<()> {
    // Using seasonal_ Use to obtain the configuration of surrealdbunconfig.json under the project package
    let config = Parsers::Json.parse_to_config(None);
    DB.connect::<Ws>(config.url()).await?;
    // transfer to credential Root
    let credentail: Root = config.get_auth().into();
    // Sigin use Root
    // Return Jwt struct
    let _ = DB.signin(credentail.to_lower_cast()).await?;
    let _ = DB.use_ns("test").use_db("test").await?;
    let select = Stmt::select().table("user".into()).field_all().to_string();
    let query = DB.query(&select).await?;
    dbg!(query);
    Ok(())
}

§Attation

There are many structures in use with the same name as the surrealdb library, which exist as extensions to the source library

Modules§

config
config and parse configuration
core
core mod for surreal_use

Macros§

impl_stmt_bridge
macro for StmtBridge