database

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package database provides persistence.

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 wraps a database connection and associated state.

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) FeedAdd

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

FeedAdd enters a Feed into the database.

func (*Database) FeedDelete

func (db *Database) FeedDelete(f *model.Feed) error

FeedDelete removes the given Feed from the database.

func (*Database) FeedGetAll

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

FeedGetAll loads all Feeds from the database.

func (*Database) FeedGetByID

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

FeedGetByID loads a Feed by its ID.

func (*Database) FeedGetPending

func (db *Database) FeedGetPending() ([]model.Feed, error)

FeedGetPending load all Feeds that need to be refreshed.

func (*Database) FeedSetActive

func (db *Database) FeedSetActive(f *model.Feed, active bool) error

FeedSetActive sets the given Feed's Active flag

func (*Database) FeedUpdateRefresh

func (db *Database) FeedUpdateRefresh(f *model.Feed, stamp time.Time) error

FeedUpdateRefresh updates the given Feed's LastRefresh timestamp

func (*Database) ItemAdd

func (db *Database) ItemAdd(i *model.Item) error

ItemAdd adds a news item to the database.

func (*Database) ItemDeleteByFeed added in v0.13.0

func (db *Database) ItemDeleteByFeed(f *model.Feed) error

ItemDeleteByFeed removes all Items that belong to the given Feed.

func (*Database) ItemExists

func (db *Database) ItemExists(i *model.Item) (bool, error)

ItemExists checks if the given Item is already in the database.

func (*Database) ItemGetByFeed

func (db *Database) ItemGetByFeed(f *model.Feed, limit, offset int64) ([]*model.Item, error)

ItemGetByFeed loads items from the given Feed.

func (*Database) ItemGetByID added in v0.2.0

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

ItemGetByID loads an Item by its ID

func (*Database) ItemGetByPeriod added in v0.14.0

func (db *Database) ItemGetByPeriod(begin, end time.Time) ([]*model.Item, error)

ItemGetByPeriod loads all Items from the given period

func (*Database) ItemGetFiltered added in v0.14.0

func (db *Database) ItemGetFiltered(q chan<- *model.Item, filter func(*model.Item) bool) error

ItemGetFiltered processes all(!) Items in the database, checks them against the given filter function, and sends the ones that pass in the given channel. When finished, this method closes the channel.

func (*Database) ItemGetRated

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

ItemGetRated loads all items that have been manually rated.

func (*Database) ItemGetRecent

func (db *Database) ItemGetRecent(begin time.Time) ([]*model.Item, error)

ItemGetRecent loads all items newer than the given timestamp.

func (*Database) ItemGetRecentPaged

func (db *Database) ItemGetRecentPaged(cnt, offset int64) ([]*model.Item, error)

ItemGetRecentPaged fetches up to cnt of the most recent news items, skipping the first offset items, in descending chronological order.

func (*Database) ItemRate

func (db *Database) ItemRate(i *model.Item, r int8) error

ItemRate sets an Item's rating to the given value

func (*Database) ItemUnrate

func (db *Database) ItemUnrate(i *model.Item) error

ItemUnrate resets an Item's rating to zero.

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) 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) SearchAdd added in v0.14.0

func (db *Database) SearchAdd(s *model.Search) error

SearchAdd enters a Search query into the database.

func (*Database) SearchDelete added in v0.14.0

func (db *Database) SearchDelete(s *model.Search) error

SearchDelete removes a search query from the database.

func (*Database) SearchExecute added in v0.14.0

func (db *Database) SearchExecute(s *model.Search) error

SearchExecute runs a Search. If everything goes well, it fills in the results (if there are any) and sets the Status, and TimeFinished fields, both in the Search object AND the database. If something goes wrong, it stores the relevant error message in the object and the database record.

func (*Database) SearchFinish added in v0.14.0

func (db *Database) SearchFinish(s *model.Search) error

SearchFinish sets the Finished timestamp of the given Search query to the current time, marking it as finished. It also updates the status, message, and results fields accordingly.

func (*Database) SearchGetActive added in v0.14.0

