meilisearch / heed

A fully typed LMDB wrapper with minimum overhead 🐦
https://docs.rs/heed
MIT License
519 stars 52 forks source link

Refine the unnamed database behavior #247

Closed Kerollmops closed 3 months ago

Kerollmops commented 4 months ago

Opening the unnamed database is fallible as it uses the same API as the named ones. As the unnamed database always exists, there is no reason to make creating the unnamed database possible.

let rtxn = env.read_txn()?;
// Opening the unnamed database is infallible.
let main = env.open_database(&rtxn, None)?.expect("infallible, always exists");
let rtxn = env.read_txn()?;
// The unnamed database always exists, no reason to create it.
let main = env.create_database(&mut wtxn, None)?;

We could simplify the API by removing the Option<&str> from both methods and giving access to the unnamed database from another API endpoint like Env::unnamed_database(&self).

Kerollmops commented 3 months ago

There could be an IO error anyway... closing.