model

package
v0.0.0-...-c4b29bc Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLimit int = 100

DefaultLimit is default limit

Variables

View Source
var DB *sqlx.DB

DB is db connection

Functions

func BalanceSheetStruct

func BalanceSheetStruct() *sqlbuilder.Struct

BalanceSheetStruct returns the BalanceSheet struct

func CashFlowStruct

func CashFlowStruct() *sqlbuilder.Struct

CashFlowStruct returns the CashFlow struct

func Count

func Count(m Model, wheres KV) (int, error)

Count counts records

func GetAll

func GetAll(ms Models) error

GetAll gets all records

func GetMany

func GetMany(ms Models, wheres KV, p Pagination, orderBys ...OrderBy) error

GetMany gets many records from db

func GetOne

func GetOne(m Model, wheres KV, orderBys ...OrderBy) error

GetOne gets one record from db

func HolderStruct

func HolderStruct() *sqlbuilder.Struct

HolderStruct returns the Holder struct

func HoldingStruct

func HoldingStruct() *sqlbuilder.Struct

HoldingStruct returns the Holding struct

func IndustryStruct

func IndustryStruct() *sqlbuilder.Struct

IndustryStruct returns the Industry struct

func InitDB

func InitDB(cfg *config.Config)

InitDB initializes db connections

func Insert

func Insert(m Model) (sql.Result, error)

Insert inserts a record

func MarketStruct

func MarketStruct() *sqlbuilder.Struct

MarketStruct returns the Market struct

func ProfitStatementStruct

func ProfitStatementStruct() *sqlbuilder.Struct

ProfitStatementStruct returns the ProfitStatement struct

func StockStruct

func StockStruct() *sqlbuilder.Struct

StockStruct returns the Stock struct

func Update

func Update(m Model, updates KV, wheres KV) (sql.Result, error)

Update updates records

Types

type BalanceSheet

type BalanceSheet struct {
	Code                string    `db:"code"`
	Date                time.Time `db:"date"`
	TotalAsset          float64   `db:"total_asset"`
	TotalLiability      float64   `db:"total_liability"`
	CurrentAsset        float64   `db:"current_asset"`
	NonCurrentAsset     float64   `db:"non_current_asset"`
	CurrentLiability    float64   `db:"current_liability"`
	NonCurrentLiability float64   `db:"non_current_liability"`
	OwnersEquity        float64   `db:"owners_equity"`
	Cash                float64   `db:"cash"`
	Receivable          float64   `db:"receivable"`
	Inventory           float64   `db:"inventory"`
	OtherCurrentAsset   float64   `db:"other_current_asset"`
	Goodwill            float64   `db:"goodwill"`
	Payable             float64   `db:"payable"`
	CreatedAt           time.Time `db:"created_at"`
	UpdatedAt           time.Time `db:"updated_at"`
}

BalanceSheet maps balance_sheet table

func (BalanceSheet) Columns

func (m BalanceSheet) Columns() []string

Columns returns the columns

func (BalanceSheet) DeleteBuilder

func (m BalanceSheet) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (BalanceSheet) InsertBuilder

func (m BalanceSheet) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (BalanceSheet) SelectBuilder

func (m BalanceSheet) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (BalanceSheet) TableName

func (m BalanceSheet) TableName() string

TableName returns the table name

func (BalanceSheet) UpdateBuilder

func (m BalanceSheet) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type BalanceSheets

type BalanceSheets []BalanceSheet

BalanceSheets is BalanceSheet list

func (BalanceSheets) SelectBuilder

func (ms BalanceSheets) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

type CashFlow

type CashFlow struct {
	Code              string    `db:"code"`
	Date              time.Time `db:"date"`
	OperatingInflow   float64   `db:"operating_inflow"`
	OperatingOutflow  float64   `db:"operating_outflow"`
	OperatingNet      float64   `db:"operating_net"`
	InvestmentInflow  float64   `db:"investment_inflow"`
	InvestmentOutflow float64   `db:"investment_outflow"`
	InvestmentNet     float64   `db:"investment_net"`
	FinancingInflow   float64   `db:"financing_inflow"`
	FinancingOutflow  float64   `db:"financing_outflow"`
	FinancingNet      float64   `db:"financing_net"`
	InitialBalance    float64   `db:"initial_balance"`
	EndingBalance     float64   `db:"ending_balance"`
	CreatedAt         time.Time `db:"created_at"`
	UpdatedAt         time.Time `db:"updated_at"`
}

CashFlow maps cash_flow table

