query

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColTypeUnknown    GoColumnType = ""
	ColTypeBytes                   = "[]byte"
	ColTypeString                  = "string"
	ColTypeInteger                 = "int"
	ColTypeUnsigned                = "uint"
	ColTypeInteger64               = "int64"
	ColTypeUnsigned64              = "uint64"
	ColTypeDateTime                = "datetime.DateTime"
	ColTypeFloat                   = "float32" // always internally represent with max bits
	ColTypeDouble                  = "float64" // always internally represent with max bits
	ColTypeBool                    = "bool"
)
View Source
const (
	// Standard logical operators
	OpEqual        Operator = "="
	OpNotEqual     Operator = "<>"
	OpAnd                   = "AND"
	OpOr                    = "OR"
	OpXor                   = "XOR"
	OpGreater               = ">"
	OpGreaterEqual          = ">="
	OpLess                  = "<"
	OpLessEqual             = "<="

	// Unary logical
	OpNot = "NOT"

	OpAll  = "1=1"
	OpNone = "1=0"

	// Math operators
	OpAdd      = "+"
	OpSubtract = "-"
	OpMultiply = "*"
	OpDivide   = "/"
	OpModulo   = "%"

	// Unary math
	OpNegate = " -"

	// Bit operators
	OpBitAnd     = "&"
	OpBitOr      = "|"
	OpBitXor     = "^"
	OpShiftLeft  = "<<"
	OpShiftRight = ">>"

	// Unary bit
	OpBitInvert = "~"

	// Function operator
	// The function name is followed by the operators in parenthesis
	OpFunc = "func"

	// SQL functions that act like operators in that the operator is put in between the operands
	OpLike  = "LIKE"
	OpIn    = "IN"
	OpNotIn = "NOT IN"

	// Special NULL tests
	OpNull    = "NULL"
	OpNotNull = "NOT NULL"
)
View Source
const AliasResults = "aliases_"

The special item to use for named aliases in the result set

Variables

This section is empty.

Functions

func ColumnNodeDbName

func ColumnNodeDbName(n *ColumnNode) string

func ExpandNode

func ExpandNode(n NodeI)

func LogNode

func LogNode(n NodeI, level int)

func ManyManyNodeDbColumn

func ManyManyNodeDbColumn(n *ManyManyNode) string

func ManyManyNodeDbTable

func ManyManyNodeDbTable(n *ManyManyNode) string

func ManyManyNodeIsArray

func ManyManyNodeIsArray(n *ManyManyNode) bool

func ManyManyNodeIsTypeTable

func ManyManyNodeIsTypeTable(n *ManyManyNode) bool

func ManyManyNodeRefColumn

func ManyManyNodeRefColumn(n *ManyManyNode) string

func ManyManyNodeRefTable

func ManyManyNodeRefTable(n *ManyManyNode) string

func NodeGoName

func NodeGoName(n NodeI) string

func NodeIsConditioner

func NodeIsConditioner(n NodeI) bool

func NodeIsExpanded

func NodeIsExpanded(n NodeI) bool

func NodeIsExpander

func NodeIsExpander(n NodeI) bool

func NodeSetCondition

func NodeSetCondition(n NodeI, condition NodeI)

func NodeSorterSortDesc

func NodeSorterSortDesc(n NodeSorter) bool

func NodeTableName

func NodeTableName(n NodeI) string

func OperationIsAggregate

func OperationIsAggregate(n *OperationNode) bool

func OperationNodeDistinct

func OperationNodeDistinct(n *OperationNode) bool

func OperationNodeFunction

func OperationNodeFunction(n *OperationNode) string

func OperationSortDescending

func OperationSortDescending(n *OperationNode) bool

func ReferenceNodeDbColumnName

func ReferenceNodeDbColumnName(n *ReferenceNode) string

func ReferenceNodeRefColumn

func ReferenceNodeRefColumn(n *ReferenceNode) string

func ReferenceNodeRefTable

func ReferenceNodeRefTable(n *ReferenceNode) string

func ReverseReferenceNodeDbColumnName

func ReverseReferenceNodeDbColumnName(n *ReverseReferenceNode) string

func ReverseReferenceNodeIsArray

func ReverseReferenceNodeIsArray(n *ReverseReferenceNode) bool

func ReverseReferenceNodeRefColumn

func ReverseReferenceNodeRefColumn(n *ReverseReferenceNode) string

func ReverseReferenceNodeRefTable

func ReverseReferenceNodeRefTable(n *ReverseReferenceNode) string

func SetParentNode

func SetParentNode(child NodeI, parent NodeI)

Used by the query builder to build a join tree, and by the codegenerator to initialize nodes

func ValueNodeGetValue

func ValueNodeGetValue(n *ValueNode) interface{}

Types

type AliasNode

type AliasNode struct {
	Node
}

func Alias

func Alias(goName string) *AliasNode

func (*AliasNode) Equals

func (n *AliasNode) Equals(n2 NodeI) bool

type AliasNodeI

