database

package
v0.0.0-...-ac5d820 Latest Latest
Warning

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

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

Documentation

Overview

Package database provides the persistence layer for jobs. It is a wrapper around an SQLite database, exposing the operations required by the application.

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 the connection to the underlying data store 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) JobCleanFinished

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

JobCleanFinished removes all finished Jobs from the database.

func (*Database) JobDelete

func (db *Database) JobDelete(j *job.Job) error

JobDelete removes a Job from the database.

func (*Database) JobFinish

func (db *Database) JobFinish(j *job.Job) error

JobFinish marks a Job as finished.

func (*Database) JobGetAll

func (db *Database) JobGetAll() ([]job.Job, error)

JobGetAll loads *all* Jobs from the database, regardless of age or status. Beware that this might be a lot.

func (*Database) JobGetByID

func (db *Database) JobGetByID(id int64) (*job.Job, error)

JobGetByID looks up a Job by its ID. If no Job with the given ID exists, it is not considered an error, in that case (nil, nil) is returned.

func (*Database) JobGetFinished

func (db *Database) JobGetFinished(max int64) ([]job.Job, error)

JobGetFinished returns the <max> most recently finished Jobs. Passing -1 for max means all of them.

func (*Database) JobGetPending

func (db *Database) JobGetPending(max int64) ([]job.Job, error)

JobGetPending returns up to <max> Jobs that have been submitted but not yet started.

func (*Database) JobGetRunning

func (db *Database) JobGetRunning() ([]job.Job, error)

JobGetRunning returns the list of Jobs (possibly empty) that are currently being executed.

func (*Database) JobGetUnfinished

func (db *Database) JobGetUnfinished() ([]job.Job, error)

JobGetUnfinished returns a slice of jobs that are currently running or enqueued to be run.

func (*Database) JobStart

func (db *Database) JobStart(j *job.Job) error

JobStart marks a Job as having started.

func (*Database) JobSubmit

func (db *Database) JobSubmit(j *job.Job) error

JobSubmit adds a new Job to the database.

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

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 for the database operations we want to perform.
Package query provides symbolic constants for the database operations we want to perform.

Jump to

Keyboard shortcuts

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