Documentation ¶
Overview ¶
Package database provides the persistence layer of the application. Internally it uses an SQLite database, but the methods it exposes are high-level operations that are database-agnostic, and the rest of the application is not affected by the specific database engine used.
Index ¶
- Variables
- type Database
- func (db *Database) Close() error
- func (db *Database) HostAdd(name string) (int64, error)
- func (db *Database) HostGetAll() ([]common.Host, error)
- func (db *Database) HostGetID(name string) (int64, error)
- func (db *Database) PerformMaintenance() error
- func (db *Database) RecentGetAll() ([]common.Record, error)
- func (db *Database) RecordAdd(r *common.Record) error
- func (db *Database) RecordGetByHost(name string, begin time.Time) ([]common.Record, error)
- func (db *Database) RecordGetByPeriod(t1, t2 time.Time) ([]common.Record, error)
- type Pool
Constants ¶
This section is empty.
Variables ¶
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 ErrNotFound = errors.New("Nothing was found")
ErrNotFound indicates that a search operation has not yielded any results.
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 ¶
Open opens a Database. If the database specified by the path does not exist, yet, it is created and initialized.
func (*Database) Close ¶
Close closes the database. If there is a pending transaction, it is rolled back.
func (*Database) HostAdd ¶
HostAdd adds the given hostname to the database and, if successful, returns the Host's ID.
func (*Database) HostGetAll ¶
HostGetAll loads all hosts from the database.
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) RecentGetAll ¶
RecentGetAll returns the most recent Record per Host
func (*Database) RecordGetByHost ¶
RecordGetByHost loads all Records for the given Host
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.