func (CashFlow) Columns

func (m CashFlow) Columns() []string

Columns returns the columns

func (CashFlow) DeleteBuilder

func (m CashFlow) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (CashFlow) InsertBuilder

func (m CashFlow) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (CashFlow) SelectBuilder

func (m CashFlow) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (CashFlow) TableName

func (m CashFlow) TableName() string

TableName returns the table name

func (CashFlow) UpdateBuilder

func (m CashFlow) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type CashFlows

type CashFlows []CashFlow

CashFlows is CashFlow list

func (CashFlows) SelectBuilder

func (ms CashFlows) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

type Holder

type Holder struct {
	Code      string    `db:"code"`
	Name      string    `db:"name"`
	CreatedAt time.Time `db:"created_at"`
}

Holder maps Holder table

func (Holder) Columns

func (m Holder) Columns() []string

Columns returns the columns

func (Holder) DeleteBuilder

func (m Holder) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (Holder) InsertBuilder

func (m Holder) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (Holder) SelectBuilder

func (m Holder) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (Holder) TableName

func (m Holder) TableName() string

TableName returns the table name

func (Holder) UpdateBuilder

func (m Holder) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type Holders

type Holders []Holder

Holders is Holder list

func (Holders) SelectBuilder

func (ms Holders) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

type Holding

type Holding struct {
	HolderCode string    `db:"holder_code"`
	StockCode  string    `db:"stock_code"`
	Date       time.Time `db:"date"`
	Quantity   int64     `db:"quantity"`
	Ratio      float64   `db:"ratio"`
	CreatedAt  time.Time `db:"created_at"`
	UpdatedAt  time.Time `db:"updated_at"`
}

Holding maps Holding table

func (Holding) Columns

func (m Holding) Columns() []string

Columns returns the columns

func (Holding) DeleteBuilder

func (m Holding) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (Holding) InsertBuilder

func (m Holding) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (Holding) SelectBuilder

func (m Holding) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (Holding) TableName

func (m Holding) TableName() string

TableName returns the table name

func (Holding) UpdateBuilder

func (m Holding) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type Holdings

type Holdings []Holding

Holdings is Holding list

func (Holdings) SelectBuilder

func (ms Holdings) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

type Industries

type Industries []Industry

Industries is industry list

func (Industries) SelectBuilder

func (ms Industries) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

type Industry

type Industry struct {
	Code string `db:"code"`
	Name string `db:"name"`
}

Industry maps industry table

func (Industry) Columns

func (m Industry) Columns() []string

Columns returns the columns

func (Industry) DeleteBuilder

func (m Industry) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (Industry) InsertBuilder

func (m Industry) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (Industry) SelectBuilder

func (m Industry) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (Industry) TableName

func (m Industry) TableName() string

TableName returns the table name

func (Industry) UpdateBuilder

func (m Industry) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type KV

type KV map[string]interface{}

KV is a kev-value map

type Market

type Market struct {
	Code            string    `db:"code"`
	Date            time.Time `db:"date"`
	IssueVolume     int32     `db:"issue_volume"`
	MarketValue     float64   `db:"market_value"`
	NegotiableValue float64   `db:"negotiable_value"`
	TradeAmount     float64   `db:"amount"`
	PE              float64   `db:"pe"`
	TurnoverRate    float64   `db:"ex"`
	CreatedAt       time.Time `db:"created_at"`
	UpdatedAt       time.Time `db:"updated_at"`
}

Market maps market table

func (Market) Columns

func (m Market) Columns() []string

Columns returns the columns

func (Market) DeleteBuilder

func (m Market) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (Market) InsertBuilder

func (m Market) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (Market) SelectBuilder

func (m Market) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (Market) TableName

func (m Market) TableName() string

TableName returns the table name

func (Market) UpdateBuilder

func (m Market) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type Markets

type Markets []Market

Markets is Market list

func (*Markets) LastFiveYears

func (ms *Markets) LastFiveYears(wheres KV, p Pagination, orderBys ...OrderBy) error

LastFiveYears gets data in last five years

func (Markets) SelectBuilder

func (ms Markets) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

type Model

type Model interface {
	TableName() string
	Columns() []string
	InsertBuilder() *sqlbuilder.InsertBuilder
	SelectBuilder() *sqlbuilder.SelectBuilder
	UpdateBuilder() *sqlbuilder.UpdateBuilder
	DeleteBuilder() *sqlbuilder.DeleteBuilder
}

Model is the interface of db model

type Models

