Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is the basic container for injecting query builder configurations.
All the Query structs can also be called directly without this builder, but we kept it here for convenience.
func (*Builder) Build ¶
Build receives a query builder struct, injects it with the configurations build the query according to its arguments.
func (*Builder) RunAndCount ¶
func (builder *Builder) RunAndCount(ctx context.Context, db ksql.Provider, targetPtr interface{}, queryBuilder Query) (count int, err error)
RunAndCount runs a paginated input query once returning the values and then runs it again just for counting the total number of results.
type Insert ¶
type Insert struct {
// Into expects a table name, e.g. "users"
Into string
// Data expected either a single record annotated with `ksql` tags
// or a list of records annotated likewise.
Data interface{}
// OmitColumns informs kbuilder of a set of columns not to use during the insertion
OmitColumns []string
// Returning causes the query to be built in a way that the selected attributes
// will be returned after the insertion.
Returning []string
}
Insert is the struct template for building INSERT queries
Experimental warning: This package is still experimental and might be subject to breaking changes in future versions.
func (Insert) Build ¶
Build is a utility function for finding the dialect based on the driver and then calling BuildQuery(dialect)
func (Insert) BuildQuery ¶
func (i Insert) BuildQuery(dialect sqldialect.Provider) (sqlQuery string, params []interface{}, _ error)
BuildQuery implements the queryBuilder interface
type Query ¶
type Query struct {
// Select expects either a struct using the `ksql` tags
// or a string listing the column names using SQL syntax,
// e.g.: `id, username, address`
Select interface{}
// From expects the FROM clause from an SQL query, e.g. `users JOIN posts USING(post_id)`
From string
// Where expects a list of WhereQuery instances built
// by the public Where() function.
Where WhereQueries
Limit int
Offset int
OrderBy string
}
Query is is the struct template for building SELECT queries.
func (Query) Build ¶
Build is a utility function for finding the dialect based on the driver and then calling BuildQuery(dialect)
func (Query) BuildQuery ¶
func (q Query) BuildQuery(dialect sqldialect.Provider) (sqlQuery string, params []interface{}, _ error)
BuildQuery implements the queryBuilder interface
type WhereQueries ¶
type WhereQueries []WhereQuery
WhereQueries is the helper for creating complex WHERE queries in a dynamic way.
func Where ¶
func Where(cond string, params ...interface{}) WhereQueries
Where adds a new boolean condition to an existing WhereQueries helper.
func WhereIf ¶
func WhereIf(ifCond bool, cond string, params ...interface{}) WhereQueries
WhereIf conditionally adds a new boolean expression to the WhereQueries helper
func (WhereQueries) Where ¶
func (w WhereQueries) Where(cond string, params ...interface{}) WhereQueries
Where adds a new boolean condition to an existing WhereQueries helper.
func (WhereQueries) WhereIf ¶
func (w WhereQueries) WhereIf(ifCond bool, cond string, params ...interface{}) WhereQueries
WhereIf conditionally adds a new boolean expression to the WhereQueries helper.
type WhereQuery ¶
type WhereQuery struct {
// contains filtered or unexported fields
}
WhereQuery represents a single condition in a WHERE expression.