项目作者: icbiadb

项目描述 :
I can't believe it's a database! Simple embedded KV & data structures database
高级语言: Rust
项目地址: git://github.com/icbiadb/icbiadb.git
创建时间: 2020-04-04T05:39:52Z
项目社区:https://github.com/icbiadb/icbiadb

开源协议:MIT License

下载


IcbiaDB | I can’t believe it’s a database   Build Status Latest Version Latest doc

Not recommended for production

Changelog

IcbiaDB is a simple embedded 3-in-1(KV, table and JSON/BSON) database interface with JIT deserialization.

The basic goal though, is merely a fast, reliable and easy-to-use database implementation for general use-cases with minimal preperation, minimal dependencies and decent performence on low-end computers with the ability to seamlessly store, manipulate and present primitives and complex data structures without too much hassle. Oh, and it comes with a free beer.

Features

KV:

  • Multiple storage options
  • Atomic operations on tuples, integers and strings
  • Filter by key, type name or value with or without regex(See “regex” crate feature)

Tables:

  • Easy macros and interface for creation, insertion, selection and deserialization
  • Seamless filtering with BvObject

JSON:
Not implemented yet

Example

  1. use serde::{Deserialize, Serialize};
  2. use icbiadb::prelude::*;
  3. use icbiadb::storage::BTreeMap;
  4. #[derive(Serialize, Deserialize)]
  5. struct Article {
  6. title: String,
  7. text: String,
  8. }
  9. fn main() -> std::io::Result<()> {
  10. let mut db = icbiadb::kv::mem::<BTreeMap>();
  11. // set, get
  12. db.set("key:welcome", "Hello World!");
  13. let v = db.get("key:welcome").unwrap(); // -> BvObject
  14. if v == "Hello World!" || v == 100 {
  15. println!("{:?} of type {}", v.extract::<String>(), v.type_name());
  16. }
  17. db.set("key:welcome", 100);
  18. let key_welcome = db.get_value::<i32>("key:welcome");
  19. if db.get("visited").is_some() {
  20. db.incr("visitors");
  21. }
  22. // Atomic operations on tuple elements, requires same type and length.
  23. db.set("my_tuple", (100, 100, "hello world!"));
  24. let mut bvtuple = db.get_tuple("my_tuple").unwrap();
  25. bvtuple.set(1, 111); // -> (100, 111, "hello world!")
  26. bvtuple.set(2, "hello!!!!!!!");
  27. bvtuple.value::<i32>(1); // -> 111
  28. let article = Article {
  29. title: "A title".to_string(),
  30. text: "Hello World!".to_string(),
  31. };
  32. db.set("articles:0", &article);
  33. // Seamless string bytes comparison, integers are atm converted natively(from_le_bytes)
  34. db.filter(|(k, v)| v.type_name() == "IcbiaDB_tests::Article" || v.contains("this is a string"));
  35. db.starts_with("calculations:")
  36. .iter()
  37. .filter(|(k, v)| k.contains(":super_calc:") && *v > 100.0 && *v < 200.0)
  38. .collect::<Vec<_>>();
  39. Ok(())
  40. }

Serialization/Deserialization

Serialization & deserialization is not necessarily a slow procedure, but for low-end computers, valuable CPU time could be spent on reading/parsing the next record instead of mass-deserialization of data, which is a contributing factor to delays just like some operations on higher-level data types. Let’s take care of stupid things like converting bytes to regular easy-to-handle types after it has been filtered, manipulated, ordered and about to be presented instead!

… IF it’s not better to deserialize it earlier, then whatever. In other words, IcbiaDB aims for JIT, mass- and just-once deserialization after thinning out the number of records.

Unsupported types

IcbiaDB stores everything as simple byte arrays and don’t mess with it once its been loaded into memory, so it’s possible to serialize your complex structure in your chosen language, store it raw, maybe manipulate it with the built-in byte utilities or your own, and deserialize it without any interference from IcbiaDB.


NOTE

Coming soon

  • substr/srange(start, length)
  • More REDIS-inspired stuff

IcbiaDB in other languages

Since this is a rather enjoyable project, if my time allows it, I plan to extend it into other languages.