db

package
v0.0.0-...-b202129 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2017 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MarkIncomplete = "0"
	MarkComplete   = "1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BarePackage

type BarePackage struct {
	ID       string
	Revision string
}

BarePackage represents the basis elements for package

type DatabaseConfig

type DatabaseConfig struct {
	Type          string      `toml:"type"`
	Path          interface{} `toml:"path"`
	MaxCacheSize  int         `toml:"max_cache_size"`
	CacheLifetime int         `toml:"cache_lifetime"`
}

DatabaseConfig defines config for database

type DatabaseStats

type DatabaseStats struct {
	Packages  int
	Marks     int
	Documents int
	Files     int
}

DatabaseStats represents the count of each bucket

type PocketBase

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

PocketBase type is a frontend for BoltDB

func NewPocketBase

func NewPocketBase(config *DatabaseConfig) *PocketBase

NewPocketBase creates a new PocketBase object

func (*PocketBase) Check

func (pb *PocketBase) Check()

Check method checks redundancy for the buckets

func (*PocketBase) Close

func (pb *PocketBase) Close()

Close method closes database connection

func (*PocketBase) DeletePackage

func (pb *PocketBase) DeletePackage(name string)

DeletePackage method deletes a package

func (*PocketBase) GetAllFiles

func (pb *PocketBase) GetAllFiles() map[string][]*url.URL

GetAllFiles method returns {name: files} map

func (*PocketBase) GetCountOfMarks

func (pb *PocketBase) GetCountOfMarks(cond bool) int

GetCountOfMarks method returns a count of marked items

func (*PocketBase) GetDocument

func (pb *PocketBase) GetDocument(id string, withfiles bool) (document string, filelist []*url.URL, err error)

GetDocument method returns a document by given name

func (*PocketBase) GetIncompletePackages

func (pb *PocketBase) GetIncompletePackages() []*BarePackage

GetIncompletePackages method returns a list of packages that are ready for queueing

func (*PocketBase) GetItemCount

func (pb *PocketBase) GetItemCount(name string) (count int)

GetItemCount method returns the count of items in the bucket

func (*PocketBase) GetRevision

func (pb *PocketBase) GetRevision(id string) (rev string)

GetRevision method returns a revision of document

func (*PocketBase) GetSequence

func (pb *PocketBase) GetSequence() (sequence int)

GetSequence method returns current sequence of registry

func (*PocketBase) GetStats

func (pb *PocketBase) GetStats() (stats *DatabaseStats)

GetStats method returns status of various buckets

func (*PocketBase) Init

func (pb *PocketBase) Init()

Init method initializes scheme

Globals bucket contains global variables such as "sequence" Packages bucket contains the map of "id": "revision" hash Marks bucket contains the state to determine whether package currently downloaded or not Documents bucket contains full document of the package Files bucket con

func (*PocketBase) IsInitialized

func (pb *PocketBase) IsInitialized() bool

IsInitialized method returns whether the database has initialized

func (*PocketBase) LogStats

func (pb *PocketBase) LogStats()

LogStats method logs database stats every 10 seconds

func (*PocketBase) Migrate

func (pb *PocketBase) Migrate(boltPath string)

func (*PocketBase) PutCompleted

func (pb *PocketBase) PutCompleted(pack *BarePackage, document string, rev string, downloads []*url.URL) (succeed bool)

PutCompleted method inserts a completed package into the appropriate buckets

func (*PocketBase) PutPackage

func (pb *PocketBase) PutPackage(tx transactionable, id string, rev string, mark bool, overwrite bool) error

PutPackage method inserts a package into the appropriate buckets

func (*PocketBase) PutPackages

func (pb *PocketBase) PutPackages(allDocs []*BarePackage)

PutPackages method is a bulk method of PutPackage

func (*PocketBase) SetSequence

func (pb *PocketBase) SetSequence(seq int)

SetSequence method sets current sequence of registry

type PocketStore

type PocketStore interface {
	Connect() error
	Close()
	Init()
	IsInitialized() bool
	GetItemCount(string) int
	GetSequence() int
	SetSequence(int)
	GetCountOfMarks(string) int
	GetIncompletePackages() []*BarePackage
	GetRevision(string) string
	GetDocument(string, bool) (string, []byte, error)
	GetAllFiles() map[string][]*url.URL
	AcquireTx() transactionable
	PutPackage(transactionable, string, string, bool, bool) error
	DeletePackage(string)
	PutCompleted(transactionable, *BarePackage, string, string, []*url.URL) bool
}

PocketStore represents the database factory interface

type StoreType

type StoreType int

StoreType represents the type for database store

const (
	// BoltStore uses boltdb as a database backend
	BoltStore StoreType = 1 << iota
	// GormStore uses gorm as a database backend controller
	GormStore
)

Jump to

Keyboard shortcuts

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