vhbit / lmdb-rs

Rust bindings for LMDB
MIT License
114 stars 46 forks source link

Add support for setting compare and dupsort functions #22

Closed frew closed 8 years ago

frew commented 8 years ago

This is a bit icky since it exposes the ffi function header, but since lmdb doesn't pass a void* to the comparison function, I couldn't think of a good way to set up a wrapper function. I guess we could do a macro, but seems like that'd probably be more confusing than just needing to interact with the ffi layer. Thoughts?

frew commented 8 years ago

Thanks for the feedback! Updated. Let me know if you'd like me to try to reduce code duplication on the sets as well (I think there's some value in having some sets in same transaction as setting the dupsort and some not to test that, so not sure how much potential there is there).

vhbit commented 8 years ago

Using different transactions is fine. What I'd like to use though is update to set_compare and set_dupsort docs to reflect warning from LMDB documentation: 'This function must be called before any data access functions are used, otherwise data corruption may occur. The same comparison function must be used by every program accessing the database, every time the database is used.'

I'm still searching for a way to avoid FFI, although probably users of this functionality are not common and they'll be happy to have it even that way.

frew commented 8 years ago

Added warnings from the lmdb docs. PTAL.

vhbit commented 8 years ago

Merged through a336047cf23057c38cbf267399198419de706187 Thanks!