db

package
v0.0.0-...-f21bc9d Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package db exports multiple utilities to work with BoltDB databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BDB

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

BDB is a simple wrapper around a BoltDB database.

func Open

func Open(path string, cols ...string) (*BDB, error)

Open tries to get the database on the received path and create the specified collection (bucket in the case of a BoltDB database) if it does not already exist. If all the previous operations have succeeded it returns the database as a *BDB. If something goes wrong while opening the database o while creating the collection it returns a error.

func (*BDB) Get

func (bdb *BDB) Get(col string, key string) ([]byte, error)

Get returns specified element on a collection if it exist. If the received key doesn't exist it returns an error.

func (*BDB) GetAll

func (bdb *BDB) GetAll(col string) ([][]byte, error)

GetAll returns all the elements on the specified collection.

func (*BDB) Remove

func (bdb *BDB) Remove(col string, key string) error

Remove removes the specified element on a collection. It never returns a non-nil error.

func (*BDB) Set

func (bdb *BDB) Set(col string, key string, val []byte) error

Set tries to add to the specified collection (bucket in the case of a BoltDB database) an element. It returns the value of the added element on a []byte if the operation was successful or an error if something went wrong.

type Bolter

type Bolter interface {
	Set(col string, key string, val []byte) error
	Get(col string, key string) ([]byte, error)
	GetAll(col string) ([][]byte, error)
	Remove(col string, key string) error
}

Bolter is the interface that wraps all the basic methods to manage a BoltDB database.

Jump to

Keyboard shortcuts

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