Documentation
¶
Overview ¶
Package databaser provides SQLite database connection and operations.
Index ¶
- func InTransaction(ctx context.Context, db *DB, f func(tx *sqlx.Tx) error) error
- func SaveManyEventsTx(ctx context.Context, tx *sqlx.Tx, events []*Event) error
- func SaveManyHolidaysTx(ctx context.Context, tx *sqlx.Tx, holidays []Holiday) error
- type DB
- func (db *DB) Close() error
- func (db *DB) GetAllEvents(ctx context.Context, limit, offset int) ([]Event, error)
- func (db *DB) GetEvents(ctx context.Context, period time.Duration) ([]Event, error)
- func (db *DB) GetHolidays(ctx context.Context, year int, location *time.Location) ([]Holiday, error)
- func (db *DB) Init(ctx context.Context) error
- func (db *DB) SaveEvent(ctx context.Context, event Event) error
- func (db *DB) SaveManyEvents(ctx context.Context, events []Event) error
- type DateOnly
- func (d *DateOnly) After(u *DateOnly) bool
- func (d *DateOnly) Before(u *DateOnly) bool
- func (d *DateOnly) Date() (year int, month time.Month, day int)
- func (d *DateOnly) EndOfYear() string
- func (d *DateOnly) Format(layout string) string
- func (d *DateOnly) Scan(value any) error
- func (d *DateOnly) SetLocation(loc *time.Location)
- func (d *DateOnly) StartOfYear() string
- func (d *DateOnly) String() string
- func (d *DateOnly) Time() time.Time
- func (d *DateOnly) Value() (driver.Value, error)
- type Event
- type Holiday
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InTransaction ¶
InTransaction executes the given function within a database transaction.
func SaveManyEventsTx ¶
SaveManyEventsTx stores multiple events in the database within a transaction.
Types ¶
type DB ¶
DB wraps sqlx.DB for database operations.
func (*DB) GetAllEvents ¶ added in v0.0.13
GetAllEvents retrieves all events with pagination.
func (*DB) GetHolidays ¶ added in v0.0.12
func (db *DB) GetHolidays(ctx context.Context, year int, location *time.Location) ([]Holiday, error)
GetHolidays retrieves holidays for the specified year and location.
type DateOnly ¶ added in v0.0.12
DateOnly is a custom type that stores only the date part of time.Time.
func (*DateOnly) SetLocation ¶ added in v0.0.12
func (*DateOnly) StartOfYear ¶ added in v0.0.12
type Event ¶
type Event struct {
Timestamp time.Time `db:"timestamp"`
Load uint8 `db:"load"`
Predict float64 `db:"-"`
}
Event represents a load event with a timestamp and load percentage.
func NewEventFromCSVRecord ¶
NewEventFromCSVRecord creates an Event from a CSV record.