db

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamespaceAnnouncements = "announcements"
)
View Source
const (
	NamespaceOrganizations = "organizations"
)

Variables

View Source
var (
	ErrNotFound           = errors.New("key not found in database")
	ErrUnsuccessfulPut    = errors.New("unable to successfully make Put request to trtl")
	ErrUnsuccessfulDelete = errors.New("unable to successfully make Delete request to trtl")
	ErrEmptyAnnouncement  = errors.New("cannot post a zero-valued announcement")
	ErrUnboundedRecent    = errors.New("cannot specify zero-valued not before otherwise announcements fetch is unbounded")
)

Functions

func Latest added in v1.5.0

func Latest(a, b string) string

Helper method to return the latest string timestamp from the two RFC3339 timestamps

Types

type Announcements added in v1.5.0

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

The Announcements type exposes methods for interacting with Network Announcements in the database. Announcements are stored as compact, compressed JSON to minimize the network requests and reduce storage requirements. This struct performs all necessary serialization on the announcements before storing and retrieving the model object. The announcement keys are ksuids - timestamp ordered unique IDs so that it is easy to scan the trtl database to find the most recent announcements.

Announcements implements the Collection interface

func (*Announcements) CreateMonth added in v1.5.0

func (a *Announcements) CreateMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)

CreateMonth from a month timestamp in the form YYYY-MM.

func (*Announcements) GetMonth added in v1.5.0

func (a *Announcements) GetMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)

GetMonth from a month timestamp in the form YYYY-MM.

func (*Announcements) GetOrCreateMonth added in v1.5.0

func (a *Announcements) GetOrCreateMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)

GetOrCreateMonth from a month timestamp in the form YYYY-MM.

func (*Announcements) Namespace added in v1.5.0

func (a *Announcements) Namespace() string

Namespace implements the collection interface

func (*Announcements) Post added in v1.5.0

func (a *Announcements) Post(ctx context.Context, in *models.Announcement) (_ string, err error)

Post an announcement, putting it to the trtl database. This method does no verification of duplicate announcements or any content verification except for a check that an empty announcement is not being put to the database. Announcements are stored in announcement months, so the month for the announcement is extracted and the announcement is inserted into the correct month, creating it if necessary.

func (*Announcements) Recent added in v1.5.0

func (a *Announcements) Recent(ctx context.Context, maxResults int, notBefore, start time.Time) (out *api.AnnouncementsReply, err error)

Recent returns the set of results whose post date is after the not before timestamp, limited to the maximum number of results. Last updated returns the timestamp that any announcement was added or changed.

func (*Announcements) SaveMonth added in v1.5.0

func (a *Announcements) SaveMonth(ctx context.Context, month *models.AnnouncementMonth) (err error)

Save a month, storing it in the database

type Collection added in v1.5.0

type Collection interface {
	Namespace() string
}

Collection is an interface that identifies utilities that manage specific namespaces.

type DB

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

DB is a wrapper around a trtl client to provide BFF-specific database interactions

func Connect

func Connect(conf config.DatabaseConfig) (db *DB, err error)

func DirectConnect

func DirectConnect(cc *grpc.ClientConn) (db *DB, err error)

func (*DB) Announcements added in v1.5.0

func (db *DB) Announcements() *Announcements

Announcements constructs the collection type for interactions with network announcement objects. This method is intended to be used with chaining, e.g. as db.Announcements().Recent(), so to reduce the number of allocations a singleton intermediate struct is used. Method calls to the collection are thread-safe.

func (*DB) Close

func (db *DB) Close() error

func (*DB) Delete added in v1.5.0

func (db *DB) Delete(ctx context.Context, key []byte, namespace string) (err error)

Delete is a high-level method for executing a delete key-value request to a namespace in trtl.

func (*DB) Get added in v1.5.0

func (db *DB) Get(ctx context.Context, key []byte, namespace string) (value []byte, err error)

Get is a high-level method for executing a fetch key request to a namespace in trtl.

func (*DB) Organizations added in v1.5.0

func (db *DB) Organizations() *Organizations

Organizations constructs the collection type for db interactions with the namespace. This method is intended to be used with chaining, e.g. db.Organizations().Get(id). To reduce the number of allocations a singleton is used. Method calls to the collection are thread-safe.

func (*DB) Put added in v1.5.0

func (db *DB) Put(ctx context.Context, key, value []byte, namespace string) (err error)

Put is a high-level method for executing a put value to key request to a namespace in trtl.

type Organizations added in v1.5.0

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

The Organizations collection exposes methods for interacting with Organization records in the database. Organizations are given UUIDs when created, and those uuids are also used as keys in the database for quick Gets by ID.

Organizations implements the Collection interface

func (*Organizations) Create added in v1.5.0

func (o *Organizations) Create(ctx context.Context) (org *models.Organization, err error)

Create an organization and get back the organization stub.

func (*Organizations) Delete added in v1.5.0

func (o *Organizations) Delete(ctx context.Context, orgID interface{}) (err error)

Delete an organization by it's ID, which can be either a []byte, string, or uuid.

func (*Organizations) Namespace added in v1.5.0

func (o *Organizations) Namespace() string

Namespace implements the collection interface

func (*Organizations) Retrieve added in v1.5.0

func (o *Organizations) Retrieve(ctx context.Context, orgID interface{}) (org *models.Organization, err error)

Retrieve an organization by it's ID, which can be either a []byte, string, or uuid.

func (*Organizations) Update added in v1.5.0

func (o *Organizations) Update(ctx context.Context, org *models.Organization) (err error)

Update an organization with the record supplied.

Directories

Path Synopsis
models
v1

Jump to

Keyboard shortcuts

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