2 个版本
0.1.5 | 2023年9月3日 |
---|---|
0.1.4 | 2023年8月27日 |
570 在 数据库接口 中
每月 31 次下载
21KB
475 行
钽存储
Sot 是用 Rust 编写的数据库。
安装
使用 cargo 安装库。
cargo add sotdb
用法
use sotdb::{actions::*, structs::*};
fn main() -> Result<(), std::io::Error> {
// Create object (requires name, path to *.sotdb file, and vec of data: (var name, datatype(data)))
let path = "*.sotdb"
create_object(
"name",
&mut vec![
// text, intnum, floatnum, boolean - name of var`s
// Str("Text".to_string()), Int(0), Float(0.0), Bool(false) - datatype`s with with their data
("text".to_string(), DataType::Str("test".to_string())),
("intnum".to_string(), DataType::Int(0)),
("floatnum".to_string(), DataType::Float(0.0)),
("boolean".to_string(), DataType::Bool(false)),
],
path,
)?;
// Get one object (requires name and path to *.sotdb file)
let object = get_object("name", path)?;
// Get all objects from file (reguires path to *.sotdb file)
let _all_objects = get_all_objects(path)?;
// Add data to object (requires name, path to *.sotdb file, and vec of data: (String, DataType))
add_data_to_object(
object.get_name(),
path,
vec![("boolean".to_string(), DataType::Bool(true))],
)?;
// Remove data from object (requires name, path to *.sotdb file, and vec of data: (var name, datatype(data)))
remove_data_from_object(object.get_name(), path, object.get_data())?;
// Delete object (requires name and path to *.sotdb file)
delete_object(object.get_name(), path)?;
Ok(())
// Program writes to file:
// [object-name]:name
// [name:<str>]:text=test
// [name:<int>]:intnum=0
// [name:<float>]:floatnum=0
// [name:<bool>]:boolean=false
// |=============================|
// And delete this all! :)
}