meilisearch / heed

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

Only keep the `Database` type and remove the `PolyDatabase` #188

Closed Kerollmops closed 6 months ago

Kerollmops commented 1 year ago

I want to think about removing the PolyDatabase and only keeping the Database one to simplify the usage of the crate.

A Database<K, D> is always typed on the key and data, which can not be used in certain cases that the PolyDatabase was fulfilling. Fortunately, we could introduce a new UnknowCodec that could either return a runtime error when used to encode/decode or, even better, couldn't be used at compile time as we don't implement the BytesDecode and BytesEncode traits. Can we change the default error message and help the users by forcing them to define the code with a call to remap_types?

If this is too complex we could also use the ByteSlice codec as the default one for when a Database is created with unspecified codecs types.

To Introduce a Database Builder

If we want to introduce a DatabaseBuilder we will need to either create two of them i.e. PolyDatabaseBuilder and DatabaseBuilder, that will switch everytime the DatabaseBuilder::untype or PolyDatabaseBuilder::type will be call or by removing the PolyDatabase type as described above.

let database: Database<Str, U32<BE>> = env
    .database_builder()
    .name("banane")
    .type::<Str, U32<BE>>()
    .dup_sort(true)
    .create(&mut wtxn)?;
Kerollmops commented 6 months ago

Implemented in v0.11 and therefore in v0.20 too!