store

package
v0.0.0-...-4d3ba93 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllAs

func AllAs[T Storable](items []Storable) ([]T, error)

func As

func As[T Storable](item Storable) T

func GetAllAs

func GetAllAs[T Storable](store Store, typeName string) ([]T, error)

func GetAs

func GetAs[T Storable](store Store, id *Id) (T, error)

func GetIndexableBoolValue

func GetIndexableBoolValue(item Storable, typeName, propertyName string) (bool, bool)

GetIndexableBoolValue uses reflection to extract the bool value of a specified property from a Storable item. It's intended for use in indexing.

Parameters:

  • item: The Storable item from which to extract the value.
  • typeName: The type name of the item, used for logging purposes.
  • propertyName: The name of the property (struct field) to extract.

Returns:

  • bool: The bool value of the property if found, accessible, and of bool type.
  • bool: True if the property was successfully extracted and is suitable for boolean indexing, false otherwise. If false, a warning will be logged.

func GetIndexableDateTimeValue

func GetIndexableDateTimeValue(item Storable, typeName, propertyName string) (time.Time, bool)

GetIndexableDateTimeValue uses reflection to extract the time.Time value of a specified property from a Storable item. It's intended for use in indexing.

Parameters:

  • item: The Storable item from which to extract the value.
  • typeName: The type name of the item, used for logging purposes.
  • propertyName: The name of the property (struct field) to extract.

Returns:

  • time.Time: The time.Time value of the property if found, accessible, and of time.Time type.
  • bool: True if the property was successfully extracted and is suitable for date/time indexing, false otherwise. If false, a warning will be logged.

func GetIndexableFloatValue

func GetIndexableFloatValue(item Storable, typeName, propertyName string) (float64, bool)

GetIndexableFloatValue uses reflection to extract the float64 value of a specified property from a Storable item. It's intended for use in indexing.

Parameters:

  • item: The Storable item from which to extract the value.
  • typeName: The type name of the item, used for logging purposes.
  • propertyName: The name of the property (struct field) to extract.

Returns:

  • float64: The float64 value of the property if found, accessible, and of float64 type.
  • bool: True if the property was successfully extracted and is suitable for float indexing, false otherwise. If false, a warning will be logged.

func GetIndexableIntValue

func GetIndexableIntValue(item Storable, typeName, propertyName string) (int64, bool)

GetIndexableIntValue uses reflection to extract the int64 value of a specified property from a Storable item. It's intended for use in indexing.

Parameters:

  • item: The Storable item from which to extract the value.
  • typeName: The type name of the item, used for logging purposes.
  • propertyName: The name of the property (struct field) to extract.

Returns:

  • int64: The int64 value of the property if found, accessible, and of int64 type.
  • bool: True if the property was successfully extracted and is suitable for integer indexing, false otherwise. If false, a warning will be logged.

func GetIndexableStringValue

func GetIndexableStringValue(item Storable, typeName, propertyName string) (string, bool)

GetIndexableStringValue uses reflection to extract the string value of a specified property from a Storable item. It's intended for use in indexing.

Parameters:

  • item: The Storable item from which to extract the value.
  • typeName: The type name of the item, used for logging purposes.
  • propertyName: The name of the property (struct field) to extract. This is passed in because item.GetTypeName() might be too generic if 'item' is an interface type at the call site.

Returns:

  • string: The string value of the property if found, accessible, and of string type.
  • bool: True if the property was successfully extracted and is suitable for string indexing, false otherwise. If false, a warning will be logged.

Types

type BoltStore

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

func (*BoltStore) AllocateBucketIfNeeded

func (bs *BoltStore) AllocateBucketIfNeeded(typeName string) error

func (*BoltStore) AllocateId

func (bs *BoltStore) AllocateId(item Storable) error

func (*BoltStore) Close

func (bs *BoltStore) Close() error

Close closes the BoltDB database.

func (*BoltStore) Delete

func (bs *BoltStore) Delete(id *Id) error

