Documentation ¶
Overview ¶
Package cue is a query construction layer.
See ...Statement to be built. (SelectStatement family is commented) See Expr about condition notation.
Index ¶
- type Builder
- type CreateStatement
- func (stmt *CreateStatement) BuildSQL() (string, []interface{})
- func (stmt *CreateStatement) Column(column string) *CreateStatement
- func (stmt *CreateStatement) Create() *CreateStatement
- func (stmt *CreateStatement) Dialect(d dialect.Dialect) *CreateStatement
- func (stmt *CreateStatement) IfNotExists() *CreateStatement
- func (stmt *CreateStatement) PrimaryKey(pks ...string) *CreateStatement
- func (stmt *CreateStatement) Select(sel *SelectStatement) *CreateStatement
- func (stmt *CreateStatement) Table(name string, columns ...string) *CreateStatement
- func (stmt *CreateStatement) View(name string, columns ...string) *CreateStatement
- type DeleteStatement
- func (stmt *DeleteStatement) BuildSQL() (string, []interface{})
- func (stmt *DeleteStatement) Delete(from string) *DeleteStatement
- func (stmt *DeleteStatement) Dialect(d dialect.Dialect) *DeleteStatement
- func (stmt *DeleteStatement) From(from string) *DeleteStatement
- func (stmt *DeleteStatement) Where(exprs ...Expr) *DeleteStatement
- type DropStatement
- func (stmt *DropStatement) BuildSQL() (string, []interface{})
- func (stmt *DropStatement) Dialect(d dialect.Dialect) *DropStatement
- func (stmt *DropStatement) Drop() *DropStatement
- func (stmt *DropStatement) Table(name string) *DropStatement
- func (stmt *DropStatement) View(name string) *DropStatement
- type Expr
- func Alias(expr Expr, alias string) Expr
- func And(exprs ...Expr) Expr
- func Assign(id string, value interface{}) Expr
- func Cmp(left, op string, right interface{}) Expr
- func Col(column interface{}, optAlias ...string) Expr
- func Eq(left string, right interface{}) Expr
- func Exists(query *SelectStatement) Expr
- func Fn(name string, args ...Expr) Expr
- func Geq(left string, right interface{}) Expr
- func Gr(left string, right interface{}) Expr
- func ID(name string) Expr
- func IDExprCmp(id, op string, expr Expr) Expr
- func IDIDCmp(leftID, op, rightID string) Expr
- func IDValCmp(id, op string, value interface{}) Expr
- func In(id string, values ...interface{}) Expr
- func Leq(left string, right interface{}) Expr
- func Like(left string, right interface{}) Expr
- func Ls(left string, right interface{}) Expr
- func Neq(left string, right interface{}) Expr
- func Or(exprs ...Expr) Expr
- func Raw(raw string, values ...interface{}) Expr
- func Val(value interface{}) Expr
- type InsertStatement
- func (stmt *InsertStatement) BuildSQL() (string, []interface{})
- func (stmt *InsertStatement) Dialect(d dialect.Dialect) *InsertStatement
- func (stmt *InsertStatement) Insert() *InsertStatement
- func (stmt *InsertStatement) Into(table string, columns ...string) *InsertStatement
- func (stmt *InsertStatement) Returning(cols ...interface{}) *InsertStatement
- func (stmt *InsertStatement) Select(sel *SelectStatement) *InsertStatement
- func (stmt *InsertStatement) Values(values ...interface{}) *InsertStatement
- type SelectStatement
- func (stmt *SelectStatement) BuildSQL() (string, []interface{})
- func (stmt *SelectStatement) CrossJoin(table string, exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) Dialect(d dialect.Dialect) *SelectStatement
- func (stmt *SelectStatement) From(from string) *SelectStatement
- func (stmt *SelectStatement) FullJoin(table string, exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) GroupBy(columns ...string) *SelectStatement
- func (stmt *SelectStatement) Having(exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) InnerJoin(table string, exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) Join(joinType, table string, exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) JoinQuery(joinType string, query *SelectStatement, alias string, exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) LeftJoin(table string, exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) Limit(limit int) *SelectStatement
- func (stmt *SelectStatement) Offset(offset int) *SelectStatement
- func (stmt *SelectStatement) OrderBy(columns ...string) *SelectStatement
- func (stmt *SelectStatement) RightJoin(table string, exprs ...Expr) *SelectStatement
- func (stmt *SelectStatement) Select(columns ...interface{}) *SelectStatement
- func (stmt *SelectStatement) Union(all bool, query *SelectStatement) *SelectStatement
- func (stmt *SelectStatement) Where(exprs ...Expr) *SelectStatement
- type UpdateStatement
- func (stmt *UpdateStatement) BuildSQL() (string, []interface{})
- func (stmt *UpdateStatement) Dialect(d dialect.Dialect) *UpdateStatement
- func (stmt *UpdateStatement) Set(exprs ...Expr) *UpdateStatement
- func (stmt *UpdateStatement) Update(table string) *UpdateStatement
- func (stmt *UpdateStatement) Where(exprs ...Expr) *UpdateStatement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder interface {
BuildSQL() (string, []interface{})
}
Builder is implemented by Statements
type CreateStatement ¶
type CreateStatement struct {
// contains filtered or unexported fields
}
CreateStatement builds a CREATE TABLE or CREATE VIEW statement.
func (*CreateStatement) BuildSQL ¶
func (stmt *CreateStatement) BuildSQL() (string, []interface{})
BuildSQL builds a query and collects args.
func (*CreateStatement) Column ¶
func (stmt *CreateStatement) Column(column string) *CreateStatement
Column appends columns of a table's or a view's.
func (*CreateStatement) Create ¶
func (stmt *CreateStatement) Create() *CreateStatement
Create restarts.
func (*CreateStatement) Dialect ¶
func (stmt *CreateStatement) Dialect(d dialect.Dialect) *CreateStatement
Dialect overwrites the dialect of statement.
func (*CreateStatement) IfNotExists ¶
func (stmt *CreateStatement) IfNotExists() *CreateStatement
IfNotExists adds `IF NOT EXISTS`.
func (*CreateStatement) PrimaryKey ¶
func (stmt *CreateStatement) PrimaryKey(pks ...string) *CreateStatement
PrimaryKey appends primary keys.
func (*CreateStatement) Select ¶
func (stmt *CreateStatement) Select(sel *SelectStatement) *CreateStatement
Select with a SelectStatement builds `CREATE TABLE xxx SELECT ...`.
sel : usual SelectStatement
func (*CreateStatement) Table ¶
func (stmt *CreateStatement) Table(name string, columns ...string) *CreateStatement
Table defines `CREATE TABLE name (columns...)`.
name : table name columns... : (optional) column names as strings
func (*CreateStatement) View ¶
func (stmt *CreateStatement) View(name string, columns ...string) *CreateStatement
View defines `CREATE VIEW name (columns...)`.
name : view name columns... : (optional) column names as strings
type DeleteStatement ¶
type DeleteStatement struct {
// contains filtered or unexported fields
}
DeleteStatement builds a DELETE FROM statement.
func Delete ¶
func Delete(from string) *DeleteStatement
Delete starts method chaining.
from : table name
func (*DeleteStatement) BuildSQL ¶
func (stmt *DeleteStatement) BuildSQL() (string, []interface{})
BuildSQL builds a query and collects args.
func (*DeleteStatement) Delete ¶
func (stmt *DeleteStatement) Delete(from string) *DeleteStatement
Delete resets with target table.
func (*DeleteStatement) Dialect ¶
func (stmt *DeleteStatement) Dialect(d dialect.Dialect) *DeleteStatement
Dialect overwrites the dialect of statement.
func (*DeleteStatement) From ¶
func (stmt *DeleteStatement) From(from string) *DeleteStatement
From specifies the target table name.
func (*DeleteStatement) Where ¶
func (stmt *DeleteStatement) Where(exprs ...Expr) *DeleteStatement
Where appends conditional Expr-s.
This method concatenates conditions with AND.
type DropStatement ¶
type DropStatement struct {
// contains filtered or unexported fields
}
DropStatement builds a DROP TABLE or DROP VIEW statement.
func (*DropStatement) BuildSQL ¶
func (stmt *DropStatement) BuildSQL() (string, []interface{})
BuildSQL builds a query and collects args
func (*DropStatement) Dialect ¶
func (stmt *DropStatement) Dialect(d dialect.Dialect) *DropStatement
Dialect overwrites the dialect of statement.
func (*DropStatement) Table ¶
func (stmt *DropStatement) Table(name string) *DropStatement
Table defines `DROP TABLE name`.
name : table name
func (*DropStatement) View ¶
func (stmt *DropStatement) View(name string) *DropStatement
View defines `DROP VIEW name`.
name : view name
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr is NOT extensible, because it requires private methods.
func Cmp ¶
Cmp is a base function declaring Eq, Neq, ...
right : Expr or any value (to be a bind-variable)
func Col ¶
Col expresses column names in Select.
column : Expr or string optAlias : (optional) alias name
func In ¶
In expresses `id IN (values...)`.
If values are not Expr, they are built as bind variables.
type InsertStatement ¶
type InsertStatement struct {
// contains filtered or unexported fields
}
InsertStatement builds a INSERT statement.
func (*InsertStatement) BuildSQL ¶
func (stmt *InsertStatement) BuildSQL() (string, []interface{})
BuildSQL builds a query and collects args.
func (*InsertStatement) Dialect ¶
func (stmt *InsertStatement) Dialect(d dialect.Dialect) *InsertStatement
Dialect overwrites the dialect of statement.
func (*InsertStatement) Insert ¶
func (stmt *InsertStatement) Insert() *InsertStatement
Insert restarts.
func (*InsertStatement) Into ¶
func (stmt *InsertStatement) Into(table string, columns ...string) *InsertStatement
Into defines `INSERT INTO name (columns...)`.
table : table name columns... : columns to be set by following clauses.
func (*InsertStatement) Returning ¶
func (stmt *InsertStatement) Returning(cols ...interface{}) *InsertStatement
func (*InsertStatement) Select ¶
func (stmt *InsertStatement) Select(sel *SelectStatement) *InsertStatement
Select with a SelectStatement builds `INSERT INTO xxx SELECT ...`.
func (*InsertStatement) Values ¶
func (stmt *InsertStatement) Values(values ...interface{}) *InsertStatement
Values defines `VALUES (values...)`.
each value means:
nil -> null Expr -> built others -> built as a bind-variable
type SelectStatement ¶
type SelectStatement struct {
// contains filtered or unexported fields
}
SelectStatement builds a SELECT statement.
func (*SelectStatement) BuildSQL ¶
func (stmt *SelectStatement) BuildSQL() (string, []interface{})
BuildSQL builds a query and collects args.
func (*SelectStatement) CrossJoin ¶
func (stmt *SelectStatement) CrossJoin(table string, exprs ...Expr) *SelectStatement
CrossJoin defines CROSS JOIN xxx ON clause.
func (*SelectStatement) Dialect ¶
func (stmt *SelectStatement) Dialect(d dialect.Dialect) *SelectStatement
Dialect overwrites the dialect of statement.
func (*SelectStatement) From ¶
func (stmt *SelectStatement) From(from string) *SelectStatement
From defines FROM clause.
func (*SelectStatement) FullJoin ¶
func (stmt *SelectStatement) FullJoin(table string, exprs ...Expr) *SelectStatement
FullJoin defines FULL JOIN xxx ON clause.
func (*SelectStatement) GroupBy ¶
func (stmt *SelectStatement) GroupBy(columns ...string) *SelectStatement
GroupBy defines GROUP BY clause
func (*SelectStatement) Having ¶
func (stmt *SelectStatement) Having(exprs ...Expr) *SelectStatement
Having appends conditional Expr-s into HAVING clause.
func (*SelectStatement) InnerJoin ¶
func (stmt *SelectStatement) InnerJoin(table string, exprs ...Expr) *SelectStatement
InnerJoin defines INNER JOIN xxx ON clause.
func (*SelectStatement) Join ¶
func (stmt *SelectStatement) Join(joinType, table string, exprs ...Expr) *SelectStatement
Join defines `jointType JOIN xxx ON` clause.
This method is used to implement XXXJoin methods.
joinType : e.g. "LEFT JOIN"
func (*SelectStatement) JoinQuery ¶
func (stmt *SelectStatement) JoinQuery(joinType string, query *SelectStatement, alias string, exprs ...Expr) *SelectStatement
JoinQuery defines JOIN with another SelectStatement.
func (*SelectStatement) LeftJoin ¶
func (stmt *SelectStatement) LeftJoin(table string, exprs ...Expr) *SelectStatement
LeftJoin defines LEFT JOIN xxx ON clause.
func (*SelectStatement) Limit ¶
func (stmt *SelectStatement) Limit(limit int) *SelectStatement
func (*SelectStatement) Offset ¶
func (stmt *SelectStatement) Offset(offset int) *SelectStatement
func (*SelectStatement) OrderBy ¶
func (stmt *SelectStatement) OrderBy(columns ...string) *SelectStatement
OrderBy defines ORDER BY clause.
func (*SelectStatement) RightJoin ¶
func (stmt *SelectStatement) RightJoin(table string, exprs ...Expr) *SelectStatement
RightJoin defines RIGHT JOIN xxx ON clause.
func (*SelectStatement) Select ¶
func (stmt *SelectStatement) Select(columns ...interface{}) *SelectStatement
Select restarts with SELECT columns.
func (*SelectStatement) Union ¶
func (stmt *SelectStatement) Union(all bool, query *SelectStatement) *SelectStatement
Union defines UNION (ALL) with another SelectStatement.
func (*SelectStatement) Where ¶
func (stmt *SelectStatement) Where(exprs ...Expr) *SelectStatement
Where appends conditional Expr-s.
This method concatenates conditions with AND.
type UpdateStatement ¶
type UpdateStatement struct {
// contains filtered or unexported fields
}
UpdateStatement builds a UPDATE statement.
func (*UpdateStatement) BuildSQL ¶
func (stmt *UpdateStatement) BuildSQL() (string, []interface{})
BuildSQL builds a query and collects args.
func (*UpdateStatement) Dialect ¶
func (stmt *UpdateStatement) Dialect(d dialect.Dialect) *UpdateStatement
Dialect overwrites the dialect of statement.
func (*UpdateStatement) Set ¶
func (stmt *UpdateStatement) Set(exprs ...Expr) *UpdateStatement
Set appends SET pairs.
exprs : in most case, cue.Assign("id", "value")...
func (*UpdateStatement) Update ¶
func (stmt *UpdateStatement) Update(table string) *UpdateStatement
Update restarts with target table.
func (*UpdateStatement) Where ¶
func (stmt *UpdateStatement) Where(exprs ...Expr) *UpdateStatement
Where appends conditional Expr-s.
This method concatenates conditions with AND.