database

package
v0.0.0-...-194264a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Logger is a global variable exported to be set by the package importing database package, in order to let it decide which logger it wants to use.

Functions

This section is empty.

Types

type BoltDB

type BoltDB struct {
	Name string
	DB   *bolt.DB
}

BoltDB database structure

func NewBoltDBProvider

func NewBoltDBProvider() *BoltDB

NewBoltDBProvider returns a bolt based database that conforms to the DBProvider interface

func (*BoltDB) DbAdd

func (db *BoltDB) DbAdd(table string, key string, value interface{}) (err error)

DbAdd adds a new element to table in Bolt database

func (*BoltDB) DbClose

func (db *BoltDB) DbClose() error

DbClose closes Bolt database

func (*BoltDB) DbDelete

func (db *BoltDB) DbDelete(table string, key string) (err error)

DbDelete deletes an element from table in Bolt database

func (*BoltDB) DbGet

func (db *BoltDB) DbGet(table string, key string, dbTable DbTable) (interface{}, error)

DbGet obtains value by key from table

func (*BoltDB) DbGetAll

func (db *BoltDB) DbGetAll(table string, dbTable DbTable) (elements []interface{}, err error)

DbGetAll gets all elements from specific table

func (*BoltDB) DbInit

func (db *BoltDB) DbInit(dbDir, dbFile string) error

DbInit initialize Bolt database

func (*BoltDB) DbTableRebuild

func (db *BoltDB) DbTableRebuild(table DbTable) error

DbTableRebuild builds bolt table into memory

func (*BoltDB) DbTablesInit

func (db *BoltDB) DbTablesInit(tables []string) (err error)

DbTablesInit initializes list of tables in Bolt

type DbProvider

type DbProvider interface {
	// Initializes the Database
	DbInit(dbDir, dbFile string) error
	// Closes the database
	DbClose() error
	// Creates the tables if the tables do not already exist in the database
	DbTablesInit(tables []string) error
	// Populates the in-memory table from the database
	DbTableRebuild(table DbTable) error
	// Adds the key/value pair to the table
	DbAdd(table string, key string, value interface{}) error
	//Deletes the key/value pair from the table
	DbDelete(table string, key string) error
	//Retrives the value corresponding to the key from the table
	DbGet(table string, key string, dbTable DbTable) (interface{}, error)
	//Retrieves all values from a table
	DbGetAll(table string, dbTable DbTable) ([]interface{}, error)
}

DbProvider represents a persistent database provider

type DbTable

type DbTable interface {
	// Creates the backing map
	NewTable()
	// Name of the table as stored in the database
	Name() string
	// Allocates and returns a single value in the table
	NewElement() interface{}
	// Add an value to the in memory table
	Add(k string, v interface{}) error
}

DbTable defines basic table operations

Jump to

Keyboard shortcuts

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