Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/factomproject/goleveldb
This repository originates from syndtr around Aug 2014
https://github.com/factomproject/goleveldb
Last synced: 15 days ago
JSON representation
This repository originates from syndtr around Aug 2014
- Host: GitHub
- URL: https://github.com/factomproject/goleveldb
- Owner: FactomProject
- License: bsd-2-clause
- Created: 2015-01-16T07:00:19.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-23T15:32:01.000Z (over 7 years ago)
- Last Synced: 2024-06-20T07:47:26.857Z (5 months ago)
- Language: Go
- Homepage:
- Size: 1.44 MB
- Stars: 2
- Watchers: 19
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is an implementation of the [LevelDB key/value database](http:code.google.com/p/leveldb) in the [Go programming language](http:golang.org).
[![Build Status](https://travis-ci.org/FactomProject/goleveldb.png?branch=master)](https://travis-ci.org/FactomProject/goleveldb)
Installation
-----------go get github.com/FactomProject/goleveldb/leveldb
Requirements
-----------* Need at least `go1.4` or newer.
Usage
-----------Create or open a database:
```go
// The returned DB instance is safe for concurrent use. Which mean that all
// DB's methods may be called concurrently from multiple goroutine.
db, err := leveldb.OpenFile("path/to/db", nil)
...
defer db.Close()
...
```
Read or modify the database content:
```go
// Remember that the contents of the returned slice should not be modified.
data, err := db.Get([]byte("key"), nil)
...
err = db.Put([]byte("key"), []byte("value"), nil)
...
err = db.Delete([]byte("key"), nil)
...
```Iterate over database content:
```go
iter := db.NewIterator(nil, nil)
for iter.Next() {
// Remember that the contents of the returned slice should not be modified, and
// only valid until the next call to Next.
key := iter.Key()
value := iter.Value()
...
}
iter.Release()
err = iter.Error()
...
```
Seek-then-Iterate:
```go
iter := db.NewIterator(nil, nil)
for ok := iter.Seek(key); ok; ok = iter.Next() {
// Use key/value.
...
}
iter.Release()
err = iter.Error()
...
```
Iterate over subset of database content:
```go
iter := db.NewIterator(&util.Range{Start: []byte("foo"), Limit: []byte("xoo")}, nil)
for iter.Next() {
// Use key/value.
...
}
iter.Release()
err = iter.Error()
...
```
Iterate over subset of database content with a particular prefix:
```go
iter := db.NewIterator(util.BytesPrefix([]byte("foo-")), nil)
for iter.Next() {
// Use key/value.
...
}
iter.Release()
err = iter.Error()
...
```
Batch writes:
```go
batch := new(leveldb.Batch)
batch.Put([]byte("foo"), []byte("value"))
batch.Put([]byte("bar"), []byte("another value"))
batch.Delete([]byte("baz"))
err = db.Write(batch, nil)
...
```
Use bloom filter:
```go
o := &opt.Options{
Filter: filter.NewBloomFilter(10),
}
db, err := leveldb.OpenFile("path/to/db", o)
...
defer db.Close()
...
```
Documentation
-----------You can read package documentation [here](http:godoc.org/github.com/syndtr/goleveldb).