func (db *Database) SearchGetActive() ([]*model.Search, error)

SearchGetActive returns all Search queries that have been marked as started but not finished.

func (*Database) SearchGetAll added in v0.14.0

func (db *Database) SearchGetAll() ([]*model.Search, error)

SearchGetAll loads all existing search queries.

func (*Database) SearchGetByID added in v0.14.0

func (db *Database) SearchGetByID(id int64) (*model.Search, error)

SearchGetByID looks up a search query by its ID. If the search has been finished, the results are included.

func (*Database) SearchGetNextPending added in v0.14.0

func (db *Database) SearchGetNextPending() (*model.Search, error)

SearchGetNextPending returns the oldest Search Query in the database that has not been started, yet.

func (*Database) SearchStart added in v0.14.0

func (db *Database) SearchStart(s *model.Search) error

SearchStart sets the start time of the given Search query to the current time, marking it as active.

func (*Database) TagAdd added in v0.3.0

func (db *Database) TagAdd(t *model.Tag) error

TagAdd adds a new Tag to the database.

func (*Database) TagDelete added in v0.3.0

func (db *Database) TagDelete(t *model.Tag) error

TagDelete removes a Tag from the database.

func (*Database) TagGetAll added in v0.3.0

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

TagGetAll loads ALL Tags from the database.

func (*Database) TagGetByID added in v0.3.0

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

TagGetByID loads a Tag by its ID

func (*Database) TagGetChildren added in v0.3.0

func (db *Database) TagGetChildren(t *model.Tag) ([]*model.Tag, error)

TagGetChildren loads all Tags that are immediate children of the given Tag.

func (*Database) TagGetItemCnt added in v0.4.0

func (db *Database) TagGetItemCnt() (map[int64]int64, error)

TagGetItemCnt returns a map of all Tag IDs and the number of Items that have the Tag linked.

func (*Database) TagGetSorted added in v0.6.0

func (db *Database) TagGetSorted() ([]*model.Tag, error)

TagGetSorted returns all Tags, sorted hierarchically.

func (*Database) TagLinkAdd added in v0.3.0

func (db *Database) TagLinkAdd(item *model.Item, tag *model.Tag) error

TagLinkAdd attaches the given Tag to the given Item.

func (*Database) TagLinkDelete added in v0.3.0

func (db *Database) TagLinkDelete(item *model.Item, tag *model.Tag) error

TagLinkDelete removes a Tag from the given Item.

func (*Database) TagLinkDeleteByFeed added in v0.13.0

func (db *Database) TagLinkDeleteByFeed(f *model.Feed) error

TagLinkDeleteByFeed removes all links to Items that belong to the given Feed.

func (*Database) TagLinkGetByItem added in v0.3.0

func (db *Database) TagLinkGetByItem(item *model.Item) ([]*model.Tag, error)

TagLinkGetByItem loads all Tags that are attached to the given Item.

func (*Database) TagLinkGetByTag added in v0.3.0

func (db *Database) TagLinkGetByTag(tag *model.Tag) ([]*model.Item, error)

TagLinkGetByTag loads all Items that have the given Tag attached to them.

func (*Database) TagLinkGetByTagMap added in v0.14.0

func (db *Database) TagLinkGetByTagMap(tag *model.Tag) (map[int64]*model.Item, error)

TagLinkGetByTagMap loads all Items that have the given Tag attached to them. This method returns the results as a map rather than a slice.

func (*Database) TagRename added in v0.3.0

func (db *Database) TagRename(t *model.Tag, name string) error

TagRename changes a Tag's name.

func (*Database) TagSetParent added in v0.4.0

func (db *Database) TagSetParent(t *model.Tag, parent int64) error

TagSetParent updates a Tag's parent ID.

func (*Database) TagUpdate added in v0.4.0

func (db *Database) TagUpdate(t *model.Tag, name string, parent int64) error

TagUpdate updates a Tag's name and parent at once.

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.

Directories

Path Synopsis
Package query provides symbolic constants to identify database queries.
Package query provides symbolic constants to identify database queries.

Jump to

Keyboard shortcuts

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