cue

package
v0.0.0-...-b8eaa0e Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cue is a query construction layer.

See ...Statement to be built. (SelectStatement family is commented) See Expr about condition notation.

Index

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 Create

func Create() *CreateStatement

Create starts method chaining.

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 Drop

func Drop() *DropStatement

Drop starts method chaining.

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) Drop

func (stmt *DropStatement) Drop() *DropStatement

Drop restarts.

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 Alias

func Alias(expr Expr, alias string) Expr

Alias expresses `expr AS alias`.

func And

func And(exprs ...Expr) Expr

And expresses an AND operator.

func Assign

func Assign(id string, value interface{}) Expr

Assign expresses `id = value`.

value : Expr or any value (to be a bind-variable)

func Cmp

func Cmp(left, op string, right interface{}) Expr

Cmp is a base function declaring Eq, Neq, ...

right : Expr or any value (to be a bind-variable)

func Col

func Col(column interface{}, optAlias ...string) Expr

Col expresses column names in Select.

column : Expr or string optAlias : (optional) alias name

func Eq

func Eq(left string, right interface{}) Expr

Eq expresses `left = ?`, [right]

func Exists

func Exists(query *SelectStatement) Expr

Exists expresses `exists (SELECT ...)`.

func Fn

func Fn(name string, args ...Expr) Expr

Fn expresses `name(args...)`.

func Geq

func Geq(left string, right interface{}) Expr

Geq expresses `left >= ?`, [right]

func Gr

func Gr(left string, right interface{}) Expr

Gr expresses `left > ?`, [right]

func ID

func ID(name string) Expr

ID expresses identifier (It is not a bind-variable).

func IDExprCmp

func IDExprCmp(id, op string, expr Expr) Expr

IDExprCmp expresses `id op expr`.

func IDIDCmp

func IDIDCmp(leftID, op, rightID string) Expr

IDIDCmp expresses `leftID op rightID`.

func IDValCmp

func IDValCmp(id, op string, value interface{}) Expr

IDValCmp expresses `id op ?` and [value]

func In

func In(id string, values ...interface{}) Expr

In expresses `id IN (values...)`.

If values are not Expr, they are built as bind variables.

func Leq

func Leq(left string, right interface{}) Expr

Leq expresses `left <= ?`, [right]

func Like

func Like(left string, right interface{}) Expr

Like expresses `left LIKE ?`, [right]

func Ls

func Ls(left string, right interface{}) Expr

Ls expresses `left < ?`, [right]

func Neq

func Neq(left string, right interface{}) Expr

Neq expresses `left != ?`, [right]

func Or

func Or(exprs ...Expr) Expr

Or expresses an OR operator.

func Raw

func Raw(raw string, values ...interface{}) Expr

Raw expresses a partial query and its parameters.

Note: placeholders in raw argument does NOT consider dialects. MySQL ... "?" PostgreSQL ... "$1" Oracle ... ":xxx"

cue.Select().Where(Raw("col1 = ? and col2 like ?", 123, "%John%"))

func Val

func Val(value interface{}) Expr

Val expresses bind-variable.

Val(100) is built for query "?" and args [100]

type InsertStatement

type InsertStatement struct {
	// contains filtered or unexported fields
}

InsertStatement builds a INSERT statement.

func Insert

func Insert() *InsertStatement

Insert starts method chaining.

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 Select

func Select(columns ...interface{}) *SelectStatement

Select starts method chaining.

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 Update

func Update(table string) *UpdateStatement

Update starts method chaining.

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.

Jump to

Keyboard shortcuts

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