store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package store (pieces ⑬ and ⑭) owns the SQLite database: opening it with safe pragmas, running migrations after an automatic backup, and mapping rows to domain types. Queries are generated by sqlc into store/db.

Index

Constants

View Source
const TimeFormat = time.RFC3339Nano

TimeFormat is how instants are stored (UTC, sortable).

Variables

This section is empty.

Functions

func CategoryFromRow

func CategoryFromRow(r db.Category) domain.Category

func ChargeFromRow

func ChargeFromRow(r db.Charge) domain.Charge

func ChargeUpdate

func ChargeUpdate(c domain.Charge, now time.Time) db.UpdateChargeParams

ChargeUpdate builds the update parameters for c (optimistic locking on c.Version).

func DatePtr

func DatePtr(d engine.Date) *string

func FormatTime

func FormatTime(t time.Time) string

FormatTime formats an instant for storage.

func HouseholdFromRow

func HouseholdFromRow(r db.Household) domain.Household

func MemberFromRow

func MemberFromRow(r db.Member) domain.Member

func NotFound

func NotFound(err error, format string, args ...any) error

NotFound converts sql.ErrNoRows into domain.ErrNotFound, with a sentence such as "subscription %s: not found" (see domain.Missing).

func ParseTime

func ParseTime(s string) time.Time

ParseTime parses a stored instant.

func PaymentMethodFromRow

func PaymentMethodFromRow(r db.PaymentMethod) domain.PaymentMethod

func Ptr

func Ptr(s string) *string

Ptr returns a pointer to s, or nil if s is empty.

func Str

func Str(p *string) string

Str dereferences a nullable string.

func SubscriptionFromRow

func SubscriptionFromRow(r db.Subscription) (domain.Subscription, error)

func SubscriptionJSON

func SubscriptionJSON(s domain.Subscription) (schedule, reminders, details string, err error)

SubscriptionJSON returns the JSON columns of a subscription.

Types

type Store

type Store struct {
	DB *sql.DB
	Q  *db.Queries
	// contains filtered or unexported fields
}

Store is the database handle.

func Open

func Open(ctx context.Context, dataDir string, log *slog.Logger) (*Store, error)

Open opens (or creates) the database in dataDir, backs it up if migrations are pending, and migrates it to the latest version.

func OpenMemory

func OpenMemory(ctx context.Context) (*Store, error)

OpenMemory opens a private in-memory database, for tests.

func (*Store) Backup

func (s *Store) Backup(ctx context.Context, name string) (string, error)

Backup writes a consistent snapshot of the database (VACUUM INTO) to <data>/backups/<name>-<timestamp>.db and returns its path.

func (*Store) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) Tx

func (s *Store) Tx(ctx context.Context, fn func(q *db.Queries) error) error

Tx runs fn in a transaction. Returning an error rolls it back.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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