db

package
v0.44.47 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

The very core database/cache data operations package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteOne

func DeleteOne(cache Cacher, key string) bool

DeleteOne deletes an item from such cache via the requested key value. Fails if the database state is locked.

func DumpAll

func DumpAll() string

func FanInChannels added in v0.44.19

func FanInChannels(l common.Logger, channels ...chan interface{}) <-chan interface{}

FanInChannels is a helper function that collects results from multiple workers.

func GetAll

func GetAll[T any](cache Cacher, model T) (map[string]T, int64)

GetAll function does a fetch-all operation on the given cache instance. After the data retrieval, all items are to be asserted their corresponding types and to be loaded into a map[string]T map, where T is a generic type. This map and number of processed items are returned.

func GetGravatarURL

func GetGravatarURL(user models.User, channel chan interface{}, wg *sync.WaitGroup) string

GetGravatarURL function returns the avatar image location/URL, or it defaults to a app logo.

func GetOne

func GetOne[T any](cache Cacher, key string, model T) (T, bool)

GetOne fetches just one very item from the given cache instance. As long as the function is generic, the type is asserted automatically, so the type passing is required. Returns the requested item and the its retrieval result as boolean.

func LoadAll

func LoadAll() string

func Lock added in v0.43.2

func Lock()

func RLock added in v0.44.19

func RLock()

func RUnlock added in v0.44.19

func RUnlock()

func ReleaseLock added in v0.44.19

func ReleaseLock()

ReleaseLock is a special function evoked when the lock needs to be released before the backend shutdown not to defer its exit, but to keep the database stack in the read-only state.

func Router

func Router() chi.Router

func RunMigrations

func RunMigrations() string

RunMigrations is a wrapper function for the migration registration and execution.

func SetOne

func SetOne[T any](cache Cacher, key string, model T) bool

SetOne writes the input value of some type to the corresponding cache storing the very same item type (TODO ensure this). Fails if the database state is locked or uninitialized. Please note that this very function has to have another sync mechanism implemented, as the combined read+write operation is not considered a thread safe.

func Unlock added in v0.43.2

func Unlock()

Types

type Cacher added in v0.44.19

type Cacher interface {
	// Load takes a key string and fetches its value from the implementing cache store.
	// Returns true if the item has been found, otherwise writes false.
	Load(key string) (interface{}, bool)

	// Store takes a key-value pair and stores the value with the associated key into the implementing cache store.
	// Simple overwrite.
	Store(key string, value interface{}) bool

	// Delete takes a key string and deletes its record in the implementing cache store.
	Delete(key string) bool

	// Range loop over all the implementing cache keys and retrieves all the associated values as interface{}.
	// Returns the pointer to a GenericMap with all keys and their associated values, and the item count.
	Range() (*GenericMap, int64)

	// GetName returns the implemented cache's name.
	GetName() string
}
var (
	FlowCache         Cacher
	PollCache         Cacher
	RequestCache      Cacher
	SubscriptionCache Cacher
	TokenCache        Cacher
	UserCache         Cacher
)

type Database added in v0.44.19

type Database struct {

	// Helper booleans to simply track the stack's state.
	RLocked bool
	Locked  bool

	// Members of the stack mush implement the Cacher interface.
	Members []Cacher
	// contains filtered or unexported fields
}

type DefaultCache added in v0.44.19

type DefaultCache struct {
	// Name of the cache.
	Name string
	// contains filtered or unexported fields
}

func NewDefaultCache added in v0.44.19

func NewDefaultCache(name string) *DefaultCache

func (*DefaultCache) Delete added in v0.44.19

func (c *DefaultCache) Delete(key string) bool

func (*DefaultCache) GetName added in v0.44.19

func (c *DefaultCache) GetName() string

func (*DefaultCache) Load added in v0.44.19

func (c *DefaultCache) Load(key string) (interface{}, bool)

func (*DefaultCache) Range added in v0.44.19

func (c *DefaultCache) Range() (*GenericMap, int64)

func (*DefaultCache) Store added in v0.44.19

func (c *DefaultCache) Store(key string, rawV interface{}) bool

type GenericMap added in v0.44.19

type GenericMap map[string]interface{}

type Repositories added in v0.44.22

type Repositories struct {
	PollRepository models.PollRepositoryInterface
	PostRepository models.PostRepositoryInterface
	UserRepository models.UserRepositoryInterface
}
var Storage *Repositories

type SignalCache added in v0.44.19

type SignalCache struct {
	// Name of the cache.
	Name string
	// contains filtered or unexported fields
}

func NewSignalCache added in v0.44.19

func NewSignalCache(name string) *SignalCache

func (*SignalCache) Delete added in v0.44.19

func (c *SignalCache) Delete(key string) bool

func (*SignalCache) GetName added in v0.44.19

func (c *SignalCache) GetName() string

func (*SignalCache) Load added in v0.44.19

func (c *SignalCache) Load(key string) (interface{}, bool)

func (*SignalCache) Range added in v0.44.19

func (c *SignalCache) Range() (*GenericMap, int64)

func (*SignalCache) Store added in v0.44.19

func (c *SignalCache) Store(key string, rawV interface{}) bool

type SimpleCache added in v0.44.19

type SimpleCache struct {
	// Name of the cache.
	Name string
	// contains filtered or unexported fields
}

func NewSimpleCache added in v0.44.19

func NewSimpleCache(name string) *SimpleCache

func (*SimpleCache) Delete added in v0.44.19

func (c *SimpleCache) Delete(key string) bool

func (*SimpleCache) GetName added in v0.44.19

func (c *SimpleCache) GetName() string

func (*SimpleCache) Load added in v0.44.19

func (c *SimpleCache) Load(key string) (interface{}, bool)

func (*SimpleCache) LoadOrStore added in v0.44.23

func (c *SimpleCache) LoadOrStore(key string, rawV interface{}) (interface{}, bool)

func (*SimpleCache) Range added in v0.44.19

func (c *SimpleCache) Range() (*GenericMap, int64)

func (*SimpleCache) Store added in v0.44.19

func (c *SimpleCache) Store(key string, rawV interface{}) bool

Jump to

Keyboard shortcuts

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