Skip to main content

open_module_db

Function open_module_db 

Source
pub fn open_module_db<P: AsRef<Path>>(data_dir: P) -> Result<Arc<dyn Database>>
Expand description

Open the module’s database at {data_dir}/db/.

Module databases need to create named trees on demand (open_tree()). Only Sled and TidesDB support fully dynamic tree creation. Redb only supports a fixed set of pre-declared tables; RocksDB requires all column families to be declared at open time.

Backend selection (first match wins):

  1. MODULE_CONFIG_DATABASE_BACKEND env var (sled, tidesdb, redb, rocksdb, auto)
  2. MODULE_DATABASE_BACKEND env var (same values)
  3. Auto-select best available: Sled → TidesDB → fallback with a warning

If the resolved backend does not support dynamic trees the function warns and falls back to the best available dynamic backend. If no dynamic backend is compiled in, it returns an error.

§Example

let db = open_module_db(module_data_dir)?;
let tree = db.open_tree("my_tree")?;
tree.insert(b"key", b"value")?;