where

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TYPES = map[string]WhereType{
	"__root__": {
		Key: "__root__",
	},
	"__field__": {
		Key: "__field__",
	},
	"and": {
		Key: "and",
		Operator: WhereOperator{
			SQL: "AND",
		},
	},
	"or": {
		Key: "or",
		Operator: WhereOperator{
			SQL: "OR",
		},
	},
	"eq": {
		Key: "eq",
		Operator: WhereOperator{
			SQL: "%s = ?",
		},
	},
	"neq": {
		Key: "neq",
		Operator: WhereOperator{
			SQL: "%s <> ?",
		},
	},
	"gt": {
		Key: "gt",
		Operator: WhereOperator{
			SQL: "%s > ?",
		},
	},
	"gte": {
		Key: "gte",
		Operator: WhereOperator{
			SQL: "%s >= ?",
		},
	},
	"lt": {
		Key: "lt",
		Operator: WhereOperator{
			SQL: "%s < ?",
		},
	},
	"lte": {
		Key: "lte",
		Operator: WhereOperator{
			SQL: "%s <= ?",
		},
	},
	"between": {
		Key: "between",
		Operator: WhereOperator{
			SQL: "%s BETWEEN ? AND ?",
		},
	},
	"in": {
		Key: "in",
		Operator: WhereOperator{
			SQL: "%s IN ?",
		},
	},
	"nin": {
		Key: "nin",
		Operator: WhereOperator{
			SQL: "%s NOT IN ?",
		},
	},
	"like": {
		Key: "like",
		Operator: WhereOperator{
			SQL: "%s LIKE ?",
		},
	},
	"nlike": {
		Key: "nlike",
		Operator: WhereOperator{
			SQL: "%s NOT LIKE ?",
		},
	},
}

Functions

This section is empty.

Types

type Node

type Node struct {
	Parent *Node
	Nodes  []*Node
	Type   WhereType
	Key    string
	Value  interface{}
	IsLast bool
}

func (*Node) AddChild

func (n *Node) AddChild(child *Node)

func (*Node) LastChild

func (n *Node) LastChild() *Node

type Query

type Query struct {
	Text  string
	Vars  []interface{}
	Error error
}

func (*Query) Append

func (q *Query) Append(txt string)

func (*Query) AppendQuoted

func (q *Query) AppendQuoted(txt string)

func (*Query) Prepend

func (q *Query) Prepend(txt string)

func (*Query) SQLAppendAND

func (q *Query) SQLAppendAND()

func (*Query) SQLAppendOR

func (q *Query) SQLAppendOR()

type Where

type Where struct {
	Root *Node
	// contains filtered or unexported fields
}

func NewFromMap

func NewFromMap(filter map[string]interface{}) *Where

func NewFromMapWithAllowedFields

func NewFromMapWithAllowedFields(filter map[string]interface{}, allowedFields []string) *Where

func (*Where) GetWhereType

func (w *Where) GetWhereType(key string) WhereType

func (*Where) ToSQL

func (w *Where) ToSQL() (Query, error)

type WhereOperator

type WhereOperator struct {
	SQL string
}

type WhereType

type WhereType struct {
	Key      string
	Operator WhereOperator
}

func (*WhereType) ApplySQL

func (wt *WhereType) ApplySQL(vars ...interface{}) (string, error)

Jump to

Keyboard shortcuts

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