db

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Collector prometheus.Collector

	Handle *sqlx.DB
	// contains filtered or unexported fields
}

DB hold the handle to a database. Provides a Prometheus DBStatsCollector to monitor DB connections

func New

func New(cfg configuration.PostgresDB) (*DB, error)

New creates a new DB connector

func (*DB) RemoveAll added in v1.2.0

func (db *DB) RemoveAll() error

RemoveAll deletes all database tables

type PGCovidStore added in v1.2.0

type PGCovidStore struct {
	DB *DB
}

PGCovidStore implements CovidStore for Postgres databases

func NewCovidStore added in v1.2.0

func NewCovidStore(db *DB) *PGCovidStore

NewCovidStore creates a new PGCovidStore and initializes the database, if necessary

func (*PGCovidStore) Add added in v1.2.0

func (store *PGCovidStore) Add(entries []models.CountryEntry) error

Add inserts new entries in the database

func (*PGCovidStore) CountEntriesByTime added in v1.2.0

func (store *PGCovidStore) CountEntriesByTime(from, to time.Time) ([]TimestampCount, error)

CountEntriesByTime counts updates per timestamp

func (*PGCovidStore) GetAllCountryNames added in v1.2.0

func (store *PGCovidStore) GetAllCountryNames() (names []string, err error)

GetAllCountryNames gets all unique country names from the database

func (*PGCovidStore) GetAllForCountryName added in v1.2.0

func (store *PGCovidStore) GetAllForCountryName(countryName string) ([]models.CountryEntry, error)

GetAllForCountryName returns all entries in the database, sorted by timestamp

func (*PGCovidStore) GetAllForRange added in v1.2.0

func (store *PGCovidStore) GetAllForRange(from, to time.Time) ([]models.CountryEntry, error)

GetAllForRange returns all entries in the database, sorted by timestamp

func (*PGCovidStore) GetLatestForCountries added in v1.2.0

func (store *PGCovidStore) GetLatestForCountries(endTime time.Time) (map[string]models.CountryEntry, error)

GetLatestForCountries gets the last entries for each country up the specified endTime. If endTime is time.Time{}, it will get the latest entries up to the current time.

func (*PGCovidStore) GetTotalsPerDay added in v1.2.0

func (store *PGCovidStore) GetTotalsPerDay() ([]models.CountryEntry, error)

GetTotalsPerDay returns the total new cases per day across all countries

func (*PGCovidStore) Rows added in v1.3.1

func (store *PGCovidStore) Rows() (int, error)

Rows returns the number of rows in the store

type PGPopulationStore added in v1.2.0

type PGPopulationStore struct {
	DB *DB
}

PGPopulationStore implements PopulationStore for Postgres databases

func NewPopulationStore added in v1.2.0

func NewPopulationStore(db *DB) *PGPopulationStore

NewPopulationStore creates a new PostgresDB object

func (*PGPopulationStore) Add added in v1.2.0

func (store *PGPopulationStore) Add(code string, pop int64) error

Add to Population database table. If a record for the specified country code already exists, it will be updated

func (*PGPopulationStore) List added in v1.2.0

func (store *PGPopulationStore) List() (map[string]int64, error)

List all records from the Population table

type TimestampCount added in v1.3.3

type TimestampCount struct {
	Timestamp time.Time
	Count     int
}

Jump to

Keyboard shortcuts

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