datastore

package
v0.7.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// SortOrderAscending defines the order of ascending for sorting
	SortOrderAscending = SortOrder(1)
	// SortOrderDescending defines the order of descending for sorting
	SortOrderDescending = SortOrder(-1)
)

Variables

View Source
var (
	// ErrPrimaryEmpty Error that primary key is empty.
	ErrPrimaryEmpty = NewDBError(fmt.Errorf("entity primary is empty"))

	// ErrTableNameEmpty Error that table name is empty.
	ErrTableNameEmpty = NewDBError(fmt.Errorf("entity table name is empty"))

	// ErrNilEntity Error that entity is nil
	ErrNilEntity = NewDBError(fmt.Errorf("entity is nil"))

	// ErrRecordExist Error that entity primary key is exist
	ErrRecordExist = NewDBError(fmt.Errorf("data record is exist"))

	// ErrRecordNotExist Error that entity primary key is not exist
	ErrRecordNotExist = NewDBError(fmt.Errorf("data record is not exist"))

	// ErrIndexInvalid Error that entity index is invalid
	ErrIndexInvalid = NewDBError(fmt.Errorf("entity index is invalid"))

	// ErrEntityInvalid Error that entity is invalid
	ErrEntityInvalid = NewDBError(fmt.Errorf("entity is invalid"))
)

Functions

func NewDBError

func NewDBError(err error) error

NewDBError new datastore error

func SetDefaultDatastore

func SetDefaultDatastore(ds Datastore)

func SetDefaultJsonDatastore

func SetDefaultJsonDatastore(jds JsonDatastore)

Types

type DBError

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

DBError datastore error

func (*DBError) Error

func (d *DBError) Error() string

type Datastore

type Datastore interface {
	Init() error
	Add(ctx context.Context, entity Entity) error
	BatchAdd(ctx context.Context, entities []Entity) error
	Put(ctx context.Context, entity Entity) error
	Delete(ctx context.Context, entity Entity) error
	Get(ctx context.Context, entity Entity) error
	List(ctx context.Context, query Entity, options *ListOptions) ([]Entity, error)
	Count(ctx context.Context, entity Entity, options *FilterOptions) (int64, error)
	IsExist(ctx context.Context, entity Entity) (bool, error)
	Commit(ctx context.Context) error
}

func GetDefaultDatastore

func GetDefaultDatastore() Datastore

type Entity

type Entity interface {
	SetCreateTime(time time.Time)
	SetUpdateTime(time time.Time)
	PrimaryKey() string
	TableName() string
	Index() map[string]interface{}
}

Entity database data model

func NewEntity

func NewEntity(in Entity) (Entity, error)

type FilterOptions

type FilterOptions struct {
	Queries    []FuzzyQueryOption
	In         []InQueryOption
	IsNotExist []IsNotExistQueryOption
}

FilterOptions filter query returned items

type Float32List added in v0.6.0

type Float32List []float32

func (*Float32List) Scan added in v0.6.0

func (f *Float32List) Scan(value interface{}) error

Scan converts a database value to a Float32List

func (Float32List) Value added in v0.6.0

func (f Float32List) Value() (driver.Value, error)

Value converts a Float32List to a value for SQL storage

type FuzzyQueryOption

type FuzzyQueryOption struct {
	Key   string
	Query string
}

FuzzyQueryOption defines the fuzzy query search filter option

type InQueryOption

type InQueryOption struct {
	Key    string
	Values []string
}

InQueryOption defines the include search filter option

type Int64List added in v0.6.0

type Int64List []int64

func (*Int64List) Scan added in v0.6.0

func (i *Int64List) Scan(value interface{}) error

func (Int64List) Value added in v0.6.0

func (i Int64List) Value() (driver.Value, error)

type IsNotExistQueryOption

type IsNotExistQueryOption struct {
	Key string
}

IsNotExistQueryOption means the value is empty

type JsonDatastore

type JsonDatastore interface {
	Init() error
	Add(ctx context.Context, entity Entity) error
	BatchAdd(ctx context.Context, entities []Entity) error
	Put(ctx context.Context, entity Entity) error
	Delete(ctx context.Context, entity Entity) error
	Get(ctx context.Context, entity Entity) error
	List(ctx context.Context, query Entity, options *ListOptions) ([]Entity, error)
	Count(ctx context.Context, entity Entity, options *FilterOptions) (int64, error)
	IsExist(ctx context.Context, entity Entity) (bool, error)
	Commit(ctx context.Context) error
}

func GetDefaultJsonDatastore

func GetDefaultJsonDatastore() JsonDatastore

type ListOptions

type ListOptions struct {
	FilterOptions
	Page     int
	PageSize int
	SortBy   []SortOption
}

ListOptions list app options

type SortOption

type SortOption struct {
	Key   string
	Order SortOrder
}

SortOption describes the sorting parameters for list

type SortOrder

type SortOrder int

SortOrder is the order of sort

type StringList added in v0.6.0

type StringList []string

func (*StringList) Scan added in v0.6.0

func (s *StringList) Scan(value interface{}) error

func (StringList) Value added in v0.6.0

func (s StringList) Value() (driver.Value, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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