store

package
v0.0.0-...-04649f3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package store contains the sql backed store. It persists objects to a sqlite database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBClient

type DBClient interface {
	BeginTx(ctx context.Context, forWriting bool) (db.TXClient, error)
	Prepare(stmt string) *sql.Stmt
	QueryForRows(ctx context.Context, stmt transaction.Stmt, params ...any) (*sql.Rows, error)
	ReadObjects(rows db.Rows, typ reflect.Type, shouldDecrypt bool) ([]any, error)
	ReadStrings(rows db.Rows) ([]string, error)
	ReadInt(rows db.Rows) (int, error)
	Upsert(tx db.TXClient, stmt *sql.Stmt, key string, obj any, shouldEncrypt bool) error
	CloseStmt(closable db.Closable) error
}

type Store

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

Store is a SQLite-backed cache.Store

func NewStore

func NewStore(example any, keyFunc cache.KeyFunc, c DBClient, shouldEncrypt bool, name 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) Delete

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

Delete deletes the given object, 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) GetName

func (s *Store) GetName() string

func (*Store) GetShouldEncrypt

func (s *Store) GetShouldEncrypt() bool

func (*Store) GetType

func (s *Store) GetType() reflect.Type

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: Atm it doesn't appear returning nil in the case of an error has any detrimental effects. An error is not uncommon enough nor does it appear to necessitate a panic.

func (*Store) RegisterAfterDelete

func (s *Store) RegisterAfterDelete(f func(key string, txC db.TXClient) error)

RegisterAfterDelete registers a func to be called after each deletion

func (*Store) RegisterAfterUpsert

func (s *Store) RegisterAfterUpsert(f func(key string, obj any, txC db.TXClient) 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) 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

Jump to

Keyboard shortcuts

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