Documentation ¶
Index ¶
- type DBConnection
- func (dbc *DBConnection) Add(bucket []byte, data []byte) error
- func (dbc *DBConnection) Close() error
- func (dbc *DBConnection) CreateBucket(bucket []byte) error
- func (dbc *DBConnection) CreateDB() error
- func (dbc *DBConnection) DBExists() bool
- func (dbc *DBConnection) Delete(bucket []byte, key []byte) error
- func (dbc *DBConnection) ForEach(bucket []byte, callback func(val []byte) error) error
- func (dbc *DBConnection) Get(bucket []byte, key []byte) ([]byte, error)
- func (dbc *DBConnection) NextIDForBucket(bucket []byte) ([]byte, error)
- func (dbc *DBConnection) Open() error
- func (dbc *DBConnection) Put(bucket []byte, key []byte, data []byte) error
- func (dbc *DBConnection) RemoveDB() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBConnection ¶
type DBConnection struct {
// contains filtered or unexported fields
}
DBConnection encapsulates primitives for working with underlying database
func New ¶
func New(filename string, perms os.FileMode) *DBConnection
New creates a new DBConnection with the provided options for the underlying database
func (*DBConnection) Add ¶
func (dbc *DBConnection) Add(bucket []byte, data []byte) error
Add creates a new record in the bucket by adding the provided data. In case of no open connection or an issue with reading bucket or adding value, an error is returned.
func (*DBConnection) Close ¶
func (dbc *DBConnection) Close() error
Close the existing connection to the underlying database. In case of no open connection or an issue with closing it, an error is returned.
func (*DBConnection) CreateBucket ¶
func (dbc *DBConnection) CreateBucket(bucket []byte) error
CreateBucket will add a new bucket with the provided identifier in the db. In case of no open connection or an issue with creating bucket, an error is returned.
func (*DBConnection) CreateDB ¶
func (dbc *DBConnection) CreateDB() error
CreateDB creates a new empty database. In case of an issue with removing old database or creating a new one, an error is returned. In case of failing to close db connection, a panic occurs.
func (*DBConnection) DBExists ¶
func (dbc *DBConnection) DBExists() bool
DBExists checks if the database exists.
func (*DBConnection) Delete ¶
func (dbc *DBConnection) Delete(bucket []byte, key []byte) error
Delete creates a new record in the bucket by adding the provided data. In case of no open connection or an issue with reading bucket or adding value, an error is returned.
func (*DBConnection) ForEach ¶
func (dbc *DBConnection) ForEach(bucket []byte, callback func(val []byte) error) error
ForEach iterates over all records in provided bucket, and invokes callback(record). In case of no open connection or an issue with reading bucket or values, an error is returned.
func (*DBConnection) Get ¶
func (dbc *DBConnection) Get(bucket []byte, key []byte) ([]byte, error)
Get the value against the given key from the provided bucket. In case of no open connection or an issue with reading bucket or retrieving value, error is returned.
func (*DBConnection) NextIDForBucket ¶
func (dbc *DBConnection) NextIDForBucket(bucket []byte) ([]byte, error)
NextIDForBucket gets the next autoincremented ID for given bucket, without actually incrementing it. In case of no open connection or an issue with reading from bucket, an error is returned.
func (*DBConnection) Open ¶
func (dbc *DBConnection) Open() error
Open a new connection to the underlying database. In case of an issue with opening connection, an error is returned.
func (*DBConnection) Put ¶
func (dbc *DBConnection) Put(bucket []byte, key []byte, data []byte) error
Put modifies the existing value from the bucket[key] with the provided data. In case of no open connection or an issue with reading bucket or putting value, an error is returned.
func (*DBConnection) RemoveDB ¶
func (dbc *DBConnection) RemoveDB() error
RemoveDB removes the existing database or does nothing if db doesn't exist. In case of an issue with removing old database, an error is returned.