Convert Figma logo to code with AI

syndtr logogoleveldb

LevelDB key/value database in Go.

6,122
968
6,122
108

Top Related Projects

8,110

An embedded key/value database for Go.

13,744

Fast key-value DB in Go.

4,766

RocksDB/LevelDB inspired key-value database in Go

1,292

Embedded key-value store for read-heavy workloads written in Go

14,138

An embedded key/value database for Go.

Quick Overview

syndtr/goleveldb is a pure Go implementation of LevelDB, a fast key-value storage library originally developed by Google. It provides a simple and efficient way to store and retrieve key-value pairs in Go applications, offering good performance and a familiar interface for developers familiar with LevelDB.

Pros

  • Pure Go implementation, making it easy to use and deploy in Go projects
  • Good performance for read and write operations
  • Supports batch operations for improved efficiency
  • Compatible with the original LevelDB API, making it easy to migrate existing projects

Cons

  • Limited features compared to some other key-value stores
  • May not be suitable for extremely large datasets or high-concurrency scenarios
  • Lacks some advanced features like transactions or multi-column indexing
  • Documentation could be more comprehensive

Code Examples

Opening a database:

db, err := leveldb.OpenFile("path/to/db", nil)
if err != nil {
    log.Fatal(err)
}
defer db.Close()

Writing and reading data:

// Write data
err = db.Put([]byte("key"), []byte("value"), nil)
if err != nil {
    log.Fatal(err)
}

// Read data
data, err := db.Get([]byte("key"), nil)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Value: %s\n", data)

Using batch operations:

batch := new(leveldb.Batch)
batch.Put([]byte("key1"), []byte("value1"))
batch.Put([]byte("key2"), []byte("value2"))
batch.Delete([]byte("key3"))

err = db.Write(batch, nil)
if err != nil {
    log.Fatal(err)
}

Getting Started

To use syndtr/goleveldb in your Go project, follow these steps:

  1. Install the package:

    go get github.com/syndtr/goleveldb/leveldb
    
  2. Import the package in your Go code:

    import "github.com/syndtr/goleveldb/leveldb"
    
  3. Open a database and start using it:

    db, err := leveldb.OpenFile("path/to/db", nil)
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()
    
    // Use db.Put(), db.Get(), db.Delete(), etc. to interact with the database
    

Remember to handle errors appropriately and close the database when you're done using it.

Competitor Comparisons

8,110

An embedded key/value database for Go.

Pros of bbolt

  • Simpler API and easier to use for basic key-value storage
  • Better suited for embedded databases and single-file storage
  • Supports fully serializable ACID transactions

Cons of bbolt

  • Generally slower performance compared to goleveldb
  • Lacks some advanced features like bloom filters and compression

Code Comparison

bbolt:

db, _ := bolt.Open("my.db", 0600, nil)
defer db.Close()

db.Update(func(tx *bolt.Tx) error {
    b, _ := tx.CreateBucketIfNotExists([]byte("MyBucket"))
    return b.Put([]byte("key"), []byte("value"))
})

goleveldb:

db, _ := leveldb.OpenFile("path/to/db", nil)
defer db.Close()

db.Put([]byte("key"), []byte("value"), nil)

Both goleveldb and bbolt are popular key-value storage solutions for Go applications. goleveldb, based on Google's LevelDB, offers better performance and advanced features like bloom filters and compression. It's well-suited for high-performance scenarios and larger datasets.

bbolt, a fork of BoltDB, provides a simpler API and is better for embedded databases and single-file storage. It supports fully serializable ACID transactions, making it suitable for applications requiring strong consistency.

The choice between the two depends on specific project requirements, such as performance needs, data size, and consistency guarantees.

13,744

Fast key-value DB in Go.

Pros of Badger

  • Better performance for write-heavy workloads due to LSM tree structure
  • Native support for transactions and ACID compliance
  • Designed for SSDs, optimizing for modern hardware

Cons of Badger

  • Higher memory usage compared to LevelDB
  • Potentially slower read performance for certain workloads
  • Less mature and battle-tested than LevelDB

Code Comparison

Badger:

db, err := badger.Open(badger.DefaultOptions("/tmp/badger"))
err = db.Update(func(txn *badger.Txn) error {
    return txn.Set([]byte("key"), []byte("value"))
})

LevelDB:

