storage

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBoltPath

func DefaultBoltPath() string

func GetBoltDb

func GetBoltDb(file string) (*bolt.DB, error)

func GetIndexNameFromQuery

func GetIndexNameFromQuery(query Query) string

GetIndexNameFromQuery gets the name of an index from a query.

func GetIndexValueFromItem

func GetIndexValueFromItem(keyParts Key, item *search.ExternalResultItem) []byte

GetIndexValueFromItem gets the index value from a key set and an item.

func GetIndexValueFromQuery

func GetIndexValueFromQuery(query Query) []byte

GetIndexValueFromQuery get the value of an index by a query.

func GetOlderThanHours

func GetOlderThanHours(h int) []search.ExternalResultItem

GetOlderThanHours gets items that are at least H hours old.

Types

type BoltStorage

type BoltStorage struct {
	Database *bolt.DB
	// contains filtered or unexported fields
}

func NewBoltStorage

func NewBoltStorage(dbPath string) (*BoltStorage, error)

func (*BoltStorage) Create

func (b *BoltStorage) Create(keyParts Key, item *search.ExternalResultItem) error

Create a new record for a result.

func (*BoltStorage) Find

func (b *BoltStorage) Find(query Query, result *search.ExternalResultItem) error

Find something by it's index keys.

func (*BoltStorage) ForChat

func (b *BoltStorage) ForChat(callback func(chat *Chat)) error

ForChat calls the callback for each chat, in an async way.

func (*BoltStorage) GetBucket

func (b *BoltStorage) GetBucket(tx *bolt.Tx, children ...string) *bolt.Bucket

GetBucket returns the given bucket. You can use an array of strings for sub-buckets.

func (*BoltStorage) GetChat

func (b *BoltStorage) GetChat(id int) (*Chat, error)

func (*BoltStorage) GetSearchResults

func (b *BoltStorage) GetSearchResults(categoryId int) ([]search.ExternalResultItem, error)

GetSearchResults by a given category id

func (*BoltStorage) StoreChat

func (b *BoltStorage) StoreChat(chat *Chat) error

StoreChat stores a new chat. The chat id is used as a keyParts.

func (*BoltStorage) StoreSearchResults

func (b *BoltStorage) StoreSearchResults(items []search.ExternalResultItem) error

StoreSearchResults stores the given results

func (*BoltStorage) Truncate

func (b *BoltStorage) Truncate() error

func (*BoltStorage) Update

func (b *BoltStorage) Update(query Query, item *search.ExternalResultItem) error

type Chat

type Chat struct {
	Username    string
	InitialText string
	ChatId      int64
}

type ChatMessage

type ChatMessage struct {
	Text   string
	ChatId string
}

type Cursor

type Cursor interface {
	First() ([]byte, []byte)
	Next() ([]byte, []byte)
	CanContinue(val []byte) bool
}

type CursorOptions

type CursorOptions struct {
	Limit   int
	Skip    int
	Reverse bool
}

func NewCursorOptions

func NewCursorOptions() *CursorOptions

func SingleItemCursor

func SingleItemCursor() *CursorOptions

type DBStorage

type DBStorage struct {
	Path string
}

func DefaultStorageBacking

func DefaultStorageBacking() *DBStorage

DefaultStorageBacking gets the default storage method for results.

func (*DBStorage) Create

func (d *DBStorage) Create(keyParts Key, tr *search.ExternalResultItem) error

Create a new result record. In sqlite we're not using the key parts.

func (*DBStorage) Find

func (d *DBStorage) Find(query Query, matchingItem *search.ExternalResultItem) error

func (*DBStorage) FindById

func (d *DBStorage) FindById(id string) *search.ExternalResultItem

Find a result by it's id

func (*DBStorage) FindByNameAndIndex

func (d *DBStorage) FindByNameAndIndex(title string, indexerSite string) *search.ExternalResultItem

FindByNameAndIndex finds an item by it's name and index.

func (*DBStorage) GetCategories

func (d *DBStorage) GetCategories() []db.TorrentCategory

func (*DBStorage) GetDb

func (d *DBStorage) GetDb() *gorm.DB

func (*DBStorage) GetLatest

