Documentation
¶
Overview ¶
Package database provides persistence.
Index ¶
- Variables
- type Database
- func (db *Database) Begin() error
- func (db *Database) Close() error
- func (db *Database) Commit() error
- func (db *Database) FeedAdd(f *model.Feed) error
- func (db *Database) FeedDelete(f *model.Feed) error
- func (db *Database) FeedGetAll() ([]model.Feed, error)
- func (db *Database) FeedGetByID(id int64) (*model.Feed, error)
- func (db *Database) FeedGetPending() ([]model.Feed, error)
- func (db *Database) FeedSetActive(f *model.Feed, active bool) error
- func (db *Database) FeedUpdateRefresh(f *model.Feed, stamp time.Time) error
- func (db *Database) ItemAdd(i *model.Item) error
- func (db *Database) ItemDeleteByFeed(f *model.Feed) error
- func (db *Database) ItemExists(i *model.Item) (bool, error)
- func (db *Database) ItemGetByFeed(f *model.Feed, limit, offset int64) ([]*model.Item, error)
- func (db *Database) ItemGetByID(id int64) (*model.Item, error)
- func (db *Database) ItemGetByPeriod(begin, end time.Time) ([]*model.Item, error)
- func (db *Database) ItemGetFiltered(q chan<- *model.Item, filter func(*model.Item) bool) error
- func (db *Database) ItemGetRated() ([]model.Item, error)
- func (db *Database) ItemGetRecent(begin time.Time) ([]*model.Item, error)
- func (db *Database) ItemGetRecentPaged(cnt, offset int64) ([]*model.Item, error)
- func (db *Database) ItemRate(i *model.Item, r int8) error
- func (db *Database) ItemUnrate(i *model.Item) error
- func (db *Database) PerformMaintenance() error
- func (db *Database) Rollback() error
- func (db *Database) SavepointCreate(name string) error
- func (db *Database) SavepointRelease(name string) error
- func (db *Database) SavepointRollback(name string) error
- func (db *Database) SearchAdd(s *model.Search) error
- func (db *Database) SearchDelete(s *model.Search) error
- func (db *Database) SearchExecute(s *model.Search) error
- func (db *Database) SearchFinish(s *model.Search) error
- func (db *Database) SearchGetActive() ([]*model.Search, error)
- func (db *Database) SearchGetAll() ([]*model.Search, error)
- func (db *Database) SearchGetByID(id int64) (*model.Search, error)
- func (db *Database) SearchGetNextPending() (*model.Search, error)
- func (db *Database) SearchStart(s *model.Search) error
- func (db *Database) TagAdd(t *model.Tag) error
- func (db *Database) TagDelete(t *model.Tag) error
- func (db *Database) TagGetAll() ([]*model.Tag, error)
- func (db *Database) TagGetByID(id int64) (*model.Tag, error)
- func (db *Database) TagGetChildren(t *model.Tag) ([]*model.Tag, error)
- func (db *Database) TagGetItemCnt() (map[int64]int64, error)
- func (db *Database) TagGetSorted() ([]*model.Tag, error)
- func (db *Database) TagLinkAdd(item *model.Item, tag *model.Tag) error
- func (db *Database) TagLinkDelete(item *model.Item, tag *model.Tag) error
- func (db *Database) TagLinkDeleteByFeed(f *model.Feed) error
- func (db *Database) TagLinkGetByItem(item *model.Item) ([]*model.Tag, error)
- func (db *Database) TagLinkGetByTag(tag *model.Tag) ([]*model.Item, error)
- func (db *Database) TagLinkGetByTagMap(tag *model.Tag) (map[int64]*model.Item, error)
- func (db *Database) TagRename(t *model.Tag, name string) error
- func (db *Database) TagSetParent(t *model.Tag, parent int64) error
- func (db *Database) TagUpdate(t *model.Tag, name string, parent int64) error
- type Pool
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyUpdate = errors.New("Update operation does not change any values")
ErrEmptyUpdate indicates that an update operation would not change any values.
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.
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.
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.
var ErrObjectNotFound = errors.New("object was not found in database")
ErrObjectNotFound indicates that an Object was not found in the database.
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 ¶
Open opens a Database. If the database specified by the path does not exist, yet, it is created and initialized.
func (*Database) Begin ¶
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 ¶
Close closes the database. If there is a pending transaction, it is rolled back.
func (*Database) Commit ¶
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) FeedDelete ¶
FeedDelete removes the given Feed from the database.
func (*Database) FeedGetAll ¶
FeedGetAll loads all Feeds from the database.
func (*Database) FeedGetByID ¶
FeedGetByID loads a Feed by its ID.
func (*Database) FeedGetPending ¶
FeedGetPending load all Feeds that need to be refreshed.
func (*Database) FeedSetActive ¶
FeedSetActive sets the given Feed's Active flag
func (*Database) FeedUpdateRefresh ¶
FeedUpdateRefresh updates the given Feed's LastRefresh timestamp
func (*Database) ItemDeleteByFeed ¶ added in v0.13.0
ItemDeleteByFeed removes all Items that belong to the given Feed.
func (*Database) ItemExists ¶
ItemExists checks if the given Item is already in the database.
func (*Database) ItemGetByFeed ¶
ItemGetByFeed loads items from the given Feed.
func (*Database) ItemGetByID ¶ added in v0.2.0
ItemGetByID loads an Item by its ID
func (*Database) ItemGetByPeriod ¶ added in v0.14.0
ItemGetByPeriod loads all Items from the given period
func (*Database) ItemGetFiltered ¶ added in v0.14.0
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 ¶
ItemGetRated loads all items that have been manually rated.
func (*Database) ItemGetRecent ¶
ItemGetRecent loads all items newer than the given timestamp.
func (*Database) ItemGetRecentPaged ¶
ItemGetRecentPaged fetches up to cnt of the most recent news items, skipping the first offset items, in descending chronological order.
func (*Database) ItemUnrate ¶
ItemUnrate resets an Item's rating to zero.
func (*Database) PerformMaintenance ¶
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 ¶
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 ¶
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 ¶
SavepointRelease releases the Savepoint with the given name, and all Savepoints created before the one being release.
func (*Database) SavepointRollback ¶
SavepointRollback rolls back the running transaction to the given savepoint.
func (*Database) SearchDelete ¶ added in v0.14.0
SearchDelete removes a search query from the database.
func (*Database) SearchExecute ¶ added in v0.14.0
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
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
SearchGetActive returns all Search queries that have been marked as started but not finished.
func (*Database) SearchGetAll ¶ added in v0.14.0
SearchGetAll loads all existing search queries.
func (*Database) SearchGetByID ¶ added in v0.14.0
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
SearchGetNextPending returns the oldest Search Query in the database that has not been started, yet.
func (*Database) SearchStart ¶ added in v0.14.0
SearchStart sets the start time of the given Search query to the current time, marking it as active.
func (*Database) TagGetByID ¶ added in v0.3.0
TagGetByID loads a Tag by its ID
func (*Database) TagGetChildren ¶ added in v0.3.0
TagGetChildren loads all Tags that are immediate children of the given Tag.
func (*Database) TagGetItemCnt ¶ added in v0.4.0
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
TagGetSorted returns all Tags, sorted hierarchically.
func (*Database) TagLinkAdd ¶ added in v0.3.0
TagLinkAdd attaches the given Tag to the given Item.
func (*Database) TagLinkDelete ¶ added in v0.3.0
TagLinkDelete removes a Tag from the given Item.
func (*Database) TagLinkDeleteByFeed ¶ added in v0.13.0
TagLinkDeleteByFeed removes all links to Items that belong to the given Feed.
func (*Database) TagLinkGetByItem ¶ added in v0.3.0
TagLinkGetByItem loads all Tags that are attached to the given Item.
func (*Database) TagLinkGetByTag ¶ added in v0.3.0
TagLinkGetByTag loads all Items that have the given Tag attached to them.
func (*Database) TagLinkGetByTagMap ¶ added in v0.14.0
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) TagSetParent ¶ added in v0.4.0
TagSetParent updates a Tag's parent ID.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pool of database connections
func NewPool ¶
NewPool creates a Pool of database connections. The number of connections to use is given by the parameter cnt.
func (*Pool) Close ¶
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 ¶
Get returns a DB connection from the pool. If the pool is empty, it waits for a connection to be returned.
func (*Pool) GetNoWait ¶
GetNoWait returns a DB connection from the pool. If the pool is empty, it creates a new one.