MIT
Surrealism依托于Surrealdb提供的Rust官方标准库:surrealdb,目的是构建一种更加统一,简单的方式对Surrealdb数据库进行各类操作
Surrealism relies on Surrealdb's official Rust standard library:surrealdb,The purpose is to build a more unified and simple way to perform various operations on Surrealdb database
toml
[dependencies]
surrealism = {version="0.2.2"}
tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread"] }
配置:
可采用JSON或TOML两种配置文件方式
设置配置文件地址可以是: - ./Surrealism.toml - ./configs/Surrealism.toml - ./templates/Surrealism.toml
configuration:
Two configuration file methods can be used: JSON or TOML
The configuration file address can be set to:
❗note:当前SurrealDB仍处于开发阶段,对应连接鉴权方式:NS和DB并为支持,所以使用Surrealism进行配置时请以Root方式进行鉴权连接,不要设置ns和db!
❗note:Currently, SurrealDB is still in the development stage, and the corresponding connection authentication methods are supported: NS and DB. Therefore, when using Surrealsm for configuration, please use Root mode for authentication connections and do not set ns and db!
json
{
"surreal" : "Single"
"auth" : "Root"
"username" : "root"
"password" : "syf20020816"
"url" : "127.0.0.1"
"port" : 10086
"mode" : "Memory"
"path" : "E:/Rust/surreal"
"log" : {"level" : "Info", "print" : true,"path" : "E:/surrealism/log" }
}
toml
[default]
surreal = "Single"
auth = "Root"
username = "root"
password = "syf20020816"
url = "127.0.0.1"
port = 10086
mode = "Memory"
path = "E:/Rust/surreal"
log = { level = "Info", print = true, path = "E:/surrealism/log" }
```rust use surrealism::{DefaultInitService, InitService, SurrealID, SurrealismCommit, SurrealismConnector, SurrealismRes, Table, UseNSDB, parse_response}; use surrealism::builder::{BaseWrapperImpl, SQLBuilderFactory, TableImpl}; use surrealism::builder::create::{CreateWrapper, CreateWrapperImpl}; use serde::{Serialize, Deserialize}; use surrealism::builder::select::SelectWrapperImpl;
struct User { username: String, pwd:String, male: bool, age: u8, }
/// create a new user table /// tablename:user /// tableid:surrealism pub fn crateusertable() -> CreateWrapper { // create a user data let user = User { username: "Tobie".tostring(), pwd: "Tobie001".tostring(), male: true, age: 23, }; // create table with content let usertable = SQLBuilderFactory::create() .table("user") .id(SurrealID::from("surrealism")) .content(&user) .derefmut(); user_table }
async fn main() -> SurrealismRes<()> { // init service let mut service = DefaultInitService::new().init(); // use ns:test and db:test let _ = service.usecommit("test", "test").await?; // get info from surrealdb // let info = SQLBuilderFactory::info().db().build(); // let infores = service.commitsql(&info).await?; // dbg!(infores); // create a table // let createstmt = crateusertable().build(); // let createres = service.commitsql(&createstmt).await?; // dbg!(createres); // select user::surrealism table let select = SQLBuilderFactory::select().table("user").id(SurrealID::from("surrealism")).column("*").build(); let selectres = service.commitsql(&select).await?; //parse response to any type you want let res: User = parseresponse(select_res); // [tests\src\main.rs:55] res = User { // username: "Tobie", // pwd: "Tobie001", // male: true, // age: 23, // } dbg!(&res); Ok(()) } ```
```bash ▄▄▄▄ ▄▄▄▄ ██ ▄█▀▀▀▀█ ▀▀██ ▀▀ ██▄ ██ ██ ██▄████ ██▄████ ▄████▄ ▄█████▄ ██ ████ ▄▄█████▄ ████▄██▄ ▀████▄ ██ ██ ██▀ ██▀ ██▄▄▄▄██ ▀ ▄▄▄██ ██ ██ ██▄▄▄▄ ▀ ██ ██ ██ ▀██ ██ ██ ██ ██ ██▀▀▀▀▀▀ ▄██▀▀▀██ ██ ██ ▀▀▀▀██▄ ██ ██ ██ █▄▄▄▄▄█▀ ██▄▄▄███ ██ ██ ▀██▄▄▄▄█ ██▄▄▄███ ██▄▄▄ ▄▄▄██▄▄▄ █▄▄▄▄▄██ ██ ██ ██ ▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀
2023-08-30T03:06:57.875Z INFO [surrealism::core::config::init::default] Welcome to use Surrealism!
2023-08-30T03:06:57.878Z INFO [surrealism::core::config::init::default] Init Service : Config Service
Successfully!
2023-08-30T03:06:57.878Z INFO [surrealism::core::config::init::default] Init Service : Log Service
Successfully!
2023-08-30T03:06:57.886Z INFO [surrealism::core::config::init::default] Please focus following print to check!
Version {
router: Ok(
Router {
conn: PhantomDataConnection Service
Successfully!
[tests\src\main.rs:60] &res = User {
username: "Tobie",
pwd: "Tobie001",
male: true,
age: 23,
}
```
0.2.2:
0.2.1:
Function::array
Function::count
Function::crypto
RELATE
语句构造错误的问题,感谢timlagrande <notifications@github.com>
(Fix the issue of incorrect construction of the RELATE
statement. Thank timlagrande <notifications@github.com>
)SELECT
语句Column
构建添加AS
关键字功能 (SELECT
statement Column
construction adds AS
keyword )surrealism::functions::{GenerateCompare, CryptoFunc}
(SurrealDB built-in encryption function,See surrealism::functions::{GenerateCompare, CryptoFunc}
)0.2.0:
重构了各类Wrapper,使用简单统一的构造器+工厂模式(Reconstructed various Wrappers using a simple and unified constructor+factory pattern)
增加row sql进行语句构建(Add row SQL for statement construction)
启动与初始化更新,你可以基于框架提供的trait和struct自己构建初始化服务(Starting and initializing updates, you can build your own initialization services based on the traits and structs provided by the framework)
增加大量构建工具(Add a large number of construction tools)
分离语句构造和语句提交(Separate statement construction and statement submission)
0.1.1:更新配置,增加基于Namespace和Database的支持,但是基于当前SurrealDB无法支持,所以并不能使用🥲(Update the configuration and add support based on Namespace and Database, but it cannot be used due to the current SurrealDB support 🥲)