Delete removes a model by its key.

func (*BoltStore) Exists

func (bs *BoltStore) Exists(id *Id) (bool, error)

Exists checks if a model with the given Id exists.

func (*BoltStore) Get

func (bs *BoltStore) Get(id *Id) (Storable, error)

Get retrieves a Storable model by its key.

func (*BoltStore) GetAll

func (bs *BoltStore) GetAll(typeId int64) ([]Storable, error)

GetAll retrieves all Storable models of a given typeId.

func (*BoltStore) GetAllByTypeName

func (bs *BoltStore) GetAllByTypeName(typeName string) ([]Storable, error)

GetAllByTypeName retrieves all Storable models of a given typeName.

func (*BoltStore) Match

func (bs *BoltStore) Match(indexName string, value interface{}) ([]Storable, error)

func (*BoltStore) Put

func (bs *BoltStore) Put(m Storable) error

Put stores a Storable model.

func (*BoltStore) PutAll

func (bs *BoltStore) PutAll(m []Storable) error

PutAll stores multiple Storable models.

func (*BoltStore) WildcardMatch

func (bs *BoltStore) WildcardMatch(indexName string, pattern string) ([]Storable, error)

type Id

type Id struct {
	TypeId   int64 `json:"type_id"`
	ObjectId int64 `json:"object_id"`
}

Every object has an Id.

func IdFromString

func IdFromString(s string) (*Id, error)

func NewId

func NewId(typeId, objectId int64) *Id

func (*Id) String

func (id *Id) String() string

type IndexDataType

type IndexDataType int
const (
	StringIndex IndexDataType = iota
	Int64Index
	Float64Index
	BoolIndex
	DateTimeIndex
)

IndexDataType specifies the underlying data type of the indexed property.

func (IndexDataType) String

func (idt IndexDataType) String() string

String returns the string representation of IndexDataType.

type IndexDefinition

type IndexDefinition struct {
	PropertyName string        `json:"propertyName"`
	Type         IndexType     `json:"type"`
	DataType     IndexDataType `json:"dataType"`
}

type IndexType

type IndexType int
const (
	UniqueIndex IndexType = iota
	NonUniqueIndex
)

func (IndexType) String

func (it IndexType) String() string

type Storable

type Storable interface {
	GetId() *Id
	SetId(id *Id)
	GetTypeName() string
	Marshal() ([]byte, error)
	Unmarshal(data []byte) error
}

type Store

type Store interface {
	Put(m Storable) error
	PutAll(m []Storable) error
	Exists(id *Id) (bool, error)
	Get(id *Id) (Storable, error)
	GetAll(typeId int64) ([]Storable, error)
	GetAllByTypeName(typeName string) ([]Storable, error)
	Delete(id *Id) error
	AllocateId(item Storable) error
	AllocateBucketIfNeeded(typeName string) error

	// Match finds storables where an indexed property exactly matches the given value.
	// The type of 'value' should correspond to the IndexDefinition.DataType of the indexed property.
	// indexName is in the form of TypeName.PropertyName.
	Match(indexName string, value interface{}) ([]Storable, error)

	// WildcardMatch finds storables where an indexed string property matches the given wildcard pattern.
	// indexName is in the form of TypeName.PropertyName.
	// The property must be indexed and of type StringIndex.
	WildcardMatch(indexName string, pattern string) ([]Storable, error)

	Close() error
}

func NewBoltStore

func NewBoltStore(path string, typeManager StoreTypeManager) (Store, error)

NewBoltStore creates and returns a new BoltStore. It takes the path to the BoltDB file.

type StoreTypeManager

type StoreTypeManager interface {
	CreateInstance(typeId int64) (Storable, error)
	GetTypeId(typeName string) (int64, error)
	GetTypeName(typeId int64) (string, error)
	AllocateId(item Storable) error
	Indexes(typeId int64) []*IndexDefinition
}

Jump to

Keyboard shortcuts

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