func (d *DBStorage) GetLatest(cnt int) []search.ExternalResultItem

func (*DBStorage) GetNewest

func (d *DBStorage) GetNewest(cnt int) []search.ExternalResultItem

GetNewest gets the CNT latest results.

func (*DBStorage) GetOlderThanHours

func (d *DBStorage) GetOlderThanHours(h int) []search.ExternalResultItem

func (*DBStorage) GetTorrentCount

func (d *DBStorage) GetTorrentCount() int64

func (*DBStorage) GetTorrentsInCategories

func (d *DBStorage) GetTorrentsInCategories(ids []int) []search.ExternalResultItem

func (*DBStorage) Truncate

func (d *DBStorage) Truncate()

func (*DBStorage) Update

func (d *DBStorage) Update(query Query, item *search.ExternalResultItem) error

Update a result with a matching keyParts.

func (*DBStorage) UpdateResult

func (d *DBStorage) UpdateResult(id uint, torrent *search.ExternalResultItem)

type Index

type Index interface {
	Add(value []byte, targetID []byte) error
	Remove(value []byte) error
	RemoveById(id []byte) error
	Get(value []byte) []byte
	All(value []byte, opts *CursorOptions) [][]byte
	AllRecords(opts *CursorOptions) [][]byte
	Range(min []byte, max []byte, opts *CursorOptions) [][]byte
}

type ItemStorage

type ItemStorage interface {
	Add(item *search.ExternalResultItem) (bool, bool)
	NewWithKey(key Key) ItemStorage
}

type ItemStorageBacking

type ItemStorageBacking interface {
	//Tries to find a single record matching the query.
	Find(query Query, result *search.ExternalResultItem) error
	Update(query Query, item *search.ExternalResultItem) error
	Create(parts Key, item *search.ExternalResultItem) error
}

type Key

type Key []string

func NewKey

func NewKey(fieldNames ...string) Key

NewKey creates a new keyParts using an array of fields.

type KeyedStorage

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

func NewKeyedStorage

func NewKeyedStorage(keyFields Key) *KeyedStorage

NewKeyedStorage creates a new keyed storage with the default storage backing.

func NewKeyedStorageWithBacking

func NewKeyedStorageWithBacking(key Key, storage ItemStorageBacking) *KeyedStorage

NewKeyedStorageWithBacking creates a new keyed storage with a custom storage backing.

func (*KeyedStorage) Add

func (s *KeyedStorage) Add(item *search.ExternalResultItem) (bool, bool)

Add handles the discovery of the result, adding additional information like staleness state.

func (*KeyedStorage) NewWithKey

func (s *KeyedStorage) NewWithKey(key Key) ItemStorage

NewWithKey gets a storage backed in the same way, with a different key.

type ListIndex

type ListIndex struct {
	ParentBucket *bolt.Bucket
	//Bucket that contains all the index values, with values being the ID
	IndexBucket *bolt.Bucket
	//An index that contains all of our IDs, with values being the index values
	IDs *UniqueIndex
}

ListIndex is an index that references values and the matching IDs

func NewListIndex

func NewListIndex(parent *bolt.Bucket, name []byte) (*ListIndex, error)

NewListIndex creates a new list index with it's sub-buckets.

func (*ListIndex) Add

func (ix *ListIndex) Add(val []byte, id []byte) error

Add a new index for an id.

func (*ListIndex) All

func (ix *ListIndex) All(indexValue []byte, opts *CursorOptions) [][]byte

All the IDs corresponding to the given value

func (*ListIndex) AllRecords

func (ix *ListIndex) AllRecords(opts *CursorOptions) [][]byte

AllRecords returns all the IDs of this index

func (*ListIndex) Get

func (ix *ListIndex) Get(indexValue []byte) []byte

Get the first ID corresponding to the given value

func (*ListIndex) Prefix

func (ix *ListIndex) Prefix(prefix []byte, opts *CursorOptions) [][]byte

Prefix returns the ids whose values have the given prefix.

func (*ListIndex) Range

func (ix *ListIndex) Range(min []byte, max []byte, opts *CursorOptions) [][]byte

Range returns the ids corresponding to the given range of values

