database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHardResetEntries

func GetHardResetEntries(db DBWrapper) int

GetHardResetEntries gets hard reset entries

func GetLastTemperatureEntry

func GetLastTemperatureEntry(db DBWrapper) int

GetLastTemperatureEntry returns last temp reading, sorted by primary key

func GetPauseEntries

func GetPauseEntries(db DBWrapper) int

GetPauseEntries gets pause entries

func GetRainEntries

func GetRainEntries(db DBWrapper) int

GetRainEntries gets rain entries

func GetSoftResetEntries

func GetSoftResetEntries(db DBWrapper) int

GetSoftResetEntries gets soft reset entries

func GetUnpauseEntries

func GetUnpauseEntries(db DBWrapper) int

GetUnpauseEntries gets pause entries

func MakeHardResetEntry

func MakeHardResetEntry(db DBWrapper)

MakeHardResetEntry AddTag a hard reset event

func MakePauseEntry

func MakePauseEntry(db DBWrapper)

MakePauseEntry AddTag a pause event

func MakeRainTallyEntry

func MakeRainTallyEntry(db DBWrapper)

MakeRainTallyEntry AddTag a rain event

func MakeRainValueEntry

func MakeRainValueEntry(db DBWrapper, value float64)

MakeRainValueEntry AddFloatRecord for a rain event

func MakeSoftResetEntry

func MakeSoftResetEntry(db DBWrapper)

MakeSoftResetEntry AddTag a soft reset event

func MakeTemperatureEntry

func MakeTemperatureEntry(db DBWrapper, tempC int)

MakeTemperatureEntry AddTag a temperature measurement

func MakeUnpauseEntry

func MakeUnpauseEntry(db DBWrapper)

MakeUnpauseEntry AddTag an unpause event

Types

type Connection

type Connection struct {
	Database *sql.DB   // database struct
	Conn     *sql.Conn // connection struct
}

Connection gets a DB and Conn struct for a sqlite File

func (*Connection) Disconnect

func (c *Connection) Disconnect()

Disconnect closes the connection to the database

type DBWrapper

type DBWrapper interface {
	// MakeSchema initializes a schema
	MakeSchema() (sql.Result, error)

	// EnterData enters data into the database without returning any rows
	EnterData(cmd string) (sql.Result, error)

	// AddIntRecord makes a single integer entry into the database for a given tag
	AddIntRecord(tag, value int) (sql.Result, error)

	// AddFloatRecord makes a single float entry into the database for a given tag
	AddFloatRecord(tag int, value float64) (sql.Result, error)

	// Tally runs sql command to count database entries for a given topic
	Tally(tag int) int

	// GetLastRecord gets the last record for a given tag
	GetLastRecord(tag int) int

	// GetSingleInt returns the first result of any SQL query that gives at least one integer result
	// simple function for confirming correct value was entered for, say, temperature
	GetSingleInt(query string) int
}

DBWrapper abstracts the underlying SQL engine/implementations

type Sqlite

type Sqlite struct {
	File     *os.File // name of the .db file
	FullPath string   // full POSIX path
	Driver   string   // sqlite driver
}

Sqlite handles connections to sqlite database

func NewSqlite

func NewSqlite(fullPath string, clobber bool, schema string) (*Sqlite, error)

NewSqlite makes a new connector struct for any sqlite database

func (*Sqlite) Connect

func (db *Sqlite) Connect() (*Connection, error)

Connect attaches to the sqlite database

func (*Sqlite) EnterData

func (db *Sqlite) EnterData(cmd string) (sql.Result, error)

EnterData enters a generic sql INSERT statement

func (*Sqlite) MakeSchema

func (db *Sqlite) MakeSchema(schema string) (sql.Result, error)

MakeSchema creates all of the database tables, etc.

Jump to

Keyboard shortcuts

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