index_i

package
v0.0.0-...-aeb4a1d Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package index allows for creating indices in the state database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPrettyLedgerKey

func GetPrettyLedgerKey(ledgerKey string) string

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

func (t *Table) AddIndex(keys []string, updateAllRows bool) error

AddIndex adds the specified index to the table. If updateAllRows is true, updates all rows in the table.

func (*Table) CreateRangeKey

func (t *Table) CreateRangeKey(fieldNames []string, fieldValues []string) (string, error)

CreateRangeKey creates a simple key for calling GetRowsByRange.

func (*Table) DeleteRow

func (t *Table) DeleteRow(id string) error

DeleteRow removes the row specified by id from the table.

func (*Table) GetIndexedFields

func (t *Table) GetIndexedFields() []string

GetIndexedFields returns a list of fields that have been indexed for this table.

func (*Table) GetPrimaryKeyId

func (t *Table) GetPrimaryKeyId() string

GetPrimaryKeyId returns the name of the field that is treated as the primary key of this table ("id" by default).

func (*Table) GetRow

func (t *Table) GetRow(id string) ([]byte, error)

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) HasIndex

func (t *Table) HasIndex(keys []string) bool

HasIndex returns true if table has the specified index, false otherwise.

func (*Table) SaveToLedger

func (t *Table) SaveToLedger() error

SaveToLedger saves the table to the ledger.

func (*Table) UpdateAllRows

func (t *Table) UpdateAllRows() error

UpdateAllRows updates index values for all rows in the table.

func (*Table) UpdateRow

func (t *Table) UpdateRow(keys map[string]string) error

UpdateRow updates index values for a row in the table.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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