Turing·DB
TuringDB is a database, written in Rust, that aims to be distributed and scaled horizontally. It aims to be a replacement for where you don't need a relational database or a schema.
The database is backed by Sled key-value store
Motivation
The motive behind this database is to have a key/value database with ACID properties, speed, type-safety, changefeeds without polling, multi-cluster queries and replication. Rust is the most qualified for speed, type-safety and compile-time checks. Furthermore, sled.rs
has been used as the embedded key/value store for this database as it is lock-free, has fully ATOMIC operations, zero-copy reads, SSD optimized log-storage and is written in Rust, hence inherits all the sweet properties of the language.
Features
The database aims to be:
- Really simple to use document database
- Have lookup and range capabilities
- Be partition tolerant and consistent
- Offer real-time push capabilities without polling, inspired by RethinkDB changefeeds
- Offer simple joins
- Offer optional distributed capabilities backed by Raft consensus algorithm
- Offer optional multi-cluster queries
- Be small enough to use as embedded database
- Be small and fast enough to be used on embedded devices or large servers
- Be really fun to use
Features under development include
- Replication
- Multi-cluster queries
- Changefeeds without polling, inspired by RethinkDB
- JSON support
Server Usage
-
Install from crates-io
-
Start the server
-
Create a new cargo repository
-
Edit
Cargo.toml
file
#[dependencies] turingdb-helpers = #add the latest version here bincode = #add the latest version async-std = #add latest version here anyhow = # add latest version custom_codes = #add latest vesion ```
Alternatively you could use `cargo-edit` if it is already installed, instead of adding dependencies manually
```sh
$ cargo add turingdb-helpers bincode async-std anyhow custom_codes
```
-
Open
src/main.rs
file in an editoruse TcpStream; use *; use ; use DbOps; const BUFFER_CAPACITY: usize = 64 * 1024; //16Kb const BUFFER_DATA_CAPACITY: usize = 1024 * 1024 * 16; // Db cannot hold data more than 16MB in size pub async
Current query methods supported by the database
-
Repository Queries
turingdb_helpers::RepoQuery::create()
creates a new repository in the current directoryturingdb_helpers::RepoQuery::drop()
drops a repository in the current directory
-
Database Queries
-
DbQuery::create()
creates a new database in the repositoryuse DatabaseQuery; let mut foo = new.await; foo .db.await .create.await;
-
DbQuery::drop()
drops a database in the repositoryuse DatabaseQuery; let mut foo = new.await; foo .db.await .drop.await;
-
DbQuery::list()
list all database in the repositoryuse DatabaseQuery; let mut foo = new.await; foo.drop.await;
-
-
Document Queries
-
DocumentQuery::create()
create a document in the databaseuse DocumentQuery; let mut foo = new.await; foo .db.await .document.await .create.await;
-
DocumentQuery::drop()
drops a document in the databaseuse DocumentQuery; let mut foo = new.await; foo .db.await .document.await .drop.await;
-
DocumentQuery::list()
lists all documents in the databaseuse DocumentQuery; let mut foo = new.await; foo .db.await .list.await;
-
-
Field Queries
-
Field::set()
create a field in a document based on a keyuse FieldQuery; let mut foo = new.await; let data = "my_data_converted_into_bytes".as_bytes; foo .db.await .document.await .field.await .payload.await .set.await
-
Field::get()
gets a field in a document based on a keyuse FieldQuery; let mut foo = new.await; foo .db.await .document.await .field.await .get.await
-
Field::modify()
updates a field in a document based on a keyuse FieldQuery; let mut foo = new.await; let data = "my_new_data_converted_into_bytes".as_bytes; foo .db.await .document.await .field.await .payload.await .modify.await
-
Field::remove()
remove a field in a document based on a keyuse FieldQuery; let mut foo = new.await; foo .db.await .document.await .field.await .remove.await
-
Field::list()
get all keys of fieldsuse FieldQuery; let mut foo = new.await; foo .db.await .document.await .list.await
-
Warning
A document cannot hold more that 16MiB
of data and if this threshold is exceeded, an error from the custom_codes
crate DbOps::EncounteredErrors([TuringDB::<GLOBAL>::(ERROR)-BUFFER_CAPACITY_EXCEEDED_16MB])
Contributing
We follow the Rust Code of Conduct in making contributions
License
All code contributions to this project must be licensed under Apache license
Acknowledgement
All libraries used in this project are subject to their own licenses