Skip to content

Commit

Permalink
docs: updating usage to readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
peeeuzin committed Feb 13, 2024
1 parent 4f2b828 commit 394be83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 50 deletions.
75 changes: 25 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,68 @@
[![crates.io](https://img.shields.io/crates/v/dustdata?color=EA4342&style=flat-square)](https://crates.io/crates/dustdata)

# DustData

A data concurrency control storage engine to [Rustbase](https://github.com/rustbase/rustbase)

Join our [community](https://discord.gg/m5ZzWPumbd) and [chat](https://discord.gg/m5ZzWPumbd) with other Rust users.

# ⚠️ Warning

This is a work in progress. The API is not stable yet.

# 🔗 Contribute

[Click here](./CONTRIBUTING.md) to see how to Contribute

# Dependencies

These are dependencies that are required to use the DustData.

- [bson](https://crates.io/crates/bson)

# How to install

Add the following to your `Cargo.toml`:

```toml
[dependencies]
dustdata = "2.0.0-beta.0"
dustdata = "2.0.0-beta.1"
```

# Usage

Initialize a DustData interface.

Initialize a new `DustData` instance with the default configuration:
```rust
// DustData Configuration
let config = LsmConfig {
flush_threshold: 10240 // 10KB
sstable_path: PathBuf::from("./test_data"),
};
use dustdata::DustData;

let dustdata = Lsm::new(config);
let mut dustdata = DustData::new(Default::default()).unwrap();
```

## Insert a data
## Inserting data into a collection

```rust
// ...
// Creating a data
let data = bson::doc! {
"name": "John Doe",
"age": 30,
#[derive(Serialize, Deserialize, Clone, Debug)]
struct User {
name: String,
age: i32,
}

dustdata.insert("key", data);
```
let collection = dustdata.collection::<User>("users");

## Getting a data
let user = User {
name: "Pedro".to_string(),
age: 21,
};

```rust
// ...
let value = dustdata.get("key").unwrap().unwrap();
println!("{:?}", value);
```
// Creating a new transaction.
let mut transaction = collection.start();

## Updating a data
// Inserting the user into the transaction.
transaction.insert("user:1", user);

```rust
// ...
let data = bson::doc! {
"name": "Joe Mamma",
"age": 42,
}
// Committing the transaction.
collection.commit(&mut transaction).unwrap();

dustdata.update("key", data);
// Done!
```

## Deleting a data
## Reading data from a collection

```rust
// ...
dustdata.delete("key");
```
let collection = dustdata.collection::<User>("users").unwrap();

# To-dos
let user = collection.get("user:1").unwrap();
```

- [x] Memtable (06/19/22)
- [x] SSTable (08/20/22)
- [x] Snapshots (12/16/22)

# Authors

Expand Down
1 change: 1 addition & 0 deletions tests/collection_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dustdata::DustData;
use serde::{Deserialize, Serialize};

pub fn test_config() -> dustdata::DustDataConfig {
dustdata::DustDataConfig::default()
Expand Down

0 comments on commit 394be83

Please sign in to comment.