db

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDBConnection added in v1.2.0

func NewDBConnection(options PostgresOptions) (*sql.DB, func() error, error)

DO NOT use as a direct path to the database

use NewPostgresClientFromDBInstance right after

func WriteAppUsage

func WriteAppUsage(ctx context.Context, tx *sql.Tx, counts map[types.PortalAppPublicKey]api.RelayCounts) error

func WriteOriginUsage

func WriteOriginUsage(ctx context.Context, tx *sql.Tx, counts map[types.PortalAppOrigin]api.RelayCounts) error

Types

type PostgresClient

type PostgresClient interface {
	Reporter
	Writer
}

func NewPostgresClientFromDBInstance added in v0.0.48

func NewPostgresClientFromDBInstance(db *sql.DB) PostgresClient

type PostgresOptions

type PostgresOptions struct {
	Host       string
	User       string
	Password   string
	DB         string
	UsePrivate bool
}

type Reporter

type Reporter interface {
	// DailyUsage returns saved daily metrics for the specified time period, with each day being an entry in the results map
	DailyUsage(from time.Time, to time.Time) (map[time.Time]map[types.PortalAppPublicKey]api.RelayCounts, error)
	// TodaysUsage returns the metrics for today so far
	TodaysUsage() (map[types.PortalAppPublicKey]api.RelayCounts, error)
	TodaysOriginUsage() (map[types.PortalAppOrigin]api.RelayCounts, error)
	TodaysLatency() (map[types.PortalAppPublicKey][]api.Latency, error)
}

Will be implemented by Postgres DB interface

type Writer

type Writer interface {
	// TODO: rollover of entries
	WriteDailyUsage(counts map[time.Time]map[types.PortalAppPublicKey]api.RelayCounts, countsOrigin map[types.PortalAppOrigin]api.RelayCounts) error
	// WriteTodaysUsage writes todays relay counts to the underlying storage.
	WriteTodaysUsage(ctx context.Context, tx *sql.Tx, counts map[types.PortalAppPublicKey]api.RelayCounts, countsOrigin map[types.PortalAppOrigin]api.RelayCounts) error
	WriteTodaysMetrics(counts map[types.PortalAppPublicKey]api.RelayCounts, countsOrigin map[types.PortalAppOrigin]api.RelayCounts, latencies map[types.PortalAppPublicKey][]api.Latency) error
	// Returns oldest and most recent timestamps for stored metrics
	ExistingMetricsTimespan() (time.Time, time.Time, error)
}

Will be implemented by Postgres DB interface

Jump to

Keyboard shortcuts

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