Skip to main content

Crate fiole

Crate fiole 

Source
Expand description

fiole is a high level opinionated wrapper around fjall.

§Why “opinionated”

It’s because I made some big changes to the fjall API that I didn’t like. Here’s a non exhaustive list:

  • I only re-exposed the fjall::OptimisticTxDatabase because I don’t think I ever needed a database without transaction.
  • I got rids of all the methods that runs wrapped in a transaction like fjall::OptimisticTxKeyspace::take, forcing you to always use a transaction. I find that less error prone.
  • I “inverted” the way we access to data. Instead of doing txn.get(keyspace) we’re now doing keyspace.get(txn). I find that easier to understand as a end user.

§Why “high level”

Because we have types, you can now specify the type of the key values in a keyspace through a codec system. See all the codec availabe at codec.

§Example

use std::fs;
use std::path::Path;
use fiole::{Keyspace, KeyspaceCreateOptions, Database};
use fiole::codec::{Str, U32};

let dir = tempfile::tempdir().unwrap();
let db = Database::builder(&dir.path()).unwrap();

let ks: Keyspace<Str, U32<byteorder::NativeEndian>> = db.keyspace("Hey you!", || KeyspaceCreateOptions::default()).unwrap();

// opening a write transaction
let mut wtxn = db.write_tx().unwrap();

ks.insert(&mut wtxn, "seven", &7).unwrap();
ks.insert(&mut wtxn, "zero", &0).unwrap();
ks.insert(&mut wtxn, "five", &5).unwrap();
ks.insert(&mut wtxn, "three", &3).unwrap();
wtxn.commit().unwrap();

// opening a read transaction
// to check if those values are now available
let mut rtxn = db.read_tx();

let ret = ks.get(&rtxn, "zero").unwrap();
assert_eq!(ret, Some(0));

let ret = ks.get(&rtxn, "five").unwrap();
assert_eq!(ret, Some(5));

Re-exports§

pub use byteorder;

Modules§

codec
Types that can be used to serialize and deserialize keys or values inside crate::Keyspace

Structs§

Database
Wrapper around a fjall::OptimisticTxDatabase.
Guard
Guard to access key-value pairs.
Iter
Refer to fjall::Iter for more info.
Keyspace
Wrapper around a fjall::OptimisticTxKeyspace. You must specify the type of its key and value through the crate::codec.
KeyspaceCreateOptions
Options to configure a keyspace
Rtxn
A read-only transaction.
Wtxn
A read and write transaction.

Enums§

Error
Main error type of this crate. When possible we return a fjall::Error directly, but if we have to encode or decode a value we have to return the associated error.

Traits§

Readable
To be used when your function needs to read data from the database.