CovenantSQL: github.com/CovenantSQL/CovenantSQL/api/models Index | Files

package models

import "github.com/CovenantSQL/CovenantSQL/api/models"

Index

Package Files

blocks.go models.go pagination.go transactions.go utils.go

func InitModels Uses

func InitModels(dbFile string) error

InitModels setup the models package.

func OpenSQLiteDBAsGorp Uses

func OpenSQLiteDBAsGorp(dbFile, mode string, maxOpen, maxIdle int) (db *gorp.DbMap, err error)

OpenSQLiteDBAsGorp opens a sqlite database an wrapped it in gorp.DbMap.

type Block Uses

type Block struct {
    Height         int       `db:"height" json:"height"` // pk
    Hash           string    `db:"hash" json:"hash"`
    Timestamp      int64     `db:"timestamp" json:"timestamp"`
    TimestampHuman time.Time `db:"-" json:"timestamp_human"`
    Version        int32     `db:"version"  json:"version"`
    Producer       string    `db:"producer" json:"producer"`
    MerkleRoot     string    `db:"merkle_root" json:"merkle_root"`
    Parent         string    `db:"parent" json:"parent"`
    TxCount        int       `db:"tx_count" json:"tx_count"`
}

Block is a block.

func (*Block) PostGet Uses

func (b *Block) PostGet(s gorp.SqlExecutor) error

PostGet is the hook after SELECT query.

type BlocksModel Uses

type BlocksModel struct{}

BlocksModel groups operations on Blocks.

func (*BlocksModel) GetBlockByHash Uses

func (m *BlocksModel) GetBlockByHash(hash string) (block *Block, err error)

GetBlockByHash get a block by its hash.

func (*BlocksModel) GetBlockByHeight Uses

func (m *BlocksModel) GetBlockByHeight(height int) (block *Block, err error)

GetBlockByHeight get a block by its height.

func (*BlocksModel) GetBlockList Uses

func (m *BlocksModel) GetBlockList(since, page, size int) (blocks []*Block, pagination *Pagination, err error)

GetBlockList get a list of blocks with height in [from, to).

type Pagination Uses

type Pagination struct {
    Page  int `json:"page"`
    Size  int `json:"size"`
    Total int `json:"total"`
    Pages int `json:"pages"`
    // contains filtered or unexported fields
}

Pagination holds paging info for list like API.

func NewPagination Uses

func NewPagination(page, size int, opts ...PaginationOpt) *Pagination

NewPagination creates a new Pagination.

func (*Pagination) Limit Uses

func (p *Pagination) Limit() int

Limit returns the page size. Attened to be used in SQL statements.

func (*Pagination) Offset Uses

func (p *Pagination) Offset() int

Offset returns the size of skipped items of current page. Attened to be used in SQL statements.

func (*Pagination) SetPage Uses

func (p *Pagination) SetPage(page int)

SetPage update current page index.

func (*Pagination) SetSize Uses

func (p *Pagination) SetSize(size int)

SetSize update page size.

func (*Pagination) SetTotal Uses

func (p *Pagination) SetTotal(total int)

SetTotal update the total records.

type PaginationOpt Uses

type PaginationOpt func(*Pagination)

PaginationOpt represents extra pagination options to apply.

func WithDefaultSize Uses

func WithDefaultSize(size int) PaginationOpt

WithDefaultSize set pagination default size.

type Transaction Uses

type Transaction struct {
    BlockHeight    int         `db:"block_height" json:"block_height"` // pk1
    TxIndex        int         `db:"tx_index" json:"index"`            // pk2
    Hash           string      `db:"hash" json:"hash"`
    BlockHash      string      `db:"block_hash" json:"block_hash"`
    Timestamp      int64       `db:"timestamp" json:"timestamp"`
    TimestampHuman time.Time   `db:"-" json:"timestamp_human"`
    TxType         int         `db:"tx_type" json:"type"`
    Address        string      `db:"address" json:"address"`
    Raw            string      `db:"raw" json:"raw"`
    Tx             interface{} `db:"-" json:"tx"`
}

Transaction is a transaction.

func (*Transaction) PostGet Uses

func (tx *Transaction) PostGet(s gorp.SqlExecutor) error

PostGet is the hook after SELECT query.

type TransactionsModel Uses

type TransactionsModel struct{}

TransactionsModel groups operations on Transactions.

func (*TransactionsModel) GetTransactionByHash Uses

func (m *TransactionsModel) GetTransactionByHash(hash string) (tx *Transaction, err error)

GetTransactionByHash get a transaction by its hash.

func (*TransactionsModel) GetTransactionList Uses

func (m *TransactionsModel) GetTransactionList(since string, page, size int) (
    txs []*Transaction, pagination *Pagination, err error,
)

GetTransactionList get a transaction list by hash marker.

func (*TransactionsModel) GetTransactionListOfBlock Uses

func (m *TransactionsModel) GetTransactionListOfBlock(ofBlockHeight int, page, size int) (
    txs []*Transaction, pagination *Pagination, err error,
)

GetTransactionListOfBlock get a transaction list of block.

Package models imports 10 packages (graph) and is imported by 2 packages. Updated 2019-01-24. Refresh now. Tools for package owners.