MCPcopy Index your code
hub / github.com/akrylysov/pogreb

github.com/akrylysov/pogreb @v0.10.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.10.2 ↗ · + Follow
297 symbols 1,051 edges 49 files 63 documented · 21% 15 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Pogreb

Docs Build Status Go Report Card Codecov

Pogreb is an embedded key-value store for read-heavy workloads written in Go.

Key characteristics

  • 100% Go.
  • Optimized for fast random lookups and infrequent bulk inserts.
  • Can store larger-than-memory data sets.
  • Low memory usage.
  • All DB methods are safe for concurrent use by multiple goroutines.

Installation

$ go get -u github.com/akrylysov/pogreb

Usage

Opening a database

To open or create a new database, use the pogreb.Open() function:

package main

import (
    "log"

    "github.com/akrylysov/pogreb"
)

func main() {
    db, err := pogreb.Open("pogreb.test", nil)
    if err != nil {
        log.Fatal(err)
        return
    }   
    defer db.Close()
}

Writing to a database

Use the DB.Put() function to insert a new key-value pair:

err := db.Put([]byte("testKey"), []byte("testValue"))
if err != nil {
    log.Fatal(err)
}

Reading from a database

To retrieve the inserted value, use the DB.Get() function:

val, err := db.Get([]byte("testKey"))
if err != nil {
    log.Fatal(err)
}
log.Printf("%s", val)

Deleting from a database

Use the DB.Delete() function to delete a key-value pair:

err := db.Delete([]byte("testKey"))
if err != nil {
    log.Fatal(err)
}

Iterating over items

To iterate over items, use ItemIterator returned by DB.Items():

it := db.Items()
for {
    key, val, err := it.Next()
    if err == pogreb.ErrIterationDone {
        break
    }
    if err != nil { 
        log.Fatal(err)
    }
    log.Printf("%s %s", key, val)
}

Performance

The benchmarking code can be found in the pogreb-bench repository.

Results of read performance benchmark of pogreb, goleveldb, bolt and badgerdb on DigitalOcean 8 CPUs / 16 GB RAM / 160 GB SSD + Ubuntu 16.04.3 (higher is better):

Internals

Design document.

Extension points exported contracts — how you extend this code

FileSystem (Interface)
FileSystem represents a file system. [4 implementers]
fs/fs.go
LockFile (Interface)
LockFile represents a lock file. [3 implementers]
fs/fs.go
File (Interface)
File is the interface compatible with os.File. [2 implementers]
fs/fs.go

Core symbols most depended-on inside this repo

Nil
called by 202
internal/assert/assert.go
Equal
called by 180
internal/assert/assert.go
Close
called by 47
db.go
Put
called by 46
db.go
Stat
called by 17
fs/fs.go
Compact
called by 15
compaction.go
Get
called by 14
db.go
Count
called by 14
db.go

Shape

Method 158
Function 100
Struct 34
Interface 3
FuncType 1
TypeAlias 1

Languages

Go100%

Modules by API surface

file_test.go27 symbols
fs/mem.go26 symbols
db_test.go22 symbols
db.go22 symbols
index.go20 symbols
datalog.go16 symbols
fs/fs.go14 symbols
segment.go13 symbols
fs/os_mmap.go12 symbols
bucket.go12 symbols
fs/os.go11 symbols
fs/sub.go8 symbols

For agents

$ claude mcp add pogreb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact