Documentation
¶
Index ¶
- Constants
- Variables
- func BinaryDataStoreTest(t *testing.T, ctx context.Context, ds BinaryDataStore)
- func JsonDataStoreTest(t *testing.T, ctx context.Context, ds JsonDataStore[TestItem])
- func QueryJsonDataStoreTest(t *testing.T, ctx context.Context, ds JsonDataStore[TestQueryItem])
- func RegisterJsonDatastore(providerName string, factory JsonDataStoreFactory)
- type AfterGetInterceptor
- type AfterSaveInterceptor
- type BeforeGetInterceptor
- type BeforeSaveInterceptor
- type BinaryDataStore
- type Datatype
- func (dt *Datatype[T]) Delete(ctx context.Context, key string) error
- func (dt *Datatype[T]) Exists(ctx context.Context, id string) (bool, error)
- func (dt *Datatype[T]) GenerateID() string
- func (dt *Datatype[T]) Get(ctx context.Context, ID string) (*T, error)
- func (dt *Datatype[T]) GetAll(ctx context.Context) ([]*T, error)
- func (dt *Datatype[T]) GetID(ctx context.Context, item *T) string
- func (dt *Datatype[T]) GetRaw(ctx context.Context, ID string) (*T, error)
- func (dt *Datatype[T]) Initialize(ctx context.Context) error
- func (dt *Datatype[T]) NativeQuery(ctx context.Context, query interface{}) ([]T, error)
- func (dt *Datatype[T]) Query(ctx context.Context, query *SimpleQuery) ([]*T, error)
- func (dt *Datatype[T]) Save(ctx context.Context, item *T) (*T, error)
- func (dt *Datatype[T]) SaveRaw(ctx context.Context, item *T) (*T, error)
- func (dt *Datatype[T]) SetID(ctx context.Context, item *T, id string)
- func (dt *Datatype[T]) Shutdown(ctx context.Context) error
- type DatatypeCollection
- func (dtc *DatatypeCollection) Add(dt *Datatype[any]) error
- func (dtc *DatatypeCollection) FindByName(name string) *Datatype[any]
- func (dtc *DatatypeCollection) FindByPrefix(prefix string) *Datatype[any]
- func (dtc *DatatypeCollection) FindForId(id string) *Datatype[any]
- func (dtc *DatatypeCollection) Initialize(ctx context.Context) error
- func (dtc *DatatypeCollection) Shutdown(ctx context.Context)
- type FilesystemStore
- func (fs *FilesystemStore) Close(ctx context.Context) error
- func (fs *FilesystemStore) Delete(ctx context.Context, key string) error
- func (fs *FilesystemStore) Exists(ctx context.Context, key string) (bool, error)
- func (fs *FilesystemStore) Get(ctx context.Context, key string) ([]byte, error)
- func (fs *FilesystemStore) Init() error
- func (fs *FilesystemStore) Open(ctx context.Context, config interface{}) error
- func (fs *FilesystemStore) Save(ctx context.Context, data []byte, key string) error
- func (fs *FilesystemStore) SaveStream(ctx context.Context, data io.ReadCloser, key string) (int64, error)
- type FilesystemStoreConfig
- type FilesystemStoreFactory
- type Filetype
- type IdGenerator
- type InMemoryStore
- func (mem *InMemoryStore) Close(ctx context.Context) error
- func (mem *InMemoryStore) Delete(ctx context.Context, key string) error
- func (mem *InMemoryStore) Exists(ctx context.Context, key string) (bool, error)
- func (mem *InMemoryStore) Get(ctx context.Context, key string) ([]byte, error)
- func (mem *InMemoryStore) Open(ctx context.Context, config interface{}) error
- func (mem *InMemoryStore) Save(ctx context.Context, data []byte, key string) error
- func (mem *InMemoryStore) SaveStream(ctx context.Context, data io.ReadCloser, key string) (int64, error)
- type InMemoryStoreFactory
- type Indexer
- type JsonDataStore
- type JsonDataStoreAdapter
- type JsonDataStoreFactory
- type LoadInput
- type LoadOutput
- type NativeQuerable
- type SimpleQuery
- type SimpleQueryCondition
- func (sqc *SimpleQueryCondition) GetDate(key string) (val time.Time)
- func (sqc *SimpleQueryCondition) GetFloat(key string) float64
- func (sqc *SimpleQueryCondition) GetInt(key string) int
- func (sqc *SimpleQueryCondition) GetString(key string) string
- func (sqc *SimpleQueryCondition) GetStringArr(key string) []string
- func (sqc *SimpleQueryCondition) Set(key string, value interface{})
- type SimpleQueryConditionGroup
- func (cg *SimpleQueryConditionGroup) After(field string, value time.Time)
- func (cg *SimpleQueryConditionGroup) And() *SimpleQueryConditionGroup
- func (cg *SimpleQueryConditionGroup) Before(field string, value time.Time)
- func (cg *SimpleQueryConditionGroup) Between(field string, gte string, lte string)
- func (cg *SimpleQueryConditionGroup) Contains(field string, value string)
- func (cg *SimpleQueryConditionGroup) Equals(field string, value string)
- func (cg *SimpleQueryConditionGroup) Exists(field string, value string)
- func (cg *SimpleQueryConditionGroup) GreaterThan(field string, value string)
- func (cg *SimpleQueryConditionGroup) GreaterThanOrEqual(field string, value string)
- func (cg *SimpleQueryConditionGroup) Includes(field string, values []string)
- func (cg *SimpleQueryConditionGroup) LessThan(field string, value string)
- func (cg *SimpleQueryConditionGroup) LessThanOrEqual(field string, value string)
- func (cg *SimpleQueryConditionGroup) Not() *SimpleQueryConditionGroup
- func (cg *SimpleQueryConditionGroup) Or() *SimpleQueryConditionGroup
- type SortBy
- type TestItem
- type TestQueryItem
- type TestQueryItemChild
- type TypedJsonStore
- func (ts *TypedJsonStore[T]) Close(ctx context.Context) error
- func (ts *TypedJsonStore[T]) Delete(ctx context.Context, key string) error
- func (ts *TypedJsonStore[T]) Exists(ctx context.Context, key string) (bool, error)
- func (ts *TypedJsonStore[T]) Get(ctx context.Context, key string) (*T, error)
- func (ts *TypedJsonStore[T]) GetAll(ctx context.Context) ([]*T, error)
- func (ts *TypedJsonStore[T]) Open(ctx context.Context, config interface{}) error
- func (ts *TypedJsonStore[T]) Query(ctx context.Context, query *SimpleQuery) ([]*T, error)
- func (ts *TypedJsonStore[T]) Save(ctx context.Context, item *T, key string) error
- type UntypedJsonDataStore
Constants ¶
const FileSytemBinaryStoreID = "file-system"
const InMemoryinaryStoreID = "memory"
Variables ¶
var BinaryDataStoreProviders = cloudy.NewProviderRegistry[BinaryDataStore]()
var ErrInvalidConfiguration = errors.New("invalid configuration object")
var IndexerProviders = cloudy.NewProviderRegistry[Indexer[any]]()
var JsonDataStoreProviders = cloudy.NewProviderRegistry[UntypedJsonDataStore]()
var PrefixSeparator = "-"
var RootFSDir = ""
Functions ¶
func BinaryDataStoreTest ¶ added in v0.0.2
func BinaryDataStoreTest(t *testing.T, ctx context.Context, ds BinaryDataStore)
func JsonDataStoreTest ¶ added in v0.0.2
func QueryJsonDataStoreTest ¶ added in v0.0.2
func QueryJsonDataStoreTest(t *testing.T, ctx context.Context, ds JsonDataStore[TestQueryItem])
func RegisterJsonDatastore ¶
func RegisterJsonDatastore(providerName string, factory JsonDataStoreFactory)
Types ¶
type AfterGetInterceptor ¶
type AfterSaveInterceptor ¶
type BeforeGetInterceptor ¶
type BeforeSaveInterceptor ¶
type BinaryDataStore ¶
type BinaryDataStore interface {
Open(ctx context.Context, config interface{}) error
Close(ctx context.Context) error
Save(ctx context.Context, data []byte, key string) error
SaveStream(ctx context.Context, data io.ReadCloser, key string) (int64, error)
Get(ctx context.Context, key string) ([]byte, error)
Delete(ctx context.Context, key string) error
Exists(ctx context.Context, key string) (bool, error)
}
type Datatype ¶
type Datatype[T any] struct { Name string Prefix string IDField string GetIDFunc func(dt *Datatype[T], item *T) string SetIDFunc func(dt *Datatype[T], item *T, id string) string DataStore JsonDataStore[T] Indexer Indexer[T] ItemType interface{} BeforeSave []BeforeSaveInterceptor[T] AfterSave []AfterSaveInterceptor[T] BeforeGet []BeforeGetInterceptor[T] AfterGet []AfterGetInterceptor[T] // contains filtered or unexported fields }
func (*Datatype[T]) GenerateID ¶
func (*Datatype[T]) GetRaw ¶
Retrieves the Raw Data from the data store and then attempts to unmarshall it using reflection
func (*Datatype[T]) NativeQuery ¶
func (*Datatype[T]) Query ¶
func (dt *Datatype[T]) Query(ctx context.Context, query *SimpleQuery) ([]*T, error)
type DatatypeCollection ¶
type DatatypeCollection struct {
// contains filtered or unexported fields
}
var Datatypes *DatatypeCollection
func NewDatatypeCollection ¶
func NewDatatypeCollection() *DatatypeCollection
func (*DatatypeCollection) FindByName ¶
func (dtc *DatatypeCollection) FindByName(name string) *Datatype[any]
func (*DatatypeCollection) FindByPrefix ¶
func (dtc *DatatypeCollection) FindByPrefix(prefix string) *Datatype[any]
func (*DatatypeCollection) FindForId ¶
func (dtc *DatatypeCollection) FindForId(id string) *Datatype[any]
func (*DatatypeCollection) Initialize ¶
func (dtc *DatatypeCollection) Initialize(ctx context.Context) error
func (*DatatypeCollection) Shutdown ¶
func (dtc *DatatypeCollection) Shutdown(ctx context.Context)
type FilesystemStore ¶
func NewFilesystemStore ¶
func NewFilesystemStore(ext string, dir ...string) *FilesystemStore
func (*FilesystemStore) Delete ¶
func (fs *FilesystemStore) Delete(ctx context.Context, key string) error
func (*FilesystemStore) Init ¶
func (fs *FilesystemStore) Init() error
func (*FilesystemStore) Open ¶
func (fs *FilesystemStore) Open(ctx context.Context, config interface{}) error
func (*FilesystemStore) SaveStream ¶
func (fs *FilesystemStore) SaveStream(ctx context.Context, data io.ReadCloser, key string) (int64, error)
type FilesystemStoreConfig ¶ added in v0.0.2
type FilesystemStoreFactory ¶
type FilesystemStoreFactory struct{}
func (*FilesystemStoreFactory) Create ¶
func (f *FilesystemStoreFactory) Create(cfg interface{}) (BinaryDataStore, error)
func (*FilesystemStoreFactory) FromEnv ¶
func (f *FilesystemStoreFactory) FromEnv(env *cloudy.Environment) (interface{}, error)
type IdGenerator ¶
type IdGenerator[T any] struct{}
func (*IdGenerator[T]) BeforeSave ¶
func (idgen *IdGenerator[T]) BeforeSave(ctx context.Context, dt *Datatype[T], item *T) (*T, error)
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
func NewInMemoryStore ¶
func NewInMemoryStore() *InMemoryStore
func (*InMemoryStore) Delete ¶
func (mem *InMemoryStore) Delete(ctx context.Context, key string) error
func (*InMemoryStore) Open ¶
func (mem *InMemoryStore) Open(ctx context.Context, config interface{}) error
func (*InMemoryStore) SaveStream ¶
func (mem *InMemoryStore) SaveStream(ctx context.Context, data io.ReadCloser, key string) (int64, error)
type InMemoryStoreFactory ¶
type InMemoryStoreFactory struct{}
func (*InMemoryStoreFactory) Create ¶
func (f *InMemoryStoreFactory) Create(cfg interface{}) (BinaryDataStore, error)
func (*InMemoryStoreFactory) FromEnv ¶
func (f *InMemoryStoreFactory) FromEnv(env *cloudy.Environment) (interface{}, error)
type JsonDataStore ¶
type JsonDataStore[T any] interface { // Open will open the datastore for usage. This should // only be done once per datastore Open(ctx context.Context, config interface{}) error // Close should be called to cleannly close the datastore Close(ctx context.Context) error // Save stores an item in the datastore. There is no difference // between an insert and an update. Save(ctx context.Context, item *T, key string) error // Get retrieves an item by it's unique id Get(ctx context.Context, key string) (*T, error) // Gets all the items in the store. GetAll(ctx context.Context) ([]*T, error) // Deletes an item Delete(ctx context.Context, key string) error // Checks to see if a key exists Exists(ctx context.Context, key string) (bool, error) // Sends a simple Query Query(ctx context.Context, query *SimpleQuery) ([]*T, error) }
JsonDataStore stores data structures as JSON. The type argument can be any struct that the json package can marshal. The type argument must NOT be a pointer type. The config information is based on the driver being used. This will typically contain connection information and the necessary information for generating the table or index.
func NewJsonDatastore ¶
func NewJsonDatastore[M any](providerName string, cfg interface{}) (JsonDataStore[M], error)
func NewTypedStore ¶
func NewTypedStore[T any](store UntypedJsonDataStore) JsonDataStore[T]
type JsonDataStoreAdapter ¶
type JsonDataStoreAdapter[T any] struct { DS BinaryDataStore Model T }
func ToJsonDataStore ¶
func ToJsonDataStore[T any](ds BinaryDataStore) *JsonDataStoreAdapter[T]
type JsonDataStoreFactory ¶
type JsonDataStoreFactory interface {
Create(cfg interface{}) (UntypedJsonDataStore, error)
ToConfig(cfgMap map[string]interface{}) (interface{}, error)
}
type LoadOutput ¶
type NativeQuerable ¶
type SimpleQuery ¶
type SimpleQuery struct {
Size int
Offset int
Colums []string
Conditions *SimpleQueryConditionGroup
SortBy []*SortBy
}
SimpleQuery is a simple way to describe conditions and a query
func NewQuery ¶
func NewQuery() *SimpleQuery
type SimpleQueryCondition ¶
func (*SimpleQueryCondition) GetDate ¶
func (sqc *SimpleQueryCondition) GetDate(key string) (val time.Time)
func (*SimpleQueryCondition) GetFloat ¶
func (sqc *SimpleQueryCondition) GetFloat(key string) float64
func (*SimpleQueryCondition) GetInt ¶
func (sqc *SimpleQueryCondition) GetInt(key string) int
func (*SimpleQueryCondition) GetString ¶
func (sqc *SimpleQueryCondition) GetString(key string) string
func (*SimpleQueryCondition) GetStringArr ¶
func (sqc *SimpleQueryCondition) GetStringArr(key string) []string
func (*SimpleQueryCondition) Set ¶
func (sqc *SimpleQueryCondition) Set(key string, value interface{})
type SimpleQueryConditionGroup ¶
type SimpleQueryConditionGroup struct {
Operator string //and, or, no
Conditions []*SimpleQueryCondition
Groups []*SimpleQueryConditionGroup
}
func (*SimpleQueryConditionGroup) After ¶
func (cg *SimpleQueryConditionGroup) After(field string, value time.Time)
func (*SimpleQueryConditionGroup) And ¶
func (cg *SimpleQueryConditionGroup) And() *SimpleQueryConditionGroup
func (*SimpleQueryConditionGroup) Before ¶
func (cg *SimpleQueryConditionGroup) Before(field string, value time.Time)
func (*SimpleQueryConditionGroup) Between ¶
func (cg *SimpleQueryConditionGroup) Between(field string, gte string, lte string)
func (*SimpleQueryConditionGroup) Contains ¶
func (cg *SimpleQueryConditionGroup) Contains(field string, value string)
func (*SimpleQueryConditionGroup) Equals ¶
func (cg *SimpleQueryConditionGroup) Equals(field string, value string)
func (*SimpleQueryConditionGroup) Exists ¶
func (cg *SimpleQueryConditionGroup) Exists(field string, value string)
func (*SimpleQueryConditionGroup) GreaterThan ¶
func (cg *SimpleQueryConditionGroup) GreaterThan(field string, value string)
func (*SimpleQueryConditionGroup) GreaterThanOrEqual ¶
func (cg *SimpleQueryConditionGroup) GreaterThanOrEqual(field string, value string)
func (*SimpleQueryConditionGroup) Includes ¶
func (cg *SimpleQueryConditionGroup) Includes(field string, values []string)
func (*SimpleQueryConditionGroup) LessThan ¶
func (cg *SimpleQueryConditionGroup) LessThan(field string, value string)
func (*SimpleQueryConditionGroup) LessThanOrEqual ¶
func (cg *SimpleQueryConditionGroup) LessThanOrEqual(field string, value string)
func (*SimpleQueryConditionGroup) Not ¶
func (cg *SimpleQueryConditionGroup) Not() *SimpleQueryConditionGroup
func (*SimpleQueryConditionGroup) Or ¶
func (cg *SimpleQueryConditionGroup) Or() *SimpleQueryConditionGroup
type TestQueryItem ¶ added in v0.0.2
type TestQueryItemChild ¶ added in v0.0.2
type TestQueryItemChild struct {
Name string
}
type TypedJsonStore ¶
type TypedJsonStore[T any] struct { // contains filtered or unexported fields }
func (*TypedJsonStore[T]) Close ¶
func (ts *TypedJsonStore[T]) Close(ctx context.Context) error
Close should be called to cleannly close the datastore
func (*TypedJsonStore[T]) Delete ¶
func (ts *TypedJsonStore[T]) Delete(ctx context.Context, key string) error
Deletes an item
func (*TypedJsonStore[T]) Get ¶
func (ts *TypedJsonStore[T]) Get(ctx context.Context, key string) (*T, error)
Get retrieves an item by it's unique id
func (*TypedJsonStore[T]) GetAll ¶
func (ts *TypedJsonStore[T]) GetAll(ctx context.Context) ([]*T, error)
Gets all the items in the store.
func (*TypedJsonStore[T]) Open ¶
func (ts *TypedJsonStore[T]) Open(ctx context.Context, config interface{}) error
Open will open the datastore for usage. This should only be done once per datastore
func (*TypedJsonStore[T]) Query ¶
func (ts *TypedJsonStore[T]) Query(ctx context.Context, query *SimpleQuery) ([]*T, error)
Sends a simple Query
type UntypedJsonDataStore ¶
type UntypedJsonDataStore interface {
// Open will open the datastore for usage. This should
// only be done once per datastore
Open(ctx context.Context, config interface{}) error
// Close should be called to cleannly close the datastore
Close(ctx context.Context) error
// Save stores an item in the datastore. There is no difference
// between an insert and an update.
Save(ctx context.Context, item interface{}, key string) error
// Get retrieves an item by it's unique id
Get(ctx context.Context, key string) (interface{}, error)
// Gets all the items in the store.
GetAll(ctx context.Context) ([]interface{}, error)
// Deletes an item
Delete(ctx context.Context, key string) error
// Checks to see if a key exists
Exists(ctx context.Context, key string) (bool, error)
// Sends a simple Query
Query(ctx context.Context, query *SimpleQuery) ([]interface{}, error)
}