models

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// LedgerTimestampLayout is the timestamp layout followed in Ledger
	LedgerTimestampLayout = "2006-01-02 15:04:05.000"
)

Variables

View Source
var (
	// SearchNamespaceAccounts holds search namespace of accounts
	SearchNamespaceAccounts = "accounts"
	// SearchNamespaceTransactions holds search namespace of transactions
	SearchNamespaceTransactions = "transactions"
	// SortDescByTime option sorts search items in descending order of time
	SortDescByTime = "desc"
	// SortAscByTime option sorts search items in ascending order of time
	SortAscByTime = "asc"
)

Functions

func DBError

func DBError(err error) errors.ApplicationError

DBError returns db error type

func JSONError

func JSONError(err error) errors.ApplicationError

JSONError returns invalid json error type

func SearchNamespaceInvalidError

func SearchNamespaceInvalidError(namespace string) errors.ApplicationError

SearchNamespaceInvalidError returns invalid search namespace error type

func SearchQueryInvalidError

func SearchQueryInvalidError(err error) errors.ApplicationError

SearchQueryInvalidError returns invalid search query error type

Types

type Account

type Account struct {
	ID      string                 `json:"id"`
	Balance int                    `json:"balance"`
	Data    map[string]interface{} `json:"data"`
}

Account represents the ledger account with information such as ID, balance and JSON data

type AccountDB

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

AccountDB provides all functions related to ledger account

func NewAccountDB

func NewAccountDB(db *sql.DB) AccountDB

NewAccountDB provides instance of `AccountDB`

func (*AccountDB) CreateAccount

func (a *AccountDB) CreateAccount(account *Account) ledgerError.ApplicationError

CreateAccount creates a new account in the ledger

func (*AccountDB) GetByID

GetByID returns an acccount with the given ID

func (*AccountDB) IsExists

func (a *AccountDB) IsExists(id string) (bool, ledgerError.ApplicationError)

IsExists says whether an account exists or not

func (*AccountDB) UpdateAccount

func (a *AccountDB) UpdateAccount(account *Account) ledgerError.ApplicationError

UpdateAccount updates the account with new data

type AccountResult

type AccountResult struct {
	ID      string          `json:"id"`
	Balance int             `json:"balance"`
	Data    json.RawMessage `json:"data"`
}

AccountResult represents the response format of accounts

type OrderedLines added in v1.2.0

type OrderedLines []*TransactionLine

OrderedLines implements sort.Interface for []*TransactionLine based on the AccountID and Delta fields.

func (OrderedLines) Len added in v1.2.0

func (lines OrderedLines) Len() int

func (OrderedLines) Less added in v1.2.0

func (lines OrderedLines) Less(i, j int) bool

func (OrderedLines) Swap added in v1.2.0

func (lines OrderedLines) Swap(i, j int)

type QueryContainer

type QueryContainer struct {
	Fields     []map[string]map[string]interface{} `json:"fields"`
	Terms      []map[string]interface{}            `json:"terms"`
	RangeItems []map[string]map[string]interface{} `json:"ranges"`
}

QueryContainer represents the format of query subsection inside `must` or `should`

type SearchEngine

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

SearchEngine is the interface for all search operations

func NewSearchEngine

func NewSearchEngine(db *sql.DB, namespace string) (*SearchEngine, ledgerError.ApplicationError)

NewSearchEngine returns a new instance of `SearchEngine`

func (*SearchEngine) Query

func (engine *SearchEngine) Query(q string) (interface{}, ledgerError.ApplicationError)

Query returns the results of a searc query

type SearchRawQuery

type SearchRawQuery struct {
	Offset   int    `json:"from,omitempty"`
	Limit    int    `json:"size,omitempty"`
	SortTime string `json:"sort_time,omitempty"`
	Query    struct {
		MustClause   QueryContainer `json:"must"`
		ShouldClause QueryContainer `json:"should"`
	} `json:"query"`
}

SearchRawQuery represents the format of search query

func NewSearchRawQuery

func NewSearchRawQuery(q string) (*SearchRawQuery, ledgerError.ApplicationError)

NewSearchRawQuery returns a new instance of `SearchRawQuery`

func (*SearchRawQuery) ToSQLQuery

func (rawQuery *SearchRawQuery) ToSQLQuery(namespace string) *SearchSQLQuery

ToSQLQuery converts a raw search query to SQL format of the same

type SearchSQLQuery

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

SearchSQLQuery hold information of search SQL query

type Transaction

type Transaction struct {
	ID        string                 `json:"id"`
	Data      map[string]interface{} `json:"data"`
	Timestamp string                 `json:"timestamp"`
	Lines     []*TransactionLine     `json:"lines"`
}

Transaction represents a transaction in a ledger

func (*Transaction) IsValid

func (t *Transaction) IsValid() bool

IsValid validates the delta list of a transaction

type TransactionDB

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

TransactionDB is the interface to all transaction operations

func NewTransactionDB

func NewTransactionDB(db *sql.DB) TransactionDB

NewTransactionDB returns a new instance of `TransactionDB`

func (*TransactionDB) IsConflict

func (t *TransactionDB) IsConflict(transaction *Transaction) (bool, ledgerError.ApplicationError)

IsConflict says whether a transaction conflicts with an existing transaction

func (*TransactionDB) IsExists

IsExists says whether a transaction already exists or not

func (*TransactionDB) Transact

func (t *TransactionDB) Transact(txn *Transaction) bool

Transact creates the input transaction in the DB

func (*TransactionDB) UpdateTransaction

func (t *TransactionDB) UpdateTransaction(txn *Transaction) ledgerError.ApplicationError

UpdateTransaction updates data of the given transaction

type TransactionLine

type TransactionLine struct {
	AccountID string `json:"account"`
	Delta     int    `json:"delta"`
}

TransactionLine represents a transaction line in a ledger

type TransactionLineResult

type TransactionLineResult struct {
	AccountID string `json:"account"`
	Delta     int    `json:"delta"`
}

TransactionLineResult represents the response format of transaction lines

type TransactionResult

type TransactionResult struct {
	ID        string                   `json:"id"`
	Timestamp string                   `json:"timestamp"`
	Data      json.RawMessage          `json:"data"`
	Lines     []*TransactionLineResult `json:"lines"`
}

TransactionResult represents the response format of transactions

Jump to

Keyboard shortcuts

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