mdb

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

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

Go to latest
Published: Apr 1, 2014 License: BSD-3-Clause Imports: 7 Imported by: 0

README

gomdb

Go wrapper for OpenLDAP Lightning Memory-Mapped Database (LMDB). Read more about LMDB here: http://symas.com/mdb/

GoDoc available here: http://godoc.org/github.com/szferi/gomdb

Build

git clone -b mdb.master --single-branch git://git.openldap.org/openldap.git

make

make install

It will install to /usr/local

export LD_LIBRARY_PATH=/usr/local/lib

go test -v

TODO

  • write more documentation
  • write more unit test
  • benchmark
  • figure out how can you write go binding for MDB_comp_func and MDB_rel_func
  • Handle go *Cursor close with txn.Commit and txn.Abort transparently

Documentation

Index

Constants

View Source
const (
	FIRST = iota
	FIRST_DUP
	GET_BOTH
	GET_RANGE
	GET_CURRENT
	GET_MULTIPLE
	LAST
	LAST_DUP
	NEXT
	NEXT_DUP
	NEXT_MULTIPLE
	NEXT_NODUP
	PREV
	PREV_DUP
	PREV_NODUP
	SET
	SET_KEY
	SET_RANGE
)

MDB_cursor_op

View Source
const (
	FIXEDMAP   = C.MDB_FIXEDMAP   // mmap at a fixed address (experimental)
	NOSUBDIR   = C.MDB_NOSUBDIR   // no environment directory
	NOSYNC     = C.MDB_NOSYNC     // don't fsync after commit
	RDONLY     = C.MDB_RDONLY     // read only
	NOMETASYNC = C.MDB_NOMETASYNC // don't fsync metapage after commit
	WRITEMAP   = C.MDB_WRITEMAP   // use writable mmap
	MAPASYNC   = C.MDB_MAPASYNC   // use asynchronous msync when MDB_WRITEMAP is use
	NOTLS      = C.MDB_NOTLS      // tie reader locktable slots to Txn objects instead of threads
)

mdb_env Environment Flags

View Source
const (
	REVERSEKEY = C.MDB_REVERSEKEY // use reverse string keys
	DUPSORT    = C.MDB_DUPSORT    // use sorted duplicates
	INTEGERKEY = C.MDB_INTEGERKEY // numeric keys in native byte order. The keys must all be of the same size.
	DUPFIXED   = C.MDB_DUPFIXED   // with DUPSORT, sorted dup items have fixed size
	INTEGERDUP = C.MDB_INTEGERDUP // with DUPSORT, dups are numeric in native byte order
	REVERSEDUP = C.MDB_REVERSEDUP // with DUPSORT, use reverse string dups
	CREATE     = C.MDB_CREATE     // create DB if not already existing
)

DBIOpen Database Flags

View Source
const (
	NODUPDATA   = C.MDB_NODUPDATA
	NOOVERWRITE = C.MDB_NOOVERWRITE
	RESERVE     = C.MDB_RESERVE
	APPEND      = C.MDB_APPEND
	APPENDDUP   = C.MDB_APPENDDUP
)

put flags

View Source
const (
	SUCCESS = 0
)

Variables

View Source
var (
	KeyExist        error = Errno(-30799)
	NotFound        error = Errno(-30798)
	PageNotFound    error = Errno(-30797)
	Corrupted       error = Errno(-30796)
	Panic           error = Errno(-30795)
	VersionMismatch error = Errno(-30794)
	Invalid         error = Errno(-30793)
	MapFull         error = Errno(-30792)
	DbsFull         error = Errno(-30791)
	ReadersFull     error = Errno(-30790)
	TlsFull         error = Errno(-30789)
	TxnFull         error = Errno(-30788)
	CursorFull      error = Errno(-30787)
	PageFull        error = Errno(-30786)
	MapResized      error = Errno(-30785)
	Incompatibile   error = Errno(-30784)
)

error codes

Functions

func Version

func Version() string

Types

type Cursor

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

func (*Cursor) Close

func (cursor *Cursor) Close() error

func (*Cursor) Count

func (cursor *Cursor) Count() (uint64, error)

func (*Cursor) DBI

func (cursor *Cursor) DBI() DBI

func (*Cursor) Del

func (cursor *Cursor) Del(flags uint) error

func (*Cursor) Get

func (cursor *Cursor) Get(set_key []byte, op uint) (key, val []byte, err error)

