Documentation ¶
Index ¶
- Constants
- Variables
- func DBError(err error) errors.ApplicationError
- func JSONError(err error) errors.ApplicationError
- func SearchNamespaceInvalidError(namespace string) errors.ApplicationError
- func SearchQueryInvalidError(err error) errors.ApplicationError
- type Account
- type AccountDB
- func (a *AccountDB) CreateAccount(account *Account) ledgerError.ApplicationError
- func (a *AccountDB) GetByID(id string) (*Account, ledgerError.ApplicationError)
- func (a *AccountDB) IsExists(id string) (bool, ledgerError.ApplicationError)
- func (a *AccountDB) UpdateAccount(account *Account) ledgerError.ApplicationError
- type AccountResult
- type OrderedLines
- type QueryContainer
- type SearchEngine
- type SearchRawQuery
- type SearchSQLQuery
- type Transaction
- type TransactionDB
- func (t *TransactionDB) IsConflict(transaction *Transaction) (bool, ledgerError.ApplicationError)
- func (t *TransactionDB) IsExists(id string) (bool, ledgerError.ApplicationError)
- func (t *TransactionDB) Transact(txn *Transaction) bool
- func (t *TransactionDB) UpdateTransaction(txn *Transaction) ledgerError.ApplicationError
- type TransactionLine
- type TransactionLineResult
- type TransactionResult
Constants ¶
const (
// LedgerTimestampLayout is the timestamp layout followed in Ledger
LedgerTimestampLayout = "2006-01-02 15:04:05.000"
)
Variables ¶
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 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 ¶
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 ¶
func (a *AccountDB) GetByID(id string) (*Account, ledgerError.ApplicationError)
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 ¶
func (t *TransactionDB) IsExists(id string) (bool, ledgerError.ApplicationError)
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 ¶
TransactionLine represents a transaction line in a ledger
type TransactionLineResult ¶
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