db

package
v0.0.0-...-22c49a1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close the default repository

func Initialize

func Initialize(path string) error

Initialize initializes the global repository

func ReplaceDefaultRepositoryWith

func ReplaceDefaultRepositoryWith(repo Repository) func()

ReplaceDefaultRepositoryWith replace the default repository

Types

type BoltRepository

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

BoltRepository represents a bbolt database

func (BoltRepository) Close

func (repo BoltRepository) Close() error

Close closes bbolt db connection

func (BoltRepository) Delete

func (repo BoltRepository) Delete(bucketName string, model Model) error

Delete deletes the model from bucketName

func (BoltRepository) Fetch

func (repo BoltRepository) Fetch(bucketName string, name string, model Model) (bool, error)

Fetch retrieves the model identified by name from the bucket named bucketName

func (BoltRepository) FetchAll

func (repo BoltRepository) FetchAll(bucketName string, modelFn func([]byte) (Model, error)) (interface{}, error)

FetchAll returns all the models available in the bucketName and error if any

func (BoltRepository) Save

func (repo BoltRepository) Save(bucketName string, model Model) error

Save persists the model in the bucketName

type EntryNotFound

type EntryNotFound string

EntryNotFound represents a not found entity error

func (EntryNotFound) Error

func (e EntryNotFound) Error() string

Error returns the error string

type Model

type Model interface {
	ID() string
}

Model which can persisted in the repository

type Repository

type Repository interface {
	Save(bucketName string, model Model) error
	Delete(bucketName string, model Model) error
	Fetch(bucketName string, name string, model Model) (bool, error)
	FetchAll(bucketName string, modelFn func(data []byte) (Model, error)) (interface{}, error)
	Close() error
}

Repository holds the necessary method to persist and retrieve data from database

func DefaultRepository

func DefaultRepository() Repository

DefaultRepository returns the global repository

func NewBoltRepository

func NewBoltRepository(path string) (Repository, error)

NewBoltRepository returns the repository and error if any

Jump to

Keyboard shortcuts

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