qm

package
v5.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(q *queries.Query, mods ...QueryMod)

Apply the query mods to the Query object

func Rels

func Rels(r ...string) string

Rels is an alias for strings.Join to make it easier to use relationship name constants in Load.

Types

type QueryMod

type QueryMod interface {
	Apply(q *queries.Query)
}

QueryMod modifies a query object.

func And

func And(clause string, args ...interface{}) QueryMod

And allows you to specify a where clause separated by an AND for your statement And is a duplicate of the Where function, but allows for more natural looking query mod chains, for example: (Where("a=?"), And("b=?"), Or("c=?")))

Because Where statements are by default combined with and, there's no reason to call this method as it behaves the same as "Where"

func AndIn

func AndIn(clause string, args ...interface{}) QueryMod

AndIn allows you to specify a "x IN (set)" clause separated by an AndIn for your where statement. AndIn is a duplicate of the WhereIn function, but allows for more natural looking query mod chains, for example: (WhereIn("column1 in ?"), AndIn("column2 in ?"), OrIn("column3 in ?"))

func AndNotIn

func AndNotIn(clause string, args ...interface{}) QueryMod

AndNotIn allows you to specify a "x NOT IN (set)" clause separated by an AndNotIn for your where statement. AndNotIn is a duplicate of the WhereNotIn function, but allows for more natural looking query mod chains, for example: (WhereNotIn("column1 not in ?"), AndIn("column2 not in ?"), OrIn("column3 not in ?"))

func Comment

func Comment(comment string) QueryMod

Comment inserts a custom comment at the begin of your query

func Distinct

func Distinct(clause string) QueryMod

Distinct allows you to filter duplicates

func Expr

func Expr(wheremods ...QueryMod) QueryMod

Expr groups where query mods. It's detrimental to use this with any other type of Query Mod because the effects will always only affect where clauses.

When Expr is used, the entire query will stop doing automatic paretheses for the where statement and you must use Expr anywhere you would like them.

Do NOT use with anything except where.

func For

func For(clause string) QueryMod

For inserts a concurrency locking clause at the end of your statement

func From

func From(from string) QueryMod

From allows to specify the table for your statement

func FullOuterJoin

func FullOuterJoin(clause string, args ...interface{}) QueryMod

FullOuterJoin on another table

func GroupBy

func GroupBy(clause string) QueryMod

GroupBy allows you to specify a group by clause for your statement

func Having

func Having(clause string, args ...interface{}) QueryMod

Having allows you to specify a having clause for your statement

func InnerJoin

func InnerJoin(clause string, args ...interface{}) QueryMod

InnerJoin on another table

func LeftOuterJoin

func LeftOuterJoin(clause string, args ...interface{}) QueryMod

LeftOuterJoin on another table

func Limit

func Limit(limit int) QueryMod

Limit the number of returned rows

func Load

func Load(relationship string, mods ...QueryMod) QueryMod

Load allows you to specify foreign key relationships to eager load for your query. Passed in relationships need to be in the format MyThing or MyThings. Relationship name plurality is important, if your relationship is singular, you need to specify the singular form and vice versa.

In the following example we see how to eager load a users's videos and the video's tags comments, and publisher during a query to find users.

models.Users(qm.Load("Videos.Tags"))

In order to filter better on the query for the relationships you can additionally supply query mods.

models.Users(qm.Load("Videos.Tags", Where("deleted = ?", isDeleted)))

Keep in mind the above only sets the query mods for the query on the last specified relationship. In this case, only Tags will get the query mod. If you want to do intermediate relationships with query mods you must specify them separately:

models.Users(
  qm.Load("Videos", Where("deleted = false"))
  qm.Load("Videos.Tags", Where("deleted = ?", isDeleted))
)

func Offset

func Offset(offset int) QueryMod

Offset into the results

func Or

func Or(clause string, args ...interface{}) QueryMod

Or allows you to specify a where clause separated by an OR for your statement

func Or2

func Or2(q QueryMod) QueryMod

Or2 takes a Where query mod and turns it into an Or. It can be detrimental if used on things that are not Where query mods as it will still modify the last Where statement into an Or.

func OrIn

func OrIn(clause string, args ...interface{}) QueryMod

OrIn allows you to specify an IN clause separated by an OR for your where statement

func OrNotIn

func OrNotIn(clause string, args ...interface{}) QueryMod

OrNotIn allows you to specify a NOT IN clause separated by an OR for your where statement

func OrderBy

func OrderBy(clause string) QueryMod

OrderBy allows you to specify a order by clause for your statement

func RightOuterJoin

func RightOuterJoin(clause string, args ...interface{}) QueryMod

RightOuterJoin on another table

func SQL

func SQL(sql string, args ...interface{}) QueryMod

SQL allows you to execute a plain SQL statement

func Select

func Select(columns ...string) QueryMod

Select specific columns opposed to all columns

func Where

func Where(clause string, args ...interface{}) QueryMod

Where allows you to specify a where clause for your statement. If multiple Where statements are used they are combined with 'and'

func WhereIn

func WhereIn(clause string, args ...interface{}) QueryMod

WhereIn allows you to specify a "x IN (set)" clause for your where statement Example clauses: "column in ?", "(column1,column2) in ?"

func WhereNotIn

func WhereNotIn(clause string, args ...interface{}) QueryMod

WhereNotIn allows you to specify a "x NOT IN (set)" clause for your where statement. Example clauses: "column not in ?", "(column1,column2) not in ?"

func With

func With(clause string, args ...interface{}) QueryMod

With allows you to pass in a Common Table Expression clause (and args)

type QueryModFunc

type QueryModFunc func(q *queries.Query)

The QueryModFunc type is an adapter to allow the use of ordinary functions for query modifying. If f is a function with the appropriate signature, QueryModFunc(f) is a QueryMod that calls f.

func (QueryModFunc) Apply

func (f QueryModFunc) Apply(q *queries.Query)

Apply calls f(q).

Jump to

Keyboard shortcuts

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