reporting

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureCategory

func EnsureCategory(ctx context.Context, tx *sqlx.Tx, cat *db.Category) (*db.Category, error)

func EnsureDateTime

func EnsureDateTime(ctx context.Context, tx *sqlx.Tx, dt *db.DateTime) (*db.DateTime, error)

func EnsureDiscount

func EnsureDiscount(ctx context.Context, tx *sqlx.Tx, ensureDiscount *db.Discount) (*db.Discount, error)

func EnsureFact

func EnsureFact(ctx context.Context, tx *sqlx.Tx, ensureFact *db.Fact) (*db.Fact, error)

func EnsureProduct

func EnsureProduct(ctx context.Context, tx *sqlx.Tx, ensureProduct *db.Product) (*db.Product, error)

func EnsureQuery

func EnsureQuery(ctx context.Context, tx *sqlx.Tx, ensureQuery *db.Query) (*db.Query, error)

func EnsureTenant

func EnsureTenant(ctx context.Context, tx *sqlx.Tx, ensureTenant *db.Tenant) (*db.Tenant, error)

func GetBestMatchingDiscount

func GetBestMatchingDiscount(ctx context.Context, tx *sqlx.Tx, source string, timestamp time.Time) (*db.Discount, error)

func GetBestMatchingProduct

func GetBestMatchingProduct(ctx context.Context, tx *sqlx.Tx, source string, timestamp time.Time) (*db.Product, error)

func GetByFact

func GetByFact(ctx context.Context, tx *sqlx.Tx, fact *db.Fact) (*db.Fact, error)

func GetCategory

func GetCategory(ctx context.Context, tx *sqlx.Tx, source string) (*db.Category, error)

func GetDateTime

func GetDateTime(ctx context.Context, tx *sqlx.Tx, timestamp time.Time) (*db.DateTime, error)

func GetQueryByName

func GetQueryByName(ctx context.Context, tx *sqlx.Tx, name string) (*db.Query, error)

func GetTenantBySource

func GetTenantBySource(ctx context.Context, tx *sqlx.Tx, source string) (*db.Tenant, error)

func NewDateTime

func NewDateTime(timestamp time.Time) *db.DateTime

func NewFact

func NewFact(dateTime *db.DateTime, query *db.Query, tenant *db.Tenant, category *db.Category, product *db.Product, discount *db.Discount, quanity float64) *db.Fact

Types

type Record

type Record struct {
	TenantSource   string
	CategorySource string
	BillingDate    time.Time
	ProductSource  string
	DiscountSource string
	QueryName      string
	Value          float64
}

type Store

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

func NewStore

func NewStore(url string, logger logr.Logger) (*Store, error)

NewStore opens up a db connection to the specified db.

func (*Store) Close

func (r *Store) Close() error

Close the db connection.

func (*Store) Initialize

func (r *Store) Initialize(ctx context.Context, products []*db.Product, discounts []*db.Discount, queries []*db.Query) error

Initialize uses a transaction to ensure given entities in reporting store.

func (*Store) WithTransaction

func (r *Store) WithTransaction(ctx context.Context, fn func(*sqlx.Tx) error) error

WithTransaction runs fn within a transaction and does commit/rollback when necessary.

func (*Store) WriteRecord

func (r *Store) WriteRecord(ctx context.Context, record Record) error

type TokenizedSource

type TokenizedSource struct {
	Tokens []string
}

Does not do much, we mostly have this to make the code more readable (better than 2D string arrays)

func FindBestMatchingTokenizedSource

func FindBestMatchingTokenizedSource(reference *TokenizedSource, candidates []*TokenizedSource) *TokenizedSource

func NewTokenizedSource

func NewTokenizedSource(source string) *TokenizedSource

func (*TokenizedSource) Equals

func (ts *TokenizedSource) Equals(other *TokenizedSource) bool

func (TokenizedSource) String

func (ts TokenizedSource) String() string

Jump to

Keyboard shortcuts

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