storage

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMemory  = "memory"
	TypeMongoDB = "mongodb"
)

Storage database types

View Source
const (
	SortByASC  = "asc"
	SortByDESC = "desc"
)

SortBy values

View Source
const (
	OperatorNone             = ""
	OperatorEqual            = "eq"
	OperatorNotEqual         = "ne"
	OperatorIn               = "in"
	OperatorNotIn            = "nin"
	OperatorRangeIn          = "range_in"
	OperatorRangeNotIn       = "range_not_in"
	OperatorGreaterThan      = "gt"
	OperatorLessThan         = "lt"
	OperatorGreaterThanEqual = "gte"
	OperatorLessThanEqual    = "lte"
	OperatorExists           = "exists"
	OperatorRegex            = "regex"
)

Operators

Variables

View Source
var (
	ErrNoDocuments = errors.New("no documents in result")
	ErrNilFilter   = errors.New("filter can not be nil")
	ErrNilData     = errors.New("data can not be nil")
)

Functions

func GetStorageLogger

func GetStorageLogger() *zap.Logger

returns a logger with environment values

func WithContext

func WithContext(ctx context.Context, bus Plugin) context.Context

Types

type Filter

type Filter struct {
	Key      string      `json:"k"`
	Operator string      `json:"o"`
	Value    interface{} `json:"v"`
}

Filter used to limit the result

type Pagination

type Pagination struct {
	Limit  int64  `json:"limit"`
	Offset int64  `json:"offset"`
	SortBy []Sort `json:"sortBy"`
}

Pagination configuration

type Plugin

type Plugin interface {
	Name() string
	Ping() error
	Close() error
	Insert(entityName string, data interface{}) error
	Upsert(entityName string, data interface{}, filter []Filter) error
	Update(entityName string, data interface{}, filter []Filter) error
	FindOne(entityName string, out interface{}, filter []Filter) error
	Find(entityName string, out interface{}, filter []Filter, pagination *Pagination) (*Result, error)
	Delete(entityName string, filter []Filter) (int64, error)
	Pause() error
	Resume() error
	ClearDatabase() error
	// if your database needs start import, returns "true", "files-directory" and "file-format"
	// example: true, "/tmp/data", "yaml"
	// it is required for in-memory database at startup
	DoStartupImport() (bool, string, string)
}

Plugin interface storage

func FromContext

func FromContext(ctx context.Context) (Plugin, error)

type Result

type Result struct {
	Count  int64       `json:"count"`
	Limit  int64       `json:"limit"`
	Offset int64       `json:"offset"`
	Data   interface{} `json:"data"`
}

Result returns a list of data

type Sort

type Sort struct {
	Field   string `json:"f"`
	OrderBy string `json:"o"`
}

Sort options

Jump to

Keyboard shortcuts

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