db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicatedIntervalTag = fmt.Errorf("duplicated interval tags")
	ErrExistingOpenInterval  = fmt.Errorf("already existing opened interval")
	ErrIntervalTagsUnicity   = fmt.Errorf("interval_tags unicity failed")
	ErrInvalidInterval       = fmt.Errorf("invalid interval")
	ErrInvalidParam          = fmt.Errorf("invalid parameter")
	ErrInvalidStartTimestamp = fmt.Errorf("invalid start timestamp")
	ErrInvalidStopTimestamp  = fmt.Errorf("invalid stop timestamp")
	ErrMultipleOpenInterval  = fmt.Errorf("multiple opened interval")
	ErrNotFound              = fmt.Errorf("not found entity")
	ErrNotImplemented        = fmt.Errorf("operation not implemented")
)

Functions

This section is empty.

Types

type Interval

type Interval struct {
	ID             string
	UUID           string
	StartTimestamp time.Time
	StopTimestamp  time.Time
}

type Queryer

type Queryer interface {
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
}

type Sanity

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

Sanity object gathers all methods which implement the logic to check the data sanity in the database

func NewSanity

func NewSanity(db *sqlx.DB) *Sanity

func (*Sanity) Check

func (s *Sanity) Check() error

Check performs a full database scan to validate data. It will call:

  • checkNoOverlap
  • intervalTagsUnicity

type SyncerConfig

type SyncerConfig struct {
	Login        string
	Password     string
	Hostname     string
	Port         int
	DatabaseName string
}

func (SyncerConfig) String

func (cfg SyncerConfig) String() string

type TaggedInterval

type TaggedInterval struct {
	Interval
	Tags []string
}

type TimeTracker

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

func New

func New(databaseName string) (*TimeTracker, error)

func (*TimeTracker) Close

func (tt *TimeTracker) Close() error

Close releases resources associated with the TimeTracker object.

func (*TimeTracker) Continue

func (tt *TimeTracker) Continue(t time.Time, id string) (ret error)

Continue opens a new interval with the same tags as the last closed one. It will return an error if there is already an opened interval.

func (*TimeTracker) Current

func (tt *TimeTracker) Current() (*TaggedInterval, error)

Current returned the currently single opened interval if any.

func (*TimeTracker) Delete

func (tt *TimeTracker) Delete(id string) (ret error)

func (*TimeTracker) List

func (tt *TimeTracker) List(since, until time.Time) (retTi []TaggedInterval, retErr error)

List returns a list of interval whose start timestamp is equal or after the timestamp given as parameter. XXX add unit test

func (*TimeTracker) Start

func (tt *TimeTracker) Start(t time.Time, tags []string) (ret error)

Start registers a new opened interval with a set of tags. This method ensures that no other opened is currently registered in the database and that the wanted start time doesn't already belong to a closed interval.

func (*TimeTracker) StopAt

func (tt *TimeTracker) StopAt(t time.Time) error

func (*TimeTracker) StopFor

func (tt *TimeTracker) StopFor(d time.Duration) error

func (*TimeTracker) Sync

func (tt *TimeTracker) Sync(cfg SyncerConfig) (ret error)

Sync performs a bidirectional synchronisation with the central database.

func (*TimeTracker) Tag

func (tt *TimeTracker) Tag(id string, tags []string) (ret error)

XXX add unit test

func (*TimeTracker) Untag

func (tt *TimeTracker) Untag(id string, tags []string) (ret error)

func (*TimeTracker) Vacuum

func (tt *TimeTracker) Vacuum(before time.Time) (ret error)

Vacuum hard deletes all data which has been soft deleted before the timestamp. It will also remove unused tags. At the end of the clean process, it will perform a database vacuum.

Jump to

Keyboard shortcuts

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