func (*Cursor) GetGo

func (cursor *Cursor) GetGo(set_key interface{}, op uint, key, val interface{}) error

func (*Cursor) MdbCursor

func (cursor *Cursor) MdbCursor() *C.MDB_cursor

Retrieves the low-level MDB cursor.

func (*Cursor) Put

func (cursor *Cursor) Put(key, val []byte, flags uint) error

func (*Cursor) PutGo

func (cursor *Cursor) PutGo(key, val interface{}, flags uint) error

func (*Cursor) Txn

func (cursor *Cursor) Txn() *Txn

type DBI

type DBI uint

type Env

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

Env is opaque structure for a database environment. A DB environment supports multiple databases, all residing in the same shared-memory map.

func NewEnv

func NewEnv() (*Env, error)

Create an MDB environment handle.

func (*Env) BeginTxn

func (env *Env) BeginTxn(parent *Txn, flags uint) (*Txn, error)

func (*Env) Close

func (env *Env) Close() error

func (*Env) Copy

func (env *Env) Copy(path string) error

func (*Env) DBIClose

func (env *Env) DBIClose(dbi DBI)

func (*Env) Flags

func (env *Env) Flags() (uint, error)

func (*Env) Info

func (env *Env) Info() (*Info, error)

func (*Env) Open

func (env *Env) Open(path string, flags uint, mode uint) error

Open an environment handle. If this function fails Close() must be called to discard the Env handle.

func (*Env) Path

func (env *Env) Path() (string, error)

func (*Env) SetFlags

func (env *Env) SetFlags(flags uint, onoff int) error

func (*Env) SetMapSize

func (env *Env) SetMapSize(size uint64) error

func (*Env) SetMaxDBs

func (env *Env) SetMaxDBs(size DBI) error

func (*Env) SetMaxReaders

func (env *Env) SetMaxReaders(size uint) error

func (*Env) Stat

func (env *Env) Stat() (*Stat, error)

func (*Env) Sync

func (env *Env) Sync(force int) error

type Errno

type Errno int

func (Errno) Error

func (e Errno) Error() string

type Info

type Info struct {
	MapSize    uint64 // Size of the data memory map
	LastPNO    uint64 // ID of the last used page
	LastTxnID  uint64 // ID of the last committed transaction
	MaxReaders uint   // maximum number of threads for the environment
	NumReaders uint   // maximum number of threads used in the environment
}

type Stat

type Stat struct {
	PSize         uint   // Size of a database page. This is currently the same for all databases.
	Depth         uint   // Depth (height) of the B-tree
	BranchPages   uint64 // Number of internal (non-leaf) pages
	LeafPages     uint64 // Number of leaf pages
	OwerflowPages uint64 // Number of overflow pages
	Entries       uint64 // Number of data items
}

Statistics for a database in the environment

type Txn

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

Txn is Opaque structure for a transaction handle. All database operations require a transaction handle. Transactions may be read-only or read-write.

func (*Txn) Abort

func (txn *Txn) Abort()

func (*Txn) Commit

func (txn *Txn) Commit() error

func (*Txn) CursorOpen

func (txn *Txn) CursorOpen(dbi DBI) (*Cursor, error)

func (*Txn) CursorRenew

func (txn *Txn) CursorRenew(cursor *Cursor) error

func (*Txn) DBIOpen

func (txn *Txn) DBIOpen(name *string, flags uint) (DBI, error)

func (*Txn) Del

func (txn *Txn) Del(dbi DBI, key, val []byte) error

func (*Txn) DelGo

func (txn *Txn) DelGo(dbi DBI, key, val interface{}) error

func (*Txn) Drop

func (txn *Txn) Drop(dbi DBI, del int) error

func (*Txn) Get

func (txn *Txn) Get(dbi DBI, key []byte) ([]byte, error)

func (*Txn) GetGo

func (txn *Txn) GetGo(dbi DBI, key, val interface{}) error

func (*Txn) Put

func (txn *Txn) Put(dbi DBI, key []byte, val []byte, flags uint) error

func (*Txn) PutGo

func (txn *Txn) PutGo(dbi DBI, key, val interface{}, flags uint) error

func (*Txn) Renew

func (txn *Txn) Renew() error

func (*Txn) Reset

func (txn *Txn) Reset()

func (*Txn) Stat

func (txn *Txn) Stat(dbi DBI) (*Stat, error)

Jump to

Keyboard shortcuts

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