type AliasNodeI interface {
	NodeI
}

type AliasValue

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

func NewAliasValue

func NewAliasValue(a interface{}) AliasValue

func (AliasValue) Bool

func (a AliasValue) Bool() bool

func (AliasValue) DateTime

func (a AliasValue) DateTime() datetime.DateTime

func (AliasValue) Float

func (a AliasValue) Float() float64

func (AliasValue) Int

func (a AliasValue) Int() int

func (AliasValue) IsNil

func (a AliasValue) IsNil() bool

func (AliasValue) IsNull

func (a AliasValue) IsNull() bool

func (AliasValue) String

func (a AliasValue) String() string

type ClauseI

type ClauseI interface {
	AddToBuilder(b QueryBuilderI)
}

type ColumnNode

type ColumnNode struct {
	Node
	// contains filtered or unexported fields
}

A Column represents a table or field in a database structure, and is the leaf of a node tree or chain.

func NewColumnNode

func NewColumnNode(dbKey string, dbTable string, dbName string, goName string, goType GoColumnType) *ColumnNode

func (*ColumnNode) Ascending

func (n *ColumnNode) Ascending() NodeI

func (*ColumnNode) Descending

func (n *ColumnNode) Descending() NodeI

func (*ColumnNode) Equals

func (n *ColumnNode) Equals(n2 NodeI) bool

func (*ColumnNode) SetValue

func (n *ColumnNode) SetValue(v interface{}) error

type ExpandClause

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

func Expand

func Expand(node NodeI, condition NodeI) *ExpandClause

func (*ExpandClause) AddToBuilder

func (c *ExpandClause) AddToBuilder(b QueryBuilderI)

type Expander

type Expander interface {
	Expand()
	// contains filtered or unexported methods
}

type FieldType

type FieldType int
const (
	Blob FieldType = iota
	Integer
	VarChar
	Char
	DateTime
	Date
	Time
	Float
	Bit
)

type GoColumnType

type GoColumnType string

func ColumnNodeGoType

func ColumnNodeGoType(n *ColumnNode) GoColumnType

func (GoColumnType) DefaultValue

func (g GoColumnType) DefaultValue() string

func (GoColumnType) String

func (g GoColumnType) String() string

type LimitClause

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

func Limit

func Limit(maxRowCount int, offset int) *LimitClause

func (*LimitClause) AddToBuilder

func (c *LimitClause) AddToBuilder(b QueryBuilderI)

type ManyManyNode

type ManyManyNode struct {
	Node
	// contains filtered or unexported fields
}

ManyManyNode creates an association node. Some of the columns have overloaded meanings depending on SQL or NoSQL mode.

func NewManyManyNode

func NewManyManyNode(
	dbKey string,

	dbTable string,

	dbColumn string,

	goName string,

	refTableName string,

	refColumn string,

	isType bool,
) *ManyManyNode

func (*ManyManyNode) Equals

func (n *ManyManyNode) Equals(n2 NodeI) bool

func (*ManyManyNode) Expand

func (n *ManyManyNode) Expand()

Expand tells this node to create multiple objects for each joined item, rather than to create an array of joined items

type Node

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

func (*Node) GetAlias

func (n *Node) GetAlias() string

func (*Node) SetAlias

func (n *Node) SetAlias(a string)

type NodeI

type NodeI interface {
	Equals(NodeI) bool
	SetAlias(string)
	GetAlias() string
	// contains filtered or unexported methods
}

func ChildNodes

func ChildNodes(n nodeLinkI) []NodeI

func ContainedNodes

func ContainedNodes(n NodeI) (nodes []NodeI)

func NewValueNode

func NewValueNode(i interface{}) NodeI

func NodeCondition

func NodeCondition(n NodeI) NodeI

func OperationNodeOperands

func OperationNodeOperands(n *OperationNode) []NodeI

func ParentNode

func ParentNode(n NodeI) NodeI

func RelatedColumnNode

func RelatedColumnNode(n NodeI) NodeI

func RootNode

func RootNode(n nodeLinkI) NodeI

func Value

func Value(i interface{}) NodeI

Shortcut for converting a constant value to a node

type NodeSorter

type NodeSorter interface {
	Ascending() NodeI
	Descending() NodeI
	// contains filtered or unexported methods
}

type NodeType

type NodeType int
const (
	UNKNOWN_NODE_TYPE NodeType = iota
	TABLE_NODE
	COLUMN_NODE
	REFERENCE_NODE // forward reference from a foreign key
	MANYMANY_NODE
	REVERSE_REFERENCE_NODE
	VALUE_NODE
	OPERATION_NODE
	ALIAS_NODE
	SUBQUERY_NODE
)

func GetNodeType

func GetNodeType(n NodeI) NodeType

type OperationNode

type OperationNode struct {
	Node
	// contains filtered or unexported fields
}

An operation is a general purpose structure that specs an operation on a node or group of nodes The operation could be arithmetic, boolean, or a function.

func NewCountNode

