sqlcache

package
v0.0.0-...-75230cb Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewThreadSafeStore

func NewThreadSafeStore(example any, path string, indexers cache.Indexers) (cache.ThreadSafeStore, error)

NewThreadSafeStore returns a cache.ThreadSafeStore backed by SQLite for the example type

func UnsafeGet

func UnsafeGet(object any, field string) any

func UnsafeSet

func UnsafeSet(object any, field string, value any)

Types

type FieldFunc

type FieldFunc func(obj any) any

FieldFunc is a function from an object to a filterable/sortable property. Result can be string, int or bool

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter represents a field to filter by. A subfield in an object is represented in a request query using . notation, e.g. 'metadata.name'. The subfield is internally represented as a slice, e.g. [metadata, name].

type Indexer

type Indexer struct {
	*Store
	// contains filtered or unexported fields
}

Indexer is a SQLite-backed cache.Indexer which builds upon Store adding an index table

func NewIndexer

func NewIndexer(example any, keyFunc cache.KeyFunc, path string, indexers cache.Indexers) (*Indexer, error)

NewIndexer returns a cache.Indexer backed by SQLite for objects of the given example type

func (*Indexer) AddIndexers

func (i *Indexer) AddIndexers(newIndexers cache.Indexers) error

AddIndexers adds more indexers to this Store. If you call this after you already have data in the Store, the results are undefined.

func (*Indexer) AfterUpsert

func (i *Indexer) AfterUpsert(key string, obj any, tx *sql.Tx) error

AfterUpsert updates indices of an object

func (*Indexer) ByIndex

func (i *Indexer) ByIndex(indexName, indexedValue string) ([]any, error)

ByIndex returns the stored objects whose set of indexed values for the named index includes the given indexed value

func (*Indexer) GetIndexers

func (i *Indexer) GetIndexers() cache.Indexers

GetIndexers returns the indexers

func (*Indexer) Index

func (i *Indexer) Index(indexName string, obj any) ([]any, error)

Index returns a list of items that match the given object on the index function

func (*Indexer) IndexKeys

func (i *Indexer) IndexKeys(indexName, indexedValue string) ([]string, error)

IndexKeys returns a list of the Store keys of the objects whose indexed values in the given index include the given indexed value

func (*Indexer) ListIndexFuncValues

func (i *Indexer) ListIndexFuncValues(name string) []string

ListIndexFuncValues wraps SafeListIndexFuncValues and panics in case of I/O errors

func (*Indexer) SafeListIndexFuncValues

func (i *Indexer) SafeListIndexFuncValues(indexName string) ([]string, error)

SafeListIndexFuncValues returns all the indexed values of the given index

type ListOptionIndexer

type ListOptionIndexer struct {
	*VersionedIndexer
	// contains filtered or unexported fields
}

ListOptionIndexer extends VersionedIndexer by allowing queries based on ListOption

func NewCustomListOptionIndexer

func NewCustomListOptionIndexer(example meta.Object, keyFunc cache.KeyFunc, path string, fieldFuncs map[string]FieldFunc, indexers cache.Indexers) (*ListOptionIndexer, error)

NewCustomListOptionIndexer returns a cache.Indexer on a Kubernetes resource that is also able to satisfy ListOption queries with custom keyFunc and Indexers

func NewListOptionIndexer

func NewListOptionIndexer(example meta.Object, path string, fieldFuncs map[string]FieldFunc) (*ListOptionIndexer, error)

NewListOptionIndexer returns a cache.Indexer on a Kubernetes resource that is also able to satisfy ListOption queries

func (*ListOptionIndexer) AfterUpsert

func (l *ListOptionIndexer) AfterUpsert(key string, obj any, tx *sql.Tx) error

AfterUpsert saves sortable/filterable fields into tables

func (*ListOptionIndexer) ListByOptions

func (l *ListOptionIndexer) ListByOptions(lo ListOptions) ([]any, error)

ListByOptions returns objects according to the ListOptions struct

type ListOptions

type ListOptions struct {
	ChunkSize  int
	Resume     string
	Filters    []Filter
	Sort       Sort
	Pagination Pagination
	Revision   string
}

ListOptions represents the query parameters that may be included in a list request.

type Pagination

type Pagination struct {
	// contains filtered or unexported fields
}

Pagination represents how to return paginated results.

type Sort

type Sort struct {
	// contains filtered or unexported fields
}

Sort represents the criteria to sort on. The subfield to sort by is represented in a request query using . notation, e.g. 'metadata.name'. The subfield is internally represented as a slice, e.g. [metadata, name]. The order is represented by prefixing the sort key by '-', e.g. sort=-metadata.name.

