lmdb support empty values, but not empty keys (#674)

This commit is contained in:
Alex Sharov 2020-06-18 12:20:33 +07:00 committed by GitHub
parent 5b051d9ab3
commit e09b386fc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 9 deletions

View File

@ -95,7 +95,7 @@ func testPutGet(db MinDatabase, t *testing.T) {
t.Parallel()
for _, k := range testValues {
err := db.Put(testBucket, []byte(k), []byte{1})
err := db.Put(testBucket, []byte(k), []byte{})
if err != nil {
t.Fatalf("put failed: %v", err)
}
@ -106,8 +106,8 @@ func testPutGet(db MinDatabase, t *testing.T) {
if err != nil {
t.Fatalf("get failed: %v", err)
}
if len(data) != 1 {
t.Fatalf("get returned wrong result, got %q expected 1", string(data))
if len(data) != 0 {
t.Fatalf("get returned wrong result, got %q expected nil", string(data))
}
}

View File

@ -425,9 +425,6 @@ func (b *lmdbBucket) Put(key []byte, value []byte) error {
if len(key) == 0 {
return fmt.Errorf("lmdb doesn't support empty keys. bucket: %s", dbutils.Buckets[b.id])
}
if len(value) == 0 {
return fmt.Errorf("lmdb doesn't support empty values. bucket: %s", dbutils.Buckets[b.id])
}
err := b.tx.tx.Put(b.dbi, key, value, 0)
if err != nil {
@ -601,9 +598,6 @@ func (c *lmdbCursor) Put(key []byte, value []byte) error {
if len(key) == 0 {
return fmt.Errorf("lmdb doesn't support empty keys. bucket: %s", dbutils.Buckets[c.bucket.id])
}
if len(value) == 0 {
return fmt.Errorf("lmdb doesn't support empty values. bucket: %s", dbutils.Buckets[c.bucket.id])
}
if c.cursor == nil {
if err := c.initCursor(); err != nil {
return err