sqlite

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sqlite implements myhours.Database on top of SQLite.

Contains also utilities for initializing a new SQLite databases with the required schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitiateSQLiteDatabase

func InitiateSQLiteDatabase(dbFile string) (*sql.DB, error)

InitiateSQLiteDatabase opens or creates an SQLite database to given destination.

If no database exists in the given location, new database is initialized and opened instead. Creates directories as needed.

Types

type Option

type Option func(*SQLite)

Option defines option function for SQLite based Database solution.

func Logger

func Logger(l *slog.Logger) Option

Logger sets the logger for the SQLite Database implementation.

type SQLite

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

SQLite implements Database on top of SQLite.

func NewSQLite

func NewSQLite(handle *sql.DB, options ...Option) *SQLite

NewSQLite return a SQLite database implementation using given *sql.DB handle.

Use for example InitiateSQLiteDatabase to open/initiate an SQLite based *sql.DB handle.

func (*SQLite) ActiveRecord

func (db *SQLite) ActiveRecord() (*myhours.Record, error)

ActiveRecord finds the first myhours.Record from database that has no end time set yet.

func (*SQLite) Categories

func (db *SQLite) Categories() ([]myhours.Category, error)

Categories returns all myhours.Category entries.

func (*SQLite) ImportRecords

func (db *SQLite) ImportRecords(records []myhours.Record) ([]int64, error)

ImportRecords inserts the given records into the database. All records are validated before insert.

Inserts are done in a transaction, so the result is all or nothing.

Returns the IDs of created records.

func (*SQLite) Record added in v0.1.0

func (db *SQLite) Record(id int64) (*myhours.Record, error)

Record retrieves a myhours.Record matching given ID.

func (*SQLite) Records

func (db *SQLite) Records(from, before time.Time) ([]myhours.Record, error)

Records retrieves records for given timestamps [from, before).

func (*SQLite) RecordsInCategory

func (db *SQLite) RecordsInCategory(from, before time.Time, categoryID int64) ([]myhours.Record, error)

RecordsInCategory retrieves records for given timestamps [from, before) that have the given category.

func (*SQLite) Settings

func (db *SQLite) Settings() (*myhours.Settings, error)

Settings returns the full application settings.

func (*SQLite) StartRecord

func (db *SQLite) StartRecord(start time.Time, categoryID int64, notes string) (int64, error)

StartRecord inserts a new myhours.Record into the database, setting only the start time to indicate the record is started, but not finished.

func (*SQLite) UpdateRecord added in v0.1.0

func (db *SQLite) UpdateRecord(recordID int64, categoryID int64, start, end time.Time, notes string) error

UpdateRecord sets record details for the record matching recordID.

func (*SQLite) UpdateSetting

func (db *SQLite) UpdateSetting(key myhours.Setting, value string) error

UpdateSetting sets value of a setting identified by key.

Jump to

Keyboard shortcuts

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