database

package
v0.0.0-...-c8b2685 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package database provides the storage/persistence layer, using good old SQLite as its backend.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyUpdate = errors.New("Update operation does not change any values")

ErrEmptyUpdate indicates that an update operation would not change any values.

View Source
var ErrInvalidSavepoint = errors.New("that save point does not exist")

ErrInvalidSavepoint is returned when a user of the Database uses an unkown (or expired) savepoint name.

View Source
var ErrInvalidValue = errors.New("Invalid value for parameter")

ErrInvalidValue indicates that one or more parameters passed to a method had values that are invalid for that operation.

View Source
var ErrNoTxInProgress = errors.New("There is no transaction in progress")

ErrNoTxInProgress indicates that an attempt was made to finish a transaction when none was active.

View Source
var ErrObjectNotFound = errors.New("object was not found in database")

ErrObjectNotFound indicates that an Object was not found in the database.

View Source
var ErrTxInProgress = errors.New("A Transaction is already in progress")

ErrTxInProgress indicates that an attempt to initiate a transaction failed because there is already one in progress.

Functions

This section is empty.

Types

type Database

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

Database is the storage backend for managing Feeds and news.

It is not safe to share a Database instance between goroutines, however opening multiple connections to the same Database is safe.

func Open

func Open(path string) (*Database, error)

Open opens a Database. If the database specified by the path does not exist, yet, it is created and initialized.

func (*Database) Begin

func (db *Database) Begin() error

Begin begins an explicit database transaction. Only one transaction can be in progress at once, attempting to start one, while another transaction is already in progress will yield ErrTxInProgress.

func (*Database) Close

func (db *Database) Close() error

Close closes the database. If there is a pending transaction, it is rolled back.

func (*Database) Commit

func (db *Database) Commit() error

Commit ends the active transaction, making any changes made during that transaction permanent and visible to other connections. If no transaction is active, it returns ErrNoTxInProgress

func (*Database) FTSRebuild

func (db *Database) FTSRebuild() error

FTSRebuild rebuilds the index used in the full-text search.

func (*Database) FeedAdd

func (db *Database) FeedAdd(f *feed.Feed) error

FeedAdd adds a Feed to the database.

func (*Database) FeedDelete

func (db *Database) FeedDelete(id int64) error

FeedDelete deletes the Feed with the given ID from the database.

func (*Database) FeedGetAll

func (db *Database) FeedGetAll() ([]feed.Feed, error)

FeedGetAll returns a list of all Feeds stored in the datbase.

func (*Database) FeedGetByID

func (db *Database) FeedGetByID(id int64) (*feed.Feed, error)

FeedGetByID fetches the Feed with the given ID.

func (*Database) FeedGetDue

func (db *Database) FeedGetDue() ([]feed.Feed, error)

FeedGetDue fetches only those Feeds that are due for a refresh.

func (*Database) FeedGetMap

func (db *Database) FeedGetMap() (map[int64]feed.Feed, error)

FeedGetMap returns a map of Feeds usable in HTML templates.

func (*Database) FeedModify

func (db *Database) FeedModify(
	f *feed.Feed,
	name, lnk, homepage string,
	interval time.Duration) error

FeedModify modifies a Feed.

func (*Database) FeedSetActive

func (db *Database) FeedSetActive(id int64, active bool) error

FeedSetActive sets the Feed's Active flag to the given value.

func (*Database) FeedSetTimestamp

func (db *Database) FeedSetTimestamp(f *feed.Feed, stamp time.Time) error

FeedSetTimestamp updates the refresh timestamp of the given Feed.

func (*Database) ItemAdd

func (db *Database) ItemAdd(item *feed.Item) error

ItemAdd adds an Item to the database.

func (*Database) ItemGetAll

func (db *Database) ItemGetAll(cnt, offset int64) ([]feed.Item, error)

ItemGetAll fetches items from all feeds, ordered by their timestamps in descending order, skipping the first <offset> items, returning the next <cnt> items.

func (*Database) ItemGetByFeed

func (db *Database) ItemGetByFeed(feedID, limit int64) ([]feed.Item, error)

ItemGetByFeed fetches the <limit> most recent Items belonging to the given <feedID>.

func (*Database) ItemGetByID

func (db *Database) ItemGetByID(id int64) (*feed.Item, error)

ItemGetByID fetches an Item by its ID.

func (*Database) ItemGetByTag

func (db *Database) ItemGetByTag(t *tag.Tag) ([]feed.Item, error)

ItemGetByTag fetches all Items the given Tag is attached to.

Currently, this does not take the Tag hierarchy into account.

func (*Database) ItemGetByTagRecursive

func (db *Database) ItemGetByTagRecursive(t *tag.Tag) ([]feed.Item, error)

ItemGetByTagRecursive returns all Items marked with the given Tag or any of its children (recursively, obviously).

func (*Database) ItemGetByURL

func (db *Database) ItemGetByURL(uri string) (*feed.Item, error)

ItemGetByURL fetches an Item by its URL.

