internal

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   string
	GitCommit string
	GitBranch string
)

These variables are populated at build time REFERENCE: https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications to find where the variables are...

go tool nm ./app | grep app

Functions

func EmployeeDelete

func EmployeeDelete(db interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}, employee *Employee) error

EmployeeDelete can be used to delete a specific employee or all employees

func GenerateID

func GenerateID() string

GenerateID can be used to generate a v4 uuid and return it as a string, if it's unable to, it'll panic

func Initialize

func Initialize(config *Configuration) (*sql.DB, error)

Initialize can be used to create a database pointer with the provided configuration

func Main

func Main(pwd string, args []string, envs map[string]string, osSignal chan os.Signal) error

func RowsAffected

func RowsAffected(result sql.Result, errorString string) error

RowsAffected can be used to return a pre-determined error via errorString in the event no rows are affected; this function assumes that in the event no error is returned and rows were supposed to be affected, an error will be returned

func TimerDelete

func TimerDelete(db interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}, timerID string) error

TimerDelete can be used to delete one or all timers

Types

type Configuration

type Configuration struct {
	Hostname  string `json:"hostname"`   //hostame to user to access the database
	Port      string `json:"port"`       //port to connect to
	Username  string `json:"username"`   //username to authenticate with
	Password  string `json:"password"`   //password to authenticate with
	Database  string `json:"database"`   //database to connect to
	ParseTime bool   `json:"parse_time"` //whether or not to parse time
}

Configuration provides the different items we can use to configure how we connect to the database

func ConfigFromEnv

func ConfigFromEnv(envs map[string]string) *Configuration

ConfigFromEnv can be used to generate a configuration pointer from a list of environments, it'll set the default configuraton as well

type DB

type DB interface {
	Begin() (*sql.Tx, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

DB provides an interface that implements all functions required by the DB

type Employee

type Employee struct {
	ID           string `json:"id"`
	FirstName    string `json:"first_name,omitempty"`
	LastName     string `json:"last_name,omitempty"`
	EmailAddress string `json:"email_address"`
	Version      int    `json:"version"`
	LastUpdated  int64  `json:"last_updated"`
}

Employee models the information that describes an employee

func EmployeeCreate

func EmployeeCreate(db interface {
	QueryRow(query string, args ...interface{}) *sql.Row
}, employee *Employee) (*Employee, error)

EmployeeCreate can be used to upsert an employee, if the employee exists via its candidate keys, it'll return that employee rather than create its own

func EmployeeRead

func EmployeeRead(db interface {
	Begin() (*sql.Tx, error)
}, employeeUUID string) (*Employee, error)

func EmployeeWrite

func EmployeeWrite(db interface {
	Begin() (*sql.Tx, error)
}, employee *Employee) (*Employee, error)

EmployeeWrite can be used to mutate an existing employee, it will return an error if the provided version for employee isn't the current version

type Timer

type Timer struct {
	ID          string `json:"id"`
	Comment     string `json:"comment"`
	Start       int64  `json:"start"`
	Finish      int64  `json:"finish"`
	ElapsedTime int64  `json:"elapsed_time"`
	Completed   bool   `json:"completed"`
	Version     int    `json:"version"`
	EmployeeID  string `json:"employee_id"`
}

Timer models a given timer with a start/stop time, its specifically used to show the relationship between timers and employees

func TimerCreate

func TimerCreate(db interface {
	Begin() (*sql.Tx, error)
}, timer *Timer) (*Timer, error)

TimerCreate can be used to create a timer, if the timer already exists it'll return that timer and update that timer

func TimerRead

func TimerRead(db interface {
	Begin() (*sql.Tx, error)
}, timerUUID string) (*Timer, error)

TimerRead can be used to read a given timer

func TimerWrite

func TimerWrite(db interface {
	Begin() (*sql.Tx, error)
}, timer *Timer) (*Timer, error)

TimerWrite can be used to mutate an existing timer

Jump to

Keyboard shortcuts

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