Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithBatch(ctx context.Context, batch Batch) context.Context
- func ContextWithSyncBatch(ctx context.Context, batch *SyncBatch) context.Context
- func DefaultKeyComparer() *pebble.Comparer
- func DefaultPebbleOptions() *pebble.Options
- func FilterInitialize(ctx context.Context, filter Filter, filterStorer FilterStorer, ...) error
- func KeyEncode(key Key, rawBuffs ...[]byte) []byte
- func KeyEncodeRaw(tableID TableID, indexID IndexID, ...) []byte
- func MigratePebbleFormatVersion(dir string, upgradeVersion uint64) error
- func PebbleFormatVersion(dir string) (uint64, error)
- func TableUpsertOnConflictReplace[T any](_, new T) T
- type Applier
- type Backup
- type Batch
- type BatchType
- type Batcher
- type Closer
- type Committer
- type DB
- type Deleter
- type DeleterWithRange
- type Filter
- type FilterInitializable
- type FilterStorer
- type Getter
- type Index
- func (idx *Index[T]) ID() IndexID
- func (idx *Index[T]) Intersect(ctx context.Context, table Table[T], sel Selector[T], indexes []*Index[T], ...) ([][]byte, error)
- func (idx *Index[T]) Iter(table Table[T], selector Selector[T], optBatch ...Batch) Iterator
- func (idx *Index[T]) Name() string
- func (idx *Index[T]) OnDelete(table Table[T], tr T, batch Batch, buffs ...[]byte) error
- func (idx *Index[T]) OnInsert(table Table[T], tr T, batch Batch, buffs ...[]byte) error
- func (idx *Index[T]) OnUpdate(table Table[T], oldTr T, tr T, batch Batch, buffs ...[]byte) error
- type IndexFilterFunction
- type IndexID
- type IndexInfo
- type IndexKeyFunction
- type IndexOptions
- type IndexOrder
- func (o IndexOrder) Bytes() []byte
- func (o IndexOrder) OrderBigInt(b *big.Int, bits int, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderByte(b byte, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderBytes(b []byte, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderInt16(i int16, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderInt32(i int32, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderInt64(i int64, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderUint16(i uint16, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderUint32(i uint32, orderType IndexOrderType) IndexOrder
- func (o IndexOrder) OrderUint64(i uint64, orderType IndexOrderType) IndexOrder
- type IndexOrderFunction
- type IndexOrderType
- type IterOptions
- type Iterationer
- type Iterator
- type Key
- type KeyBuilder
- func (b KeyBuilder) AddBigIntField(bi *big.Int, bits int) KeyBuilder
- func (b KeyBuilder) AddByteField(btt byte) KeyBuilder
- func (b KeyBuilder) AddBytesField(bs []byte) KeyBuilder
- func (b KeyBuilder) AddInt16Field(i int16) KeyBuilder
- func (b KeyBuilder) AddInt32Field(i int32) KeyBuilder
- func (b KeyBuilder) AddInt64Field(i int64) KeyBuilder
- func (b KeyBuilder) AddStringField(s string) KeyBuilder
- func (b KeyBuilder) AddUint16Field(i uint16) KeyBuilder
- func (b KeyBuilder) AddUint32Field(i uint32) KeyBuilder
- func (b KeyBuilder) AddUint64Field(i uint64) KeyBuilder
- func (b KeyBuilder) Bytes() []byte
- type KeyBytes
- type Lazy
- type NumberSequence
- type Options
- type OrderLessFunc
- type Query
- func (q Query[T]) After(sel T) Query[T]
- func (q Query[T]) CondFuncType() reflect.Type
- func (q Query[T]) Execute(ctx context.Context, r *[]T, optBatch ...Batch) error
- func (q Query[T]) Filter(cond cond.Cond[T]) Query[T]
- func (q Query[T]) Intersects(queries ...Query[T]) Query[T]
- func (q Query[T]) Limit(limit uint64) Query[T]
- func (q Query[T]) Offset(offset uint64) Query[T]
- func (q Query[T]) Order(less OrderLessFunc[T]) Query[T]
- func (q Query[T]) Reverse() Query[T]
- func (q Query[T]) Table() Table[T]
- func (q Query[T]) With(idx *Index[T], selector Selector[T]) Query[T]
- type Selector
- type SelectorPoint
- type SelectorPoints
- type SelectorRange
- type SelectorRanges
- type SelectorType
- type Serializer
- type SerializerAnyWrapper
- type SerializerWithBuffer
- type SerializerWithClosable
- type Setter
- type SyncBatch
- type Table
- type TableDeleter
- type TableExistChecker
- type TableGetter
- type TableID
- type TableInfo
- type TableInserter
- type TableIterationer
- type TableOptions
- type TablePrimaryKeyFunc
- type TableQuerier
- type TableReader
- type TableScanner
- type TableUnsafeInserter
- type TableUnsafeUpdater
- type TableUpdater
- type TableUpserter
- type TableWriter
- type UUIDGenerator
- type UniqueKeyGenerator
- type WriteOptions
Constants ¶
const ( // BOND_DB_DATA_TABLE_ID .. BOND_DB_DATA_TABLE_ID = 0x0 // BOND_DB_DATA_USER_SPACE_INDEX_ID BOND_DB_DATA_USER_SPACE_INDEX_ID = 0xFF )
const (
// BOND_DB_DATA_VERSION ..
BOND_DB_DATA_VERSION = 1
)
const DefaultKeyBufferSize = 2048
const DefaultMaxConcurrentCompactions = 4
const DefaultMaxWriterConcurrency = 8
const DefaultNumberOfKeyBuffersInMultiKeyBuffer = 1000
const DefaultNumberOfPreAllocBytesArrays = 50
const DefaultNumberOfPreAllocKeyBuffers = 2 * persistentBatchSize
const DefaultNumberOfPreAllocMultiKeyBuffers = 10
const DefaultNumberOfPreAllocValueBuffers = 10 * DefaultScanPrefetchSize
const DefaultScanPrefetchSize = 100
const DefaultValueBufferSize = 2048
const NumberSequenceBitShift = 24
const NumberSequenceSequenceNumberMask = 0x0000000000FFFFFF
const NumberSequenceTimestampMask = 0xFFFFFFFFFF000000
const PebbleFormatFile = "PEBBLE_FORMAT_VERSION"
const PrimaryIndexID = IndexID(0)
const PrimaryIndexName = "primary"
const ReindexBatchSize = 10_000
Variables ¶
var ( Sync = WriteOptions{Sync: true} NoSync = WriteOptions{Sync: false} )
var (
ErrNotFound = fmt.Errorf("bond: not found")
)
Functions ¶
func ContextWithSyncBatch ¶
func DefaultKeyComparer ¶
func DefaultPebbleOptions ¶
func FilterInitialize ¶
func FilterInitialize(ctx context.Context, filter Filter, filterStorer FilterStorer, scanners []TableScanner[any]) error
func KeyEncodeRaw ¶
func MigratePebbleFormatVersion ¶ added in v0.1.48
func PebbleFormatVersion ¶ added in v0.1.48
func TableUpsertOnConflictReplace ¶
func TableUpsertOnConflictReplace[T any](_, new T) T
Types ¶
type Applier ¶
type Applier interface {
Apply(b Batch, opt WriteOptions) error
}
type Batch ¶
type Batch interface { ID() uint64 Len() int Empty() bool Reset() Type() BatchType Getter Setter Deleter DeleterWithRange Iterationer Applier Committer Closer }
func ContextRetrieveBatch ¶
type DB ¶
type DB interface { Backend() *pebble.DB Serializer() Serializer[any] Getter Setter Deleter DeleterWithRange Iterationer Batcher Applier Closer Backup OnClose(func(db DB)) // contains filtered or unexported methods }
type Deleter ¶
type Deleter interface {
Delete(key []byte, opt WriteOptions, batch ...Batch) error
}
type DeleterWithRange ¶
type DeleterWithRange interface {
DeleteRange(start []byte, end []byte, opt WriteOptions, batch ...Batch) error
}
type FilterInitializable ¶
type FilterInitializable struct { Filter // contains filtered or unexported fields }
func (*FilterInitializable) Initialize ¶
func (f *FilterInitializable) Initialize(ctx context.Context, filterStorer FilterStorer, scanners []TableScanner[any]) error
func (*FilterInitializable) MayContain ¶
func (f *FilterInitializable) MayContain(ctx context.Context, key []byte) bool
func (*FilterInitializable) Save ¶
func (f *FilterInitializable) Save(ctx context.Context, store FilterStorer) error
type FilterStorer ¶
type FilterStorer interface { Getter Setter DeleterWithRange }
type Index ¶
type Index[T any] struct { IndexID IndexID IndexName string IndexKeyFunction IndexKeyFunction[T] IndexFilterFunction IndexFilterFunction[T] IndexOrderFunction IndexOrderFunction[T] }
func NewIndex ¶
func NewIndex[T any](opt IndexOptions[T]) *Index[T]
type IndexFilterFunction ¶
type IndexKeyFunction ¶
type IndexKeyFunction[T any] func(builder KeyBuilder, t T) []byte
type IndexOptions ¶
type IndexOptions[T any] struct { IndexID IndexID IndexName string IndexKeyFunc IndexKeyFunction[T] IndexOrderFunc IndexOrderFunction[T] IndexFilterFunc IndexFilterFunction[T] }
type IndexOrder ¶
type IndexOrder struct {
KeyBuilder KeyBuilder
}
func IndexOrderDefault ¶
func IndexOrderDefault[T any](o IndexOrder, t T) IndexOrder
func (IndexOrder) Bytes ¶
func (o IndexOrder) Bytes() []byte
func (IndexOrder) OrderBigInt ¶
func (o IndexOrder) OrderBigInt(b *big.Int, bits int, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderByte ¶
func (o IndexOrder) OrderByte(b byte, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderBytes ¶
func (o IndexOrder) OrderBytes(b []byte, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderInt16 ¶
func (o IndexOrder) OrderInt16(i int16, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderInt32 ¶
func (o IndexOrder) OrderInt32(i int32, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderInt64 ¶
func (o IndexOrder) OrderInt64(i int64, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderUint16 ¶
func (o IndexOrder) OrderUint16(i uint16, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderUint32 ¶
func (o IndexOrder) OrderUint32(i uint32, orderType IndexOrderType) IndexOrder
func (IndexOrder) OrderUint64 ¶
func (o IndexOrder) OrderUint64(i uint64, orderType IndexOrderType) IndexOrder
type IndexOrderFunction ¶
type IndexOrderFunction[T any] func(o IndexOrder, t T) IndexOrder
type IndexOrderType ¶
type IndexOrderType bool
const ( IndexOrderTypeASC IndexOrderType = false IndexOrderTypeDESC = true )
type IterOptions ¶
type IterOptions struct { pebble.IterOptions // contains filtered or unexported fields }
type Iterationer ¶
type Iterationer interface {
Iter(opt *IterOptions, batch ...Batch) Iterator
}
type Key ¶
type Key struct { TableID TableID IndexID IndexID Index []byte IndexOrder []byte PrimaryKey []byte }
func (Key) IsIndexKey ¶
func (Key) IsKeyPrefix ¶
func (Key) ToKeyPrefix ¶
type KeyBuilder ¶
type KeyBuilder struct {
// contains filtered or unexported fields
}
func NewKeyBuilder ¶
func NewKeyBuilder(buff []byte) KeyBuilder
func (KeyBuilder) AddBigIntField ¶
func (b KeyBuilder) AddBigIntField(bi *big.Int, bits int) KeyBuilder
func (KeyBuilder) AddByteField ¶
func (b KeyBuilder) AddByteField(btt byte) KeyBuilder
func (KeyBuilder) AddBytesField ¶
func (b KeyBuilder) AddBytesField(bs []byte) KeyBuilder
func (KeyBuilder) AddInt16Field ¶
func (b KeyBuilder) AddInt16Field(i int16) KeyBuilder
func (KeyBuilder) AddInt32Field ¶
func (b KeyBuilder) AddInt32Field(i int32) KeyBuilder
func (KeyBuilder) AddInt64Field ¶
func (b KeyBuilder) AddInt64Field(i int64) KeyBuilder
func (KeyBuilder) AddStringField ¶
func (b KeyBuilder) AddStringField(s string) KeyBuilder
func (KeyBuilder) AddUint16Field ¶
func (b KeyBuilder) AddUint16Field(i uint16) KeyBuilder
func (KeyBuilder) AddUint32Field ¶
func (b KeyBuilder) AddUint32Field(i uint32) KeyBuilder
func (KeyBuilder) AddUint64Field ¶
func (b KeyBuilder) AddUint64Field(i uint64) KeyBuilder
func (KeyBuilder) Bytes ¶
func (b KeyBuilder) Bytes() []byte
type KeyBytes ¶
type KeyBytes []byte
func NewUserKey ¶
func (KeyBytes) IsIndexKey ¶
func (KeyBytes) ToDataKeyBytes ¶
type NumberSequence ¶
type NumberSequence struct {
// contains filtered or unexported fields
}
func (*NumberSequence) Next ¶
func (n *NumberSequence) Next() (uint64, error)
func (*NumberSequence) SequenceNumber ¶
func (n *NumberSequence) SequenceNumber(ns uint64) uint64
func (*NumberSequence) Timestamp ¶
func (n *NumberSequence) Timestamp(ns uint64) uint64
type Options ¶
type Options struct { PebbleOptions *pebble.Options Serializer Serializer[any] }
func DefaultOptions ¶
func DefaultOptions() *Options
type OrderLessFunc ¶
OrderLessFunc is the function template to be used for record sorting.
type Query ¶
type Query[T any] struct { // contains filtered or unexported fields }
Query is the structure that is used to build record query.
Example:
t.Query(). With(ContractTypeIndex, bond.NewSelectorPoint(&Contract{ContractType: ContractTypeERC20})). Filter(cond.Func(func(c *Contract) bool { return c.Balance > 25 })). Limit(50)
func (Query[T]) CondFuncType ¶
CondFuncType returns the type of the filter function.
func (Query[T]) Filter ¶
Filter adds additional filtering to the query. The conditions can be built with structures that implement Cond interface.
func (Query[T]) Intersects ¶
func (Query[T]) Limit ¶
Limit sets the maximal number of records returned.
WARNING: If not defined it will return all rows. Please be mindful of your memory constrains.
func (Query[T]) Offset ¶
Offset sets offset of the records.
WARNING: Using Offset requires traversing through all the rows that are skipped. This may take a long time. Bond allows to use more efficient way to do that by passing last received row to With method as a selector. This will jump to that row instantly and start iterating from that point.
func (Query[T]) Order ¶
func (q Query[T]) Order(less OrderLessFunc[T]) Query[T]
Order sets order of the records.
func (Query[T]) Reverse ¶
Reverse reverses the order of the records. If not defined the order will be ASC. If defined it will be DESC. If defined twice it will be ASC again.
func (Query[T]) With ¶
With selects index for query execution. If not stated the default index will be used. The index need to be supplemented with a record selector that has indexed and order fields set. This is very important as selector also defines the row at which we start the query.
WARNING: if we have DESC order on ID field, and we try to query with a selector that has ID set to 0 it will start from the last row.
type Selector ¶
type Selector[T any] interface { Type() SelectorType }
Selector is the interface for all selectors.
type SelectorPoint ¶
SelectorPoint is the interface for point selector.
func NewSelectorPoint ¶
func NewSelectorPoint[T any](point T) SelectorPoint[T]
NewSelectorPoint creates a new point selector.
type SelectorPoints ¶
SelectorPoints is the interface for multi-point selector.
func NewSelectorPoints ¶
func NewSelectorPoints[T any](points ...T) SelectorPoints[T]
NewSelectorPoints creates a new multi-point selector.
type SelectorRange ¶
SelectorRange is the interface for range selector. The range is represented as a two-element slice. The first element is the start of the range, and the second element is the end of the range. The range is inclusive on both ends.
func NewSelectorRange ¶
func NewSelectorRange[T any](start, end T) SelectorRange[T]
NewSelectorRange creates a new range selector.
type SelectorRanges ¶
SelectorRanges is the interface for multi-range selector. The ranges are represented as a slice of two-element slices. The first element of each slice is the start of the range, and the second element is the end of the range. The range is inclusive on both ends.
func NewSelectorRanges ¶
func NewSelectorRanges[T any](ranges ...[]T) SelectorRanges[T]
NewSelectorRanges creates a new multi-range selector.
type SelectorType ¶
type SelectorType uint8
SelectorType is the type of selector.
const ( SelectorTypePoint SelectorType = iota SelectorTypePoints SelectorTypeRange SelectorTypeRanges )
type Serializer ¶
type SerializerAnyWrapper ¶
type SerializerAnyWrapper[T any] struct { Serializer Serializer[any] }
func (*SerializerAnyWrapper[T]) Deserialize ¶
func (s *SerializerAnyWrapper[T]) Deserialize(b []byte, t T) error
func (*SerializerAnyWrapper[T]) Serialize ¶
func (s *SerializerAnyWrapper[T]) Serialize(t T) ([]byte, error)
type SerializerWithBuffer ¶
type SerializerWithClosable ¶
type Setter ¶
type Setter interface {
Set(key []byte, value []byte, opt WriteOptions, batch ...Batch) error
}
type SyncBatch ¶
type SyncBatch struct {
// contains filtered or unexported fields
}
func NewSyncBatch ¶
type Table ¶
type Table[T any] interface { TableReader[T] TableWriter[T] }
func NewTable ¶
func NewTable[T any](opt TableOptions[T]) Table[T]
type TableDeleter ¶
type TableExistChecker ¶
type TableGetter ¶
type TableInserter ¶
type TableIterationer ¶
type TableOptions ¶
type TableOptions[T any] struct { DB DB TableID TableID TableName string TablePrimaryKeyFunc TablePrimaryKeyFunc[T] Serializer Serializer[any] ScanPrefetchSize int Filter Filter }
type TablePrimaryKeyFunc ¶
type TablePrimaryKeyFunc[T any] func(builder KeyBuilder, t T) []byte
type TableQuerier ¶
type TableReader ¶
type TableReader[T any] interface { TableInfo DB() DB PrimaryKey(builder KeyBuilder, tr T) []byte PrimaryIndex() *Index[T] SecondaryIndexes() []*Index[T] Serializer() Serializer[*T] TableGetter[T] TableExistChecker[T] TableQuerier[T] TableScanner[T] TableIterationer[T] }
type TableScanner ¶
type TableScanner[T any] interface { Scan(ctx context.Context, tr *[]T, reverse bool, optBatch ...Batch) error ScanIndex(ctx context.Context, i *Index[T], s Selector[T], tr *[]T, reverse bool, optBatch ...Batch) error ScanForEach(ctx context.Context, f func(keyBytes KeyBytes, l Lazy[T]) (bool, error), reverse bool, optBatch ...Batch) error ScanIndexForEach(ctx context.Context, idx *Index[T], s Selector[T], f func(keyBytes KeyBytes, t Lazy[T]) (bool, error), reverse bool, optBatch ...Batch) error }
func TableAnyScanner ¶
func TableAnyScanner[T any](scanner TableScanner[T]) TableScanner[any]
type TableUnsafeInserter ¶ added in v0.1.51
type TableUnsafeInserter[T any] interface { UnsafeInsert(ctx context.Context, trs []T, optBatch ...Batch) error }
Warning: The indices of the records won't be updated properly if the records already exist.
type TableUnsafeUpdater ¶
type TableUnsafeUpdater[T any] interface { UnsafeUpdate(ctx context.Context, trs []T, oldTrs []T, optBatch ...Batch) error }
TableUnsafeUpdater provides access to UnsafeUpdate method that allows to reduce number of database calls if you already have original version of the entry.
Warning: If you provide outdated rows the table indexes may be corrupted.
type TableUpdater ¶
type TableUpserter ¶
type TableWriter ¶
type TableWriter[T any] interface { AddIndex(idxs []*Index[T], reIndex ...bool) error ReIndex(idxs []*Index[T]) error TableInserter[T] TableUpdater[T] TableUpserter[T] TableDeleter[T] }
type UUIDGenerator ¶
type UUIDGenerator struct { }
type UniqueKeyGenerator ¶
type WriteOptions ¶
type WriteOptions struct {
Sync bool
}