func (*Database) ItemGetFTS

func (db *Database) ItemGetFTS(fts string) ([]feed.Item, error)

ItemGetFTS retrieves Items that match a full-text search query.

func (*Database) ItemGetPrefetch

func (db *Database) ItemGetPrefetch(lim int) ([]feed.Item, error)

ItemGetPrefetch fetches a number of Items that have not been processed for prefetching, yet.

func (*Database) ItemGetRated

func (db *Database) ItemGetRated() ([]feed.Item, error)

ItemGetRated returns all Items that have been rated.

func (*Database) ItemGetRecent

func (db *Database) ItemGetRecent(limit int) ([]feed.Item, error)

ItemGetRecent returns the <limit> most recent news Items.

func (*Database) ItemGetSearchExtended

func (db *Database) ItemGetSearchExtended(qstr string, tags []int64, begin, end time.Time) ([]feed.Item, error)

ItemGetSearchExtended performs an extended search on the database, retrieving Items by a search string and a list of tags.

func (*Database) ItemGetTotalCnt

func (db *Database) ItemGetTotalCnt() (int64, error)

ItemGetTotalCnt returns the total number of items in the database.

func (*Database) ItemHasDuplicate

func (db *Database) ItemHasDuplicate(i *feed.Item) (bool, error)

ItemHasDuplicate checks if a possible duplicate of the given Item already exists in the database.

func (*Database) ItemPrefetchSet

func (db *Database) ItemPrefetchSet(i *feed.Item, description string) error

ItemPrefetchSet updates an Item after the Prefetcher has processed it.

func (*Database) ItemRatingClear

func (db *Database) ItemRatingClear(i *feed.Item) error

ItemRatingClear clears an Item's Rating.

func (*Database) ItemRatingSet

func (db *Database) ItemRatingSet(i *feed.Item, rating float64) error

ItemRatingSet sets an Item's Rating.

func (*Database) PerformMaintenance

func (db *Database) PerformMaintenance() error

PerformMaintenance performs some maintenance operations on the database. It cannot be called while a transaction is in progress and will block pretty much all access to the database while it is running.

func (*Database) ReadLaterAdd

func (db *Database) ReadLaterAdd(item *feed.Item, note string, deadline time.Time) (*feed.ReadLater, error)

ReadLaterAdd adds a ReadLater note to the database.

func (*Database) ReadLaterDelete

func (db *Database) ReadLaterDelete(id int64) error

ReadLaterDelete deletes a ReadLater note from the database.

func (*Database) ReadLaterGetAll

func (db *Database) ReadLaterGetAll() ([]feed.ReadLater, error)

ReadLaterGetAll returns all ReadLater notes.

func (*Database) ReadLaterGetByItem

func (db *Database) ReadLaterGetByItem(item *feed.Item) (*feed.ReadLater, error)

ReadLaterGetByItem returns the ReadLater note for the given Item.

func (*Database) ReadLaterGetUnread

func (db *Database) ReadLaterGetUnread() (map[int64]feed.ReadLater, error)

ReadLaterGetUnread returns all ReadLater items that are not marked a read.

func (*Database) ReadLaterMarkRead

func (db *Database) ReadLaterMarkRead(itemID int64) error

ReadLaterMarkRead marks a ReadLater note as read.

func (*Database) ReadLaterMarkUnread

func (db *Database) ReadLaterMarkUnread(itemID int64) error

ReadLaterMarkUnread marks a ReadLater note as read.

func (*Database) ReadLaterSetDeadline

func (db *Database) ReadLaterSetDeadline(l *feed.ReadLater, deadline time.Time) error

ReadLaterSetDeadline updates the deadline of a ReadLater note.

func (*Database) ReadLaterSetNote

func (db *Database) ReadLaterSetNote(l *feed.ReadLater, note string) error

ReadLaterSetNote updates the Note on a ReadLater item.

func (*Database) Rollback

func (db *Database) Rollback() error

Rollback terminates a pending transaction, undoing any changes to the database made during that transaction. If no transaction is active, it returns ErrNoTxInProgress

func (*Database) SavepointCreate

func (db *Database) SavepointCreate(name string) error

SavepointCreate creates a savepoint with the given name.

Savepoints only make sense within a running transaction, and just like with explicit transactions, managing them is the responsibility of the user of the Database.

Creating a savepoint without a surrounding transaction is not allowed, even though SQLite allows it.

For details on how Savepoints work, check the excellent SQLite documentation, but here's a quick guide:

Savepoints are kind-of-like transactions within a transaction: One can create a savepoint, make some changes to the database, and roll back to that savepoint, discarding all changes made between creating the savepoint and rolling back to it. Savepoints can be quite useful, but there are a few things to keep in mind:

  • Savepoints exist within a transaction. When the surrounding transaction is finished, all savepoints created within that transaction cease to exist, no matter if the transaction is commited or rolled back.
  • When the database is recovered after being interrupted during a transaction, e.g. by a power outage, the entire transaction is rolled back, including all savepoints that might exist.
  • When a savepoint is released, nothing changes in the state of the surrounding transaction. That means rolling back the surrounding transaction rolls back the entire transaction, regardless of any savepoints within.
  • Savepoints do not nest. Releasing a savepoint releases it and *all* existing savepoints that have been created before it. Rolling back to a savepoint removes that savepoint and all savepoints created after it.

