Crates.io | surrealism |
lib.rs | surrealism |
version | 0.3.1 |
source | src |
created_at | 2023-06-10 16:59:15.640384 |
updated_at | 2023-11-04 08:23:24.781271 |
description | Rust's extension of SurrealDB's official library aims to facilitate and unify various operations |
homepage | |
repository | https://github.com/Surrealism-All/Surrealism |
max_upload_size | |
id | 886977 |
size | 308,977 |
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 perul various operations on Surrealdb database
[dependencies]
surrealism = {version="0.3.1"}
tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread"] }
配置:
username:用户名
password:密码
local:本机连接(本机使用ws,远程使用wss)
bind: 连接地址,
auth:开启权限认证
tick_interval:运行节点代理tick的间隔(包括垃圾收集),默认为10秒
strict:严格模式
mode:连接模式(Memory表示内存File表示存到文件中,Tikv表示tikv集群地址)
path:存储到文件中的文件地址,使用Memory则无需设置
log:日志级别
query_timeout:设置查询超时时间
transaction_timeout: 事务超时时间
no_banner: 打印Banner
db_connection: 数据库连接行为
http_server: 服务器行为
capabilities: 能力
可采用JSON或TOML两种配置文件方式
设置配置文件地址可以是:
configuration:
username: db username
password: db password
local: Local connection (using ws locally, using wss remotely)
bind: Connection address,
auth:Enable permission authentication
tick_interval:The interval between running node agent tickets (including garbage collection), which defaults to 10 seconds
strict:strict mode
mode:Connection mode (Memory represents memory, File represents storage to file, Tikv represents Tikv cluster address)
path:The file address stored in the file, which does not need to be set when using Memory
log:log level
query_timeout:Set query timeout time
transaction_timeout: Transaction timeout time
no_banner: Print Banner
db_connection: database connection behavior
http_server: server behavior
capabilities: db Capabilities
Two configuration file methods can be used: JSON or TOML
The configuration file address can be set to:
{
"username" : "root",
"password" : "syf20020816",
"bind" : "127.0.0.1:10086",
"mode" : "Memory",
"log" : "Info",
"local": true,
}
[default]
username = "root"
password = "syf20020816"
bind = "127.0.0.1:10086"
mode = "Memory"
log = "Info"
local = true
use surrealism::db::{SurrealID, Table};
use surrealism::builder::{BaseWrapperImpl, SQLBuilderFactory, TableImpl};
use surrealism::builder::create::{CreateWrapper, CreateWrapperImpl};
use serde::{Serialize, Deserialize};
use surrealism::builder::select::SelectWrapperImpl;
use surrealism::surreal::{parse_response, SurrealismRes,DefaultInitService,UseNSDB,InitService,SurrealismCommit};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct User {
username: String,
pwd: String,
male: bool,
age: u8,
}
/// create a new user table
/// table_name:user
/// table_id:surrealism
pub fn crate_user_table() -> CreateWrapper {
// create a user data
let user = User {
username: "Tobie".to_string(),
pwd: "Tobie001".to_string(),
male: true,
age: 23,
};
// create table with content
let user_table = SQLBuilderFactory::create()
.table("user")
.id("surrealism".into())
.content(&user)
.deref_mut();
user_table
}
//strict!
#[tokio::main]
async fn main() -> SurrealismRes<()> {
// init service
let mut service = DefaultInitService::new().init();
// you have already define test namespace and test database!
// use ns:test and db:test
let _ = service.use_commit("test", "test").await?;
// get info from surrealdb
// let info = SQLBuilderFactory::info().db().build();
// let info_res = service.commit_sql(&info).await?;
// dbg!(info_res);
// create a table (you should define user table first!)
let create_stmt = crate_user_table().build();
let _ = service.commit_sql(&create_stmt).await?;
// dbg!(create_res);
// select user::surrealism table
let select = SQLBuilderFactory::select().table("user").id("surrealism".into()).column("*", None).build();
let select_res = service.commit_sql(&select).await?;
//parse response to any type you want
let res: User = parse_response(select_res);
// [tests\src\main.rs:55] res = User {
// username: "Tobie",
// pwd: "Tobie001",
// male: true,
// age: 23,
// }
dbg!(&res);
Ok(())
}
▄▄▄▄ ▄▄▄▄ ██
▄█▀▀▀▀█ ▀▀██ ▀▀
██▄ ██ ██ ██▄████ ██▄████ ▄████▄ ▄█████▄ ██ ████ ▄▄█████▄ ████▄██▄
▀████▄ ██ ██ ██▀ ██▀ ██▄▄▄▄██ ▀ ▄▄▄██ ██ ██ ██▄▄▄▄ ▀ ██ ██ ██
▀██ ██ ██ ██ ██ ██▀▀▀▀▀▀ ▄██▀▀▀██ ██ ██ ▀▀▀▀██▄ ██ ██ ██
█▄▄▄▄▄█▀ ██▄▄▄███ ██ ██ ▀██▄▄▄▄█ ██▄▄▄███ ██▄▄▄ ▄▄▄██▄▄▄ █▄▄▄▄▄██ ██ ██ ██
▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀
2023-10-24T08:54:49.323Z INFO [surrealism::core::surreal::config::init::default] Welcome to use Surrealism!
2023-10-24T08:54:49.323Z INFO [surrealism::core::surreal::config::init::default] Init Service : `Config Service` Successfully!
2023-10-24T08:54:49.329Z INFO [surrealism::core::surreal::config::init::default] Please focus following print to check!
Version {
router: Ok(
Router {
conn: PhantomData<surrealdb::api::engine::remote::ws::Client>,
sender: Sender,
last_id: 1,
features: {},
},
),
}
2023-10-24T08:54:49.329Z INFO [surrealism::core::surreal::config::init::default] Init Service : `Connection Service` Successfully!
[tests\src\main.rs:63] &res = User {
username: "Tobie",
pwd: "Tobie001",
male: true,
age: 23,
}
default = ["builder"]
row = []
builder = []
surreal = ["builder"]
full = ["row", "builder", "surreal"]
SurrealID::Default的支持
SurrealID::Int的支持
SurrealID::Float的支持
SurrealID::String的支持
SurrealID::Array的支持
SurrealID::UUID的支持
SurrealID::ULID的支持
SurrealID::RAND的支持
SurrealID::Range的支持
INSERT INTO STMT
ON DUPLICATE KEY UPDATE STMT
FIELD
OMIT
WITH INDEX|NOINDEX
FROM
WHERE
SPLIT
GROUP
ORDER
LIMIT
START
FETCH
TIMEOUT
PARALLEL
EXPLAIN [FULL]
FIELD
FROM
WHERE
FETCH
NAMESPACE
DATABASE
USER
LOGIN
TOKEN
SCOPE
TABLE
EVENT
FUNCTION
FIELD
INDEX
PARAM
CONTENT
MERGE
PATCH
SET
WHERE
RETURN
TIMEOUT
PARALLEL
RowSql的支持
row_sql!宏
Operator | Description | Finish |
---|---|---|
&& or AND | Checks whether both of two values are truthy | ✅ |
|| or OR | Checks whether either of two values is truthy | ✅ |
?? | Check whether either of two values are truthy and not NULL |
✅ |
?: | Check whether either of two values are truthy | ✅ |
= or IS | Check whether two values are equal | ✅ |
!= or IS NOT | Check whether two values are not equal | ✅ |
== | Check whether two values are exactly equal | ✅ |
?= | Check whether any value in a set is equal to a value | ✅ |
*= | Check whether all values in a set are equal to a value | ✅ |
~ | Compare two values for equality using fuzzy matching | ✅ |
!~ | Compare two values for inequality using fuzzy matching | ✅ |
?~ | Check whether any value in a set is equal to a value using fuzzy matching | ✅ |
*~ | Check whether all values in a set are equal to a value using fuzzy matching | ✅ |
< | Check whether a value is less than another value | ✅ |
<= | Check whether a value is less than or equal to another value | ✅ |
> | Check whether a value is greater than another value | ✅ |
>= | Check whether a value is greater than or equal to another value | ✅ |
+ | Add two values together | ✅ |
- | Subtract a value from another value | ✅ |
* or × | Multiply two values together | ✅ |
/ or ÷ | Divide a value by another value | ✅ |
** | Raises a base value by another value | ✅ |
IN | Checks whether a value is contained within another value | ✅ |
NOT IN | Checks whether a value is not contained within another value | ✅ |
CONTAINS | Checks whether a value contains another value | ✅ |
CONTAINSNOT | Checks whether a value does not contain another value | ✅ |
CONTAINSALL | Checks whether a value contains all other values | ✅ |
CONTAINSANY | Checks whether a value contains any other value | ✅ |
CONTAINSNONE | Checks whether a value contains none of the following values | ✅ |
INSIDE | Checks whether a value is contained within another value | ✅ |
NOTINSIDE | Checks whether a value is not contained within another value | ✅ |
ALLINSIDE | Checks whether all values are contained within other values | ✅ |
ANYINSIDE | Checks whether any value is contained within other values | ✅ |
NONEINSIDE | Checks whether no value is contained within other values | ✅ |
OUTSIDE | Checks whether a geometry type is outside of another geometry type | ✅ |
INTERSECTS | Checks whether a geometry type intersects another geometry type | ✅ |
@@ | Checks whether the terms are found in a full-text indexed field | ✅ |
0.3.1:
0.3.0:
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 🥲)