use persy::{Persy, Config};
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let file = "./storage.persy";
    if !PathBuf::from(file).exists() {
        Persy::create("./storage.persy")?;
    }
    let persy = Persy::open("./storage.persy",Config::new())?;
    
    let mut tx = persy.begin()?;
    
    if !tx.exists_segment("seg").ok().unwrap_or(false) {
        tx.create_segment("seg")?;
    }
    
    let data = vec![1;20];
    let id = tx.insert("seg", &data)?;
    println!("Persy id: {}", id);
    
    let prepared = tx.prepare()?;
    prepared.commit()?;
    
    Ok(())
}
