store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: GPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store persists invoices in a SQLite database.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("invoice not found")

ErrNotFound reports that the store holds no invoice matching a lookup.

View Source
var ErrPaid = errors.New("invoice is paid")

ErrPaid reports that the store refused a write to a paid invoice.

Functions

This section is empty.

Types

type Invoice

type Invoice struct {
	ID       string `gorm:"primaryKey"`
	Month    int
	Year     int
	Vendor   string
	Customer string
	Project  string
	Rate     float64
	Paid     bool   `gorm:"not null;default:false"`
	Weeks    []Week `gorm:"foreignKey:InvoiceID;constraint:OnDelete:CASCADE"`
}

Invoice is the stored form of an invoice.

type Store

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

Store reads and writes invoices in a SQLite database.

func Open

func Open(path string) (*Store, error)

Open opens the database at path, creating its parent directory and running schema migrations when needed.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) Get

func (s *Store) Get(id string) (*invoice.Invoice, error)

Get returns the invoice with the given identifier.

func (*Store) GetByMonth

func (s *Store) GetByMonth(year int, month time.Month) (*invoice.Invoice, error)

GetByMonth returns the invoice for the given year and month. It reports ErrNotFound when that month holds no invoice.

func (*Store) List

func (s *Store) List() ([]*invoice.Invoice, error)

List returns every stored invoice, newest first by year and month, with its weekly line items.

func (*Store) Save

func (s *Store) Save(inv *invoice.Invoice) (string, bool, error)

Save stores an invoice and its weekly line items and returns the invoice identifier and whether the invoice was newly created. Saving an invoice for an existing year and month replaces the stored invoice, including its customer and project, and keeps its identifier.

func (*Store) SetPaid

func (s *Store) SetPaid(year int, month time.Month, paid bool) error

SetPaid sets the paid status on the invoice for the given year and month. It changes only the paid status and reports ErrNotFound when that month holds no invoice.

func (*Store) SetProject

func (s *Store) SetProject(year int, month time.Month, project string) error

SetProject sets the project on the invoice for the given year and month. It changes only the project and reports ErrNotFound when that month holds no invoice. It reports ErrPaid when the invoice is paid.

type Week

type Week struct {
	ID        uint   `gorm:"primaryKey"`
	InvoiceID string `gorm:"index;not null"`
	Start     time.Time
	End       time.Time
	Hours     float64
}

Week is the stored form of a weekly line item.

Jump to

Keyboard shortcuts

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