stored

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package stored provides interfacing methods for updating/retrieving data from the local sqlite3 database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBEvaluation

type DBEvaluation evaluate.Evaluation

DBEvaluation is an evaluation that can be stored in a SQL db, it is exactly the same as the evaluation but just with a Scan method implementation for marshalling from JSON

func (*DBEvaluation) Scan

func (d *DBEvaluation) Scan(src interface{}) error

Scan is used when reading the DBEvaluation field in from the SQL db, marshalling from a JSON string

type Evaluation

type Evaluation struct {
	ID         int          `db:"id"`
	Created    time.Time    `db:"created"`
	Evaluation DBEvaluation `db:"val"`
}

Evaluation is an evaluation stored in the database, with an ID and a timestamp

type LocalStore

type LocalStore struct {
	DB *sql.DB
}

LocalStore is the implementation of a Store for updating/retrieving evaluations from a SQL db

func (*LocalStore) Add

func (s *LocalStore) Add(model string, evaluation *evaluate.Evaluation) error

Add inserts a new evaluation associated with a model

func (*LocalStore) Get

func (s *LocalStore) Get(model string) ([]*Evaluation, error)

Get returns all evaluations associated with a model

func (*LocalStore) GetModel

func (s *LocalStore) GetModel(model string) (*Model, error)

GetModel gets the model with the name provided

func (*LocalStore) Remove

func (s *LocalStore) Remove(id int) error

Remove deletes an evaluation by the ID provided

func (*LocalStore) UpdateModel

func (s *LocalStore) UpdateModel(model string, intervalsPassed int64) error

UpdateModel updates the model in the DB with the name provided, setting the intervals_passed value

type Model

type Model struct {
	ID              int    `db:"id"`
	Name            string `db:"model_name"`
	IntervalsPassed int64  `db:"intervals_passed"`
}

Model is a model stored in the database, with an ID and the number of intervals since it was last used

type Store

type Store interface {
	Get(model string) ([]*Evaluation, error)
	Add(model string, evaluation *evaluate.Evaluation) error
	Remove(id int) error
	GetModel(model string) (*Model, error)
	UpdateModel(model string, intervalsPassed int64) error
}

Store allows updating/retrieving evaluations from a data source

Directories

Path Synopsis
Package migrate handles applying migrations to the sqlite3 db for storing evaluations
Package migrate handles applying migrations to the sqlite3 db for storing evaluations

Jump to

Keyboard shortcuts

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