Documentation ¶
Overview ¶
Package database is wrapper around the actual database connection. For the time being, we use SQLite, because it is awesome.
Index ¶
- Variables
- type Database
- func (db *Database) ActorAdd(f *objects.File, p *objects.Person) error
- func (db *Database) ActorDelete(f *objects.File, p *objects.Person) error
- func (db *Database) ActorGetByFile(f *objects.File) ([]objects.Person, error)
- func (db *Database) ActorGetByPerson(p *objects.Person) ([]objects.File, error)
- func (db *Database) Begin() error
- func (db *Database) Close() error
- func (db *Database) Commit() error
- func (db *Database) DirectorAdd(f *objects.File, p *objects.Person) error
- func (db *Database) DirectorDelete(f *objects.File, p *objects.Person) error
- func (db *Database) DirectorGetByFile(f *objects.File) ([]objects.Person, error)
- func (db *Database) DirectorGetByPerson(p *objects.Person) ([]objects.File, error)
- func (db *Database) FileAdd(path string, folder *objects.Folder) (*objects.File, error)
- func (db *Database) FileGetAll() ([]objects.File, error)
- func (db *Database) FileGetByID(id int64) (*objects.File, error)
- func (db *Database) FileGetByPath(path string) (*objects.File, error)
- func (db *Database) FileRemove(f *objects.File) error
- func (db *Database) FileUpdateTitle(f *objects.File, title string) error
- func (db *Database) FileUpdateYear(f *objects.File, year int64) error
- func (db *Database) FolderAdd(path string) (*objects.Folder, error)
- func (db *Database) FolderGetAll() ([]objects.Folder, error)
- func (db *Database) FolderGetByPath(path string) (*objects.Folder, error)
- func (db *Database) FolderRemove(f *objects.Folder) error
- func (db *Database) FolderUpdateScan(f *objects.Folder, stamp time.Time) error
- func (db *Database) PerformMaintenance() error
- func (db *Database) PersonAdd(name string, birthday time.Time) (*objects.Person, error)
- func (db *Database) PersonGetAll() ([]objects.Person, error)
- func (db *Database) PersonGetByID(id int64) (*objects.Person, error)
- func (db *Database) PersonURLAdd(p *objects.Person, l *objects.Link) error
- func (db *Database) PersonURLDelete(l *objects.Link) error
- func (db *Database) PersonURLGetByPerson(p *objects.Person) ([]objects.Link, 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) TagAdd(name string) (*objects.Tag, error)
- func (db *Database) TagDelete(t *objects.Tag) error
- func (db *Database) TagGetAll() ([]objects.Tag, error)
- func (db *Database) TagLinkAdd(f *objects.File, t *objects.Tag) error
- func (db *Database) TagLinkDelete(f *objects.File, t *objects.Tag) error
- func (db *Database) TagLinkGetByFile(f *objects.File) (map[int64]objects.Tag, error)
- func (db *Database) TagLinkGetByTag(t *objects.Tag) ([]objects.File, 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 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 ¶
Open opens a Database. If the database specified by the path does not exist, yet, it is created and initialized.
func (*Database) ActorDelete ¶
ActorDelete removes a Person from a Files "acting credits".
func (*Database) ActorGetByFile ¶
ActorGetByFile gets all the People that have acted in the given File.
func (*Database) ActorGetByPerson ¶
ActorGetByPerson gets all the Files the given Person has acted in.
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) DirectorAdd ¶
DirectorAdd adds a Person to a File as an director/actress.
func (*Database) DirectorDelete ¶
DirectorDelete removes a Person from a Files "acting credits".
func (*Database) DirectorGetByFile ¶
DirectorGetByFile gets all the People that have acted in the given File.
func (*Database) DirectorGetByPerson ¶
DirectorGetByPerson gets all the Files the given Person has acted in.
func (*Database) FileGetAll ¶
FileGetAll retrieves all registered Files from the Database.
func (*Database) FileGetByID ¶
FileGetByID loads a File by its ID.
func (*Database) FileGetByPath ¶
FileGetByPath retrieves a File objects by its path in the file system.
func (*Database) FileRemove ¶
FileRemove deletes a File from the Database.
func (*Database) FileUpdateTitle ¶
FileUpdateTitle sets the title of a File.
func (*Database) FileUpdateYear ¶
FileUpdateYear sets the year of a File
func (*Database) FolderGetAll ¶
FolderGetAll fetches all Folders from the Database.
func (*Database) FolderGetByPath ¶
FolderGetByPath looks up a Folder by its Path
func (*Database) FolderRemove ¶
FolderRemove removes a Folder from the Database. All Files from that Folder have to be removed from the Database before the Folder itself can be removed.
func (*Database) FolderUpdateScan ¶
FolderUpdateScan updates the timestamp for the given Folder's last scan.
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) PersonGetAll ¶
PersonGetAll loads all Persons from the Database, in no particular order.
func (*Database) PersonGetByID ¶
PersonGetByID looks up a Person by their ID.
func (*Database) PersonURLAdd ¶
PersonURLAdd attaches a Link to a Person.
func (*Database) PersonURLDelete ¶
PersonURLDelete deletes a Link that has been attached to a Person
func (*Database) PersonURLGetByPerson ¶
PersonURLGetByPerson returns all Links attached to the given Person.
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) TagDelete ¶
TagDelete removes a Tag from the Database. NB, all the links pointing to the Tag have to be deleted before the Tag itself can be deleted.
func (*Database) TagLinkAdd ¶
TagLinkAdd links the given Tag to the given File
func (*Database) TagLinkDelete ¶
TagLinkDelete removes the link between the given Tag and File.
func (*Database) TagLinkGetByFile ¶
TagLinkGetByFile loads all Tags linked to the given File.
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.