database

package
v0.0.0-...-2a5cec1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SqliteFactory = FactoryFunc(func(args ...interface{}) (Datastore, error) {
	if len(args) == 0 {
		return nil, errors.New("invalid data source")
	}

	switch filename := args[0].(type) {
	case string:
		return newSqlite(filename)
	default:
		return nil, fmt.Errorf("invalid database source: expected string, got %v", filename)
	}
})

SqliteFactory creates a new sqlite datastore

Functions

func Close

func Close() error

Close closes the database

func DeleteInterval

func DeleteInterval(i interval.Interval) error

DeleteInterval delete interval i

func FindIntervalByID

func FindIntervalByID(id int) (interval.Interval, error)

FindIntervalByID finds the interval with given id

func FindIntervalsByCriteria

func FindIntervalsByCriteria(c interval.Interval) ([]interval.Interval, error)

FindIntervalsByCriteria finds intervals matching the criteria

func FindLastOpenIntervalForTag

func FindLastOpenIntervalForTag(tag string) (interval.Interval, error)

FindLastOpenIntervalForTag finds the last open interval for tag

func FindOpenIntervalsForTag

func FindOpenIntervalsForTag(tag string) ([]interval.Interval, error)

FindOpenIntervalsForTag finds open intervals for tag

func FindOverlappingIntervals

func FindOverlappingIntervals(i interval.Interval) ([]interval.Interval, error)

FindOverlappingIntervals finds intervals that are overlapping with i

func Init

func Init(args ...interface{})

Init opens and initializes the database

func SaveInterval

func SaveInterval(i *interval.Interval) error

SaveInterval saves interval i

func SetFactory

func SetFactory(fn FactoryFunc)

SetFactory sets the factory for creating the datastore

Types

type Datastore

type Datastore interface {
	// FindIntervalByID finds the interval with given id
	FindIntervalByID(int) (interval.Interval, error)

	// DeleteInterval delete interval i
	DeleteInterval(interval.Interval) error

	// SaveInterval saves interval i
	SaveInterval(*interval.Interval) error

	// FindOverlappingIntervals finds intervals that are overlapping with i
	FindOverlappingIntervals(interval.Interval) ([]interval.Interval, error)

	// FindOpenIntervalsForTag finds open intervals for tag
	FindOpenIntervalsForTag(string) ([]interval.Interval, error)

	// FindLastOpenIntervalForTag finds the last open interval for tag
	FindLastOpenIntervalForTag(string) (interval.Interval, error)

	// FindIntervalsByCriteria finds intervals matching the criteria
	FindIntervalsByCriteria(interval.Interval) ([]interval.Interval, error)

	// Close closes the database
	Close() error
}

Datastore defines the interface for a datastore

type FactoryFunc

type FactoryFunc func(args ...interface{}) (Datastore, error)

FactoryFunc defines a function that creates a datastore

Jump to

Keyboard shortcuts

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