query

package
v1.8.29 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 3 Imported by: 0

README

Query

Performance

# https://graphviz.org/download/#mac
brew install graphviz

go test -bench=. ./core/lib/utils/query/testgen/. -cpuprofile cpu.prof
go tool pprof -svg cpu.prof > cpu.svg

go test -bench=. -trace trace.out ./core/lib/utils/query/testgen/.
go tool trace trace.out

# Data Race: Two goroutines access the same variable concurrently 
# and at least one of the accesses is a write 
# https://golang.org/doc/articles/race_detector
go test -race

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Union

func Union(queries ...*Q) (string, error)

Types

type Column added in v1.8.23

type Column string

type IModel

type IModel interface {
	Table_Name() TableName
	Table_Columns() []Column
	Table_PrimaryKey() Column
	Table_PrimaryKey_Value() int64
	Table_InsertColumns() []Column
	Table_UpdateColumns() []Column
	Table_Column_Types() map[Column]string
	String() string
	Update() string
	Create() string
	Destroy() string
	FromID(id int64) string
}

type Q

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

func Delete

func Delete(model IModel) *Q

func Insert

func Insert(model IModel) *Q

func Query

func Query(model IModel) *Q

func Select

func Select(model IModel) *Q

func Update

func Update(model IModel) *Q

func (*Q) Alias

func (q *Q) Alias(alias string) *Q

func (*Q) Count

func (q *Q) Count(name Column, as string) *Q

func (*Q) Field

func (q *Q) Field(name Column) *Q

Field includes a specific field in the columns to be returned by a result set

func (*Q) FieldAs

func (q *Q) FieldAs(name Column, as string) *Q

FieldAs includes a specific field in the columns to be returned by a set aliased by `as`

func (*Q) FieldRaw

func (q *Q) FieldRaw(fieldStr, as string) *Q

FieldRaw allows for an arbitrary string (e.g. "NOW()") to be included in the select columns

func (*Q) Fields

func (q *Q) Fields(fields ...string) *Q

func (*Q) Limit

func (q *Q) Limit(limit, offset int64) *Q

func (*Q) OrderBy

func (q *Q) OrderBy(col Column, dir QueryOrderBy) *Q

func (*Q) Set

func (q *Q) Set(fieldName Column, value interface{}) *Q

func (*Q) String

func (q *Q) String() (string, error)

func (*Q) Sum

func (q *Q) Sum(name Column, as string) *Q

func (*Q) Where

func (q *Q) Where(args ...WherePart) *Q

Where().Equals("a", "b")

type QueryOrderBy added in v1.8.23

type QueryOrderBy int
const (
	QueryOrderByASC QueryOrderBy = iota
	QueryOrderByDESC
)

func (QueryOrderBy) String added in v1.8.23

func (q QueryOrderBy) String() string

type QueryType

type QueryType int
const (
	QueryTypeNotSet QueryType = iota
	QueryTypeSelect
	QueryTypeUpdate
	QueryTypeDelete
	QueryTypeInsert
)

type TableName added in v1.8.23

type TableName string

type WherePart

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

WherePart is a part of a where clause. This object is an exposed part of the api to make conditional queries easier EXAMPLE:

wheres := []query.WherePart{
	query.EQ(models.ObjectRelationship_Column_IsDeleted, 0),
}
if objectTypeFrom != constants.ObjectTypeUnknown {
	wheres = append(wheres, query.And(), query.EQ(models.ObjectRelationship_Column_ObjectTypeFrom, objectTypeFrom))
}
if objectIDFrom > 0 {
	wheres = append(wheres, query.And(), query.EQ(models.ObjectRelationship_Column_ObjectIDFrom, objectIDFrom))
}

func And

func And(args ...WherePart) WherePart

func Between

func Between(fieldName Column, from, to interface{}) WherePart

func EQ

func EQ(fieldName Column, value interface{}) WherePart

EQ is an equals statement between a table column and a value

func EQF

func EQF(fieldName1, fieldName2 string) WherePart

func Exists

func Exists(clause *Q) WherePart

func GT

func GT(fieldName Column, value interface{}) WherePart

func GTOE

func GTOE(fieldName Column, value interface{}) WherePart

func IN

func IN(fieldName Column, values ...interface{}) WherePart

IN is an IN clause

func INInt64 added in v1.8.15

func INInt64(fieldName Column, values []int64) WherePart

INInt64 is a helper function for converting a slice of string arguments into a slice of interface arguments, passed into an IN clause and returned

func INString added in v1.8.15

func INString(fieldName Column, values []string) WherePart

INString is a helper function for converting a slice of string arguments into a slice of interface arguments, passed into an IN clause and returned

func LT

func LT(fieldName Column, value interface{}) WherePart

func LTOE

func LTOE(fieldName Column, value interface{}) WherePart

func Like added in v1.8.16

func Like(fieldName Column, value string) WherePart

func NE

func NE(fieldName Column, value interface{}) WherePart

func NotLike added in v1.8.16

func NotLike(fieldName Column, value string) WherePart

func Or

func Or(args ...WherePart) WherePart

func PE

func PE() WherePart

Parenthesis End

func PS

func PS() WherePart

Parenthesis Start

func WhereAll added in v1.8.12

func WhereAll() WherePart

type WhereType

type WhereType int
const (
	WhereTypeEquals WhereType = iota
	WhereTypeEqualsField
	WhereTypeNotEquals
	WhereTypeGreaterThan
	WhereTypeLessThan
	WhereTypeGreaterThanOrEqualTo
	WhereTypeLessThanOrEqualTo
	WhereTypeBetween
	WhereTypeLike
	WhereTypeNotLike
	WhereTypeIN
	WhereTypeExists
	WhereTypeAnd
	WhereTypeOr
	WhereTypeParenthesisEnd
	WhereTypeParenthesisStart
	// WhereTypeAll is a WHERE clause of `1=1` used for convenience
	// when conditionally adding WHERE clauses starting with a conjunction (AND/OR,etc)
	// separating them.
	// e.g. SELECT * FROM `Foo` WHERE 1=1
	//      SELECT * FROM `Foo` WHERE 1=1 AND FooID = 123;
	WhereTypeAll
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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