db, err := leveldb.OpenFile("/tmp/db", nil)
err = db.Put([]byte("key"), []byte("value"), nil)

Both Badger and LevelDB are key-value stores written in Go, but they have different design philosophies and performance characteristics. Badger is optimized for SSDs and write-heavy workloads, while LevelDB offers a more traditional approach with potentially better read performance in some scenarios. The choice between the two depends on specific use cases and hardware considerations.

4,766

RocksDB/LevelDB inspired key-value database in Go

Pros of Pebble

  • Better performance and scalability, especially for large datasets
  • More actively maintained with regular updates and improvements
  • Advanced features like bloom filters and range deletions

Cons of Pebble

  • Higher complexity and steeper learning curve
  • Larger codebase and potentially more resource-intensive
  • May be overkill for simpler use cases or smaller datasets

Code Comparison

Pebble:

db, err := pebble.Open("path/to/db", &pebble.Options{})
if err != nil {
    log.Fatal(err)
}
defer db.Close()

Goleveldb:

db, err := leveldb.OpenFile("path/to/db", nil)
if err != nil {
    log.Fatal(err)
}
defer db.Close()

Both libraries provide similar basic functionality for key-value storage, but Pebble offers more advanced features and optimizations. Pebble is designed for high-performance scenarios and large-scale deployments, while Goleveldb is simpler and may be sufficient for smaller projects or less demanding use cases.

Pebble's codebase is more extensive and actively maintained, reflecting its focus on performance and scalability. However, this comes at the cost of increased complexity and potentially higher resource usage.

Choose Pebble for projects requiring high performance, scalability, and advanced features. Opt for Goleveldb if simplicity and ease of use are priorities, and the performance requirements are less demanding.

1,292

Embedded key-value store for read-heavy workloads written in Go

Pros of Pogreb

  • Faster read and write performance, especially for large datasets
  • Lower memory usage and better memory management
  • Simpler API and easier to use for basic key-value storage needs

Cons of Pogreb

  • Less mature and less widely adopted compared to Goleveldb
  • Fewer advanced features and customization options
  • Limited support for complex data structures and indexing

Code Comparison

Pogreb:

db, _ := pogreb.Open("example.db", nil)
defer db.Close()

db.Put([]byte("key"), []byte("value"))
value, _ := db.Get([]byte("key"))

Goleveldb:

db, _ := leveldb.OpenFile("example.db", nil)
defer db.Close()

db.Put([]byte("key"), []byte("value"), nil)
value, _ := db.Get([]byte("key"), nil)

Both libraries offer similar basic functionality for key-value storage, but Goleveldb provides additional options and features through its API. Pogreb's simpler API may be preferable for straightforward use cases, while Goleveldb offers more flexibility for complex scenarios.

14,138

An embedded key/value database for Go.

Pros of Bolt

  • Simpler API and easier to use for basic key-value storage
  • ACID compliant with full transaction support
  • Better suited for read-heavy workloads

Cons of Bolt

  • Limited to a single writer at a time, which can impact write performance
  • Lacks some advanced features like compression and bloom filters
  • May consume more disk space due to its B+tree structure

Code Comparison

Bolt:

db, _ := bolt.Open("my.db", 0600, nil)
defer db.Close()

db.Update(func(tx *bolt.Tx) error {
    b, _ := tx.CreateBucketIfNotExists([]byte("MyBucket"))
    return b.Put([]byte("answer"), []byte("42"))
})

LevelDB:

db, _ := leveldb.OpenFile("path/to/db", nil)
defer db.Close()

db.Put([]byte("answer"), []byte("42"), nil)

Both Bolt and LevelDB are popular key-value storage solutions for Go, but they have different strengths. Bolt offers simplicity and ACID compliance, making it ideal for applications requiring strong consistency. LevelDB, on the other hand, provides better write performance and advanced features like compression, making it suitable for high-throughput scenarios. The choice between them depends on specific project requirements and performance needs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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

Build Status

Installation

go get github.com/syndtr/goleveldb/leveldb

Requirements

  • Need at least go1.14 or newer.

Usage

Create or open a database:

// 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:

// 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:

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:

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:

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:

iter := db.NewIterator(util.BytesPrefix([]byte("foo-")), nil)
for iter.Next() {
	// Use key/value.
	...
}
iter.Release()
err = iter.Error()
...

Batch writes:

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:

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.