func (*ListIndex) Remove

func (ix *ListIndex) Remove(indexValue []byte) error

Remove an index

func (*ListIndex) RemoveById

func (ix *ListIndex) RemoveById(id []byte) error

RemoveById removes an index and the matching ID using an ID.

type PrefixCursor

type PrefixCursor struct {
	C       *bolt.Cursor
	Reverse bool
	Prefix  []byte
}

func (*PrefixCursor) CanContinue

func (c *PrefixCursor) CanContinue(value []byte) bool

CanContinue figures out if the cursor can continue

func (*PrefixCursor) First

func (c *PrefixCursor) First() ([]byte, []byte)

First item in the cursor that matches the prefix.

func (*PrefixCursor) Next

func (c *PrefixCursor) Next() ([]byte, []byte)

Next item in the cursor

type Query

type Query interface {
	Put(k, v interface{})
	Size() int
	Keys() []interface{}
	Values() []interface{}
	Get(key interface{}) (value interface{}, found bool)
}

func GetKeyQueryFromItem

func GetKeyQueryFromItem(keyParts Key, item *search.ExternalResultItem) Query

GetKeyQueryFromItem gets the query that matches an item with the given keyParts.

func NewQuery

func NewQuery() Query

type RangeCursor

type RangeCursor struct {
	C          *bolt.Cursor
	Reverse    bool
	Min        []byte
	Max        []byte
	Comparator func(a []byte, b []byte) int
}

func (*RangeCursor) CanContinue

func (r *RangeCursor) CanContinue(value []byte) bool

CanContinue checks if the cursor can continue to the given value

func (*RangeCursor) First

func (r *RangeCursor) First() ([]byte, []byte)

First gets the first element in the range.

func (*RangeCursor) Next

func (r *RangeCursor) Next() ([]byte, []byte)

Next gets the next element in the cursor.

type ReversibleCursor

type ReversibleCursor struct {
	C       *bolt.Cursor
	Reverse bool
}

func (*ReversibleCursor) CanContinue

func (c *ReversibleCursor) CanContinue(val []byte) bool

func (*ReversibleCursor) First

func (c *ReversibleCursor) First() ([]byte, []byte)

func (*ReversibleCursor) Next

func (c *ReversibleCursor) Next() ([]byte, []byte)

type UniqueIndex

type UniqueIndex struct {
	ParentBucket *bolt.Bucket
	IndexBucket  *bolt.Bucket
}

UniqueIndex ensures the indexed values are all unique.

func NewUniqueIndex

func NewUniqueIndex(parentBucket *bolt.Bucket, name []byte) (*UniqueIndex, error)

NewUniqueIndex creates a new unique index bucket

func (*UniqueIndex) Add

func (ix *UniqueIndex) Add(indexValue []byte, id []byte) error

Add a value to the unique index. We're using the index value as a keyParts and we're storing the id in there.

func (*UniqueIndex) All

func (ix *UniqueIndex) All(indexValue []byte, _ *CursorOptions) [][]byte

All returns all the IDs corresponding to the given index value. For unique indexes this should be a single ID.

func (*UniqueIndex) AllRecords

func (ix *UniqueIndex) AllRecords(ops *CursorOptions) [][]byte

AllRecords returns all the IDs.

func (*UniqueIndex) AllWithPrefix

func (ix *UniqueIndex) AllWithPrefix(prefix []byte, ops *CursorOptions) [][]byte

AllWithPrefix finds all the IDs that are prefixed with a given byte array

func (*UniqueIndex) Get

func (ix *UniqueIndex) Get(indexValue []byte) []byte

Get the id behind an indexed value.

func (*UniqueIndex) Range

func (ix *UniqueIndex) Range(min []byte, max []byte, ops *CursorOptions) [][]byte

Range gets the IDs in the given range.

func (*UniqueIndex) Remove

func (ix *UniqueIndex) Remove(indexValue []byte) error

Remove a index value from the unique index.

func (*UniqueIndex) RemoveById

func (ix *UniqueIndex) RemoveById(id []byte) error

RemoveById removes the first id from the index that matches the given id.

Directories

Path Synopsis
gob

Jump to

Keyboard shortcuts

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