database

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHabitNotFound = app.Errorf(app.ENOTFOUND, "Habit not found.")

Functions

func NewHabitService

func NewHabitService(db *DB) models.HabitService

func SeedTestData

func SeedTestData(ctx context.Context, db *DB, year int, month time.Month)

Seed the database with random dated habits for 12 month. Given year month are guaranteed to be seeded

Types

type DB

type DB struct {

	// Datasource name.
	DSN string
	// contains filtered or unexported fields
}

DB represents the database connection.

func NewDB

func NewDB(dsn string) *DB

NewDB returns a new instance of DB associated with the given datasource name.

func SetupTestDB

func SetupTestDB() (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) Open

func (db *DB) Open() (err error)

Open creates a new DB for the given connection string.

func (*DB) QueryRow

func (db *DB) QueryRow(ctx context.Context, query string, args ...any) *sql.Row

QueryRow runs the query and returns a single row.

type HabitServiceImpl

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

func (*HabitServiceImpl) Create

func (s *HabitServiceImpl) Create(ctx context.Context, habit *models.Habit) error

func (*HabitServiceImpl) Delete

func (s *HabitServiceImpl) Delete(ctx context.Context, id models.HabitId) error

func (*HabitServiceImpl) GetAllByDay

func (s *HabitServiceImpl) GetAllByDay(ctx context.Context, day time.Time) (*models.Chain, error)

func (*HabitServiceImpl) HeatMap

func (s *HabitServiceImpl) HeatMap(ctx context.Context, from time.Time, to time.Time) (map[time.Time]*models.HeatMap, int, error)

func (*HabitServiceImpl) Update

func (s *HabitServiceImpl) Update(ctx context.Context, habit *models.Habit) error

Jump to

Keyboard shortcuts

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