tql

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tql Torpedo Query Language

Index

Constants

View Source
const (
	FilterTypeAny = "any"
	FilterTypeAll = "all"

	OpNEQ = "!="
	OpEQ  = "=="
	OpGT  = ">"
	OpGTE = ">="
	OpLT  = "<"
	OpLTE = "<="

	OpBTLimits     = "[n]"
	OpBTNoLimits   = "(n)"
	OpBTLeftLimit  = "[n)"
	OpBTRightLimit = "(n]"

	OpIN = "[?]"

	OpPrefix   = "s.."
	OpSuffix   = "..s"
	OpContains = ".s."
)
View Source
const (
	CursorNext = "next"
	CursorPrev = "prev"

	CursorAscStr  = "asc"
	CursorDescStr = "desc"

	CursorDesc CursorOrderType
	CursorAsc
)
View Source
const (
	PageTypeOffset = "offset"
	PageTypeCursor = "cursor"

	PaginationCursortOrderASC = "asc"
	PaginationCursorOrderDESC = "desc"

	PaginationCursorEmpty = ""
)

Variables

View Source
var (
	// ErrTQLNotSupported Torpedo Query Language is not supported by this repository
	ErrTQLNotSupported = errors.New("Torpedo Query Language is not supported by this repository")

	// ErrEmptyFilter filter cannot be empty
	ErrEmptyFilter = errors.New("filter cannot be empty")

	// ErrInvalidOperator the given operator is invalid
	ErrInvalidOperator = errors.New("the given operator is invalid")

	// ErrInvalidValue the given value is invalid
	ErrInvalidValue = errors.New("the given value is invalid")

	// ErrInvalidValueBTLen the given value must be a list of 2 elements (left and right limits)
	ErrInvalidValueBTLen = errors.New("the given value must be a list of 2 elements (left and right limits)")

	// ErrOperationNotSupported the given operation is not supported for the given field
	ErrOperationNotSupported = errors.New("the given operation is not supported for the given field")

	// ErrInvalidFieldName the given field name is invalid
	ErrInvalidFieldName = errors.New("the given field name is invalid")

	// ErrInvalidFieldNameAtProjection the given field name into projection list is invalid
	ErrInvalidFieldNameAtProjection = errors.New("the given field name into projection list is invalid")

	// ErrInvalidFieldNameAtSort the given field name into sort list is invalid
	ErrInvalidFieldNameAtSort = errors.New("the given field name into sort list is invalid")

	// ErrQueryResultObjectBuild something happens building a QRO from the entity
	ErrQueryResultObjectBuild = errors.New("something happens building a QRO from the entity")

	// ErrInvalidPaginationType the pagination must be 'cursor' or 'offset'
	ErrInvalidPaginationType = errors.New("the pagination must be 'cursor' or 'offset'")

	// ErrInvalidSortFieldNotProjectionMember sort field must be a member of the projection field list
	ErrInvalidSortFieldNotProjectionMember = errors.New("sort field must be a member of the projection field list")
)

Functions

func CursorToDocument

func CursorToDocument(q *Query, filter bson.D) (cursorFilter bson.D, limit int64, sortD bson.D)

func CursorToSQL

func CursorToSQL(q *Query, filter string) (sqlWhere string, sqlLimit int64, sqlOrder string)

func FieldValue added in v0.3.0

func FieldValue(qro interface{}, field string) interface{}

func MapToMongoDBFilter

func MapToMongoDBFilter(q *Query, metadata map[string]string) (bson.D, error)

func MapToSQLFilter

func MapToSQLFilter(q *Query, metadata map[string]string) (string, map[string]interface{}, error)

func ToMongoDBMetadata added in v0.3.0

func ToMongoDBMetadata(dmo interface{}, skip ...string) map[string]string

func ToSortDocument

func ToSortDocument(items []SortItem) bson.D

func ToSortSQL

func ToSortSQL(items []SortItem) string

Types

type Cursor

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

func CursorFromQuery

func CursorFromQuery(q *Query) *Cursor

func NewPaginationCursor

func NewPaginationCursor(rawCursor string) (*Cursor, error)

func NewPaginationCursorFrom

func NewPaginationCursorFrom(pivot string, sort CursorOrderType, sortField string, sortVal interface{}, sortType string) *Cursor

func NewPaginationCursorFromBeginning

func NewPaginationCursorFromBeginning(sort string) *Cursor

func NewPaginationCursorFromPivot

func NewPaginationCursorFromPivot(pivot string, sort CursorOrderType) *Cursor

func (*Cursor) Next

func (c *Cursor) Next() *string

func (*Cursor) Order

func (c *Cursor) Order() CursorOrderType

func (*Cursor) Pivot

func (c *Cursor) Pivot() string

func (*Cursor) Prev

func (c *Cursor) Prev() *string

