Documentation ¶
Overview ¶
Package database is a database interface to publish.
Index ¶
- Constants
- type IterateExposuresCriteria
- type PublishDB
- func (db *PublishDB) DeleteExposure(ctx context.Context, exposureKey []byte) (int64, error)
- func (db *PublishDB) DeleteExposuresBefore(ctx context.Context, before time.Time) (int64, error)
- func (db *PublishDB) InsertAndReviseExposures(ctx context.Context, incoming []*model.Exposure) (int, error)
- func (db *PublishDB) IterateExposures(ctx context.Context, criteria IterateExposuresCriteria, ...) (cur string, err error)
- func (db *PublishDB) ReadExposures(ctx context.Context, tx pgx.Tx, b64keys []string) (map[string]*model.Exposure, error)
Constants ¶
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 (*PublishDB) DeleteExposure ¶
DeleteExposure deletes exposure
func (*PublishDB) DeleteExposuresBefore ¶
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.