database

package
v0.0.0-...-f9c212a Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

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

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

func (db *Database) Close() error

Close closes the database. If there is a pending transaction, it is rolled back.

func (*Database) HostAdd

func (db *Database) HostAdd(name string) (int64, error)

HostAdd adds the given hostname to the database and, if successful, returns the Host's ID.

func (*Database) HostGetAll

func (db *Database) HostGetAll() ([]common.Host, error)

HostGetAll loads all hosts from the database.

func (*Database) HostGetID

func (db *Database) HostGetID(name string) (int64, error)

HostGetID looks up the ID for the given hostname.

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

func (db *Database) RecentGetAll() ([]common.Record, error)

RecentGetAll returns the most recent Record per Host

func (*Database) RecordAdd

func (db *Database) RecordAdd(r *common.Record) error

RecordAdd adds a new Record to the database.

func (*Database) RecordGetByHost

func (db *Database) RecordGetByHost(name string, begin time.Time) ([]common.Record, error)

RecordGetByHost loads all Records for the given Host

func (*Database) RecordGetByPeriod

func (db *Database) RecordGetByPeriod(t1, t2 time.Time) ([]common.Record, error)

RecordGetByPeriod returns all Records for the given period.

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 to identify SQL queries to be run on the database.
Package query provides symbolic constants to identify SQL queries to be run on the database.

Jump to

Keyboard shortcuts

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