func (*Cursor) SortField

func (c *Cursor) SortField() string

func (*Cursor) SortType

func (c *Cursor) SortType() string

func (*Cursor) SortVal

func (c *Cursor) SortVal() interface{}

func (*Cursor) ToOrder

func (c *Cursor) ToOrder() string

type CursorOrderType

type CursorOrderType int8

func PaginationCursorOrder

func PaginationCursorOrder(sort string) CursorOrderType

type ExportableCursor

type ExportableCursor struct {
	Pivot     string                `json:"pivot"`
	PivotSort string                `json:"pivotSort"`
	Sort      *ExportableCursorSort `json:"sort,omitempty"`
}

func NewExportableCursorFrom

func NewExportableCursorFrom(cursor string) (*ExportableCursor, error)

func (*ExportableCursor) String

func (ec *ExportableCursor) String() string

type ExportableCursorSort

type ExportableCursorSort struct {
	Field string      `json:"field"`
	Value interface{} `json:"value"`
	Type  string      `json:"type"`
}

type Filter

type Filter struct {
	Type_  *string      `json:"type"`
	Fields []FilterItem `json:"fields"`
}

func (*Filter) Type

func (f *Filter) Type() string

type FilterItem

type FilterItem struct {
	Field    string      `json:"field"`
	Operator string      `json:"operator"`
	Value    interface{} `json:"value"`
}

type Pagination

type Pagination struct {
	Items  *int64            `json:"items,omitempty"`
	Cursor *PaginationCursor `json:"cursor,omitempty"`
	Offset *PaginationOffset `json:"offset,omitempty"`
}

type PaginationCursor

type PaginationCursor struct {
	Meta *PaginationCursorMeta `json:"meta,omitempty"`
	Mark *string               `json:"nextToken,omitempty"`
}

type PaginationCursorMeta

type PaginationCursorMeta struct {
	Sort *SortItem `json:"sort,omitempty"`
	Kind *string   `json:"type,omitempty"`
}

type PaginationMeta

type PaginationMeta struct {
	// common
	Items *int64 `json:"items,omitempty"`

	// offset pagination
	Page *int64 `json:"page,omitempty"`

	// cursor pagination
	Cursor *string `json:"cursor,omitempty"`
}

type PaginationOffset

type PaginationOffset struct {
	Page *int64     `json:"page,omitempty"`
	Sort []SortItem `json:"sort,omitempty"`
}

type Query

type Query struct {
	Filter     *Filter     `json:"filter"`
	Projection []string    `json:"projection,omitempty"`
	Pagination *Pagination `json:"pagination,omitempty"`
}

func (*Query) CursorPaginationSort

func (q *Query) CursorPaginationSort() *SortItem

func (*Query) CursorType

func (q *Query) CursorType() string

func (*Query) HasCursorMeta

func (q *Query) HasCursorMeta() bool

func (*Query) HasPagination

func (q *Query) HasPagination() bool

func (*Query) HasSort

func (q *Query) HasSort() bool

func (*Query) HasValidPagination

func (q *Query) HasValidPagination() bool

func (*Query) IsCursorPagination

func (q *Query) IsCursorPagination() bool

func (*Query) IsCursorPaginationNext

func (q *Query) IsCursorPaginationNext() bool

func (*Query) IsCursorPaginationPrev

func (q *Query) IsCursorPaginationPrev() bool

func (*Query) IsOffsetPagination

func (q *Query) IsOffsetPagination() bool

func (*Query) IsPaginationCursorEmpty

func (q *Query) IsPaginationCursorEmpty() bool

func (*Query) OffsetPaginationSort

func (q *Query) OffsetPaginationSort() []SortItem

func (*Query) PaginationCursor

func (q *Query) PaginationCursor() string

func (*Query) PaginationCursorOrder

func (q *Query) PaginationCursorOrder() string

func (*Query) PaginationItems

func (q *Query) PaginationItems() int64

func (*Query) PaginationOffset

func (q *Query) PaginationOffset() int64

func (*Query) PaginationOffsetPage

func (q *Query) PaginationOffsetPage() int64

func (*Query) PaginationRAWItems

func (q *Query) PaginationRAWItems() int64

func (*Query) Validate

func (q *Query) Validate(fields entity.FieldMap) error

type Result

type Result struct {
	Meta ResultMeta    `json:"meta"`
	Data []interface{} `json:"data"`
}

func NewResult

func NewResult(data []interface{}, count int, prev interface{}, next interface{}) *Result

type ResultMeta

type ResultMeta struct {
	Count int64 `json:"count"`
	//Prev  interface{} `json:"prev"`
	Next interface{} `json:"next"`
}

type SortItem

type SortItem struct {
	Field string `json:"field"`
	Kind  string `json:"type"`
}

Jump to

Keyboard shortcuts

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