database

package
v0.0.0-...-48972bb Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableEffects       = "effects"
	TableLedgerheaders = "ledgerheaders"
	TableActions       = "actions"
	TableTransactions  = "transactions"
)
View Source
const (
	DBTypeSQLite3 = "sqlite3"
	DBTypeMySQL   = "mysql" // use it or not, who knows
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	ActionID    uint64         `db:"actionid"`
	Typei       int            `db:"typei"`
	Type        string         `db:"type"`
	LedgerSeq   string         `db:"ledgerseq"`
	TxHash      string         `db:"txhash"`
	FromAccount sql.NullString `db:"fromaccount"`
	ToAccount   sql.NullString `db:"toaccount"`
	CreateAt    uint64         `db:"createat"`
	JData       string         `db:"jdata"`
}

Action object for db

type Database

type Database interface {
	Init(dbname string, cfg *config.Config, logger *zap.Logger) error
	Close()
	GetInitSQLs() (qt, qi []string)
	PrepareTables(ctsqls, cisqls []string) error

	Insert(table string, fields []Feild) (sql.Result, error)
	Delete(table string, where []Where) (sql.Result, error)
	Update(table string, toupdate []Feild, where []Where) (sql.Result, error)
	SelectRows(table string, where []Where, order *Order, paging *Paging, result interface{}) error
	SelectRowsOffset(table string, where []Where, order *Order, offset, limit uint64, result interface{}) error
	SelectRawSQL(table string, sqlStr string, values []interface{}, result interface{}) error
	SelectRowsUnion(table string, wheres [][]Where, order *Order, paging *Paging, result interface{}) error
	Excute(stmt *sql.Stmt, fields []Feild) (sql.Result, error)
	Prepare(table string, fields []Feild) (*sql.Stmt, error)

	Begin() error
	Commit() error
	Rollback() error
}

Database interface for delos app database-operation

type Effect

type Effect struct {
	EffectID  uint64 `db:"effectid"`
	Typei     int    `db:"typei"`
	Type      string `db:"type"`
	LedgerSeq string `db:"ledgerseq"`
	TxHash    string `db:"txhash"`
	ActionID  uint64 `db:"actionid"`
	Account   string `db:"account"`
	CreateAt  uint64 `db:"createat"`
	JData     string `db:"jdata"`
}

Effect object for db

type Feild

type Feild struct {
	Name  string
	Value interface{}
}

Feild database field

type LedgerHeader

type LedgerHeader struct {
	LedgerID         uint64    `db:"ledgerid"`
	Sequence         string    `db:"sequence"`
	Hash             string    `db:"hash"`
	PrevHash         string    `db:"prevhash"`
	StateRoot        string    `db:"stateroot"`
	TransactionCount uint64    `db:"transactioncount"`
	OperactionCount  uint64    `db:"operactioncount"`
	ClosedAt         time.Time `db:"closedat"`
	TotalCoins       string    `db:"totalcoins"`
	FeePool          string    `db:"feepool"`
	BaseFee          string    `db:"basefee"`
	BaseReserve      string    `db:"basereserve"`
	InflationSeq     uint64    `db:"inflationseq"`
	MaxTxSetSize     uint64    `db:"maxtxsetsize"`
}

LedgerHeader object for db

type Order

type Order struct {
	Type   string   // "asc" or "desc"
	Feilds []string // order by x
}

Order used to identify query order

func MakeOrder

func MakeOrder(ordertype string, fields ...string) (*Order, error)

MakeOrder make a order object

func (*Order) GetOp

func (o *Order) GetOp() string

GetOp used in sql

type Paging

type Paging struct {
	CursorName  string // cursor column
	CursorValue uint64 // cursor column
	Limit       uint64 // limit
}

func MakePaging

func MakePaging(colName string, colValue uint64, limit uint64) *Paging

MakePaging make a paging object

type TxData

type TxData struct {
	TxID        uint64 `db:"txid"`
	TxHash      string `db:"txhash"`
	BlockHeight uint64 `db:"blockheight"`
	BlockHash   string `db:"blockhash"`
	ActionCount uint32 `db:"actioncount"`
	ActionID    uint32 `db:"actionid"`
	Src         string `db:"src"`
	Dst         string `db:"dst"`
	Nonce       uint64 `db:"nonce"`
	Amount      string `db:"amount"`
	ResultCode  uint   `db:"resultcode"`
	ResultMsg   string `db:"resultmsg"`
	CreateAt    uint64 `db:"createdat"`
	JData       string `db:"jdata"`
	Memo        string `db:"memo"`
}

TxData object for db

type Where

type Where struct {
	Name  string
	Value interface{}
	Op    string // can be =、>、<、<> and any operator supported by sql-database
}

Where query field

func (*Where) GetOp

func (w *Where) GetOp() string

GetOp get operator of current where clause, default =

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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