database

package
v0.0.0-...-075157f Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package database is a database interface to publish.

Index

Constants

View Source
const (
	// InsertExposuresBatchSize is the maximum number of exposures that can be inserted at once.
	InsertExposuresBatchSize = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IterateExposuresCriteria

type IterateExposuresCriteria struct {
	IncludeRegions []string
	ExcludeRegions []string
	SinceTimestamp time.Time
	UntilTimestamp time.Time
	LastCursor     string
	RevisedKeys    bool // If true, only revised keys that match will be selected.

	// OnlyLocalProvenance indicates that only exposures with LocalProvenance=true will be returned.
	OnlyLocalProvenance bool
}

IterateExposuresCriteria is criteria to iterate exposures.

type PublishDB

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

func New

func New(db *database.DB) *PublishDB

func (*PublishDB) DeleteExposure

func (db *PublishDB) DeleteExposure(ctx context.Context, exposureKey []byte) (int64, error)

DeleteExposure deletes exposure

func (*PublishDB) DeleteExposuresBefore

func (db *PublishDB) DeleteExposuresBefore(ctx context.Context, before time.Time) (int64, error)

DeleteExposuresBefore deletes exposures created before "before" date. Returns the number of records deleted.

func (*PublishDB) InsertAndReviseExposures

func (db *PublishDB) InsertAndReviseExposures(ctx context.Context, incoming []*model.Exposure) (int, error)

InsertAndReviseExposures transactionally revises and inserts a set of keys as necessary.

func (*PublishDB) IterateExposures

func (db *PublishDB) IterateExposures(ctx context.Context, criteria IterateExposuresCriteria, f func(*model.Exposure) error) (cur string, err error)

IterateExposures calls f on each Exposure in the database that matches the given criteria. If f returns an error, the iteration stops, and the returned error will match f's error with errors.Is.

If an error occurs during the query, IterateExposures will return a non-empty string along with a non-nil error. That string, when passed as criteria.LastCursor in a subsequent call to IterateExposures, will continue the iteration at the failed row. If IterateExposures returns a nil error, the first return value will be the empty string.

func (*PublishDB) ReadExposures

func (db *PublishDB) ReadExposures(ctx context.Context, tx pgx.Tx, b64keys []string) (map[string]*model.Exposure, error)

ReadExposures will read an existing set of exposures from the database. This is necessary in case a key needs to be revised. In the return map, the key is the base64 of the ExposureKey. The keys are read for update in a provided transaction.

Jump to

Keyboard shortcuts

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