Documentation ¶
Index ¶
- Constants
- func CountOver() string
- type DeleteQuery
- type ExistsQuery
- type InsertQuery
- type MultiWhere
- type Query
- type SelectQuery
- func (q *SelectQuery) Columns(columns ...string) *SelectQuery
- func (q *SelectQuery) Join(table, constraints string) *SelectQuery
- func (q *SelectQuery) LeftJoin(table, constraints string) *SelectQuery
- func (q *SelectQuery) Limit() *SelectQuery
- func (q *SelectQuery) Offset() *SelectQuery
- func (q *SelectQuery) OrderBy(column, direction string) *SelectQuery
- func (q *SelectQuery) Query() string
- func (q *SelectQuery) RightJoin(table, constraints string) *SelectQuery
- func (q *SelectQuery) Table(table string) *SelectQuery
- func (q *SelectQuery) With(entities ...string) *SelectQuery
- type UpdateQuery
- type WhereContainer
- func (c *WhereContainer[T]) OrStrpos(column string) T
- func (c *WhereContainer[T]) OrWhere(column ...string) T
- func (c *WhereContainer[T]) OrWhereInSubquery(column string, subQuery func(q SelectQuery) string) T
- func (c *WhereContainer[T]) OrWhereLike(column string) T
- func (c *WhereContainer[T]) OrWhereNotNull(column string) T
- func (c *WhereContainer[T]) OrWhereNull(column string) T
- func (c *WhereContainer[T]) Strpos(column string) T
- func (c *WhereContainer[T]) Where(column ...string) T
- func (c *WhereContainer[T]) WhereGroup(f func(subQuery MultiWhere) string) T
- func (c *WhereContainer[T]) WhereInSubquery(column string, subQuery func(q SelectQuery) string) T
- func (c *WhereContainer[T]) WhereLike(column string) T
- func (c *WhereContainer[T]) WhereNotNull(column string) T
- func (c *WhereContainer[T]) WhereNull(column string) T
Constants ¶
const ( // DESC sort direction for descending DESC string = "DESC" // ASC sort direction for ascending ASC string = "ASC" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DeleteQuery ¶
type DeleteQuery struct { WhereContainer[*DeleteQuery] // contains filtered or unexported fields }
func Delete ¶
func Delete(table string) *DeleteQuery
func (*DeleteQuery) Query ¶
func (q *DeleteQuery) Query() string
type ExistsQuery ¶
type ExistsQuery struct { WhereContainer[*ExistsQuery] // contains filtered or unexported fields }
func Exists ¶
func Exists(table string) *ExistsQuery
func (*ExistsQuery) Query ¶
func (q *ExistsQuery) Query() string
type InsertQuery ¶
type InsertQuery struct {
// contains filtered or unexported fields
}
func Insert ¶
func Insert(table string) InsertQuery
func (InsertQuery) Into ¶
func (q InsertQuery) Into(columns ...string) InsertQuery
func (InsertQuery) Query ¶
func (q InsertQuery) Query() string
func (InsertQuery) Returning ¶
func (q InsertQuery) Returning(columns ...string) InsertQuery
type MultiWhere ¶
type MultiWhere struct {
// contains filtered or unexported fields
}
func (MultiWhere) OrWhere ¶
func (w MultiWhere) OrWhere(condition ...string) MultiWhere
func (MultiWhere) Query ¶
func (w MultiWhere) Query() string
func (MultiWhere) Where ¶
func (w MultiWhere) Where(condition ...string) MultiWhere
type SelectQuery ¶
type SelectQuery struct { WhereContainer[*SelectQuery] // contains filtered or unexported fields }
func Select ¶
func Select(table string) *SelectQuery
func (*SelectQuery) Columns ¶
func (q *SelectQuery) Columns(columns ...string) *SelectQuery
func (*SelectQuery) Join ¶
func (q *SelectQuery) Join(table, constraints string) *SelectQuery
Join method used to add inner join to your queries
Example:
query := ququery.Select("users").Join("posts", "posts.user_id = users.id").Query() log.Println(query) => SELECT * FROM users INNER JOIN posts ON posts.user_id = users.id
func (*SelectQuery) LeftJoin ¶ added in v1.1.0
func (q *SelectQuery) LeftJoin(table, constraints string) *SelectQuery
LeftJoin method used to add left join to your queries
Example:
query := ququery.Select("users").LeftJoin("posts", "posts.user_id = users.id").Query() log.Println(query) => SELECT * FROM users LEFT JOIN posts ON posts.user_id = users.id
func (*SelectQuery) Limit ¶
func (q *SelectQuery) Limit() *SelectQuery
func (*SelectQuery) Offset ¶
func (q *SelectQuery) Offset() *SelectQuery
func (*SelectQuery) OrderBy ¶
func (q *SelectQuery) OrderBy(column, direction string) *SelectQuery
func (*SelectQuery) Query ¶
func (q *SelectQuery) Query() string
func (*SelectQuery) RightJoin ¶ added in v1.1.0
func (q *SelectQuery) RightJoin(table, constraints string) *SelectQuery
RightJoin method used to add right join to your queries
Example:
query := ququery.Select("users").RightJoin("posts", "posts.user_id = users.id").Query() log.Println(query) => SELECT * FROM users RIGHT JOIN posts ON posts.user_id = users.id
func (*SelectQuery) Table ¶
func (q *SelectQuery) Table(table string) *SelectQuery
func (*SelectQuery) With ¶
func (q *SelectQuery) With(entities ...string) *SelectQuery
With can load one-to-many relations without need to pass join column
type UpdateQuery ¶
type UpdateQuery struct { WhereContainer[*UpdateQuery] // contains filtered or unexported fields }
func Update ¶
func Update(table string) *UpdateQuery
func (*UpdateQuery) Query ¶
func (q *UpdateQuery) Query() string
func (*UpdateQuery) Set ¶
func (q *UpdateQuery) Set(columns ...string) *UpdateQuery
type WhereContainer ¶
type WhereContainer[T whereable] struct {
// contains filtered or unexported fields
}
WhereContainer is holder that contain every condinal clauses and methods.
func (*WhereContainer[T]) OrStrpos ¶ added in v1.0.0
func (c *WhereContainer[T]) OrStrpos(column string) T
OrStrpos method allows you to add an "or" clause to Strpos condition.
Example:
query := ququery.Select("users").Where("id").Strpos("name").Query() log.Println(query) => SELECT * FROM users WHERE id = $1 OR (STRPOS(name, $2) > 0 or $3 = '')
func (*WhereContainer[T]) OrWhere ¶
func (c *WhereContainer[T]) OrWhere(column ...string) T
OrWhere allows you to add an "or" clause to Where condition.
Example:
query := ququery.Delete("users").Where("id").OrWhere("email").Query() log.Println(query) => DELETE FROM users WHERE id = $1 OR email = $2
func (*WhereContainer[T]) OrWhereInSubquery ¶ added in v1.1.0
func (c *WhereContainer[T]) OrWhereInSubquery(column string, subQuery func(q SelectQuery) string) T
OrWhereInSubquery method allows you to add an "or" clause to WhereInSubquery condition.
Example:
query := ququery.Select("users").Where("age", ">=").WhereInSubquery("users.id", func(q ququery.SelectQuery) string { return q.Table("orders"). Columns("user_id"). OrderBy("total_price", ququery.DESC). Limit(). Query() }). Query() log.Println(query) => SELECT * FROM users WHERE age >= OR users.id IN (SELECT user_id FROM orders ORDER BY total_price DESC LIMIT $1)
func (*WhereContainer[T]) OrWhereLike ¶ added in v1.0.0
func (c *WhereContainer[T]) OrWhereLike(column string) T
OrWhereLike method allows you to add an "or" clause with a LIKE condition
Example:
query := ququery.Select("users").Where("id").OrWhereLike("name").Query() log.Println(query) => SELECT * FROM users WHERE id = $1 OR name LIKE $2
func (*WhereContainer[T]) OrWhereNotNull ¶ added in v1.0.0
func (c *WhereContainer[T]) OrWhereNotNull(column string) T
OrWhereNotNull method allows you to add an "or" clause to WhereNotNull codition
func (*WhereContainer[T]) OrWhereNull ¶ added in v1.0.0
func (c *WhereContainer[T]) OrWhereNull(column string) T
OrWhereNull method allows you to add an "or" clause to WhereNull condition
Example:
query := ququery.Select("users").Where("status").OrWhereNull("deleted_at").Query log.Println(query) => SELECT * FROM users WHERE status = $1 OR deleted_at IS NULL
func (*WhereContainer[T]) Strpos ¶ added in v1.0.0
func (c *WhereContainer[T]) Strpos(column string) T
Strpos method is more like whereLike method, but the difference is that strpos method is used by postgresql users for full text search.
Example:
query := ququery.Select("users").Strpos("name").Query() log.Println(query) => SELECT * FROM users WHERE (STRPOS(name, $1) > 0 or $2 = '')
func (*WhereContainer[T]) Where ¶
func (c *WhereContainer[T]) Where(column ...string) T
Where You may use the query builder's Where method to add "where" clauses to the query.
Example:
query := ququery.Select("users").Where("id").Query() log.Println(query) => SELECT * FROM users WHERE id = $1 query = ququery.Select("users").Where("age", ">=").Query() log.Println(query) => SELECT * FROM users WHERE age >= $1
func (*WhereContainer[T]) WhereGroup ¶ added in v1.0.0
func (c *WhereContainer[T]) WhereGroup(f func(subQuery MultiWhere) string) T
WhereGroup Sometimes you may need to group several "where" clauses within parentheses in order to achieve your query's desired logical grouping. In fact, you should generally always group calls to the orWhere method in parentheses in order to avoid unexpected query behavior. To accomplish this, you may user this method:
Example:
query := ququery.Select("users").WhereGroup(func(subQuery ququery.MultiWhere) string { return subQuery.Where("email"). Where("role_id"). OrWhere("type"). Query() }).Query(), log.Println(query) => SELECT * FROM users WHERE ( email = $1 AND role_id = $2 OR type = $3)
func (*WhereContainer[T]) WhereInSubquery ¶ added in v1.0.0
func (c *WhereContainer[T]) WhereInSubquery(column string, subQuery func(q SelectQuery) string) T
WhereInSubquery Sometimes you may need to construct a "where" clause that compares the results of a subquery to a given value. You may accomplish this by passing a closure and a value to the where method.
Example:
query := ququery.Select("users").WhereInSubquery("users.id", func(q ququery.SelectQuery) string { return q.Table("orders"). Columns("user_id"). OrderBy("total_price", ququery.DESC). Limit(). Query() }). Query() log.Println(query) => SELECT * FROM users WHERE users.id IN (SELECT user_id FROM orders ORDER BY total_price DESC LIMIT $1)
func (*WhereContainer[T]) WhereLike ¶ added in v1.0.0
func (c *WhereContainer[T]) WhereLike(column string) T
WhereLike method allows you to add "LIKE" clauses to your query from pattern matchinga.
Example:
query := ququery.Select("users").WhereLike("name").Query() log.Println(query) => SELECT * FROM users WHERE name LIKE $1
func (*WhereContainer[T]) WhereNotNull ¶ added in v1.0.0
func (c *WhereContainer[T]) WhereNotNull(column string) T
WhereNotNull method verifies that the column's value is not NULL:
Example:
query := ququery.Delete("users").WhereNotNull("deleted_at").Query() log.Println(query) => DELETE FROM users WHERE deleted_at IS NOT NULL
func (*WhereContainer[T]) WhereNull ¶ added in v1.0.0
func (c *WhereContainer[T]) WhereNull(column string) T
WhereNull method verifies that the value of the given column is NULL:
Example:
query := ququery.Select("users").WhereNull("deleted_at").Query() log.Println(query) => SELECT * FROM users WHERE deleted_at IS NULL