db

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package db handles the database connection and initialization.

Index

Constants

View Source
const DBFile = config.AppName + ".db"
View Source
const DateFormat = "2006-01-02"

Variables

This section is empty.

Functions

func Connect

func Connect() (*sqlx.DB, error)

Connect connects to the SQLite database, creates the necessary directories, and performs migrations if needed.

Types

type AllTimeStats

type AllTimeStats struct {
	TotalSessions      int           `db:"total_sessions"`
	TotalWorkDuration  time.Duration `db:"total_work_duration"`
	TotalBreakDuration time.Duration `db:"total_break_duration"`
}

type DailyStat

type DailyStat struct {
	Date         string        `db:"day"`
	WorkDuration time.Duration `db:"work_duration"`
}

type Session

type Session struct {
	ID        int           `db:"id"`
	Type      string        `db:"type"`
	Duration  time.Duration `db:"duration"`
	StartedAt time.Time     `db:"started_at"`
}

type SessionRepo

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

func NewSessionRepo

func NewSessionRepo(db *sqlx.DB) *SessionRepo

func (*SessionRepo) CreateSession

func (r *SessionRepo) CreateSession(startedAt time.Time, duration time.Duration, sessionType SessionType) error

CreateSession inserts a new session record into the database.

func (*SessionRepo) GetAllTimeStats

func (r *SessionRepo) GetAllTimeStats() (AllTimeStats, error)

GetAllTimeStats retrieves aggregate statistics across all sessions.

func (*SessionRepo) GetLastMonthsStats

func (r *SessionRepo) GetLastMonthsStats(numberOfMonths int) ([]DailyStat, error)

GetLastMonthsStats retrieves daily work duration statistics for the past specified number of months.

func (*SessionRepo) GetStreakStats

func (r *SessionRepo) GetStreakStats() (StreakStats, error)

GetStreakStats calculates the current and best streaks of consecutive work days. A streak is consecutive days with at least one 'work' session.

func (*SessionRepo) GetWeeklyStats

func (r *SessionRepo) GetWeeklyStats() ([]DailyStat, error)

GetWeeklyStats retrieves daily work duration statistics for the past 7 days.

type SessionType

type SessionType string
const (
	WorkSession  SessionType = "work"
	BreakSession SessionType = "break"
)

func GetSessionType

func GetSessionType(taskType config.TaskType) SessionType

type StreakStats

type StreakStats struct {
	Current int
	Best    int
}

Jump to

Keyboard shortcuts

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