#document #created #oriented #learning #collection #exp

bin+lib jrdb

用于学习的目的创建的面向文档的数据库

1 个不稳定版本

0.0.2 2020年10月21日

#1328数据库接口

MIT/Apache

47KB
1K SLoC

jrdb

Joel Rust 数据库,一个用于学习目的的面向文档的NoSql数据库

目前支持CRUD。嵌套文档/集合和索引集合尚未支持。

示例用法

use jrdb::jrdb_type::{AddGetValue, JrCollection, JrDocument};
use jrdb::Database;

use jrdb::{exp, jr_doc};

fn main() {
  //create file "main.db" if not exist
  let mut db: Database = Database::from("main");

  //use macro to create JrDocument
  let doc = jr_doc! {
    "name"; String => "Mathew".into(),
    "pass"; String => "ILoveERD".into(),
    "age"; i64 => 400,
  };

  //basic way to create JrDocument
  let mut doc2 = JrDocument::new();
  doc2.add_value("name", String::from("Joel"));
  doc2.add_value("pass", String::from("ILoveErd"));
  doc2.add_value("age", 30);

  //create collection "users" and admin if not exist
  db.insert("users", doc)
    .insert("admins", doc2)
    .execute();

  //update "users" with condition
  db.update(
    "users",
    jr_doc! {
      "name"; String => "Jason".into()
    },
  )
  .condition(exp! {"name" ;== "'Joel'"})
  .execute();

  //select "users"
  let collection: JrCollection = db.select("users").execute();
  collection.print(0);

  //select "admins"
  let collection: JrCollection = db.select("admins").execute();
  collection.print(0);

  //delete with condition
  db.delete("users")
    .condition(exp! {"name" ;== "'Jason'"})
    .execute();

  let collection: JrCollection = db.select("users").execute();
  collection.print(0);
}

下一阶段目标

  • 使用特定键选择数据
  • 修复混乱代码
  • 创建文档

依赖项

~120KB