type SortOrder

type SortOrder int

SortOrder represents whether the list should be ascending or descending.

const (
	// ASC stands for ascending order.
	ASC SortOrder = iota
	// DESC stands for descending (reverse) order.
	DESC
)

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a SQLite-backed cache.Store

func NewStore

func NewStore(example any, keyFunc cache.KeyFunc, path string) (*Store, error)

NewStore creates a SQLite-backed cache.Store for objects of the given example type

func (*Store) Add

func (s *Store) Add(obj any) error

Add saves an obj, or updates it if it exists in this Store

func (*Store) Close

func (s *Store) Close() error

Close closes the database and prevents new queries from starting

func (*Store) Delete

func (s *Store) Delete(obj any) error

Delete deletes the given object, if it exists in this Store

func (*Store) DeleteByKey

func (s *Store) DeleteByKey(key string) error

DeleteByKey deletes the object associated with key, if it exists in this Store

func (*Store) Get

func (s *Store) Get(obj any) (item any, exists bool, err error)

Get returns the object with the same key as obj

func (*Store) GetByKey

func (s *Store) GetByKey(key string) (item any, exists bool, err error)

GetByKey returns the object associated with the given object's key

func (*Store) InitExec

func (s *Store) InitExec(stmt string) error

InitExec executes a statement as part of the DB initialization, closing the connection on error

func (*Store) List

func (s *Store) List() []any

List returns a list of all the currently known objects Note: I/O errors will panic this function, as the interface signature does not allow returning errors

func (*Store) ListKeys

func (s *Store) ListKeys() []string

ListKeys returns a list of all the keys currently in this Store Note: I/O errors will panic this function, as the interface signature does not allow returning errors

func (*Store) Prepare

func (s *Store) Prepare(stmt string) *sql.Stmt

Prepare prepares a statement

func (*Store) QueryObjects

func (s *Store) QueryObjects(stmt *sql.Stmt, params ...any) ([]any, error)

QueryObjects runs a prepared statement that returns gobbed objects of type typ

func (*Store) QueryStrings

func (s *Store) QueryStrings(stmt *sql.Stmt, params ...any) ([]string, error)

QueryStrings runs a prepared statement that returns strings

func (*Store) RegisterAfterDelete

func (s *Store) RegisterAfterDelete(f func(key string, tx *sql.Tx) error)

RegisterAfterDelete registers a func to be called after each deletion

func (*Store) RegisterAfterUpsert

func (s *Store) RegisterAfterUpsert(f func(key string, obj any, tx *sql.Tx) error)

RegisterAfterUpsert registers a func to be called after each upsert

func (*Store) Replace

func (s *Store) Replace(objects []any, _ string) error

Replace will delete the contents of the Store, using instead the given list

func (*Store) ReplaceByKey

func (s *Store) ReplaceByKey(objects map[string]any) error

ReplaceByKey will delete the contents of the Store, using instead the given key to obj map

func (*Store) Resync

func (s *Store) Resync() error

Resync is a no-op and is deprecated

func (*Store) Update

func (s *Store) Update(obj any) error

Update saves an obj, or updates it if it exists in this Store

func (*Store) Upsert

func (s *Store) Upsert(key string, obj any) error

Upsert saves an obj with its key, or updates key with obj if it exists in this Store

type VersionFunc

type VersionFunc func(obj any) (int, error)

type VersionedIndexer

type VersionedIndexer struct {
	*Indexer
	// contains filtered or unexported fields
}

VersionedIndexer extends Indexer by storing a range of versions in addition to the latest one

func NewVersionedIndexer

func NewVersionedIndexer(example any, keyFunc cache.KeyFunc, versionFunc VersionFunc, path string, indexers cache.Indexers) (*VersionedIndexer, error)

NewVersionedIndexer returns an Indexer that also stores a range of versions in addition to the latest one

func (*VersionedIndexer) AfterDelete

func (v *VersionedIndexer) AfterDelete(key string, tx *sql.Tx) error

AfterDelete updates the deleted flag on the history table

func (*VersionedIndexer) AfterUpsert

func (v *VersionedIndexer) AfterUpsert(key string, obj any, tx *sql.Tx) error

AfterUpsert appends the latest version to the history table

func (*VersionedIndexer) GetByKeyAndVersion

func (v *VersionedIndexer) GetByKeyAndVersion(key string, version int) (item any, exists bool, err error)

GetByKeyAndVersion returns the object associated with the given object's key and (exact) version

Jump to

Keyboard shortcuts

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