Crate highlandcows_isam

Crate highlandcows_isam 

Source
Expand description

§highlandcows-isam

An ISAM (Indexed Sequential Access Method) library with ACID transactions and optional secondary indices.

§Quick start

use highlandcows_isam::Isam;

let db: Isam<String, String> = Isam::create(&path).unwrap();
let mut txn = db.begin_transaction().unwrap();
db.insert(&mut txn, "hello".to_string(), &"world".to_string()).unwrap();
let v = db.get(&mut txn, &"hello".to_string()).unwrap();
assert_eq!(v, Some("world".to_string()));
txn.commit().unwrap();

§Secondary indices

Secondary indices let you look up records by a field other than the primary key. Implement DeriveKey on a marker struct, then register it with Isam::register_secondary_index before any writes.

use serde::{Serialize, Deserialize};
use highlandcows_isam::{Isam, DeriveKey};

#[derive(Serialize, Deserialize, Clone)]
struct User { name: String, city: String }

struct CityIndex;
impl DeriveKey<User> for CityIndex {
    type Key = String;
    fn derive(u: &User) -> String { u.city.clone() }
}

let db: Isam<u64, User> = Isam::create(&path).unwrap();
let city_idx = db.register_secondary_index("city", CityIndex).unwrap();

let mut txn = db.begin_transaction().unwrap();
db.insert(&mut txn, 1, &User { name: "Alice".into(), city: "London".into() }).unwrap();
db.insert(&mut txn, 2, &User { name: "Bob".into(),   city: "London".into() }).unwrap();
db.insert(&mut txn, 3, &User { name: "Carol".into(), city: "Paris".into()  }).unwrap();
txn.commit().unwrap();

let mut txn = db.begin_transaction().unwrap();
let londoners = city_idx.lookup(&mut txn, &"London".to_string()).unwrap();
assert_eq!(londoners.len(), 2);
txn.commit().unwrap();

§Files on disk

FileContents
*.idbAppend-only data records (bincode)
*.idxOn-disk B-tree index (page-based)
*_<name>.sidbSecondary index data store (one per index)
*_<name>.sidxSecondary index B-tree (one per index)

Re-exports§

pub use error::IsamError;
pub use error::IsamResult;
pub use isam::Isam;
pub use isam::IsamIter;
pub use isam::RangeIter;
pub use isam::SecondaryIndexHandle;
pub use secondary_index::DeriveKey;
pub use transaction::Transaction;

Modules§

error
index
isam
manager
secondary_index
storage
store
transaction