Documentation ¶
Index ¶
- Constants
- Variables
- func PairKeyCodec[K1, K2 any](keyCodec1 codec.KeyCodec[K1], keyCodec2 codec.KeyCodec[K2]) codec.KeyCodec[Pair[K1, K2]]
- type Index
- type IndexedMap
- func (m *IndexedMap[PrimaryKey, Value, Idx]) Get(ctx context.Context, pk PrimaryKey) (Value, error)
- func (m *IndexedMap[PrimaryKey, Value, Idx]) Has(ctx context.Context, pk PrimaryKey) (bool, error)
- func (m *IndexedMap[PrimaryKey, Value, Idx]) Iterate(ctx context.Context, ranger Ranger[PrimaryKey]) (Iterator[PrimaryKey, Value], error)
- func (m *IndexedMap[PrimaryKey, Value, Idx]) IterateRaw(ctx context.Context, start, end []byte, order Order) (Iterator[PrimaryKey, Value], error)
- func (m *IndexedMap[PrimaryKey, Value, Idx]) KeyCodec() codec.KeyCodec[PrimaryKey]
- func (m *IndexedMap[PrimaryKey, Value, Idx]) Remove(ctx context.Context, pk PrimaryKey) error
- func (m *IndexedMap[PrimaryKey, Value, Idx]) Set(ctx context.Context, pk PrimaryKey, value Value) error
- func (m *IndexedMap[PrimaryKey, Value, Idx]) ValueCodec() codec.ValueCodec[Value]
- func (m *IndexedMap[PrimaryKey, Value, Idx]) Walk(ctx context.Context, ranger Ranger[PrimaryKey], ...) error
- type Indexes
- type Item
- type Iterator
- func (i Iterator[K, V]) Close() error
- func (i Iterator[K, V]) Key() (K, error)
- func (i Iterator[K, V]) KeyValue() (kv KeyValue[K, V], err error)
- func (i Iterator[K, V]) KeyValues() ([]KeyValue[K, V], error)
- func (i Iterator[K, V]) Keys() ([]K, error)
- func (i Iterator[K, V]) Next()
- func (i Iterator[K, V]) Valid() bool
- func (i Iterator[K, V]) Value() (V, error)
- func (i Iterator[K, V]) Values() ([]V, error)
- type KeySet
- func (k KeySet[K]) Has(ctx context.Context, key K) (bool, error)
- func (k KeySet[K]) Iterate(ctx context.Context, ranger Ranger[K]) (KeySetIterator[K], error)
- func (k KeySet[K]) IterateRaw(ctx context.Context, start, end []byte, order Order) (Iterator[K, NoValue], error)
- func (k KeySet[K]) KeyCodec() codec.KeyCodec[K]
- func (k KeySet[K]) Remove(ctx context.Context, key K) error
- func (k KeySet[K]) Set(ctx context.Context, key K) error
- func (k KeySet[K]) ValueCodec() codec.ValueCodec[NoValue]
- func (k KeySet[K]) Walk(ctx context.Context, ranger Ranger[K], walkFunc func(key K) bool) error
- type KeySetIterator
- type KeyValue
- type Map
- func (m Map[K, V]) Get(ctx context.Context, key K) (v V, err error)
- func (m Map[K, V]) Has(ctx context.Context, key K) (bool, error)
- func (m Map[K, V]) Iterate(ctx context.Context, ranger Ranger[K]) (Iterator[K, V], error)
- func (m Map[K, V]) IterateRaw(ctx context.Context, start, end []byte, order Order) (Iterator[K, V], error)
- func (m Map[K, V]) KeyCodec() codec.KeyCodec[K]
- func (m Map[K, V]) Remove(ctx context.Context, key K) error
- func (m Map[K, V]) Set(ctx context.Context, key K, value V) error
- func (m Map[K, V]) ValueCodec() codec.ValueCodec[V]
- func (m Map[K, V]) Walk(ctx context.Context, ranger Ranger[K], walkFunc func(K, V) bool) error
- type NoValue
- type Order
- type Pair
- type PairRange
- func (p *PairRange[K1, K2]) Descending() *PairRange[K1, K2]
- func (p *PairRange[K1, K2]) EndExclusive(k2 K2) *PairRange[K1, K2]
- func (p *PairRange[K1, K2]) EndInclusive(k2 K2) *PairRange[K1, K2]
- func (p *PairRange[K1, K2]) RangeValues() (start, end *RangeKey[Pair[K1, K2]], order Order, err error)
- func (p *PairRange[K1, K2]) StartExclusive(k2 K2) *PairRange[K1, K2]
- func (p *PairRange[K1, K2]) StartInclusive(k2 K2) *PairRange[K1, K2]
- type Prefix
- type Range
- func (r *Range[K]) Descending() *Range[K]
- func (r *Range[K]) EndExclusive(end K) *Range[K]
- func (r *Range[K]) EndInclusive(end K) *Range[K]
- func (r *Range[K]) Prefix(key K) *Range[K]
- func (r *Range[K]) RangeValues() (start, end *RangeKey[K], order Order, err error)
- func (r *Range[K]) StartExclusive(start K) *Range[K]
- func (r *Range[K]) StartInclusive(start K) *Range[K]
- type RangeKey
- type Ranger
- type Schema
- func (s Schema) DefaultGenesis(target appmodule.GenesisTarget) error
- func (s Schema) ExportGenesis(ctx context.Context, target appmodule.GenesisTarget) error
- func (s Schema) InitGenesis(ctx context.Context, source appmodule.GenesisSource) error
- func (s Schema) ValidateGenesis(source appmodule.GenesisSource) error
- type SchemaBuilder
- type Sequence
Constants ¶
const DefaultSequenceStart uint64 = 0
DefaultSequenceStart defines the default starting number of a sequence.
const NameRegex = "[A-Za-z][A-Za-z0-9_]*"
NameRegex is the regular expression that all valid collection names must match.
Variables ¶
var ( // ErrNotFound is returned when the provided key is not present in the StorageProvider. ErrNotFound = errors.New("collections: not found") // ErrEncoding is returned when something fails during key or value encoding/decoding. ErrEncoding = codec.ErrEncoding // ErrConflict is returned when there are conflicts, for example in UniqueIndex. ErrConflict = errors.New("collections: conflict") )
var ( // Uint16Key can be used to encode uint16 keys. Encoding is big endian to retain ordering. Uint16Key = codec.NewUint16Key[uint16]() // Uint32Key can be used to encode uint32 keys. Encoding is big endian to retain ordering. Uint32Key = codec.NewUint32Key[uint32]() // Uint64Key can be used to encode uint64 keys. Encoding is big endian to retain ordering. Uint64Key = codec.NewUint64Key[uint64]() // Int32Key can be used to encode int32 keys. Encoding retains ordering by toggling the MSB. Int32Key = codec.NewInt32Key[int32]() // Int64Key can be used to encode int64. Encoding retains ordering by toggling the MSB. Int64Key = codec.NewInt64Key[int64]() // StringKey can be used to encode string keys. The encoding just converts the string // to bytes. // Non-terminality in multipart keys is handled by appending the StringDelimiter, // this means that a string key when used as the non final part of a multipart key cannot // contain the StringDelimiter. // Lexicographical ordering is retained both in non and multipart keys. StringKey = codec.NewStringKeyCodec[string]() // BytesKey can be used to encode bytes keys. The encoding will just use // the provided bytes. // When used as the non-terminal part of a multipart key, we prefix the bytes key // with a single byte representing the length of the key. This means two things: // 1. When used in multipart keys the length can be at maximum 255 (max number that // can be represented with a single byte). // 2. When used in multipart keys the lexicographical ordering is lost due to the // length prefixing. // JSON encoding represents a bytes key as a hex encoded string. BytesKey = codec.NewBytesKey[[]byte]() // BoolKey can be used to encode booleans. It uses a single byte to represent the boolean. // 0x0 is used to represent false, and 0x1 is used to represent true. BoolKey = codec.NewBoolKey[bool]() )
var ( // BoolValue implements a ValueCodec for bool. BoolValue = codec.KeyToValueCodec(BoolKey) // Uint16Value implements a ValueCodec for uint16. Uint16Value = codec.KeyToValueCodec(Uint16Key) // Uint32Value implements a ValueCodec for uint32. Uint32Value = codec.KeyToValueCodec(Uint32Key) // Uint64Value implements a ValueCodec for uint64. Uint64Value = codec.KeyToValueCodec(Uint64Key) // Int32Value implements a ValueCodec for int32. Int32Value = codec.KeyToValueCodec(Int32Key) // Int64Value implements a ValueCodec for int64. Int64Value = codec.KeyToValueCodec(Int64Key) // StringValue implements a ValueCodec for string. StringValue = codec.KeyToValueCodec(StringKey) // BytesValue implements a ValueCodec for bytes. BytesValue = codec.KeyToValueCodec(BytesKey) )
ErrInvalidIterator is returned when an Iterate call resulted in an invalid iterator.
Functions ¶
func PairKeyCodec ¶
func PairKeyCodec[K1, K2 any](keyCodec1 codec.KeyCodec[K1], keyCodec2 codec.KeyCodec[K2]) codec.KeyCodec[Pair[K1, K2]]
PairKeyCodec instantiates a new KeyCodec instance that can encode the Pair, given the KeyCodec of the first part of the key and the KeyCodec of the second part of the key.
Types ¶
type Index ¶
type Index[PrimaryKey, Value any] interface { // Reference creates a reference between the provided primary key and value. // It provides a lazyOldValue function that if called will attempt to fetch // the previous old value, returns ErrNotFound if no value existed. Reference(ctx context.Context, pk PrimaryKey, newValue Value, lazyOldValue func() (Value, error)) error // Unreference removes the reference between the primary key and value. // If error is ErrNotFound then it means that the value did not exist before. Unreference(ctx context.Context, pk PrimaryKey, lazyOldValue func() (Value, error)) error }
Index represents an index of the Value indexed using the type PrimaryKey.
type IndexedMap ¶
type IndexedMap[PrimaryKey, Value any, Idx Indexes[PrimaryKey, Value]] struct { Indexes Idx // contains filtered or unexported fields }
IndexedMap works like a Map but creates references between fields of Value and its PrimaryKey. These relationships are expressed and maintained using the Indexes type. Internally IndexedMap can be seen as a partitioned collection, one partition is a Map[PrimaryKey, Value], that maintains the object, the second are the Indexes.
func NewIndexedMap ¶
func NewIndexedMap[PrimaryKey, Value any, Idx Indexes[PrimaryKey, Value]]( schema *SchemaBuilder, prefix Prefix, name string, pkCodec codec.KeyCodec[PrimaryKey], valueCodec codec.ValueCodec[Value], indexes Idx, ) *IndexedMap[PrimaryKey, Value, Idx]
NewIndexedMap instantiates a new IndexedMap. Accepts a SchemaBuilder, a Prefix, a humanized name that defines the name of the collection, the primary key codec which is basically what IndexedMap uses to encode the primary key to bytes, the value codec which is what the IndexedMap uses to encode the value. Then it expects the initialized indexes.
func (*IndexedMap[PrimaryKey, Value, Idx]) Get ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) Get(ctx context.Context, pk PrimaryKey) (Value, error)
Get gets the object given its primary key.
func (*IndexedMap[PrimaryKey, Value, Idx]) Has ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) Has(ctx context.Context, pk PrimaryKey) (bool, error)
Has reports if exists a value with the provided primary key.
func (*IndexedMap[PrimaryKey, Value, Idx]) Iterate ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) Iterate(ctx context.Context, ranger Ranger[PrimaryKey]) (Iterator[PrimaryKey, Value], error)
Iterate allows to iterate over the objects given a Ranger of the primary key.
func (*IndexedMap[PrimaryKey, Value, Idx]) IterateRaw ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) IterateRaw(ctx context.Context, start, end []byte, order Order) (Iterator[PrimaryKey, Value], error)
IterateRaw iterates the IndexedMap using raw bytes keys. Follows the same semantics as Map.IterateRaw
func (*IndexedMap[PrimaryKey, Value, Idx]) KeyCodec ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) KeyCodec() codec.KeyCodec[PrimaryKey]
func (*IndexedMap[PrimaryKey, Value, Idx]) Remove ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) Remove(ctx context.Context, pk PrimaryKey) error
Remove removes the value associated with the primary key from the map. Then it iterates over all the indexes and instructs them to remove all the references associated with the removed value.
func (*IndexedMap[PrimaryKey, Value, Idx]) Set ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) Set(ctx context.Context, pk PrimaryKey, value Value) error
Set maps the value using the primary key. It will also iterate every index and instruct them to add or update the indexes.
func (*IndexedMap[PrimaryKey, Value, Idx]) ValueCodec ¶
func (m *IndexedMap[PrimaryKey, Value, Idx]) ValueCodec() codec.ValueCodec[Value]
type Indexes ¶
type Indexes[PrimaryKey, Value any] interface { // IndexesList is implemented by the Indexes type // and returns all the grouped Index of Value. IndexesList() []Index[PrimaryKey, Value] }
Indexes represents a type which groups multiple Index of one Value saved with the provided PrimaryKey. Indexes is just meant to be a struct containing all the indexes to maintain relationship for.
type Item ¶
Item is a type declaration based on Map with a non-existent key.
func NewItem ¶
func NewItem[V any]( schema *SchemaBuilder, prefix Prefix, name string, valueCodec codec.ValueCodec[V], ) Item[V]
NewItem instantiates a new Item instance, given the value encoder of the item V. Name and prefix must be unique within the schema and name must match the format specified by NameRegex, or else this method will panic.
func (Item[V]) Get ¶
Get gets the item, if it is not set it returns an ErrNotFound error. If value decoding fails then an ErrEncoding is returned.
func (Item[V]) Has ¶
Has reports whether the item exists in the store or not. Returns an error in case
func (Item[V]) Remove ¶
Remove removes the item in the store.
type Iterator ¶
type Iterator[K, V any] struct { // contains filtered or unexported fields }
Iterator defines a generic wrapper around an storetypes.Iterator. This iterator provides automatic key and value encoding, it assumes all the keys and values contained within the storetypes.Iterator range are the same.
func (Iterator[K, V]) Key ¶
Key returns the current storetypes.Iterator decoded key.
func (Iterator[K, V]) KeyValue ¶
KeyValue returns the current key and value decoded.
func (Iterator[K, V]) KeyValues ¶
KeyValues fully consumes the iterator and returns the list of key and values within the iterator range.
func (Iterator[K, V]) Keys ¶
Keys fully consumes the iterator and returns all the decoded keys contained within the range.
func (Iterator[K, V]) Value ¶
Value returns the current iterator value bytes decoded.
type KeySet ¶
KeySet builds on top of a Map and represents a collection retaining only a set of keys and no value. It can be used, for example, in an allow list.
func NewKeySet ¶
func NewKeySet[K any](schema *SchemaBuilder, prefix Prefix, name string, keyCodec codec.KeyCodec[K]) KeySet[K]
NewKeySet returns a KeySet given a Schema, Prefix a human name for the collection and a KeyCodec for the key K.
func (KeySet[K]) Has ¶
Has returns if the key is present in the KeySet. An error is returned only in case of encoding problems.
func (KeySet[K]) Iterate ¶
Iterate iterates over the keys given the provided Ranger. If ranger is nil, the KeySetIterator will include all the existing keys within the KeySet.
func (KeySet[K]) IterateRaw ¶
func (KeySet[K]) Remove ¶
Remove removes the key for the KeySet. An error is returned in case of encoding error, it won't report through the error if the key was removed or not.
func (KeySet[K]) Set ¶
Set adds the key to the KeySet. Errors on encoding problems.
func (KeySet[K]) ValueCodec ¶
func (k KeySet[K]) ValueCodec() codec.ValueCodec[NoValue]
type KeySetIterator ¶
KeySetIterator works like an Iterator, but it does not expose any API to deal with values.
func (KeySetIterator[K]) Close ¶
func (i KeySetIterator[K]) Close() error
func (KeySetIterator[K]) Key ¶
func (i KeySetIterator[K]) Key() (K, error)
func (KeySetIterator[K]) Keys ¶
func (i KeySetIterator[K]) Keys() ([]K, error)
func (KeySetIterator[K]) Next ¶
func (i KeySetIterator[K]) Next()
func (KeySetIterator[K]) Valid ¶
func (i KeySetIterator[K]) Valid() bool
type KeyValue ¶
type KeyValue[K, V any] struct { Key K Value V }
KeyValue represent a Key and Value pair of an iteration.
type Map ¶
type Map[K, V any] struct { // contains filtered or unexported fields }
Map represents the basic collections object. It is used to map arbitrary keys to arbitrary objects.
func NewMap ¶
func NewMap[K, V any]( schemaBuilder *SchemaBuilder, prefix Prefix, name string, keyCodec codec.KeyCodec[K], valueCodec codec.ValueCodec[V], ) Map[K, V]
NewMap returns a Map given a StoreKey, a Prefix, human-readable name and the relative value and key encoders. Name and prefix must be unique within the schema and name must match the format specified by NameRegex, or else this method will panic.
func (Map[K, V]) Get ¶
Get returns the value associated with the provided key, errors with ErrNotFound if the key does not exist, or with ErrEncoding if the key or value decoding fails.
func (Map[K, V]) Has ¶
Has reports whether the key is present in storage or not. Errors with ErrEncoding if key encoding fails.
func (Map[K, V]) Iterate ¶
Iterate provides an Iterator over K and V. It accepts a Ranger interface. A nil ranger equals to iterate over all the keys in ascending order.
func (Map[K, V]) IterateRaw ¶
func (m Map[K, V]) IterateRaw(ctx context.Context, start, end []byte, order Order) (Iterator[K, V], error)
IterateRaw iterates over the collection. The iteration range is untyped, it uses raw bytes. The resulting Iterator is typed. A nil start iterates from the first key contained in the collection. A nil end iterates up to the last key contained in the collection. A nil start and a nil end iterates over every key contained in the collection. TODO(tip): simplify after https://github.com/cosmos/cosmos-sdk/pull/14310 is merged
func (Map[K, V]) KeyCodec ¶
KeyCodec returns the Map's KeyCodec.
func (Map[K, V]) Remove ¶
Remove removes the key from the storage. Errors with ErrEncoding if key encoding fails. If the key does not exist then this is a no-op.
func (Map[K, V]) Set ¶
Set maps the provided value to the provided key in the store. Errors with ErrEncoding if key or value encoding fails.
func (Map[K, V]) ValueCodec ¶
func (m Map[K, V]) ValueCodec() codec.ValueCodec[V]
ValueCodec returns the Map's ValueCodec.
func (Map[K, V]) Walk ¶
Walk iterates over the Map with the provided range, calls the provided walk function with the decoded key and value. If the callback function returns true then the walking is stopped. A nil ranger equals to walking over the entire key and value set.
type NoValue ¶
type NoValue struct{}
type Pair ¶
type Pair[K1, K2 any] struct { // contains filtered or unexported fields }
Pair defines a key composed of two keys.
func Join ¶
Join creates a new Pair instance composed of the two provided keys, in order.
func PairPrefix ¶
PairPrefix creates a new Pair instance composed only of the first part of the key.
type PairRange ¶
type PairRange[K1, K2 any] struct { // contains filtered or unexported fields }
PairRange is an API that facilitates working with Pair iteration. It implements the Ranger API. Unstable: API and methods are currently unstable.
func NewPrefixedPairRange ¶
NewPrefixedPairRange creates a new PairRange which will prefix over all the keys starting with the provided prefix.
func (*PairRange[K1, K2]) EndExclusive ¶
func (*PairRange[K1, K2]) EndInclusive ¶
func (*PairRange[K1, K2]) RangeValues ¶
func (*PairRange[K1, K2]) StartExclusive ¶
type Prefix ¶
type Prefix []byte
Prefix defines a segregation bytes namespace for specific collections objects.
func NewPrefix ¶
NewPrefix returns a Prefix given the provided namespace identifier. In the same module, no prefixes should share the same starting bytes meaning that having two namespaces whose bytes representation is: p1 := []byte("prefix") p2 := []byte("prefix1") yields to iterations of p1 overlapping over p2. If a numeric prefix is provided, it must be between 0 and 255 (uint8). If out of bounds this function will panic. Reason for which this function is constrained to `int` instead of `uint8` is for API ergonomics, golang's type inference will infer int properly but not uint8 meaning that developers would need to write NewPrefix(uint8(number)) for numeric prefixes.
type Range ¶
type Range[K any] struct { // contains filtered or unexported fields }
Range is a Ranger implementer.
func (*Range[K]) EndExclusive ¶
EndExclusive makes the range contain only keys which are smaller to the provided end K.
func (*Range[K]) EndInclusive ¶
EndInclusive makes the range contain only keys which are smaller or equal to the provided end K.
func (*Range[K]) Prefix ¶
Prefix sets a fixed prefix for the key range.
func (*Range[K]) RangeValues ¶
func (*Range[K]) StartExclusive ¶
StartExclusive makes the range contain only keys which are bigger to the provided start K.
type RangeKey ¶
type RangeKey[K any] struct { // contains filtered or unexported fields }
RangeKey wraps a generic range key K, acts as an enum which defines different ways to encode the wrapped key to bytes when it's being used in an iteration.
func RangeKeyExact ¶
RangeKeyExact instantiates a RangeKey that applies no modifications to the key K. So its bytes representation will not be altered.
func RangeKeyNext ¶
RangeKeyNext instantiates a RangeKey that when encoded to bytes identifies the next key after the provided key K. Example: given a string key "ABCD" the next key is bytes("ABCD\0") It's useful when defining inclusivity or exclusivity of a key in store iteration. Specifically: to make an Iterator start exclude key K I would return a RangeKeyNext(key) in the Ranger start.
type Ranger ¶
type Ranger[K any] interface { // RangeValues is defined by Ranger implementers. // The implementer can optionally return a start and an end. // If start is nil and end is not, the iteration will include all the keys // in the collection up until the provided end. // If start is defined and end is nil, the iteration will include all the keys // in the collection starting from the provided start. // If both are nil then the iteration will include all the possible keys in the // collection. // Order defines the order of the iteration, if order is OrderAscending then the // iteration will yield keys from the smallest to the biggest, if order // is OrderDescending then the iteration will yield keys from the biggest to the smallest. // Ordering is defined by the keys bytes representation, which is dependent on the KeyCodec used. RangeValues() (start, end *RangeKey[K], order Order, err error) }
Ranger defines a generic interface that provides a range of keys.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema specifies a group of collections stored within the storage specified by a single store key. All the collections within the schema must have a unique binary prefix and human-readable name. Schema will eventually include methods for importing/exporting genesis data and for schema reflection for clients.
func NewMemoryStoreSchema ¶
func NewMemoryStoreSchema(service store.MemoryStoreService) Schema
NewMemoryStoreSchema creates a new schema for the provided MemoryStoreService.
func NewSchema ¶
func NewSchema(service store.KVStoreService) Schema
NewSchema creates a new schema for the provided KVStoreService.
func NewSchemaFromAccessor ¶
NewSchemaFromAccessor(func(ctx context.Context) store.KVStore { return sdk.UnwrapSDKContext(ctx).KVStore(kvStoreKey) }
func (Schema) DefaultGenesis ¶
func (s Schema) DefaultGenesis(target appmodule.GenesisTarget) error
DefaultGenesis implements the appmodule.HasGenesis.DefaultGenesis method.
func (Schema) ExportGenesis ¶
ExportGenesis implements the appmodule.HasGenesis.ExportGenesis method.
func (Schema) InitGenesis ¶
InitGenesis implements the appmodule.HasGenesis.InitGenesis method.
func (Schema) ValidateGenesis ¶
func (s Schema) ValidateGenesis(source appmodule.GenesisSource) error
ValidateGenesis implements the appmodule.HasGenesis.ValidateGenesis method.
type SchemaBuilder ¶
type SchemaBuilder struct {
// contains filtered or unexported fields
}
SchemaBuilder is used for building schemas. The Build method should always be called after all collections have been initialized. Initializing new collections with the builder after initialization will result in panics.
func NewSchemaBuilder ¶
func NewSchemaBuilder(service store.KVStoreService) *SchemaBuilder
NewSchemaBuilder creates a new schema builder from the provided store key. Callers should always call the SchemaBuilder.Build method when they are done adding collections to the schema.
func NewSchemaBuilderFromAccessor ¶
func NewSchemaBuilderFromAccessor(accessorFunc func(ctx context.Context) store.KVStore) *SchemaBuilder
NewSchemaBuilderFromAccessor creates a new schema builder from the provided store accessor function.
func (*SchemaBuilder) Build ¶
func (s *SchemaBuilder) Build() (Schema, error)
Build should be called after all collections that are part of the schema have been initialized in order to get a reference to the Schema. It is important to check the returned error for any initialization errors. The SchemaBuilder CANNOT be used after Build is called - doing so will result in panics.
type Sequence ¶
Sequence builds on top of an Item, and represents a monotonically increasing number.
func NewSequence ¶
func NewSequence(schema *SchemaBuilder, prefix Prefix, name string) Sequence
NewSequence instantiates a new sequence given a Schema, a Prefix and humanized name for the sequence.
func (Sequence) Next ¶
Next returns the next sequence number, and sets the next expected sequence. Errors on encoding issues.
func (Sequence) Peek ¶
Peek returns the current sequence value, if no number is set then the DefaultSequenceStart is returned. Errors on encoding issues.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package codec defines how collections transform keys and values into and from bytes.
|
Package codec defines how collections transform keys and values into and from bytes. |
Package indexes contains the most common indexes types to be used with a collections.IndexedMap.
|
Package indexes contains the most common indexes types to be used with a collections.IndexedMap. |