func (*Database) SavepointRelease

func (db *Database) SavepointRelease(name string) error

SavepointRelease releases the Savepoint with the given name, and all Savepoints created before the one being release.

func (*Database) SavepointRollback

func (db *Database) SavepointRollback(name string) error

SavepointRollback rolls back the running transaction to the given savepoint.

func (*Database) TagCreate

func (db *Database) TagCreate(name, desc string, parentID int64) (*tag.Tag, error)

TagCreate creates a new Tag. <parent> is the ID of the parent tag. A value of 0 means no parent.

func (*Database) TagDelete

func (db *Database) TagDelete(id int64) error

TagDelete removes the Tag with the given ID from the database.

This will automatically remove all links of the given Tag to Items as well.

func (*Database) TagDescriptionUpdate

func (db *Database) TagDescriptionUpdate(t *tag.Tag, desc string) error

TagDescriptionUpdate changes the given Tag's Description.

func (*Database) TagGetAll

func (db *Database) TagGetAll() ([]tag.Tag, error)

TagGetAll fetches all Tags from the database, in no particular order.

func (*Database) TagGetAllByHierarchy

func (db *Database) TagGetAllByHierarchy() ([]tag.Tag, error)

TagGetAllByHierarchy returns all Tags ordered by hierarchy.

func (*Database) TagGetByID

func (db *Database) TagGetByID(id int64) (*tag.Tag, error)

TagGetByID loads a Tag by its database ID.

func (*Database) TagGetByItem

func (db *Database) TagGetByItem(itemID int64) ([]tag.Tag, error)

TagGetByItem returns a (possibly empty) slice of all Tags attached to an Item.

func (*Database) TagGetByName

func (db *Database) TagGetByName(name string) (*tag.Tag, error)

TagGetByName loads a Tag by its database ID.

func (*Database) TagGetChildren

func (db *Database) TagGetChildren(id int64) ([]tag.Tag, error)

TagGetChildren fetches all the children - recursively - of the given Tag.

func (*Database) TagGetChildrenImmediate

func (db *Database) TagGetChildrenImmediate(id int64) ([]tag.Tag, error)

TagGetChildrenImmediate fetches all Tags that are directly descended from the given parent Tag, i.e. Tags whose parent ID equals the argument.

func (*Database) TagGetHierarchy

func (db *Database) TagGetHierarchy() ([]tag.Tag, error)

TagGetHierarchy retrieves a slice of all Tags, organized in a hierarchical fashion.

func (*Database) TagLinkCreate

func (db *Database) TagLinkCreate(itemID, tagID int64) error

TagLinkCreate attaches the given Tag to the given Item.

func (*Database) TagLinkDelete

func (db *Database) TagLinkDelete(itemID, tagID int64) error

TagLinkDelete detaches a Tag from an Item.

func (*Database) TagLinkGetByItem

func (db *Database) TagLinkGetByItem(itemID int64) ([]int64, error)

TagLinkGetByItem returns a slice of *the IDs* of all the Tags attached to a given Item.

func (*Database) TagNameUpdate

func (db *Database) TagNameUpdate(t *tag.Tag, name string) error

TagNameUpdate renames the given Tag to the new name.

func (*Database) TagParentClear

func (db *Database) TagParentClear(t *tag.Tag) error

TagParentClear clears the given Tag's Parent field.

func (*Database) TagParentSet

func (db *Database) TagParentSet(t *tag.Tag, parent int64) error

TagParentSet updates the given Tag's Parent field.

func (*Database) TagUpdate

func (db *Database) TagUpdate(t *tag.Tag) error

TagUpdate updates a Tag.

type Pool

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

Pool is a pool of database connections

func NewPool

func NewPool(cnt int) (*Pool, error)

NewPool creates a Pool of database connections. The number of connections to use is given by the parameter cnt.

func (*Pool) Close

func (pool *Pool) Close() error

Close closes all open database connections currently in the pool and empties the pool. Any connections retrieved from the pool that are in use at the time Close is called are unaffected.

func (*Pool) Get

func (pool *Pool) Get() *Database

Get returns a DB connection from the pool. If the pool is empty, it waits for a connection to be returned.

func (*Pool) GetNoWait

func (pool *Pool) GetNoWait() (*Database, error)

GetNoWait returns a DB connection from the pool. If the pool is empty, it creates a new one.

func (*Pool) IsEmpty

func (pool *Pool) IsEmpty() bool

IsEmpty returns true if the pool is currently empty.

func (*Pool) Put

func (pool *Pool) Put(db *Database)

Put returns a DB connection to the pool.

Jump to

Keyboard shortcuts

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