Documentation ¶
Overview ¶
Package GobDB implements a persistant key-value store of gob-compatible types. This is accomplished with a light wrapper around leveldb and Go's gob encoding library.
Index ¶
- type DB
- func (db *DB) Close()
- func (db *DB) Compact() error
- func (db *DB) Delete(key interface{}) error
- func (db *DB) Entries() int
- func (db *DB) Get(key, value interface{}) error
- func (db DB) Has(key interface{}) bool
- func (db *DB) Internal() *leveldb.DB
- func (db DB) IsOpen() bool
- func (db *DB) Open() error
- func (db *DB) Put(key, value interface{}) error
- func (db *DB) Reset()
- type Decoder
- type FilteredEncoder
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
}
DB is a LevelDB wrapper that stores key-value pairs of gob-compatible types.
func (*DB) Close ¶
func (db *DB) Close()
Close tears down the internal leveldb, writing all contents to file.
func (*DB) Compact ¶
Compact performs leveldb.CompactRange on the range of key-value mappings maintained by GobDB. Pairs outside the 'GobDB:' prefix aren't affected.
func (*DB) Delete ¶
Delete encodes given key via gob, deleting the resulting byte slice from the database's internal leveldb.
func (*DB) Entries ¶
Entries counts key-value pairs in the database. This includes only pairs written through GobDB.Put.
func (*DB) Get ¶
Get ncodes given key via gob, fetches the corresponding value from within leveldb, and decodes that value into parameter two.
func (DB) Has ¶
Has encodes given key via gob and checks if the resulting byte slice exists in the database's internal leveldb.
func (*DB) Internal ¶
Internal opens and fetches the underlying leveldb. Clients may use this to perform direct writing of byte slices, or to access leveldb APIs left out of this wrapper.
Note: GobDB stores its mappings in the prefix "GobDB:", so that prefix should be avoided.
Note: closing the parent GobDB will invalidate the returned value of this function.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder provides a goroutine-safe method of decoding gobbed objects individually. Assumes that gob type definitions are registered in the necessary order.
NOTE: Decoder pointers to the same address will be forced to use mutex locks when utilized concurrently. On the other hand, if you copy a decoder itself, the two copies may be interacted with concurrently and lock-free.
type FilteredEncoder ¶
type FilteredEncoder struct {
// contains filtered or unexported fields
}
FilteredEncoder wraps gob.Encoder in such a way to retain all of gobs internal type definitions, and to return byte slices of type-value pairs without any additional data.
Returns bytes of encoded objects, writes only type definitions and uniquely-typed objects (i.e. one object of each type).
func (*FilteredEncoder) Encode ¶
func (f *FilteredEncoder) Encode(e interface{}) ([]byte, []byte, error)
Encode performs gob.Encode twice, compares the two encodings to deduce whether or not the value had been encoded before. If it has the gob type definition is returned in position one. Regardless, the actual encoded value (without typedef bytes) is returned in position two.