db

package
v0.0.0-...-3bcaa81 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	FilePath   string
	BucketName string
}

Structure to encapsulate configuration needed to initialize the Db

type Db

type Db struct {
	Config
	// contains filtered or unexported fields
}

Structure to abtract away the underlying database implementation. This is the main handle into the database.

func NewDb

func NewDb(config Config) *Db

Constructor for Db object

func (*Db) ClearMessages

func (db *Db) ClearMessages() error

Delete all Messages from the database. Fast way of doing so is to just delete and re create the bucket.

This function isn't called in the core application. It's created to be called by the unit testing code.

func (*Db) Close

func (db *Db) Close()

Closes the Db. Not strictly necessary in this application, but good practice regardless

func (*Db) CreateMessage

func (db *Db) CreateMessage(detailedMessage *model.DetailedMessage) error

Inserts a new DetailedMessage in the database using "detailedMessage" at the index specified in the message. Returns an error if something went wrong during the transaction.

func (*Db) DeleteMessage

func (db *Db) DeleteMessage(id uint64) error

Deletes a DetailedMessage from the database at index "id". Returns an error if something went wrong during the transaction.

func (*Db) GetMessage

func (db *Db) GetMessage(id uint64) (*model.DetailedMessage, error)

Retrieves a DetailedMessage from the database at index "id". Returns an error if something went wrong during the transaction.

func (*Db) Initialize

func (db *Db) Initialize() error

Creates/opens and initializes a bbolt DB

func (*Db) ListMessages

func (db *Db) ListMessages(limit uint64, id uint64) ([]*model.DetailedMessage, uint64, error)

Returns a list of up to "limit" number of DetailedMessage starting with the first entry from index "id". A non-0 "afterId" returned indicates that there are more messages left to retrieve from the database.

func (*Db) UpdateMessage

func (db *Db) UpdateMessage(detailedMessage *model.DetailedMessage) error

Replaces a DetailedMessage in the database with "detailedMessage" at the index specified in the message. Returns an error if something went wrong during the transaction.

Jump to

Keyboard shortcuts

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