leveldbwrapper

package module
v0.0.0-...-061fb86 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: Apache-2.0 Imports: 11 Imported by: 3

README

leveldb-wrapper

Leveldb-wrapper is a simple library that supporing leveldb and provides an interface for key-value based database.

KeyValueDB Interface

type KeyValueDB interface{
	//OpenDB
	Open()
	//CloseDB
	Close()
	//Get Value by Key
 	Get(key []byte) ([]byte, error)
 	Put(key []byte, value []byte, sync bool) error
 	Delete(key []byte, sync bool) error
 	WriteBatch(KVs map[string][]byte, sync bool) error
	GetIteratorWithPrefix(prefix []byte) KeyValueDBIterator
	GetIterator(startKey []byte, endKey []byte) KeyValueDBIterator
	Snapshot() (map[string][]byte, error)
}

type KeyValueDBIterator interface {
	// It returns whether such pair exist.
	First() bool

	// Last moves the iterator to the last key/value pair. If the iterator
	// only contains one key/value pair then First and Last would moves
	// to the same key/value pair.
	// It returns whether such pair exist.
	Last() bool

	// Seek moves the iterator to the first key/value pair whose key is greater
	// than or equal to the given key.
	// It returns whether such pair exist.
	//
	// It is safe to modify the contents of the argument after Seek returns.
	Seek(key []byte) bool

	// Next moves the iterator to the next key/value pair.
	// It returns whether the iterator is exhausted.
	Next() bool

	// Prev moves the iterator to the previous key/value pair.
	// It returns whether the iterator is exhausted.
	Prev() bool

	// util.Releaser is the interface that wraps basic Release method.
	// When called Release will releases any resources associated with the
	// iterator.
	Release()

	//todo invaild when SetReleaser()
	// util.ReleaseSetter is the interface that wraps the basic SetReleaser
	// method.
	//SetReleaser(asd MyReleaser)

	// TODO: Remove this when ready.
	Valid() bool

	// Error returns any accumulated error. Exhausting all the key/value pairs
	// is not considered to be an error.
	Error() error

	// Key returns the key of the current key/value pair, or nil if done.
	// The caller should not modify the contents of the returned slice, and
	// its contents may change on the next call to any 'seeks method'.
	Key() []byte

	// Value returns the value of the current key/value pair, or nil if done.
	// The caller should not modify the contents of the returned slice, and
	// its contents may change on the next call to any 'seeks method'.
	Value() []byte
}

Getting Started with leveldb-wrapper

Installation
go get -u github.com/DE-labtory/leveldb-wrapper
Usage
package main

import (
	"github.com/DE-labtory/leveldb-wrapper"
	"fmt"
	"os"
)

func main(){

	path := "./leveldb"
	dbProvider := leveldbwrapper.CreateNewDBProvider(path)
	defer os.RemoveAll(path)

	studentDB := dbProvider.GetDBHandle("Student")
	studentDB.Put([]byte("20164403"),[]byte("JUN"),true)

	name, _ := studentDB.Get([]byte("20164403"))

	fmt.Printf("%s",name)
}

Lincese

Heimdall source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func CreateNewDB

func CreateNewDB(levelDbPath string) *DB

tested

func (*DB) Close

func (db *DB) Close()

func (*DB) Delete

func (db *DB) Delete(key []byte, sync bool) error

Delete deletes the given key

func (*DB) Get

func (db *DB) Get(key []byte) ([]byte, error)

func (*DB) GetIterator

func (db *DB) GetIterator(startKey []byte, endKey []byte) key_value_db.KeyValueDBIterator

func (*DB) GetIteratorWithPrefix

func (db *DB) GetIteratorWithPrefix(prefix []byte) key_value_db.KeyValueDBIterator

func (*DB) Open

func (db *DB) Open()

tested

func (*DB) Put

func (db *DB) Put(key []byte, value []byte, sync bool) error

sync 옵션은 write buffer를 file io와 항상 동기화 시키는지 여부 sync false면 시스템 crash발생시 정보의 손실 가능성이 있다.

func (*DB) Snapshot

func (db *DB) Snapshot() (map[string][]byte, error)

func (*DB) WriteBatch

func (db *DB) WriteBatch(KVs map[string][]byte, sync bool) error

WriteBatch writes a batch

type DBHandle

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

func (*DBHandle) Delete

func (h *DBHandle) Delete(key []byte, sync bool) error

func (*DBHandle) Get

func (h *DBHandle) Get(key []byte) ([]byte, error)

func (*DBHandle) GetIteratorWithPrefix

func (h *DBHandle) GetIteratorWithPrefix() key_value_db.KeyValueDBIterator

func (*DBHandle) Put

func (h *DBHandle) Put(key []byte, value []byte, sync bool) error

func (*DBHandle) Snapshot

func (h *DBHandle) Snapshot() (map[string][]byte, error)

func (*DBHandle) WriteBatch

func (h *DBHandle) WriteBatch(KVs map[string][]byte, sync bool) error

type DBProvider

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

func CreateNewDBProvider

func CreateNewDBProvider(levelDbPath string) *DBProvider

func (*DBProvider) Close

func (p *DBProvider) Close()

func (*DBProvider) GetDBHandle

func (p *DBProvider) GetDBHandle(dbName string) *DBHandle

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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