func NewCountNode(operands ...NodeI) *OperationNode

NewCountNode creates a Count function node. If no operands are given, it will use * as the parameter to the function which means it will count nulls. To NOT count nulls, at least one table name needs to be specified.

func NewFunctionNode

func NewFunctionNode(functionName string, operands ...interface{}) *OperationNode

func NewOperationNode

func NewOperationNode(op Operator, operands ...interface{}) *OperationNode

func (*OperationNode) Ascending

func (n *OperationNode) Ascending() *OperationNode

func (*OperationNode) Descending

func (n *OperationNode) Descending() *OperationNode

func (*OperationNode) Distinct

func (n *OperationNode) Distinct() *OperationNode

func (*OperationNode) Equals

func (n *OperationNode) Equals(n2 NodeI) bool

type Operator

type Operator string

func OperationNodeOperator

func OperationNodeOperator(n *OperationNode) Operator

func (Operator) String

func (o Operator) String() string

type OrderByClause

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

func OrderBy

func OrderBy(nodes ...NodeI) *OrderByClause

func (*OrderByClause) AddToBuilder

func (c *OrderByClause) AddToBuilder(b QueryBuilderI)

type QueryBuilderI

type QueryBuilderI interface {
	Join(n NodeI, condition NodeI) QueryBuilderI
	Expand(n NodeI) QueryBuilderI
	Condition(c NodeI) QueryBuilderI
	Having(c NodeI) QueryBuilderI
	OrderBy(nodes ...NodeI) QueryBuilderI
	GroupBy(nodes ...NodeI) QueryBuilderI
	Limit(maxRowCount int, offset int) QueryBuilderI
	Select(nodes ...NodeI) QueryBuilderI
	Distinct() QueryBuilderI
	Alias(name string, n NodeI) QueryBuilderI
	Load(ctx context.Context) []map[string]interface{}
	Delete(ctx context.Context)
	Count(ctx context.Context, distinct bool, nodes ...NodeI) uint
	Subquery() *SubqueryNode
}

The query builder is the primary aid in creating cross-platform, portable queries to the database(s)

func SubqueryBuilder

func SubqueryBuilder(n *SubqueryNode) QueryBuilderI

type ReferenceNode

type ReferenceNode struct {
	Node
	// contains filtered or unexported fields
}

A ReferenceNode is a forward-pointing foreignKey relationship, and can define a one-to-one or one-to-many relationship, with this side always being the one side. It also sets up a many-to-one relationship, if it is not unique, when viewed from the other side of the relationship.

func NewReferenceNode

func NewReferenceNode(
	dbKey string,
	dbTableName string,
	dbColumnName string,
	goColumnName string,
	goName string,
	refTableName string,
	refColumn string,
	isType bool,
) *ReferenceNode

NewReferenceNode creates a forward reference node.

func (*ReferenceNode) Equals

func (n *ReferenceNode) Equals(n2 NodeI) bool

type ReverseReferenceNode

type ReverseReferenceNode struct {
	Node
	// contains filtered or unexported fields
}

ReverseReferenceNode creates a reverse reference node representing a one to many relationship. This is the many side of that relationship.

func NewReverseReferenceNode

func NewReverseReferenceNode(
	dbKey string,

	dbTable string,

	dbColumn string,

	goName string,

	refTable string,

	refColumn string,
	isArray bool,
) *ReverseReferenceNode

func (*ReverseReferenceNode) Equals

func (n *ReverseReferenceNode) Equals(n2 NodeI) bool

func (*ReverseReferenceNode) Expand

func (n *ReverseReferenceNode) Expand()

func (*ReverseReferenceNode) IsArray

func (n *ReverseReferenceNode) IsArray() bool

type SelectClause

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

func Select

func Select(nodes ...NodeI) *SelectClause

func (*SelectClause) AddToBuilder

func (c *SelectClause) AddToBuilder(b QueryBuilderI)

type SubqueryNode

type SubqueryNode struct {
	Node
	// contains filtered or unexported fields
}

func NewSubqueryNode

func NewSubqueryNode(b QueryBuilderI) *SubqueryNode

func (*SubqueryNode) Equals

func (n *SubqueryNode) Equals(n2 NodeI) bool

type TableNode

type TableNode struct {
	Node
	// contains filtered or unexported fields
}

func NewTableNode

func NewTableNode(dbKey string, dbName string, goName string) *TableNode

NewTableNode creates a table node, which is always the starting node in a node chain

func (*TableNode) Equals

func (n *TableNode) Equals(n2 NodeI) bool

type TableNodeI

type TableNodeI interface {
	NodeI
	SelectNodes_() []*ColumnNode
	PrimaryKeyNode_() *ColumnNode
	EmbeddedNode_() NodeI
}

type ValueNode

type ValueNode struct {
	Node
	// contains filtered or unexported fields
}

func (*ValueNode) Equals

func (n *ValueNode) Equals(n2 NodeI) bool

Jump to

Keyboard shortcuts

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