khonsulabs / bonsaidb

A developer-friendly document database that grows with you, written in Rust
https://bonsaidb.io/
Apache License 2.0
1.01k stars 37 forks source link

Supply dynamic database object #255

Open FlixCoder opened 2 years ago

FlixCoder commented 2 years ago

Hi!

Thank you for the great work on bonsaidb, it is a really nice project!

While working with it, I stumbled upon the following issue: Making a library for any database via the AsyncConnection trait is easy with generics. However, keeping those generics everywhere forces me to forward these to the library user as well in some types, making it unwieldy to use. I would like to have a dyn AsyncConnection object, but it forces me to specify the storage object as well, which I am unsure how to do and whether it is possible to be compatible with bonsaidb at the same time.

It would be great if there would be some enum that wraps all database types, which one can use internally without generics. Is there anything I missed, that I can use right now?

Thank you in advance!

ecton commented 2 years ago

Thank you for the feedback!

I started down an enum path already, but I don't think it's the right design decision. I think I need to come up with a way to Box dyn [Async]Connecitons instead -- but with all of the generic usage, that will be a little bit of a challenge.

ecton commented 1 year ago

I worked on this over yesterday and today, but it's a lot harder than it might seem at first glance. This is due to all the generic functions not being trait-object safe. That being said, it looks completely feasible to come up with a way to use methods like SerializedCollection::get and pass an &dyn Connection to it.

The amount of work required, though, is quite significant, and it introduces fun naming challenges. I'm going to move this from the next milestone, but I do want to add this someday.