orm

package
v0.0.0-...-38575d5 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: AGPL-3.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(o interface{}, query interface{}) (int64, error)

func Create

func Create(ctx *Context, o interface{}) error

func Delete

func Delete(ctx *Context, o interface{}) error

func DeleteBy

func DeleteBy(o interface{}, query interface{}) error

func FilterFieldsByProtected

func FilterFieldsByProtected(obj interface{}, protected bool) map[string]interface{}

FilterFieldsByProtected filter struct fields by tag protected recursively, returns a filtered fields map

func Get

func Get(o interface{}) (bool, error)

func GetIndexName

func GetIndexName(o interface{}) string

func GetWildcardIndexName

func GetWildcardIndexName(o interface{}) string

func GroupBy

func GroupBy(o interface{}, selectField, groupField, haveQuery string, haveValue interface{}) (error, map[string]interface{})

func InitSchema

func InitSchema() error

func MustRegisterSchemaWithIndexName

func MustRegisterSchemaWithIndexName(t interface{}, index string)

func Register

func Register(name string, h ORM)

func RegisterSchemaWithIndexName

func RegisterSchemaWithIndexName(t interface{}, index string) error

func Save

func Save(ctx *Context, o interface{}) error

func Update

func Update(ctx *Context, o interface{}) error

func UpdateBy

func UpdateBy(o interface{}, query interface{}) error

Types

type BoolType

type BoolType string
const Must BoolType = "must"
const MustNot BoolType = "must_not"
const Should BoolType = "should"

type Cond

type Cond struct {
	Field       string
	SQLOperator string
	QueryType   QueryType
	BoolType    BoolType
	Value       interface{}
}

func And

func And(conds ...*Cond) []*Cond

func Combine

func Combine(conds ...[]*Cond) []*Cond

func Eq

func Eq(field string, value interface{}) *Cond

func Ge

func Ge(field string, value interface{}) *Cond

func Gt

func Gt(field string, value interface{}) *Cond

func In

func In(field string, value []interface{}) *Cond

func InStringArray

func InStringArray(field string, value []string) *Cond

func Le

func Le(field string, value interface{}) *Cond

func Lt

func Lt(field string, value interface{}) *Cond

func NotEq

func NotEq(field string, value interface{}) *Cond

func Or

func Or(conds ...*Cond) []*Cond

type Context

type Context struct {
	context.Context
	Refresh string
}

type ORM

type ORM interface {
	RegisterSchemaWithIndexName(t interface{}, indexName string) error

	GetIndexName(o interface{}) string

	GetWildcardIndexName(o interface{}) string

	Save(ctx *Context, o interface{}) error

	Update(ctx *Context, o interface{}) error

	Delete(ctx *Context, o interface{}) error

	Search(o interface{}, q *Query) (error, Result)

	Get(o interface{}) (bool, error)

	GetBy(field string, value interface{}, o interface{}) (error, Result)

	Count(o interface{}, query interface{}) (int64, error)

	GroupBy(o interface{}, selectField, groupField string, haveQuery string, haveValue interface{}) (error, map[string]interface{})
	DeleteBy(o interface{}, query interface{}) error
	UpdateBy(o interface{}, query interface{}) error
}

type ORMObjectBase

type ORMObjectBase struct {
	ID      string     `config:"id"  json:"id,omitempty" protected:"true"   elastic_meta:"_id" elastic_mapping:"id: { type: keyword }"`
	Created *time.Time `json:"created,omitempty" elastic_mapping:"created: { type: date }"`
	Updated *time.Time `json:"updated,omitempty" elastic_mapping:"updated: { type: date }"`
}

func (*ORMObjectBase) GetID

func (obj *ORMObjectBase) GetID() string

func (*ORMObjectBase) SetID

func (obj *ORMObjectBase) SetID(ID string)

type Object

type Object interface {
	GetID() string
	SetID(ID string)
}

type ProtectedFilterKeyType

type ProtectedFilterKeyType string
const ProtectedFilterKey ProtectedFilterKeyType = "FILTER_PROTECTED"

type Query

type Query struct {
	Sort           *[]Sort
	QueryArgs      *[]util.KV
	From           int
	CollapseField  string
	Size           int
	Conds          []*Cond
	RawQuery       []byte
	TemplatedQuery *TemplatedQuery
	WildcardIndex  bool
	IndexName      string
}

func (*Query) AddQueryArgs

func (q *Query) AddQueryArgs(name string, value string) *Query

func (*Query) AddSort

func (q *Query) AddSort(field string, sortType SortType) *Query

func (*Query) Collapse

func (q *Query) Collapse(field string) *Query

type QueryType

type QueryType string
const Match QueryType = "match"
const Prefix QueryType = "prefix"
const RangeGt QueryType = "gt"
const RangeGte QueryType = "gte"
const RangeLt QueryType = "lt"
const RangeLte QueryType = "lte"
const Regexp QueryType = "regexp" //TODO check
const StringTerms QueryType = "string_terms"
const Term QueryType = "term"
const Terms QueryType = "terms"
const Wildcard QueryType = "wildcard"

type Result

type Result struct {
	Total  int64
	Raw    []byte
	Result []interface{}
}

func GetBy

func GetBy(field string, value interface{}, t interface{}) (error, Result)
func Search(o interface{}, q *Query) (error, Result)

type Sort

type Sort struct {
	Field    string
	SortType SortType
}

type SortType

type SortType string
const ASC SortType = "asc"
const DESC SortType = "desc"

type TemplatedQuery

type TemplatedQuery struct {
	TemplateID string                 `json:"id"`
	Parameters map[string]interface{} `json:"params"`
}

Jump to

Keyboard shortcuts

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