query

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRelatedEntityNotFound = errors.New("related entity not found")
	ErrRelatedFieldNotFound  = errors.New("related field not found")
)
View Source
var Preprocessor preprocessor

Functions

func Visit

func Visit(q *Query, visitor func(pred interface{}))

Types

type AndNestedWhere

type AndNestedWhere struct {
	NestedWhere
}

type AndWhere

type AndWhere struct {
	Where
}

type Columns

type Columns []string

type FetchPlan

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

func (*FetchPlan) CanFetchRelation

func (e *FetchPlan) CanFetchRelation(rel entity.Relation) bool

func (*FetchPlan) EntityName

func (e *FetchPlan) EntityName() entity.Name

func (*FetchPlan) GetChildPlan

func (e *FetchPlan) GetChildPlan(rel entity.Relation) *FetchPlan

func (*FetchPlan) HasJoins

func (e *FetchPlan) HasJoins() bool

func (*FetchPlan) NoNestedWhere

func (e *FetchPlan) NoNestedWhere() bool

func (*FetchPlan) PKs

func (e *FetchPlan) PKs() []interface{}

func (*FetchPlan) WhereExprCount

func (e *FetchPlan) WhereExprCount() int

type From

type From string

type GroupBy

type GroupBy string

type Having

type Having struct {
	Field  string
	Op     string
	Params []interface{}
}

type Join

type Join struct {
	Join string
	On   string
	Type JoinType
}

type JoinType

type JoinType int
const (
	JoinLeft JoinType
	JoinRight
	JoinInner
)

type Limit

type Limit int

type NestedWhere

type NestedWhere struct {
	Supply func(query *Query)
}

type Offset

type Offset int

type OrNestedWhere

type OrNestedWhere struct {
	NestedWhere
}

type OrWhere

type OrWhere struct {
	Where
}

type Order

type Order []string

type Query

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

func New

func New() *Query

ForEntity - create new query.

func (*Query) AndNestedWhere

func (q *Query) AndNestedWhere(f func(q *Query)) *Query

AndNestedWhere join nested WHERE expression in select query with AND operator. Example:

q.AndWhere("a", "=", 1).AndNestedWhere(func(q *Query){
    q.OrWhere("b", "=", 2).OrWhere("c", "=", 3)
}) - generate sql: WHERE a=? AND (b=? OR c=?)

func (*Query) AndWhere

func (q *Query) AndWhere(field, operator string, params ...interface{}) *Query

AndWhere join WHERE expression in select query with AND operator. Example: q.AndWhere("a", "=", 1).AndWhere("b", "=",2) - generate sql: WHERE a=? AND b=?

q.AndWhere("a", "IS NOT NULL") - generate sql: WHERE a IS NOT NULL

func (*Query) ForEntity

func (q *Query) ForEntity(targetEntityMeta *entity.MetaInfo) *Query

ForEntity - bind entity to query.

func (*Query) From

func (q *Query) From(tableName string) *Query

From - set table name in FROM query section.

func (*Query) GroupBy

func (q *Query) GroupBy(expr string) *Query

GroupBy - add GROUP BY clause to query.

func (*Query) Having

func (q *Query) Having(field, operator string, params ...interface{}) *Query

Having - add HAVING clause to query.

func (*Query) Join

func (q *Query) Join(joinType JoinType, table string, on string) *Query

Join - add JOIN clause to query. Example: q.Join(JoinRight, "profile", "user.id=profile.user_id")

func (*Query) Limit

func (q *Query) Limit(l int) *Query

Limit - add LIMIT clause to query.

func (*Query) Offset

func (q *Query) Offset(o int) *Query

Offset - add OFFSET clause to query.

func (*Query) OrNestedWhere

func (q *Query) OrNestedWhere(f func(q *Query)) *Query

OrNestedWhere join nested WHERE expression in select query with OR operator. Example:

q.OrWhere("a", "=", 1).OrNestedWhere(func(q *Query){
    q.AndWhere("b", "=", 2).AndWhere("c", "=", 3)
}) - generate sql: WHERE a=? OR (b=? AND c=?)

func (*Query) OrWhere

func (q *Query) OrWhere(field, operator string, params ...interface{}) *Query

OrWhere join WHERE expression in select query with OR operator. Example: q.AndWhere("a", "=", 1).OrWhere("b", "=",2) - generate sql: WHERE a=? OR b=?

q.OrWhere("a", "IS NOT NULL") - generate sql: WHERE a IS NOT NULL

func (*Query) OrderBy

func (q *Query) OrderBy(stmts ...string) *Query

OrderBy - add ORDER BY clause to query.

func (*Query) Select

func (q *Query) Select(columns ...string) *Query

Select - add columns to SELECT query section.

func (*Query) Union

func (q *Query) Union(query *Query) *Query

Union - add UNION operator to query. Example: q.Union(q2.AndWhere("a=?", 1))

func (*Query) Where

func (q *Query) Where(field, operator string, params ...interface{}) *Query

AndWhere add WHERE expression in select query. Example: q.Where("a", "=", 1) - generate sql: WHERE a=?

q.Where("a", "IS NOT NULL") - generate sql: WHERE a IS NOT NULL

func (*Query) With

func (q *Query) With(entityName entity.Name) error

With - d3 will load with main entity related entities in same query. Example: q.With("myPkg/Entity2")

type Union

type Union struct {
	Q *Query
}

type Where

type Where struct {
	Field  string
	Op     string
	Params []interface{}
}

Jump to

Keyboard shortcuts

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