Skip to content

Commit

Permalink
delete
Browse files Browse the repository at this point in the history
  • Loading branch information
maiha committed Dec 2, 2016
1 parent 9e2f3e2 commit febcc5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ db = RocksDB::DB.new("tmp/db1")

db.put("foo", "1")
db.get("foo") # => "1"
db.delete("foo")

db.get("xxx") # => ""
db.get?("xxx") # => nil
db.get!("xxx") # raise RocksDB::NotFound.new("xxx")
db.get("foo") # => ""
db.get?("foo") # => nil
db.get!("foo") # raise RocksDB::NotFound.new("foo")

db.close
```
Expand All @@ -39,7 +40,7 @@ db.close
#### 0.2.0

- [x] `get`, `put`
- [ ] `delete`
- [x] `delete`

## Testing

Expand Down
8 changes: 8 additions & 0 deletions spec/rocksdb_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ describe RocksDB do
db.close
end

it "Delete" do
db = RocksDB::DB.new(path)
db.get("key").should eq("value")
db.delete("key")
db.get("key").should eq("")
db.close
end

it "Empty keys" do
db = RocksDB::DB.new(path)
db.get("xxx").should eq("")
Expand Down
6 changes: 5 additions & 1 deletion src/rocksdb/commands.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module RocksDB::Commands
def get?(key : String) : String?
ptr = rocksdb_get(db, @read_options.raw, key, key.bytesize, @len)
@len.value == 0 ? nil : String.new(ptr)
@len.value == 0 ? nil : String.new(ptr, @len.value)
end

def get(key : String) : String
Expand All @@ -27,4 +27,8 @@ module RocksDB::Commands
def []=(key : String, value : String)
put(key, value)
end

def delete(key : String)
rocksdb_delete(db, @write_options.raw, key, key.bytesize)
end
end

0 comments on commit febcc5d

Please sign in to comment.