db

package
v0.0.0-...-0c63773 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNeedWriteMode = errors.New("Need WriteMode. Mode of the db is ReadOnly")
)

Functions

func SetOffset

func SetOffset(offset int)

SetOffset change value of maxOffset (default – 100)

Types

type BoltAPI

type BoltAPI struct {
	Name     string `json:"name"`
	DBPath   string `json:"dbPath"`
	Size     int64  `json:"size"`
	ReadOnly bool
	// contains filtered or unexported fields
}

BoltAPI is a warrep for *bolt.DB

pages is a number of pages (1 page = maxOffset) 1 – [0, maxOffset) 2 – [maxOffset, 2*maxOffset) 3 – [2*maxOffset, 3*maxOffset) etc.

func Create

func Create(path string) (*BoltAPI, error)

Create a new db. If path consists only a name, the db will be created on the Desktop The function calls Open() and returns result of this calling

func Open

func Open(path string, opt Options) (*BoltAPI, error)

Open returns info about the file of db, wrapper for *bolt.DB

func (*BoltAPI) AddBucket

func (db *BoltAPI) AddBucket(bucketName string) (err error)

AddBucket adds a new bucket. Function returns an error if: * the bucket already exists - "bucket already exists" * there's a record with same key - "it's a record"

func (*BoltAPI) AddRecord

func (db *BoltAPI) AddRecord(key, value string) (err error)

AddRecord adds a new record. Function returns an error if: * there's a bucket with same key - "it's a bucket" * the record already exists - "record already exists"

func (*BoltAPI) Back

func (db *BoltAPI) Back() (data Data, err error)

Back return records from previous bucket

func (*BoltAPI) Close

func (db *BoltAPI) Close() error

Close closes db

func (*BoltAPI) DeleteBucket

func (db *BoltAPI) DeleteBucket(key string) (err error)

DeleteBucket deletes a bucket. Function returns an error if: * it's a record, not bucket - "it's a record" * there's no such bucket - "there's no such bucket"

func (*BoltAPI) DeleteRecord

func (db *BoltAPI) DeleteRecord(key string) (err error)

DeleteRecord deletes a record Function returns an error if: * it's a bucket, nor record - "it's a bucket" * there's no such record - "there's no such record"

func (*BoltAPI) EditBucketName

func (db *BoltAPI) EditBucketName(oldKey, newKey string) (err error)

EditBucketName renames buckets Process: * firstly, data of a bucket is copied to memory (it is a tree); * secondary, bucket with old name is deleted, bucket with new name is created; * thirdly, the data from memory is copied to the new bucket. Copying works recursively.

func (*BoltAPI) EditRecord

func (db *BoltAPI) EditRecord(oldKey, newKey, newValue string) error

EditRecord edits a record Function returns an error if: * there's a bucket with key == oldKey - "it's a bucket" * there's no record with key == oldKey - "there's no such record" * there's a bucket with key == newKey - "there's a bucket with key == newKey" * there's a record with key == newKey - "there's a record with key == newKey"

func (*BoltAPI) GetCurrent

func (db *BoltAPI) GetCurrent() (data Data, err error)

GetCurrent returns records from current bucket

func (*BoltAPI) GetRoot

func (db *BoltAPI) GetRoot() (data Data, err error)

GetRoot returns records from root of db

func (*BoltAPI) Next

func (db *BoltAPI) Next(name string) (data Data, err error)

Next return records from next bucket with according name

func (*BoltAPI) NextRecords

func (db *BoltAPI) NextRecords() (data Data, err error)

NextRecords return next part of records and bool, which shows is there next records

func (*BoltAPI) PrevRecords

func (db *BoltAPI) PrevRecords() (data Data, err error)

PrevRecords return prev part of records and bool, which shows is there previous records

func (*BoltAPI) Search

func (db *BoltAPI) Search(needle string) (records []Record, path string, recordsAmount int, err error)

Search use bytes.Contains()

func (*BoltAPI) SearchRegexp

func (db *BoltAPI) SearchRegexp(expr string) (records []Record, path string, recordsAmount int, err error)

SearchRegexp use regexp.Match()

type Data

type Data struct {
	Records       []Record
	PrevBucket    bool
	PrevRecords   bool
	NextRecords   bool
	RecordsAmount int
	Path          string
}

Data serves for returning

type Options

type Options struct {
	ReadOnly bool
}

Options for opening of a db `Options{}` can be used for getting of default options

type Record

type Record struct {
	T     string `json:"type"`
	Key   string `json:"key"`
	Value string `json:"value"`
}

Record consists information about record in the db

Jump to

Keyboard shortcuts

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