database

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTable added in v0.0.10

func CreateTable(db *sql.DB, createString string)

CreateTable creates the table(s) required for calor

func FetchLatest added in v0.0.10

func FetchLatest(db *sql.DB, querySQL string, thermometer string, readingMaker func(rows *sql.Rows) thermometers.Reading) (thermometers.Reading, error)

Fetches a single reading from the DB

func PrepareStatement added in v0.0.10

func PrepareStatement(db *sql.DB, statement string) (*sql.Tx, *sql.Stmt)

Prepare statements prepares the given statement for a transaction

Types

type CalorDB

type CalorDB interface {
	Init()
	Latest(thermometer string) (thermometers.Reading, error)
	InsertReading(reading thermometers.Reading)
	Between(name string, timestampRange UnixTimestampRange) ([]thermometers.Reading, error)
}

A CalorDB implements the functions required to record and read back readings from calor thermometers

type PostgresDB added in v0.0.10

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

func CreatePostgresDB added in v0.0.10

func CreatePostgresDB(user string, password string, host string) PostgresDB

func (PostgresDB) Between added in v0.0.10

func (psql PostgresDB) Between(name string, timestampRange UnixTimestampRange) ([]thermometers.Reading, error)

ALL of the DBS will share a similar between, but they'll differ in how they process dates because they'll represent dates differently

func (PostgresDB) Init added in v0.0.10

func (psql PostgresDB) Init()

func (PostgresDB) InsertReading added in v0.0.10

func (psql PostgresDB) InsertReading(reading thermometers.Reading)

func (PostgresDB) Latest added in v0.0.10

func (psql PostgresDB) Latest(thermometer string) (thermometers.Reading, error)

type SqliteDB

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

A SqliteDB is a CalorDB that is backed by a SqliteDB file

func CreateSqliteDB

func CreateSqliteDB(file string) SqliteDB

func (SqliteDB) Between

func (sqldb SqliteDB) Between(name string, timestampRange UnixTimestampRange) ([]thermometers.Reading, error)

func (SqliteDB) DB

func (sqlite SqliteDB) DB() *sql.DB

func (SqliteDB) Init

func (sqlite SqliteDB) Init()

func (SqliteDB) InsertReading

func (sqldb SqliteDB) InsertReading(reading thermometers.Reading)

func (SqliteDB) Latest

func (sqldb SqliteDB) Latest(thermometer string) (thermometers.Reading, error)

type UnixTimestampRange

type UnixTimestampRange struct {
	Begin int64
	End   int64
}

Some DB drivers are weird about dates (SQLITE), hence when we query we'd like to do so with integers representing exact unix timestamp

Jump to

Keyboard shortcuts

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