Documentation
¶
Index ¶
- Constants
- Variables
- func BytesToString(b []byte) string
- func ContextWithBatch(ctx context.Context, batch Batch) context.Context
- func ContextWithSyncBatch(ctx context.Context, batch *SyncBatch) context.Context
- func DefaultKeyComparer() *pebble.Comparer
- func DefaultPebbleOptions(performanceProfile ...PerformanceProfile) *pebble.Options
- func FilterInitialize(ctx context.Context, filter Filter, filterStorer FilterStorer, ...) error
- func HighPerformancePebbleOptions() *pebble.Options
- func KeyEncode(key Key, rawBuffs ...[]byte) []byte
- func KeyEncodeRaw(tableID TableID, indexID IndexID, ...) []byte
- func LowPerformancePebbleOptions() *pebble.Options
- func MediumPerformancePebbleOptions() *pebble.Options
- func MigratePebbleFormatVersion(dir string, upgradeVersion uint64) error
- func PebbleFormatVersion(dir string) (uint64, error)
- func StringToBytes(s string) []byte
- 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
- func (f *FilterInitializable) Add(ctx context.Context, key []byte)
- func (f *FilterInitializable) Clear(ctx context.Context, store FilterStorer) error
- func (f *FilterInitializable) Initialize(ctx context.Context, filterStorer FilterStorer, scanners []TableScanner[any]) error
- func (f *FilterInitializable) IsInitialized() bool
- func (f *FilterInitializable) Load(ctx context.Context, store FilterStorer) error
- func (f *FilterInitializable) MayContain(ctx context.Context, key []byte) bool
- func (f *FilterInitializable) RecordFalsePositive()
- func (f *FilterInitializable) Save(ctx context.Context, store FilterStorer) error
- func (f *FilterInitializable) Stats() FilterStats
- type FilterStats
- type FilterStorer
- type FilterWithStats
- 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 IndexMultiKeyFunction
- 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 Iterable
- type Iterator
- type Key
- type KeyBuilder
- type KeyBytes
- type Lazy
- type NumberSequence
- type Options
- type OrderLessFunc
- type PerformanceProfile
- 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 Setter
- type SyncBatch
- type Table
- type TableDeleter
- type TableExistChecker
- type TableGetter
- type TableID
- type TableInfo
- type TableInserter
- type TableIterable
- 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 = 512
const DefaultMaxConcurrentCompactions = 8
const DefaultNumberOfKeyBuffersInMultiKeyBuffer = 1000
const DefaultNumberOfPreAllocBytesArrays = 50
const DefaultNumberOfPreAllocKeyBuffers = 2 * persistentBatchSize
const DefaultNumberOfPreAllocMultiKeyBuffers = 10
const DefaultNumberOfPreAllocValueBuffers = 10 * DefaultScanPrefetchSize
const DefaultScanPrefetchSize = 100
const DefaultValueBufferSize = 1024
const NumberSequenceBitShift = 24
const NumberSequenceSequenceNumberMask = 0x0000000000FFFFFF
const NumberSequenceTimestampMask = 0xFFFFFFFFFF000000
const PebbleDBFormat = pebble.FormatV2BlobFiles
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 BytesToString ¶ added in v0.2.0
BytesToString converts a byte slice to a string without copying. IMPORTANT: The original byte slice should not be modified after this conversion.
func ContextWithSyncBatch ¶
func DefaultKeyComparer ¶
func DefaultPebbleOptions ¶
func DefaultPebbleOptions(performanceProfile ...PerformanceProfile) *pebble.Options
func FilterInitialize ¶
func FilterInitialize(ctx context.Context, filter Filter, filterStorer FilterStorer, scanners []TableScanner[any]) error
func HighPerformancePebbleOptions ¶ added in v0.2.0
func KeyEncodeRaw ¶
func LowPerformancePebbleOptions ¶ added in v0.2.0
func MediumPerformancePebbleOptions ¶ added in v0.2.0
func MigratePebbleFormatVersion ¶ added in v0.1.48
func PebbleFormatVersion ¶ added in v0.1.48
func StringToBytes ¶ added in v0.2.0
StringToBytes converts a string to a byte slice without copying. IMPORTANT: The returned byte slice must NOT be modified, as this will corrupt the original string. Only use this for READ-ONLY operations.
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 // len is the length in bytes
Count() uint32 // count is the number of keys in the batch
Empty() bool
Reset()
Type() BatchType
Getter
Setter
Deleter
DeleterWithRange
Iterable
Applier
Committer
Closer
}
func ContextRetrieveBatch ¶
type DB ¶
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 Filter ¶
type Filter interface {
Add(ctx context.Context, key []byte)
MayContain(ctx context.Context, key []byte) bool
Stats() FilterStats
RecordFalsePositive()
Load(ctx context.Context, store FilterStorer) error
Save(ctx context.Context, store FilterStorer) error
Clear(ctx context.Context, store FilterStorer) error
}
type FilterInitializable ¶
type FilterInitializable struct {
// contains filtered or unexported fields
}
func NewFilterInitializable ¶ added in v0.2.6
func NewFilterInitializable(filter Filter) *FilterInitializable
func (*FilterInitializable) Add ¶ added in v0.2.6
func (f *FilterInitializable) Add(ctx context.Context, key []byte)
func (*FilterInitializable) Clear ¶ added in v0.2.6
func (f *FilterInitializable) Clear(ctx context.Context, store FilterStorer) error
func (*FilterInitializable) Initialize ¶
func (f *FilterInitializable) Initialize(ctx context.Context, filterStorer FilterStorer, scanners []TableScanner[any]) error
func (*FilterInitializable) IsInitialized ¶ added in v0.2.6
func (f *FilterInitializable) IsInitialized() bool
func (*FilterInitializable) Load ¶ added in v0.2.6
func (f *FilterInitializable) Load(ctx context.Context, store FilterStorer) error
func (*FilterInitializable) MayContain ¶
func (f *FilterInitializable) MayContain(ctx context.Context, key []byte) bool
func (*FilterInitializable) RecordFalsePositive ¶ added in v0.2.6
func (f *FilterInitializable) RecordFalsePositive()
func (*FilterInitializable) Save ¶
func (f *FilterInitializable) Save(ctx context.Context, store FilterStorer) error
func (*FilterInitializable) Stats ¶ added in v0.2.6
func (f *FilterInitializable) Stats() FilterStats
type FilterStats ¶ added in v0.2.6
type FilterStorer ¶
type FilterStorer interface {
Getter
Setter
DeleterWithRange
}
type FilterWithStats ¶ added in v0.2.6
type FilterWithStats interface {
Filter
Stats() FilterStats
RecordFalsePositive()
}
type Index ¶
type Index[T any] struct { IndexID IndexID IndexName string IndexKeyFunction IndexKeyFunction[T] IndexMultiKeyFunction IndexMultiKeyFunction[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 IndexMultiKeyFunction ¶ added in v0.2.0
type IndexMultiKeyFunction[T any] func(builder KeyBuilder, t T) [][]byte
type IndexOptions ¶
type IndexOptions[T any] struct { // IndexID is the ID of the index used when generating the index prefix // of an index entry. IndexID IndexID // IndexName is the name of the index useful for a human readable name. IndexName string // IndexKeyFunc is the function that generates the index key for a given // record. It is also used querying data via an index where you pass the // partial record and set the field values that you want to query on, // which then generates the corresponding index key entry. IndexKeyFunc IndexKeyFunction[T] // IndexMultiKeyFunc is the function that generates multiple index keys // for a given record. This is helpful for a some what "OR" query operation // on multiple fields that will always point to the same record. Note, that // during query time, the IndexKeyFunc is still used during query time. // See table_test.go for an example of how to use this. IndexMultiKeyFunc IndexMultiKeyFunction[T] // IndexOrderFunc is the function that generates the index order for a given // record. This is useful for a query operation that you want to sort the // results by a given field. IndexOrderFunc IndexOrderFunction[T] // IndexFilterFunc is the function that filters the records that will be // indexed. This is useful for a query operation that you want to filter // the records that will be indexed. 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 Iterable ¶ added in v0.2.0
type Iterable 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 interface {
Reset() KeyBuilder
AddInt64Field(i int64) KeyBuilder
AddInt32Field(i int32) KeyBuilder
AddInt16Field(i int16) KeyBuilder
AddUint64Field(i uint64) KeyBuilder
AddUint32Field(i uint32) KeyBuilder
AddUint16Field(i uint16) KeyBuilder
AddByteField(btt byte) KeyBuilder
AddStringField(s string) KeyBuilder
AddBytesField(bs []byte) KeyBuilder
AddBigIntField(bi *big.Int, bits int) KeyBuilder
Bytes() []byte
}
func NewKeyBuilder ¶
func NewKeyBuilder(buff []byte) KeyBuilder
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(performanceProfile ...PerformanceProfile) *Options
type OrderLessFunc ¶
OrderLessFunc is the function template to be used for record sorting.
type PerformanceProfile ¶ added in v0.2.0
type PerformanceProfile int
PerformanceProfile is a profile for the performance of the database depending on the intensity of the workload. Default is MediumPerformance.
const ( LowPerformance PerformanceProfile = iota MediumPerformance HighPerformance )
func ToPerformanceProfile ¶ added in v0.2.0
func ToPerformanceProfile(performanceProfile string) PerformanceProfile
func (PerformanceProfile) String ¶ added in v0.2.0
func (p PerformanceProfile) String() string
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 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 TableIterable ¶ added in v0.2.0
type TableOptions ¶
type TableOptions[T any] struct { DB DB TableID TableID TableName string TablePrimaryKeyFunc TablePrimaryKeyFunc[T] Serializer Serializer[any] Filter FilterWithStats ScanPrefetchSize int }
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] TableIterable[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 }
TableUnsafeInserter provides access to UnsafeInsert method that allows to insert records wihout checking if they already exist in the database.
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], mutable ...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
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
cli
command
|
|
|
cli_direct
command
|
|
|
simple
command
|
|
|
cmd
|
|
|
bond-cli
command
|
|
|
tools/immense_bench
command
|
|
|
testing/mocks/bond
Package bondmock is a generated GoMock package.
|
Package bondmock is a generated GoMock package. |