sqlite

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 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 implements myhours.Database ActiveRecord on top of SQLite

func (*SQLite) Categories

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

func (*SQLite) FinishRecord

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

func (*SQLite) ImportRecords

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

ImportRecords implements Database.ImportRecords on top of SQLite.

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

Returns the IDs of created records.

func (*SQLite) Records

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

Records implements myhours.Database Records on top of SQLite

func (*SQLite) RecordsInCategory

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

RecordsInCategory implements myhours.Database RecordsInCategory on top of SQLite

func (*SQLite) Settings

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

func (*SQLite) StartRecord

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

func (*SQLite) UpdateRecordCategory

func (db *SQLite) UpdateRecordCategory(recordID int64, categoryID int64) error

func (*SQLite) UpdateSetting

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

Jump to

Keyboard shortcuts

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