goleveldown

package module
v0.0.0-...-bfaf6dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2017 License: ISC Imports: 6 Imported by: 0

README

travis ci badge

goleveldown

This package implements the levelup interface.

how to use

package main

import (
    "github.com/fiatjaf/goleveldown"
    "github.com/fiatjaf/levelup"
    "github.com/fiatjaf/levelup/stringlevelup"
)

func main() {
    bdb := goleveldown.NewDatabase("/tmp/leveldownexample")
    defer bdb.Erase()

    db := stringlevelup.StringDB(bdb)

    fmt.Println("setting key1 to x")
    db.Put("key1", "x")
    res, _ := db.Get("key1")
    fmt.Println("setting key2 to 2")
    fmt.Println("res at key2: ", res)
    db.Put("key2", "y")
    res, _ = db.Get("key2")
    fmt.Println("res at key2: ", res)
    fmt.Println("deleting key1")
    db.Del("key1")
    res, _ = db.Get("key1")
    fmt.Println("res at key1: ", res)

    fmt.Println("batch")
    db.Batch([]levelup.Operation{
        stringlevelup.Put("key2", "w"),
        stringlevelup.Put("key3", "z"),
        stringlevelup.Del("key1"),
        stringlevelup.Put("key1", "t"),
        stringlevelup.Put("key4", "m"),
        stringlevelup.Put("key5", "n"),
        stringlevelup.Del("key3"),
    })
    res, _ = db.Get("key1")
    fmt.Println("res at key1: ", res)
    res, _ = db.Get("key2")
    fmt.Println("res at key2: ", res)
    res, _ = db.Get("key3")
    fmt.Println("res at key3: ", res)

    fmt.Println("reading all")
    iter := db.ReadRange(nil)
    for ; iter.Valid(); iter.Next() {
        fmt.Println("row: ", iter.Key(), " ", iter.Value())
    }
    fmt.Println("iter error: ", iter.Error())
    iter.Release()
}

if you don't call stringlevelup.StringDB on the object returned by NewDatabase you still can use the same methods, only replacing all string arguments with []byte (returned values will also be bytes). I've just used the string approach here for readability, but it is slower.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDatabase

func NewDatabase(path string) levelup.DB

Types

type LevelDown

type LevelDown struct {
	// contains filtered or unexported fields
}

func (LevelDown) Batch

func (l LevelDown) Batch(ops []levelup.Operation) error

func (LevelDown) Close

func (l LevelDown) Close()

func (LevelDown) Del

func (l LevelDown) Del(key []byte) error

func (LevelDown) Erase

func (l LevelDown) Erase()

func (LevelDown) Get

func (l LevelDown) Get(key []byte) ([]byte, error)

func (LevelDown) Put

func (l LevelDown) Put(key, value []byte) error

func (LevelDown) ReadRange

func (l LevelDown) ReadRange(opts *levelup.RangeOpts) levelup.ReadIterator

type ReadIterator

type ReadIterator struct {
	// contains filtered or unexported fields
}

func (*ReadIterator) Error

func (ri *ReadIterator) Error() error

func (*ReadIterator) Key

func (ri *ReadIterator) Key() []byte

func (*ReadIterator) Next

func (ri *ReadIterator) Next()

func (*ReadIterator) Release

func (ri *ReadIterator) Release()

func (*ReadIterator) Valid

func (ri *ReadIterator) Valid() bool

func (*ReadIterator) Value

func (ri *ReadIterator) Value() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL