/*
    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) 2026 metamuffin <metamuffin.org>
*/

use crate::{Config, backends::CacheStorage};
use anyhow::Result;
use rocksdb::DB;

pub struct Rocksdb(DB);

impl Rocksdb {
    pub fn new(config: &Config) -> Result<Self> {
        Ok(Self(rocksdb::DB::open_default(config.path.clone())?))
    }
}

impl CacheStorage for Rocksdb {
    fn store(&self, key: String, value: &[u8]) -> Result<()> {
        Ok(self.0.put(key, value)?)
    }
    fn read(&self, key: &str) -> Result<Option<Vec<u8>>> {
        Ok(self.0.get(key)?)
    }
}
