Documentation
¶
Overview ¶
Package index allows for creating indices in the state database.
Index ¶
- func GetPrettyLedgerKey(ledgerKey string) string
- func GetTable(stub cached_stub.CachedStubInterface, name string, options ...interface{}) table_interface.Table
- func Init(stub cached_stub.CachedStubInterface, logLevel ...shim.LoggingLevel) ([]byte, error)
- type Table
- func (t *Table) AddIndex(keys []string, updateAllRows bool) error
- func (t *Table) CreateRangeKey(fieldNames []string, fieldValues []string) (string, error)
- func (t *Table) DeleteRow(id string) error
- func (t *Table) GetIndexedFields() []string
- func (t *Table) GetPrimaryKeyId() string
- func (t *Table) GetRow(id string) ([]byte, error)
- func (t *Table) GetRowsByPartialKey(fieldNames []string, fieldValues []string) (shim.StateQueryIteratorInterface, error)
- func (t *Table) GetRowsByRange(startKey string, endKey string) (shim.StateQueryIteratorInterface, error)
- func (t *Table) HasIndex(keys []string) bool
- func (t *Table) SaveToLedger() error
- func (t *Table) UpdateAllRows() error
- func (t *Table) UpdateRow(keys map[string]string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPrettyLedgerKey ¶
GetPrettyLedgerKey is to be used for debug print statements only! Replaces global.MIN_UNICODE_RUNE_VALUE with "_" and global.MAX_UNICODE_RUNE_VALUE with "*". Composite keys are also prefixed with a global.MIN_UNICODE_RUNE_VALUE.
func GetTable ¶
func GetTable(stub cached_stub.CachedStubInterface, name string, options ...interface{}) table_interface.Table
GetTable returns the table from the ledger or creates a new one. name is the name of the index table. Note: All options are ignored if table already exist since you won't be able to change the options once the table is already created. options[0] is the name of the index field that will be used to uniquely identify a row in the table. If not provided, the table's primaryKeyId is set to "id". options[1] indicates whether to useTree or not. Default value is false. options[2] indicates whether to encrypt index or not. Default value is true. options[3] datastoreID. if specified it will store index data to off-chain datastore
func Init ¶
func Init(stub cached_stub.CachedStubInterface, logLevel ...shim.LoggingLevel) ([]byte, error)
Init sets up the index package.
Types ¶
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents an index table for querying items (represented by rows).
Note that the primary key must be unique for all assets in the table. For example, user_name can be an indexed field but not a primary key because user_name might have duplicates. But user_id can be the primary key.
func (*Table) AddIndex ¶
AddIndex adds the specified index to the table. If updateAllRows is true, updates all rows in the table.
func (*Table) CreateRangeKey ¶
CreateRangeKey creates a simple key for calling GetRowsByRange.
func (*Table) GetIndexedFields ¶
GetIndexedFields returns a list of fields that have been indexed for this table.
func (*Table) GetPrimaryKeyId ¶
GetPrimaryKeyId returns the name of the field that is treated as the primary key of this table ("id" by default).
func (*Table) GetRow ¶
GetRow returns the row specified by id from the table. Note that only field you will get in a row is the primaryID field.
func (*Table) GetRowsByPartialKey ¶
func (t *Table) GetRowsByPartialKey(fieldNames []string, fieldValues []string) (shim.StateQueryIteratorInterface, error)
GetRowsByPartialKey returns an iterator over a set of rows in this table. The iterator can be used to iterate over all rows that satisfy the provided index values. Note: sort order is disabled if index is encrypted
func (*Table) GetRowsByRange ¶
func (t *Table) GetRowsByRange(startKey string, endKey string) (shim.StateQueryIteratorInterface, error)
GetRowsByRange returns a range iterator over a set of rows in this table. The iterator can be used to iterate over all rows between the startKey (inclusive) and endKey (exclusive). The rows are returned by the iterator in lexical order. Note that startKey and endKey can be empty strings, which implies an unbounded range query at start or end. GetRowsByRange is not allowed if index is encrypted (if table's isEncrypted = true).
func (*Table) SaveToLedger ¶
SaveToLedger saves the table to the ledger.
func (*Table) UpdateAllRows ¶
UpdateAllRows updates index values for all rows in the table.