type Models interface {
	SelectBuilder() *sqlbuilder.SelectBuilder
}

Models is the interface of a set of Model

type OrderBy

type OrderBy struct {
	Column string
	Asc    bool // default is false which means DESC
}

OrderBy is ORDER BY in sql

type Pagination

type Pagination struct {
	Offset int
	Limit  int
}

Pagination is LIMIT and OFFSET in sql

func (*Pagination) GetLimit

func (p *Pagination) GetLimit() int

GetLimit returns a valid limit

func (*Pagination) GetOffset

func (p *Pagination) GetOffset() int

GetOffset returns a valid offset

type ProfitStatement

type ProfitStatement struct {
	Code                    string    `db:"code"`
	Date                    time.Time `db:"date"`
	Income                  float64   `db:"income"`
	Cost                    float64   `db:"cost"`
	OperatingCost           float64   `db:"operating_cost"`
	SellingExpense          float64   `db:"selling_expense"`
	AdminExpense            float64   `db:"admin_expense"`
	FinancialExpense        float64   `db:"financial_expense"`
	OperatingProfit         float64   `db:"operating_profit"`
	TotalProfit             float64   `db:"total_profit"`
	NetProfit               float64   `db:"net_profit"`
	OtherConsolidatedIncome float64   `db:"other_consolidated_income"`
	TotalConsolidatedIncome float64   `db:"total_consolidated_income"`
	CreatedAt               time.Time `db:"created_at"`
	UpdatedAt               time.Time `db:"updated_at"`
}

ProfitStatement maps profit_statement table

func (ProfitStatement) Columns

func (m ProfitStatement) Columns() []string

Columns returns the columns

func (ProfitStatement) DeleteBuilder

func (m ProfitStatement) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (ProfitStatement) InsertBuilder

func (m ProfitStatement) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (ProfitStatement) SelectBuilder

func (m ProfitStatement) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (ProfitStatement) TableName

func (m ProfitStatement) TableName() string

TableName returns the table name

func (ProfitStatement) UpdateBuilder

func (m ProfitStatement) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type ProfitStatements

type ProfitStatements []ProfitStatement

ProfitStatements is ProfitStatement list

func (ProfitStatements) SelectBuilder

func (ms ProfitStatements) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

type Result

type Result struct {
	Inserted bool
	Updated  bool
}

Result shows whether insertion or update is excuted

func UpdateOrInsert

func UpdateOrInsert(m Model, updates KV, wheres KV) (Result, error)

UpdateOrInsert updates record or inserts new record if it does not exist

type Stock

type Stock struct {
	Code            string    `db:"code"`
	Name            string    `db:"name"`
	MarketValue     float64   `db:"market_value"`
	NegotiableValue float64   `db:"negotiable_value"`
	OpeningPrice    float64   `db:"open"`
	ClosingPrice    float64   `db:"close"`
	BottomPrice     float64   `db:"low"`
	TopPrice        float64   `db:"high"`
	LastPrice       float64   `db:"last"`
	ChangeRate      float64   `db:"rate"`
	TurnoverRate    float64   `db:"ex"`
	TradeAmount     float64   `db:"amount"`
	TradeVolume     int64     `db:"volume"`
	PB              float64   `db:"pb"`
	PE              float64   `db:"pe"`
	IndustryCode    string    `db:"industry_code"`
	CreatedAt       time.Time `db:"created_at"`
	UpdatedAt       time.Time `db:"updated_at"`
}

Stock maps stock table

func (Stock) Columns

func (m Stock) Columns() []string

Columns returns the columns

func (Stock) DeleteBuilder

func (m Stock) DeleteBuilder() *sqlbuilder.DeleteBuilder

DeleteBuilder returns a delete builder

func (Stock) GetIndustryName

func (m Stock) GetIndustryName() string

GetIndustryName gets industry name

func (Stock) InsertBuilder

func (m Stock) InsertBuilder() *sqlbuilder.InsertBuilder

InsertBuilder returns an insert builder

func (Stock) SelectBuilder

func (m Stock) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

func (Stock) TableName

func (m Stock) TableName() string

TableName returns the table name

func (Stock) UpdateBuilder

func (m Stock) UpdateBuilder() *sqlbuilder.UpdateBuilder

UpdateBuilder returns an update builder

type Stocks

type Stocks []Stock

Stocks is stock list

func (Stocks) SelectBuilder

func (ms Stocks) SelectBuilder() *sqlbuilder.SelectBuilder

SelectBuilder returns a select builder

Jump to

Keyboard shortcuts

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