db

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: GPL-3.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const TableName = "activities"

TableName is the name of the table in the sqlite database.

Variables

This section is empty.

Functions

func Close added in v0.0.12

func Close(db *DB) error

Close closes the db connection

Types

type DB

type DB struct {
	DB *sql.DB
}

A DB stores a pointer to a sqlite database connection.

func New

func New(path string) (*DB, error)

New creates a new instance of the DB type by initializing and opening a database. located at the specified 'path'. It returns a pointer to the created DB and an error, if any. The returned DB is ready for use, and the associated database file is opened. It should be noted that the DB connection should be closed after use.

func (*DB) DeleteActivities added in v0.0.7

func (db *DB) DeleteActivities(ids []int) (n int64, err error)

DeleteActivities deletes the activities with the specified ids from the database. It returns the number of affected rows and an error if the deletion operation encounters any issues.

func (*DB) DeleteActivity added in v0.0.7

func (db *DB) DeleteActivity(id int) (n int64, err error)

DeleteActivity deletes the activity with the specified id from the database. It returns the number of affected rows and an error if the deletion operation encounters any issues.

func (*DB) GetActivities added in v0.0.7

func (db *DB) GetActivities(ids []int) (activities []*activity.Activity, err error)

GetActivities retrieves the activities with the specified ids from the database.

func (*DB) GetActivitiesAll added in v0.0.7

func (db *DB) GetActivitiesAll() (activities []*activity.Activity, err error)

GetActivitiesAll retrieves all activities from the database. It returns a slice of pointers to activities.

func (*DB) GetActivitiesAllMap added in v0.0.7

func (db *DB) GetActivitiesAllMap() (activitiesMap map[int]*activity.Activity, err error)

GetActivitiesAllMap retrieves all activities from the database, and returns them as a map with activity ids as keys and pointers to activities as values.

func (*DB) GetActivity added in v0.0.7

func (db *DB) GetActivity(id int) (act *activity.Activity, err error)

GetActivity retrieves the activity with the specified id from the database.

func (*DB) InsertActivities

func (db *DB) InsertActivities(activities []*activity.Activity, duplicateInsertPolicy DuplicateInsertPolicy) (err error)

InsertActivities inserts the provided activities into the database.

func (*DB) InsertActivity

func (db *DB) InsertActivity(act *activity.Activity, duplicateInsertPolicy DuplicateInsertPolicy) (n int64, err error)

InsertActivity inserts the provided activity into the database.

func (*DB) UpdateActivity added in v0.0.7

func (db *DB) UpdateActivity(act *activity.Activity, id int) (n int64, err error)

UpdateActivity updates the activity with the specified id in the database using the information provided in the activity.

func (*DB) UpdateCost added in v0.0.7

func (db *DB) UpdateCost(id int, newCost float64) (n int64, err error)

UpdateCost updates the cost of an activity with the specified id in the database

func (*DB) UpdateDescription added in v0.0.7

func (db *DB) UpdateDescription(id int, newDescription string) (n int64, err error)

UpdateDescription updates the description of an activity with the specified id in the database

func (*DB) UpdateDuration added in v0.0.10

func (db *DB) UpdateDuration(id int, newDuration time.Duration) (n int64, err error)

UpdateDuration updates the duration of an activity with the specified id in the database

func (*DB) UpdateFinish added in v0.0.7

func (db *DB) UpdateFinish(id int, newFinish time.Time) (n int64, err error)

UpdateFinish updates the finish time of an activity with the specified id in the database

func (*DB) UpdateId added in v0.0.7

func (db *DB) UpdateId(oldId, newId int) (n int64, err error)

UpdateId updates the id of an activity with the specified id in the database

func (*DB) UpdatePredecessors added in v0.0.7

func (db *DB) UpdatePredecessors(id int, predecessorsId []int) (n int64, err error)

UpdatePredecessors updates the predecessors of the activity with the specified id in the database.

func (*DB) UpdateStart added in v0.0.7

func (db *DB) UpdateStart(id int, newStart time.Time) (n int64, err error)

UpdateStart updates the start time of an activity with the specified id in the database

func (*DB) UpdateSuccessors added in v0.0.7

func (db *DB) UpdateSuccessors(id int, successorsId []int) (n int64, err error)

UpdateSuccessors updates the successors of the activity with the specified id in the database.

type DuplicateInsertPolicy added in v0.0.12

type DuplicateInsertPolicy int

DuplicateInsertPolicy defines the policy for handling duplicate inserts in a database.

const (
	None    DuplicateInsertPolicy = 0 // Do nothing
	Ignore  DuplicateInsertPolicy = 1 // Ignore duplicate inserts
	Replace DuplicateInsertPolicy = 2 // Replace duplicate inserts
)

Enumeration of available duplicate insert policies.

Jump to

Keyboard shortcuts

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