exclause

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 2 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CTE

type CTE struct {
	Name     string
	Columns  []string
	Subquery clause.Expression
}

CTE common table expressions

func (CTE) Build

func (cte CTE) Build(builder clause.Builder)

Build build CTE

type Except added in v0.2.0

type Except struct {
	Statements []clause.Expression
}

Except is except clause

func NewExcept added in v0.2.0

func NewExcept(query interface{}, args ...interface{}) Except

NewExcept is easy to create new Except

// examples
// SELECT * FROM `general_users` EXCEPT SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewExcept("SELECT * FROM `admin_users`")).Scan(&users)

// SELECT * FROM `general_users` EXCEPT SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewExcept(db.Table("admin_users"))).Scan(&users)

// SELECT * FROM `general_users` EXCEPT ALL SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewExcept("ALL ?", db.Table("admin_users"))).Scan(&users)

func (Except) Build added in v0.2.0

func (except Except) Build(builder clause.Builder)

Build build except clause

func (Except) MergeClause added in v0.2.0

func (except Except) MergeClause(mergeClause *clause.Clause)

MergeClause merge Except clauses

func (Except) Name added in v0.2.0

func (except Except) Name() string

Name except clause name

type Intersect added in v0.2.0

type Intersect struct {
	Statements []clause.Expression
}

Intersect is intersect clause

func NewIntersect added in v0.2.0

func NewIntersect(query interface{}, args ...interface{}) Intersect

NewIntersect is easy to create new Intersect

// examples
// SELECT * FROM `general_users` INTERSECT SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewIntersect("SELECT * FROM `admin_users`")).Scan(&users)

// SELECT * FROM `general_users` INTERSECT SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewIntersect(db.Table("admin_users"))).Scan(&users)

// SELECT * FROM `general_users` INTERSECT ALL SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewIntersect("ALL ?", db.Table("admin_users"))).Scan(&users)

func (Intersect) Build added in v0.2.0

func (intersect Intersect) Build(builder clause.Builder)

Build build intersect clause

func (Intersect) MergeClause added in v0.2.0

func (intersect Intersect) MergeClause(mergeClause *clause.Clause)

MergeClause merge Intersect clauses

func (Intersect) Name added in v0.2.0

func (intersect Intersect) Name() string

Name intersect clause name

type Subquery

type Subquery struct {
	DB *gorm.DB
}

Subquery is subquery statement

func (Subquery) Build

func (subquery Subquery) Build(builder clause.Builder)

Build build subquery

type Union

type Union struct {
	Statements []clause.Expression
}

Union is union clause

func NewUnion

func NewUnion(query interface{}, args ...interface{}) Union

NewUnion is easy to create new Union

// examples
// SELECT * FROM `general_users` UNION SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewUnion("SELECT * FROM `admin_users`")).Scan(&users)

// SELECT * FROM `general_users` UNION SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewUnion(db.Table("admin_users"))).Scan(&users)

// SELECT * FROM `general_users` UNION ALL SELECT * FROM `admin_users`
db.Table("general_users").Clauses(exclause.NewUnion("ALL ?", db.Table("admin_users"))).Scan(&users)

func (Union) Build

func (union Union) Build(builder clause.Builder)

Build build union clause

func (Union) MergeClause

func (union Union) MergeClause(mergeClause *clause.Clause)

MergeClause merge Union clauses

func (Union) Name

func (union Union) Name() string

Name union clause name

type With

type With struct {
	Recursive bool
	CTEs      []CTE
}

With with clause

// examples
// WITH `cte` AS (SELECT * FROM `users`) SELECT * FROM `cte`
db.Clauses(exclause.With{CTEs: []exclause.CTE{{Name: "cte", Subquery: clause.Expr{SQL: "SELECT * FROM `users`"}}}}).Table("cte").Scan(&users)

// WITH `cte` AS (SELECT * FROM `users`) SELECT * FROM `cte`
db.Clauses(exclause.With{CTEs: []exclause.CTE{{Name: "cte", Subquery: exclause.Subquery{DB: db.Table("users")}}}}).Table("cte").Scan(&users)

// WITH `cte` (`id`,`name`) AS (SELECT * FROM `users`) SELECT * FROM `cte`
db.Clauses(exclause.With{CTEs: []exclause.CTE{{Name: "cte", Columns: []string{"id", "name"}, Subquery: exclause.Subquery{DB: db.Table("users")}}}}).Table("cte").Scan(&users)

// WITH RECURSIVE `cte` AS (SELECT * FROM `users`) SELECT * FROM `cte`
db.Clauses(exclause.With{Recursive: true, CTEs: []exclause.CTE{{Name: "cte", Subquery: exclause.Subquery{DB: db.Table("users")}}}}).Table("cte").Scan(&users)

func NewWith

func NewWith(name string, subquery interface{}, args ...interface{}) With

NewWith is easy to create new With

// examples
// WITH `cte` AS (SELECT * FROM `users`) SELECT * FROM `cte`
db.Clauses(exclause.NewWith("cte", "SELECT * FROM `users`")).Table("cte").Scan(&users)

// WITH `cte` AS (SELECT * FROM `users` WHERE `name` = 'WinterYukky') SELECT * FROM `cte`
db.Clauses(exclause.NewWith("cte", "SELECT * FROM `users` WHERE `name` = ?", "WinterYukky")).Table("cte").Scan(&users)

// WITH `cte` AS (SELECT * FROM `users` WHERE `name` = 'WinterYukky') SELECT * FROM `cte`
db.Clauses(exclause.NewWith("cte", db.Table("users").Where("`name` = ?", "WinterYukky"))).Table("cte").Scan(&users)

If you need more advanced WITH clause, you can see With struct.

func (With) Build

func (with With) Build(builder clause.Builder)

Build build with clause

func (With) MergeClause

func (with With) MergeClause(clause *clause.Clause)

MergeClause merge With clauses

func (With) Name

func (with With) Name() string

Name with clause name

Jump to

Keyboard shortcuts

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