store

package
v0.0.0-...-0ee189b Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package store provides the worklog data storage layer.

Index

Constants

View Source
const (
	EventsRange = `` /* 278-byte string literal not displayed */

	EventsRangeUntil = `` /* 221-byte string literal not displayed */

	EventsRangeFrom = `` /* 219-byte string literal not displayed */

	EventsLimit = `` /* 162-byte string literal not displayed */

)
View Source
const AmendEvents = `` /* 1327-byte string literal not displayed */
View Source
const BucketMetadata = `select id, name, type, client, hostname, created, datastr from buckets where id = ?`
View Source
const Buckets = `select id, name, type, client, hostname, created, datastr from buckets`
View Source
const CreateBucket = `insert into buckets(id, name, type, client, hostname, created, datastr) values (?, ?, ?, ?, ?, ?, ?)`
View Source
const DeleteBucket = `delete from buckets where id = ?`
View Source
const DeleteBucketEvents = `delete from events where bucketrow in (
	select rowid from buckets where id = ?
)`
View Source
const DeleteEvent = `delete from events where bucketrow = (
	select rowid from buckets where id = ?
) and id = ?`
View Source
const Event = `` /* 131-byte string literal not displayed */
View Source
const Events = `select id, starttime, endtime, datastr from events where bucketrow = (
	select rowid from buckets where id = ?
)`
View Source
const InsertEvent = `insert into events(bucketrow, starttime, endtime, datastr) values ((select rowid from buckets where id = ?), ?, ?, ?)`
View Source
const LastEvent = `` /* 285-byte string literal not displayed */
View Source
const Schema = `` /* 832-byte string literal not displayed */

Schema is the DB schema.

View Source
const UpdateEvent = `` /* 130-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is a persistent store.

func Open

func Open(ctx context.Context, name, host string) (*DB, error)

Open opens an existing DB. See https://pkg.go.dev/modernc.org/sqlite#Driver.Open for name handling details. Two connections to the database are created, one with mode=rwc and one with mode=ro. Any mode in the provided name will be ignored. Open attempts to get the CNAME for the host, which may wait indefinitely, so a timeout context can be provided to fall back to the kernel-provided hostname.

func (*DB) AmendEvents

func (db *DB) AmendEvents(ctx context.Context, ts time.Time, note *worklog.Amendment) (sql.Result, error)

AmendEvents adds amendment notes to the data for events in the store overlapping the note. On return the note.Replace slice will be sorted.

The SQL command run is AmendEvents.

func (*DB) Backup

func (db *DB) Backup(ctx context.Context, n int, sleep time.Duration) (string, error)

Backup creates a backup of the DB using the SQLite backup API, sleeping between each step of n pages. n must fit into an int32, and if it is zero or less, the full database will be backed up in a single step. It returns the path of the backup.

func (*DB) BucketID

func (db *DB) BucketID(uid string) string

BucketID returns the internal bucket ID for the provided bucket uid.

func (*DB) BucketMetadata

func (db *DB) BucketMetadata(ctx context.Context, bid string) (*worklog.BucketMetadata, error)

BucketMetadata returns the metadata for the bucket with the provided internal bucket ID. The SQL command run is BucketMetadata.

func (*DB) Buckets

func (db *DB) Buckets(ctx context.Context) ([]worklog.BucketMetadata, error)

Buckets returns the full set of bucket metadata. The SQL command run is Buckets.

func (*DB) Close

func (db *DB) Close(_ context.Context) error

Close closes the database.

func (*DB) CreateBucket

func (db *DB) CreateBucket(ctx context.Context, uid, name, typ, client string, created time.Time, data map[string]any) (m *worklog.BucketMetadata, err error)

CreateBucket creates a new entry in the bucket table. If the entry already exists it will return an sqlite.Error with the code sqlite3.SQLITE_CONSTRAINT_UNIQUE. The SQL command run is CreateBucket.

func (*DB) Dump

func (db *DB) Dump(ctx context.Context) ([]worklog.BucketMetadata, error)

Dump dumps the complete database into a slice of worklog.BucketMetadata.

func (*DB) DumpRange

func (db *DB) DumpRange(ctx context.Context, start, end time.Time) ([]worklog.BucketMetadata, error)

DumpRange dumps the database spanning the specified time range into a slice of worklog.BucketMetadata.

func (*DB) Events

func (db *DB) Events(ctx context.Context, bid string) ([]worklog.Event, error)

Buckets returns the full set of events in the bucket with the provided internal bucket ID. The SQL command run is Events.

func (*DB) EventsRange

func (db *DB) EventsRange(ctx context.Context, bid string, start, end time.Time, limit int) ([]worklog.Event, error)

EventsRange returns the events in the bucket with the provided bucket ID within the specified time range, sorted descending by end time. The SQL command run is EventsRange, EventsRangeUntil, EventsRangeFrom or EventsLimit depending on whether start and end are zero.

func (*DB) EventsRangeFunc

func (db *DB) EventsRangeFunc(ctx context.Context, bid string, start, end time.Time, limit int, fn func(worklog.Event) error) error

EventsRange calls fn on all the events in the bucket with the provided bucket ID within the specified time range, sorted descending by end time. The SQL command run is EventsRange, EventsRangeUntil, EventsRangeFrom or EventsLimit depending on whether start and end are zero.

func (*DB) InsertEvent

func (db *DB) InsertEvent(ctx context.Context, e *worklog.Event) (sql.Result, error)

InsertEvent inserts a new event into the events table. The SQL command run is InsertEvent.

func (*DB) LastEvent

func (db *DB) LastEvent(ctx context.Context, uid string) (*worklog.Event, error)

LastEvent returns the last event in the named bucket. The SQL command run is LastEvent.

func (*DB) Load

func (db *DB) Load(ctx context.Context, buckets []worklog.BucketMetadata, replace bool) (err error)

Load loads a complete database from a slice of worklog.BucketMetadata. Event IDs will be regenerated by the backing database and so will not match the input data. If replace is true and a bucket already exists matching the bucket in the provided buckets slice, the existing events will be deleted and replaced. If replace is false, the new events will be added to the existing events in the store.

func (*DB) Name

func (db *DB) Name() string

Name returns the name of the database as provided to Open.

func (*DB) Select

func (db *DB) Select(ctx context.Context, query string) ([]map[string]any, error)

Select allows running an SQLite SELECT query. The query is run on a read-only connection to the database.

func (*DB) UpdateEvent

func (db *DB) UpdateEvent(ctx context.Context, e *worklog.Event) (sql.Result, error)

UpdateEvent updates the event in the store corresponding to the provided event. The SQL command run is UpdateEvent.

Jump to

Keyboard shortcuts

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