Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

goleveldb

> 数据库
Open source

LevelDB key/value database in Go.

6.3K stars0 likes2 views
WebsiteGitHub

About

LevelDB key/value database in Go.

This is an implementation of the LevelDB key/value database in the Go programming language. Installation

go get github.com/syndtr/goleveldb/leveldb

Requirements

  • Need at least go1.14 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.

Issues· 111 open

View all issuesOpen on GitHub
  • #452

    Incomplete Data Retrieval in Go Bindings Compared to C++ Interface

    Updated Aug 13, 2026
  • #454

    Panic with read only open/recover db

    Updated Nov 13, 2025
  • #448

    NewIterator search bug, cannot retrieve the key within range

    Updated Jan 17, 2025
  • #443

    Abandoned?

    Updated Jul 26, 2024
  • #441

    Can I set file permissions?

    Updated Dec 21, 2023
  • #224

    panic in db.NewIterator when Limit > Start

    bugUpdated Nov 2, 2023
  • #408

    long time no update release

    Updated Nov 2, 2023
  • #442

    How to read assigned start and end pos data?

    Updated Sep 29, 2023
  • #244

    is it crash resistant?

    help wantedUpdated Sep 2, 2023
  • #440

    is the leveldb write (to disk) rate is 25MB ?

    Updated Aug 24, 2023

> Tags

Godatabasegoleveldb

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 25, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库