Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultLmdbConfig = LmdbEnvConfig{ OpenPath: ".", OpenFSMode: 0644, MapSize: 1 << 30, MaxReaders: 1, Databases: []DbConfig{{DbName: "default"}}, Marshal: msgpack.MarshalAsArray, Unmarshal: msgpack.UnmarshalAsArray, }
Functions ¶
This section is empty.
Types ¶
type Db ¶
type Db struct {
// contains filtered or unexported fields
}
Db reperesents a single Database inside LmdbEnv
Db should always be accessed through LmdbEnv.GetDatabase(dbName) or LmdbEnv.GetSingleDatabase()
Do not create Db struct directly
func (*Db) Del ¶
Del a value with key inside the database
The call will block until the transaction is finished
func (*Db) Get ¶
Get returns the binary value at key inside the database
If the key does not exist, an error is returned ¶
The returned value is copied for safe use outside the lmdb.TxnOp
func (*Db) GetAndMarshal ¶
GetAndMarshal marshals value at key into &dest
If the key does not exist, an error is returned ¶
The value is first copied for safe use outside the lmdb.TxnOp ¶
Returned value is safe to use across goroutines
type DbConfig ¶
type DbConfig struct { DbName string Marshal func(v interface{}) ([]byte, error) Unmarshal func(data []byte, v interface{}) error }
DbConfig is configuration that will be created as entries in LmdbEnv.Databases
Marshal and Unmarshal are optional and defaults to the parent LmdbEnv's methods.
Different Marshal and Unmarshal per database is possible, but should never change for the lifetime of the database.
type LmdbEnv ¶
type LmdbEnv struct { // Direct access to *lmdb.Env LmdbEnv *lmdb.Env // contains filtered or unexported fields }
LmdbEnv wraps LmdbEnv with tested configurations
LmdbEnv should always be created by calling NewLmdb(LmdbEnvConfig)
Do not create the struct directly
func NewLmdb ¶
func NewLmdb(config LmdbEnvConfig) (*LmdbEnv, error)
NewLmdb initialize a single LmdbEnv
Initialized LmdbEnv would spawn a single "updater" goroutine for Update transactions
The methods should be safe to use across multiple goroutines
func (*LmdbEnv) Close ¶
func (e *LmdbEnv) Close()
Close flushes the Lmdb databases to disk and stop the updater goroutine
Note that closed LmdbEnv should not be used for any transactions
func (*LmdbEnv) GetDatabase ¶
GetDatabase returns a database with name dbName
Non-existing entries will return nil
func (*LmdbEnv) GetSingleDatabase ¶
GetSingleDatabase returns a single database
if Databases contains more than a single entry, GetSingleDatabase returns an error
type LmdbEnvConfig ¶
type LmdbEnvConfig struct { OpenPath string OpenFlag uint OpenFSMode fs.FileMode MapSize int64 MaxReaders int // minimum 1 entry Databases []DbConfig // optional Marshal func(v interface{}) ([]byte, error) // optional Unmarshal func(data []byte, v interface{}) error }
LmdbEnvConfig is configuration for LmdbEnv
There should be minimum 1 Databases []DbConfig entry
Marshal and Unmarshal are optional and defaults to github.com/shamaton/msgpack
All other fields should be set