storage

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Migration001_UTCTimestamps = "001_utc_timestamps"
)

Migration keys ! I'm adding this system so that future database migrations will be easier - Dylan

Variables

View Source
var CurrentSchemaVersion = len(allMigrationKeys)

CurrentSchemaVersion is the number of migrations the current binary knows about.

Functions

func GetBackupDir added in v0.7.0

func GetBackupDir() (string, error)

func GetDBPath added in v0.7.0

func GetDBPath() (string, error)

func RestoreBackup added in v0.7.0

func RestoreBackup(backupPath string) error

RestoreBackup copies a backup file over the live database. The caller must ensure no DB connection is open.

Types

type BackupInfo added in v0.7.0

type BackupInfo struct {
	ID            int
	Filename      string
	Path          string
	CreatedAt     time.Time
	Size          int64
	SchemaVersion int
	IsUpToDate    bool
}

func ListBackups added in v0.7.0

func ListBackups() ([]BackupInfo, error)

ListBackups returns all backups sorted newest-first with display IDs assigned (1 = newest).

type Database

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

func Initialize

func Initialize() (*Database, error)

func (*Database) Close

func (d *Database) Close() error

func (*Database) CreateBackup added in v0.7.0

func (d *Database) CreateBackup() (*BackupInfo, error)

CreateBackup uses SQLite's VACUUM INTO to produce a clean, consistent snapshot of the live database.

func (*Database) CreateEntry

func (d *Database) CreateEntry(projectName, description string, hourlyRate *float64, milestoneName *string) (*TimeEntry, error)

func (*Database) CreateManualEntry

func (d *Database) CreateManualEntry(projectName, description string, startTime, endTime time.Time, hourlyRate *float64, milestoneName *string) (*TimeEntry, error)

func (*Database) CreateMilestone added in v0.3.0

func (d *Database) CreateMilestone(projectName, name string) (*Milestone, error)

func (*Database) DeleteTimeEntry

func (d *Database) DeleteTimeEntry(id int64) error

func (*Database) FinishMilestone added in v0.3.0

func (d *Database) FinishMilestone(id int64) error

func (*Database) GetActiveMilestoneForProject added in v0.3.0

func (d *Database) GetActiveMilestoneForProject(projectName string) (*Milestone, error)

func (*Database) GetAllMilestones added in v0.3.0

func (d *Database) GetAllMilestones() ([]*Milestone, error)

func (*Database) GetAllProjects

func (d *Database) GetAllProjects() ([]string, error)

func (*Database) GetCompletedEntriesByProject

func (d *Database) GetCompletedEntriesByProject(projectName string) ([]*TimeEntry, error)

func (*Database) GetEntries

func (d *Database) GetEntries(limit int) ([]*TimeEntry, error)

func (*Database) GetEntriesByDateRange

func (d *Database) GetEntriesByDateRange(start, end time.Time) ([]*TimeEntry, error)

func (*Database) GetEntriesByMilestone added in v0.3.0

func (d *Database) GetEntriesByMilestone(projectName, milestoneName string) ([]*TimeEntry, error)

func (*Database) GetEntriesByProject

func (d *Database) GetEntriesByProject(projectName string) ([]*TimeEntry, error)

func (*Database) GetEntry

func (d *Database) GetEntry(id int64) (*TimeEntry, error)

func (*Database) GetLastStoppedEntry added in v0.1.2

func (d *Database) GetLastStoppedEntry() (*TimeEntry, error)

func (*Database) GetLastStoppedEntryByProject added in v0.4.5

func (d *Database) GetLastStoppedEntryByProject(projectName string) (*TimeEntry, error)

func (*Database) GetMilestone added in v0.3.0

func (d *Database) GetMilestone(id int64) (*Milestone, error)

func (*Database) GetMilestoneByName added in v0.3.0

func (d *Database) GetMilestoneByName(projectName, milestoneName string) (*Milestone, error)

func (*Database) GetMilestonesByProject added in v0.3.0

func (d *Database) GetMilestonesByProject(projectName string) ([]*Milestone, error)

func (*Database) GetProjectsWithCompletedEntries

func (d *Database) GetProjectsWithCompletedEntries() ([]string, error)

func (*Database) GetRunningEntry

func (d *Database) GetRunningEntry() (*TimeEntry, error)

func (*Database) StopEntry

func (d *Database) StopEntry(id int64) error

func (*Database) UpdateTimeEntry

func (d *Database) UpdateTimeEntry(id int64, entry *TimeEntry) error

type Milestone added in v0.3.0

type Milestone struct {
	ID          int64
	ProjectName string
	Name        string
	StartTime   time.Time
	EndTime     *time.Time
}

func (*Milestone) Duration added in v0.3.0

func (m *Milestone) Duration() time.Duration

func (*Milestone) IsActive added in v0.3.0

func (m *Milestone) IsActive() bool

type TimeEntry

type TimeEntry struct {
	ID            int64
	ProjectName   string
	StartTime     time.Time
	EndTime       *time.Time
	Description   string
	HourlyRate    *float64
	MilestoneName *string
}

func (*TimeEntry) Duration

func (t *TimeEntry) Duration() time.Duration

func (*TimeEntry) IsRunning

func (t *TimeEntry) IsRunning() bool

func (*TimeEntry) RoundedHours added in v0.1.3

func (t *TimeEntry) RoundedHours() float64

RoundedHours returns duration in hours rounded to 2 decimal places for billing. Could be made configurable to support different rounding increments (0.1h, 0.25h, etc).

Jump to

Keyboard shortcuts

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