database

package
v0.0.0-...-253cea0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package database provides persistence for the application's data.

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 podcasts audio books.

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

func (db *Database) NotificationAcknowledge(n *objects.Notification, t time.Time) error

NotificationAcknowledge stores the time when a Notification has been acknowledged by the user and is thus completed.

func (*Database) NotificationAdd

func (db *Database) NotificationAdd(r *objects.Reminder, t time.Time) (*objects.Notification, error)

NotificationAdd creates a new Notification to be displayed for a recurring Reminder at a certain point in time.

func (*Database) NotificationCleanup

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

NotificationCleanup removes stale notifications from the database that are more than a week old and have either been acknowledged at least a week ago or never displayed in the first place.

func (*Database) NotificationDisplay

func (db *Database) NotificationDisplay(n *objects.Notification, t time.Time) error

NotificationDisplay stores the time when a Notification has been last displayed.

func (*Database) NotificationGetByID

func (db *Database) NotificationGetByID(id int64) (*objects.Notification, error)

NotificationGetByID fetches a Notification by its database ID.

func (*Database) NotificationGetByReminder

func (db *Database) NotificationGetByReminder(r *objects.Reminder, max int) ([]objects.Notification, error)

NotificationGetByReminder fetches all Notifications stored for the given Reminder, in reverse chronological order, up to the specified limit. If the limit is a negative number, all Notifications will be fetched.

func (*Database) NotificationGetByReminderPending

func (db *Database) NotificationGetByReminderPending(r *objects.Reminder) ([]objects.Notification, error)

NotificationGetByReminderPending fetches all Notifications for the given Reminder that have not been acknowledged.

func (*Database) NotificationGetByReminderStamp

func (db *Database) NotificationGetByReminderStamp(r *objects.Reminder, t time.Time) (*objects.Notification, error)

NotificationGetByReminderStamp fetches a Notification by the given Reminder and Timestamp.

func (*Database) NotificationGetPending

func (db *Database) NotificationGetPending() ([]objects.Notification, error)

NotificationGetPending fetches all Notifications that have not been acknowledged, yet.

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

func (db *Database) ReminderAdd(r *objects.Reminder) error

ReminderAdd adds a Reminder to the Database.

func (*Database) ReminderDelete

func (db *Database) ReminderDelete(r *objects.Reminder) error

ReminderDelete removes a Reminder entry from the database.

func (*Database) ReminderGetAll

func (db *Database) ReminderGetAll() ([]objects.Reminder, error)

ReminderGetAll retrieves all Reminders from the database.

func (*Database) ReminderGetByID

func (db *Database) ReminderGetByID(id int64) (*objects.Reminder, error)

ReminderGetByID looks up a Reminder by its Title

func (*Database) ReminderGetFinished

func (db *Database) ReminderGetFinished() ([]objects.Reminder, error)

ReminderGetFinished returns all the Reminder entries that have already passed and been acknowledged by the user.

func (*Database) ReminderGetPending

func (db *Database) ReminderGetPending(t time.Time) ([]objects.Reminder, error)

ReminderGetPending fetches all Reminder entries from the database that have not been marked as finished.

func (*Database) ReminderGetPendingWithNotifications

func (db *Database) ReminderGetPendingWithNotifications(t time.Time) ([]objects.Reminder, error)

ReminderGetPendingWithNotifications fetches all Reminder entries from the database that have not been marked as finished.

func (*Database) ReminderIncCounter

func (db *Database) ReminderIncCounter(r *objects.Reminder) error

ReminderIncCounter increments the Reminder's counter by 1.

func (*Database) ReminderReactivate

func (db *Database) ReminderReactivate(r *objects.Reminder, t time.Time) error

ReminderReactivate updates a Reminder's timestamp to the given value.

func (*Database) ReminderResetCounter

func (db *Database) ReminderResetCounter(r *objects.Reminder) error

ReminderResetCounter resets a Reminder's counter to zero.

func (*Database) ReminderSetChanged

func (db *Database) ReminderSetChanged(r *objects.Reminder, t time.Time) error

ReminderSetChanged sets the Reminder's ctime to a specific point in time, used for synchronization.

func (*Database) ReminderSetDescription

func (db *Database) ReminderSetDescription(r *objects.Reminder, desc string) error

ReminderSetDescription updates a Reminder's Description.

func (*Database) ReminderSetFinished

func (db *Database) ReminderSetFinished(r *objects.Reminder, flag bool) error

ReminderSetFinished sets the Finished-flag of the given Reminder entry to the given state.

func (*Database) ReminderSetLimit

func (db *Database) ReminderSetLimit(r *objects.Reminder, limit int) error

ReminderSetLimit sets the repeat limit to the speficied value.

func (*Database) ReminderSetRepeat

func (db *Database) ReminderSetRepeat(r *objects.Reminder, c repeat.Repeat) error

ReminderSetRepeat sets the Reminder's Repeat mode

func (*Database) ReminderSetTimestamp

func (db *Database) ReminderSetTimestamp(r *objects.Reminder, t time.Time) error

ReminderSetTimestamp updates a Reminder's timestamp to the given value.

func (*Database) ReminderSetTitle

func (db *Database) ReminderSetTitle(r *objects.Reminder, title string) error

ReminderSetTitle sets the Finished-flag of the given Reminder entry to the given state.

func (*Database) ReminderSetWeekdays

func (db *Database) ReminderSetWeekdays(r *objects.Reminder, days objects.Weekdays) error

ReminderSetWeekdays sets the Weekdays the Reminder is to go off, assuming it is set to the appropriate repeat mode.

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.

type Pool

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

Pool is a pool of database connections

*Maybe* I should make this a "singleton"?

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 for identifying SQL queries.
Package query provides symbolic constants for identifying SQL queries.

Jump to

Keyboard shortcuts

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