models

package
v0.0.0-...-1775ad9 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseSession

func CloseSession(db HasSession)

CloseSession end the DB session

func EnsureStats

func EnsureStats(ctx context.Context, db HasSession) error

EnsureStats creates all stats related tables if they are missing

func EnsureUsers

func EnsureUsers(ctx context.Context, db HasSession) error

EnsureUsers creates all user related tables if they are missing

func OpenSession

func OpenSession(db HasSession, hosts []string) error

OpenSession creates a news db session and sets to HasSession interface

Types

type DB

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

DB stores the session and model methods are defined on it

func Connect

func Connect(hosts ...string) (*DB, error)

Connect opens a new DB session

func (*DB) Disconnect

func (db *DB) Disconnect()

Disconnect closes the db session

func (*DB) GetAllUserAccounts

func (db *DB) GetAllUserAccounts(ctx context.Context) <-chan *UserAccountWithError

GetAllUserAccounts returns all accounts for all users with a channel

func (*DB) GetSession

func (db *DB) GetSession() *gocql.Session

GetSession return session to satisfy HasSession interface

func (*DB) Init

func (db *DB) Init() error

Init creates missing tables and fills in default values

func (*DB) SetSession

func (db *DB) SetSession(session *gocql.Session) error

SetSession sets the session to satisfy HasSession interface

func (*DB) UpdateDailyRecord

func (db *DB) UpdateDailyRecord(ctx context.Context, portfolio *PortfolioValue) error

UpdateDailyRecord updates daily AVG, MAX, MIN records for portfolios

type DailyPortfolioStats

type DailyPortfolioStats struct {
	UserID      gocql.UUID
	AccountType string
	Date        string
	Avg         float64
	Last        float64
	Max         float64
	Min         float64
	N           int
}

DailyPortfolioStats contains main portfolio stats for a single day

type HasSession

type HasSession interface {
	SetSession(*gocql.Session) error
	GetSession() *gocql.Session
}

HasSession can store and return gocql session

type PortfolioValue

type PortfolioValue struct {
	UserID      gocql.UUID
	AccountType string
	Date        string
	Invested    float64
	Yield       float64
}

PortfolioValue contains total portfolio value with separate Invested and Yield fields

type UserAccount

type UserAccount struct {
	UserID      gocql.UUID
	AccountType string
	Token       string
}

UserAccount represents one of user's stocks account

type UserAccountWithError

type UserAccountWithError struct {
	Account *UserAccount
	Error   error
}

UserAccountWithError contains UserAccount bundled with an error

Jump to

Keyboard shortcuts

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