berkeleydb

package module
v0.0.0-...-5cde5ea Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2017 License: MIT Imports: 4 Imported by: 9

README

GoDoc Travis

BEWARE

This library is unmaintained and may stop working at any time.

BerkeleyDB Bindings

This package provides BerkeleyDB wrappers for the C library using cgo.

To build, you will need a relatively recent version of BerkeleyDB.

Example

package main

import (
        "fmt"

        "github.com/jsimonetti/berkeleydb"
)

func main() {
        var err error

        db, err := berkeleydb.NewDB()
        if err != nil {
                fmt.Printf("Unexpected failure of CreateDB %s\n", err)
        }

        err = db.Open("./test.db", berkeleydb.DbHash, berkeleydb.DbCreate)
        if err != nil {
                fmt.Printf("Could not open test_db.db. Error code %s", err)
                return
        }
        defer db.Close()

        err = db.Put("key", "value")
        if err != nil {
                fmt.Printf("Expected clean Put: %s\n", err)
        }

        value, err := db.Get("key")
        if err != nil {
                fmt.Printf("Unexpected error in Get: %s\n", err)
                return
        }
        fmt.Printf("value: %s\n", value)

}

Documentation

Index

Constants

View Source
const (
	DbCreate   = C.DB_CREATE
	DbExcl     = C.DB_EXCL
	DbRdOnly   = C.DB_RDONLY
	DbTruncate = C.DB_TRUNCATE

	// DbInitMpool is used in environment only
	DbInitMpool = C.DB_INIT_MPOOL
)

Flags for opening a database or environment.

View Source
const (
	DbBtree   = C.DB_BTREE
	DbHash    = C.DB_HASH
	DbRecno   = C.DB_RECNO
	DbQueue   = C.DB_QUEUE
	DbUnknown = C.DB_UNKNOWN
)

Database types.

Variables

This section is empty.

Functions

func Version

func Version() string

Version returns the version of the database and binding

Types

type Cursor

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

Cursor holds the current cursor position

func (*Cursor) GetFirst

func (cursor *Cursor) GetFirst() (string, string, error)

GetFirst moves the cursor to the first entry and returns the key/value pair

func (*Cursor) GetLast

func (cursor *Cursor) GetLast() (string, string, error)

GetLast moves the cursor to the last entry and returns the key/value pair

func (*Cursor) GetNext

func (cursor *Cursor) GetNext() (string, string, error)

GetNext moves the cursor to the next entry and returns the key/value pair

func (*Cursor) GetPrevious

func (cursor *Cursor) GetPrevious() (string, string, error)

GetPrevious moves the cursor to the previous entry and returns the key/value pair

type DBError

type DBError struct {
	Code    int
	Message string
}

DBError contains the database Error

func (*DBError) Error

func (e *DBError) Error() string

Error return the string representation of the error

type Db

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

Db is the structure that holds the database connection

func NewDB

func NewDB() (*Db, error)

NewDB initialises a new bdb connection

func NewDBInEnvironment

func NewDBInEnvironment(env *Environment) (*Db, error)

NewDBInEnvironment initialises a new bdb connection in an environment

func (*Db) Close

func (handle *Db) Close() error

Close the database file

func (*Db) Cursor

func (handle *Db) Cursor() (*Cursor, error)

Cursor returns a handle for the database cursor

func (*Db) Delete

func (handle *Db) Delete(name string) error

Delete a value from the database by key

func (*Db) Flags

func (handle *Db) Flags() (C.u_int32_t, error)

Flags returns the flags of the database connection

func (*Db) Get

func (handle *Db) Get(name string) (string, error)

Get a value from the database by key

func (*Db) Open

func (handle *Db) Open(filename string, dbtype C.DBTYPE, flags C.u_int32_t) error

Open a database file

func (*Db) OpenWithTxn

func (handle *Db) OpenWithTxn(filename string, txn *C.DB_TXN, dbtype C.DBTYPE, flags C.u_int32_t) error

OpenWithTxn opens the database in transaction mode (transactions are not yet supported by all funtions)

func (*Db) Put

func (handle *Db) Put(name, value string) error

Put a key/value pair into the database

func (*Db) Remove

func (handle *Db) Remove(filename string) error

Remove the database

func (*Db) Rename

func (handle *Db) Rename(oldname, newname string) error

Rename the database filename

type Environment

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

Environment holds the database environment

func NewEnvironment

func NewEnvironment() (*Environment, error)

NewEnvironment creates a new database environment

func (*Environment) Close

func (env *Environment) Close() error

Close a database in the environment

func (*Environment) Open

func (env *Environment) Open(path string, flags C.u_int32_t, fileMode int) error

Open a database in the environment

type Errno

type Errno int

Errno is the error number

Jump to

Keyboard shortcuts

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