db

package
v0.0.0-...-84a99a9 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package db keeps persistence syntax: https://github.com/mattn/go-sqlite3/blob/master/_example/simple/simple.go driver: https://pkg.go.dev/modernc.org/sqlite

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWindowNameRequired is a preflight check before window db operations
	ErrWindowNameRequired = errors.New("cannot do operations on a nameless window")
	// ErrZeroID is used when an ID is expected, e.g. a read did not scan an ID
	ErrZeroID = errors.New("failed to read record id was zero")
	// ErrMissingValue is used when a value is missing, e.g. a read did not scan
	ErrMissingValue = errors.New("missing an expected value")
	// ErrUnexpectedValue is used when a value is not met, e.g. an update was incomplete
	ErrUnexpectedValue = errors.New("expected value was not met")
	// DBName is the filename of the sqlite file for standard operation
	DBName = ".focustime.db"
	// DBNameTest is the filename of the sqlite file for tests, distinct to allow for dropping
	DBNameTest = ".focustime_test.db"
	// CSVFileName is the filename of the csv document generated
	CSVFileName = "focustime.csv"
)

Functions

This section is empty.

Types

type Database

type Database struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

Database stores the database connection and name

func DefaultSqliteConn

func DefaultSqliteConn() (*Database, error)

DefaultSqliteConn provides a connection for standard operation

func (*Database) Init

func (db *Database) Init() error

Init creates the database if it does not exist

func (*Database) PrintGroupedReport

func (db *Database) PrintGroupedReport(filter ReportFilter)

PrintGroupedReport will print a report of focused windows, grouped by suffix

func (*Database) Report

func (db *Database) Report(filter ReportFilter) (*Report, error)

Report provides all records with at least certain amount of duration time tracked

func (*Database) SaveChange

func (db *Database) SaveChange(windowTitle string, seconds int) error

SaveChange will, given a title and seconds, create or update records accordingly

func (*Database) WriteCSV

func (db *Database) WriteCSV(filter ReportFilter)

WriteCSV will write a report of focused windows, grouped by suffix, to current working dir

type Day

type Day struct {
	ID    int
	Value time.Time
}

Day is a database record of a particular day

func NewDay

func NewDay() Day

NewDay provides a day record for use in the database

type DayWindow

type DayWindow struct {
	Seconds  int
	DayID    int
	WindowID int
}

DayWindow is a database record

func NewDayWindow

func NewDayWindow(day Day, window Window) DayWindow

NewDayWindow is a associative database record of a particular day and window

func (*DayWindow) AddSeconds

func (dw *DayWindow) AddSeconds(db *Database, n int) error

AddSeconds grabs current seconds from db, adds n, and updates the record

type Report

type Report struct {
	Items []ReportItem
}

Report is a report derived from joined tables

func (*Report) GroupedByTitleSuffix

func (r *Report) GroupedByTitleSuffix() map[string][]ReportItem

GroupedByTitleSuffix will attempt to group items by their suffix according to common delimiters

type ReportFilter

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

ReportFilter is the filters that can be applied to a report

func NewReportFilter

func NewReportFilter(startDateStr, endDateStr *string, duration *time.Duration) ReportFilter

NewReportFilter takes in flags and generates a report filter that can be used

type ReportItem

type ReportItem struct {
	Title   string
	When    time.Time
	Seconds int
}

ReportItem is an item in a report

type Window

type Window struct {
	ID   int
	Name string
}

Window is a database record of a desktop window

func NewWindow

func NewWindow(name string) Window

NewWindow provides a window record for use in the database

Jump to

Keyboard shortcuts

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