table

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedTable

type CachedTable[K comparable, E any] struct {
	reconciler.ManagerImpl
	// contains filtered or unexported fields
}

CachedTable is a generic table type providing common functions and types to specific structures each table is built using. This table also ensure keeping an inmemory cache information to enable better responsiveness for critical path data fetch, where we are required to be consistent, but it is ok to let go some part of accuracy, assuming system will automatically converge as it settles down with change propagation. It also ensures sanity checks and provides common functionality for database-backed tables.

K: Key type (must NOT be a pointer type, typically a struct or primitive) E: Entry type (must NOT be a pointer type)

func (*CachedTable[K, E]) Count

func (t *CachedTable[K, E]) Count(ctx context.Context, filter any) (int64, error)

Count retrieves count of entries matching the provided filter. Returns count of entries and error if none found or if the table is not initialized.

func (*CachedTable[K, E]) DBFind

func (t *CachedTable[K, E]) DBFind(ctx context.Context, key *K) (*E, error)

DBFind retrieves an entry by key from the Database Returns the entry and error if not found or if the table is not initialized.

func (*CachedTable[K, E]) DBFindMany

func (t *CachedTable[K, E]) DBFindMany(ctx context.Context, filter any, offset, limit int32) ([]*E, error)

DBFindMany retrieves multiple entries matching the provided filter from database. Returns a slice of entries and error if none found or if the table is not initialized.

func (*CachedTable[K, E]) DeleteByFilter

func (t *CachedTable[K, E]) DeleteByFilter(ctx context.Context, filter any) (int64, error)

DeleteByFilter deletes entries matching the provided filter. Returns number of entries deleted and error if any

func (*CachedTable[K, E]) DeleteKey

func (t *CachedTable[K, E]) DeleteKey(ctx context.Context, key *K) error

DeleteKey removes an entry by key from the table. Returns an error if the table is not initialized or the delete fails.

func (*CachedTable[K, E]) Find

func (t *CachedTable[K, E]) Find(ctx context.Context, key *K) (*E, error)

Find retrieves an entry by key from the Cache Returns the entry and error if not found or if the table is not initialized.

func (*CachedTable[K, E]) Initialize

func (t *CachedTable[K, E]) Initialize(col db.StoreCollection) error

Initialize sets up the Table with the provided db.StoreCollection. It performs sanity checks on the entry and key types and registers the key type with the collection. Must be called before any other operation.

Returns an error if the table is already initialized, the entry or key type is a pointer, or if the collection setup fails.

func (*CachedTable[K, E]) Insert

func (t *CachedTable[K, E]) Insert(ctx context.Context, key *K, entry *E) error

Insert adds a new entry to the table with the given key. Returns an error if the table is not initialized or the insert fails.

func (*CachedTable[K, E]) Locate

func (t *CachedTable[K, E]) Locate(ctx context.Context, key *K, entry *E) error

Locate finds an entry by key, inserts it if it doesn't exist, or updates it if it does. Returns an error if the table is not initialized or the operation fails.

func (*CachedTable[K, E]) ReconcilerGetAllKeys

func (t *CachedTable[K, E]) ReconcilerGetAllKeys() []any

ReconcilerGetAllKeys returns all keys in the table. Used by the reconciler to enumerate all managed entries.

func (*CachedTable[K, E]) Update

func (t *CachedTable[K, E]) Update(ctx context.Context, key *K, entry *E) error

Update modifies an existing entry with the given key. Returns an error if the table is not initialized or the update fails.

type Table

type Table[K any, E any] struct {
	reconciler.ManagerImpl
	// contains filtered or unexported fields
}

Table is a generic table type providing common functions and types to specific structures each table is built using. It ensures sanity checks and provides common functionality for database-backed tables.

K: Key type (must NOT be a pointer type, typically a struct or primitive) E: Entry type (must NOT be a pointer type)

func (*Table[K, E]) Count

func (t *Table[K, E]) Count(ctx context.Context, filter any) (int64, error)

Count retrieves count of entries matching the provided filter. Returns count of entries and error if none found or if the table is not initialized.

func (*Table[K, E]) DeleteByFilter

func (t *Table[K, E]) DeleteByFilter(ctx context.Context, filter any) (int64, error)

DeleteByFilter deletes entries matching the provided filter. Returns number of entries deleted and error if any

func (*Table[K, E]) DeleteKey

func (t *Table[K, E]) DeleteKey(ctx context.Context, key *K) error

DeleteKey removes an entry by key from the table. Returns an error if the table is not initialized or the delete fails.

func (*Table[K, E]) Find

func (t *Table[K, E]) Find(ctx context.Context, key *K) (*E, error)

Find retrieves an entry by key. Returns the entry and error if not found or if the table is not initialized.

func (*Table[K, E]) FindMany

func (t *Table[K, E]) FindMany(ctx context.Context, filter any, offset, limit int32) ([]*E, error)

FindMany retrieves multiple entries matching the provided filter. Returns a slice of entries and error if none found or if the table is not initialized.

func (*Table[K, E]) Initialize

func (t *Table[K, E]) Initialize(col db.StoreCollection) error

Initialize sets up the Table with the provided db.StoreCollection. It performs sanity checks on the entry and key types and registers the key type with the collection. Must be called before any other operation.

Returns an error if the table is already initialized, the entry or key type is a pointer, or if the collection setup fails.

func (*Table[K, E]) Insert

func (t *Table[K, E]) Insert(ctx context.Context, key *K, entry *E) error

Insert adds a new entry to the table with the given key. Returns an error if the table is not initialized or the insert fails.

func (*Table[K, E]) Locate

func (t *Table[K, E]) Locate(ctx context.Context, key *K, entry *E) error

Locate finds an entry by key, inserts it if it doesn't exist, or updates it if it does. Returns an error if the table is not initialized or the operation fails.

func (*Table[K, E]) ReconcilerGetAllKeys

func (t *Table[K, E]) ReconcilerGetAllKeys() []any

ReconcilerGetAllKeys returns all keys in the table. Used by the reconciler to enumerate all managed entries.

func (*Table[K, E]) Update

func (t *Table[K, E]) Update(ctx context.Context, key *K, entry *E) error

Update modifies an existing entry with the given key. Returns an error if the table is not initialized or the update fails.

Jump to

Keyboard shortcuts

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