/* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin */ use anyhow::{Result, bail}; use crate::{ backends::{KV, memory::Memory, redb::Redb, rocksdb::Rocksdb}, indices::Index, }; use std::{path::Path, sync::Arc}; pub mod backends; pub mod indices; pub struct Database { storage: Arc, } impl Database { pub fn new(driver: &str, path: &Path) -> Result { Ok(Self { storage: match driver { "rocksdb" => Arc::new(Rocksdb::new(path)?), "redb" => Arc::new(Redb::new(path)?), "memory" => Arc::new(Memory::new()), _ => bail!("unknown db driver"), }, }) } } pub struct Table { id: u32, indices: Vec>>, db: Arc, } impl Table { pub fn new(db: &Database, id: u32) -> Self { Self { id, indices: Vec::new(), db: db.storage.clone(), } } }