New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow put/write of empty values #223
Comments
What is a use case for wanting to save an empty values to a database? |
You can use empty values to store events that happened. |
same, i've used |
https://github.com/rvagg/node-levelup#batch
the empty string is neither my use case: i simply want to avoid |
Not saying it's not a good idea or not worth having. This is just food for thought. But two reasons I avoid doing this are...
|
a not found error, and an empty record are totally different things. for example, even if you don't know the exact location of a key you can seek past it and find it that way. you have still stored the key, which is useful. maybe you want to have the key store values... for example, in an index you might want to keep a tuple of I think you should make this into a pull request. |
Yes, there are valid use cases where keys contain sufficient data making the actual values obsolete. |
hmm, then maybe you need a key store and not a key-value store ;) |
@hij1nx that's super useful for sets, like reserved slugs. And key-value stores are a superset of key stores, so I think the concern is valid. |
@juliangruber i'm not disagreeing, im simply saying that there are down sides to storing empty values. |
@hij1nx I am trying to save git objects to leveldb. Git objects are content-addressable by their SHA1. Since a Blob object for an empty file is perfectly reasonable, this check is preventing me from storing empty git files. In theory, I could add in custom code everywhere a read and write to leveldb to short-circuit on the sha1 of an empty buffer, but that seems extreme. Perhaps this fits the description of a legitimate use-case. |
As silly as it sounds, I'd like to be able to save empty values to leveldb. Right now, I get "WriteError: value cannot be an empty String" if I try.
I traced the code back to the LD_STRING_OR_BUFFER_TO_SLICE macro in leveldown: https://github.com/rvagg/node-leveldown/blob/master/src/leveldown.h#L45
This macro is correct for validating keys, but leveldb allows for empty values. If this is not intentional behavior, I think I'll try to fix it and submit a pull request.
The text was updated successfully, but these errors were encountered: