localdb

package module
v0.0.0-...-ba4b50b Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2020 License: MIT Imports: 4 Imported by: 0

README

localdb

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package localdb is a wrapper around bbolt key-value database to manage messaging data in a local database Its primary purpose is to be used persist messages if sending queues like NATS fails.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLocalDatabaseNotYetOpened = errors.New(`local database not yet opened`)
	ErrCorruptedInternalBucket   = errors.New(`corrupted internal bucket`)
	ErrBucketDoesNotExist        = errors.New(`bucket does not exist`)
	ErrNoKeysSet                 = errors.New(`no keys set`)
)

Errors

Functions

This section is empty.

Types

type ChunkData

type ChunkData struct {
	Key   string
	Value []byte
}

ChunkData used to represent chunks of data

type LocalDB

type LocalDB struct {
	FileName string
	// contains filtered or unexported fields
}

LocalDB is a wrapper around bbolt key-value database to manage messaging data in a local database

func Open

func Open(file string) (*LocalDB, error)

Open opens the local database file

func (*LocalDB) Close

func (db *LocalDB) Close() error

Close closes the local database

func (*LocalDB) Count

func (db *LocalDB) Count(bucket string) (int, error)

Count records in the bucket

func (*LocalDB) CutChunkDown

func (db *LocalDB) CutChunkDown(bucket string, max int) ([]ChunkData, error)

CutChunkDown gets chunk of data from the bucket from top to bottom in ascending order and removes them.

func (*LocalDB) CutChunkUp

func (db *LocalDB) CutChunkUp(bucket string, max int) ([]ChunkData, error)

CutChunkUp gets chunk of data from the bucket from bottom to top in descending order and removes them.

func (*LocalDB) Delete

func (db *LocalDB) Delete(bucket string, key string) error

Delete a record in the database

func (*LocalDB) DeleteOnce

func (db *LocalDB) DeleteOnce(bucket string, key []string) error

DeleteOnce deletes data in the local database in one go

func (*LocalDB) Fetch

func (db *LocalDB) Fetch(bucket string, key string) (data []byte, err error)

Fetch fetches data from the local database

func (*LocalDB) FetchChunkDown

func (db *LocalDB) FetchChunkDown(bucket string, max int, offset int) ([]ChunkData, error)

FetchChunkDown gets chunk of data starting from the top to bottom limited by max

func (*LocalDB) FetchChunkUp

func (db *LocalDB) FetchChunkUp(bucket string, max int, offset int) ([]ChunkData, error)

FetchChunkUp gets chunk of data starting from the bottom to top limited by max

func (*LocalDB) FetchDelete

func (db *LocalDB) FetchDelete(bucket string, key string) ([]byte, error)

FetchDelete fetches the data in the key and deletes it

func (*LocalDB) SliceDown

func (db *LocalDB) SliceDown(bucket string) (data []byte, err error)

SliceDown fetches and deletes the item from top to bottom

func (*LocalDB) SliceUp

func (db *LocalDB) SliceUp(bucket string) (data []byte, err error)

SliceUp fetches and deletes the item from bottom to top

func (*LocalDB) Store

func (db *LocalDB) Store(bucket string, key string, data []byte) error

Store stores data in the local database

func (*LocalDB) StoreOnce

func (db *LocalDB) StoreOnce(bucket string, data []ChunkData) error

StoreOnce stores data in the local database in one go

Jump to

Keyboard shortcuts

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