Support for raw sql input.
This commit is contained in:
parent
384c0c67f5
commit
8f51662fe5
31 changed files with 307 additions and 279 deletions
|
|
@ -1,11 +1,11 @@
|
|||
package sqlbuilder
|
||||
|
||||
type Alias struct {
|
||||
expression expression
|
||||
expression Expression
|
||||
alias string
|
||||
}
|
||||
|
||||
func NewAlias(expression expression, alias string) *Alias {
|
||||
func NewAlias(expression Expression, alias string) *Alias {
|
||||
return &Alias{
|
||||
expression: expression,
|
||||
alias: alias,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type BoolExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(expression BoolExpression) BoolExpression
|
||||
NOT_EQ(expression BoolExpression) BoolExpression
|
||||
|
|
@ -79,7 +79,7 @@ type binaryBoolExpression struct {
|
|||
binaryOpExpression
|
||||
}
|
||||
|
||||
func newBinaryBoolExpression(lhs, rhs expression, operator string) BoolExpression {
|
||||
func newBinaryBoolExpression(lhs, rhs Expression, operator string) BoolExpression {
|
||||
boolExpression := binaryBoolExpression{}
|
||||
|
||||
boolExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
||||
|
|
@ -97,7 +97,7 @@ type prefixBoolExpression struct {
|
|||
prefixOpExpression
|
||||
}
|
||||
|
||||
func newPrefixBoolExpression(expression expression, operator string) BoolExpression {
|
||||
func newPrefixBoolExpression(expression Expression, operator string) BoolExpression {
|
||||
exp := prefixBoolExpression{}
|
||||
exp.prefixOpExpression = newPrefixExpression(expression, operator)
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ type postfixBoolOpExpression struct {
|
|||
postfixOpExpression
|
||||
}
|
||||
|
||||
func newPostifxBoolExpression(expression expression, operator string) BoolExpression {
|
||||
func newPostifxBoolExpression(expression Expression, operator string) BoolExpression {
|
||||
exp := postfixBoolOpExpression{}
|
||||
exp.postfixOpExpression = newPostfixOpExpression(expression, operator)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
package sqlbuilder
|
||||
|
||||
type cast struct {
|
||||
expression
|
||||
Expression
|
||||
castType string
|
||||
}
|
||||
|
||||
func newCast(expression expression, castType string) *cast {
|
||||
func newCast(expression Expression, castType string) *cast {
|
||||
return &cast{
|
||||
expression: expression,
|
||||
Expression: expression,
|
||||
castType: castType,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *cast) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
err := b.expression.serialize(statement, out, options...)
|
||||
err := b.Expression.serialize(statement, out, options...)
|
||||
out.writeString("::" + b.castType)
|
||||
return err
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ type boolCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newBoolCast(expression expression) BoolExpression {
|
||||
func newBoolCast(expression Expression) BoolExpression {
|
||||
boolCast := &boolCast{cast: *newCast(expression, "boolean")}
|
||||
|
||||
boolCast.boolInterfaceImpl.parent = boolCast
|
||||
|
|
@ -39,7 +39,7 @@ type integerCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newIntegerCast(expression expression) IntegerExpression {
|
||||
func newIntegerCast(expression Expression) IntegerExpression {
|
||||
integerCast := &integerCast{cast: *newCast(expression, "integer")}
|
||||
|
||||
integerCast.integerInterfaceImpl.parent = integerCast
|
||||
|
|
@ -54,7 +54,7 @@ type floatCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newDoubleCast(expression expression) FloatExpression {
|
||||
func newDoubleCast(expression Expression) FloatExpression {
|
||||
floatCast := &floatCast{cast: *newCast(expression, "double precision")}
|
||||
|
||||
floatCast.floatInterfaceImpl.parent = floatCast
|
||||
|
|
@ -69,7 +69,7 @@ type textCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newTextCast(expression expression) StringExpression {
|
||||
func newTextCast(expression Expression) StringExpression {
|
||||
textCast := &textCast{cast: *newCast(expression, "text")}
|
||||
|
||||
textCast.stringInterfaceImpl.parent = textCast
|
||||
|
|
@ -84,7 +84,7 @@ type dateCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newDateCast(expression expression) DateExpression {
|
||||
func newDateCast(expression Expression) DateExpression {
|
||||
dateCast := &dateCast{cast: *newCast(expression, "date")}
|
||||
|
||||
dateCast.dateInterfaceImpl.parent = dateCast
|
||||
|
|
@ -99,7 +99,7 @@ type timeCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newTimeCast(expression expression) TimeExpression {
|
||||
func newTimeCast(expression Expression) TimeExpression {
|
||||
timeCast := &timeCast{cast: *newCast(expression, "time without time zone")}
|
||||
|
||||
timeCast.timeInterfaceImpl.parent = timeCast
|
||||
|
|
@ -114,7 +114,7 @@ type timezCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newTimezCast(expression expression) TimezExpression {
|
||||
func newTimezCast(expression Expression) TimezExpression {
|
||||
timezCast := &timezCast{cast: *newCast(expression, "time with time zone")}
|
||||
|
||||
timezCast.timezInterfaceImpl.parent = timezCast
|
||||
|
|
@ -129,7 +129,7 @@ type timestampCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newTimestampCast(expression expression) TimestampExpression {
|
||||
func newTimestampCast(expression Expression) TimestampExpression {
|
||||
timestampCast := ×tampCast{cast: *newCast(expression, "timestamp without time zone")}
|
||||
|
||||
timestampCast.timestampInterfaceImpl.parent = timestampCast
|
||||
|
|
@ -144,7 +144,7 @@ type timestampzCast struct {
|
|||
cast
|
||||
}
|
||||
|
||||
func newTimestampzCast(expression expression) TimestampzExpression {
|
||||
func newTimestampzCast(expression Expression) TimestampzExpression {
|
||||
timestampzCast := ×tampzCast{cast: *newCast(expression, "timestamp with time zone")}
|
||||
|
||||
timestampzCast.timestampzInterfaceImpl.parent = timestampzCast
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func (q *queryData) writeFrom(statement statementType, table tableInterface) err
|
|||
return err
|
||||
}
|
||||
|
||||
func (q *queryData) writeWhere(statement statementType, where expression) error {
|
||||
func (q *queryData) writeWhere(statement statementType, where Expression) error {
|
||||
q.nextLine()
|
||||
q.writeString("WHERE")
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ func (q *queryData) writeGroupBy(statement statementType, groupBy []groupByClaus
|
|||
return err
|
||||
}
|
||||
|
||||
func (q *queryData) writeOrderBy(statement statementType, orderBy []orderByClause) error {
|
||||
func (q *queryData) writeOrderBy(statement statementType, orderBy []OrderByClause) error {
|
||||
q.nextLine()
|
||||
q.writeString("ORDER BY")
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ func (q *queryData) writeOrderBy(statement statementType, orderBy []orderByClaus
|
|||
return err
|
||||
}
|
||||
|
||||
func (q *queryData) writeHaving(statement statementType, having expression) error {
|
||||
func (q *queryData) writeHaving(statement statementType, having Expression) error {
|
||||
q.nextLine()
|
||||
q.writeString("HAVING")
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
type column interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
Name() string
|
||||
TableName() string
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type DateExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs DateExpression) BoolExpression
|
||||
NOT_EQ(rhs DateExpression) BoolExpression
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ import (
|
|||
"github.com/sub0zero/go-sqlbuilder/sqlbuilder/execution"
|
||||
)
|
||||
|
||||
type deleteStatement interface {
|
||||
type DeleteStatement interface {
|
||||
Statement
|
||||
|
||||
WHERE(expression BoolExpression) deleteStatement
|
||||
WHERE(expression BoolExpression) DeleteStatement
|
||||
}
|
||||
|
||||
func newDeleteStatement(table writableTable) deleteStatement {
|
||||
func newDeleteStatement(table writableTable) DeleteStatement {
|
||||
return &deleteStatementImpl{
|
||||
table: table,
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ type deleteStatementImpl struct {
|
|||
where BoolExpression
|
||||
}
|
||||
|
||||
func (d *deleteStatementImpl) WHERE(expression BoolExpression) deleteStatement {
|
||||
func (d *deleteStatementImpl) WHERE(expression BoolExpression) DeleteStatement {
|
||||
d.where = expression
|
||||
return d
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,25 +4,25 @@ import (
|
|||
"github.com/dropbox/godropbox/errors"
|
||||
)
|
||||
|
||||
// An expression
|
||||
type expression interface {
|
||||
// An Expression
|
||||
type Expression interface {
|
||||
clause
|
||||
projection
|
||||
groupByClause
|
||||
orderByClause
|
||||
OrderByClause
|
||||
|
||||
IS_NULL() BoolExpression
|
||||
IS_NOT_NULL() BoolExpression
|
||||
|
||||
IN(expressions ...expression) BoolExpression
|
||||
NOT_IN(expressions ...expression) BoolExpression
|
||||
IN(expressions ...Expression) BoolExpression
|
||||
NOT_IN(expressions ...Expression) BoolExpression
|
||||
|
||||
AS(alias string) projection
|
||||
|
||||
ASC() orderByClause
|
||||
DESC() orderByClause
|
||||
ASC() OrderByClause
|
||||
DESC() OrderByClause
|
||||
|
||||
CAST_TO(dbType string) expression
|
||||
CAST_TO(dbType string) Expression
|
||||
CAST_TO_BOOL() BoolExpression
|
||||
CAST_TO_INTEGER() IntegerExpression
|
||||
CAST_TO_DOUBLE() FloatExpression
|
||||
|
|
@ -35,7 +35,7 @@ type expression interface {
|
|||
}
|
||||
|
||||
type expressionInterfaceImpl struct {
|
||||
parent expression
|
||||
parent Expression
|
||||
}
|
||||
|
||||
func (e *expressionInterfaceImpl) IS_NULL() BoolExpression {
|
||||
|
|
@ -46,11 +46,11 @@ func (e *expressionInterfaceImpl) IS_NOT_NULL() BoolExpression {
|
|||
return newPostifxBoolExpression(e.parent, "IS NOT NULL")
|
||||
}
|
||||
|
||||
func (e *expressionInterfaceImpl) IN(expressions ...expression) BoolExpression {
|
||||
func (e *expressionInterfaceImpl) IN(expressions ...Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(e.parent, WRAP(expressions...), "IN")
|
||||
}
|
||||
|
||||
func (e *expressionInterfaceImpl) NOT_IN(expressions ...expression) BoolExpression {
|
||||
func (e *expressionInterfaceImpl) NOT_IN(expressions ...Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(e.parent, WRAP(expressions...), "NOT IN")
|
||||
}
|
||||
|
||||
|
|
@ -58,15 +58,15 @@ func (e *expressionInterfaceImpl) AS(alias string) projection {
|
|||
return NewAlias(e.parent, alias)
|
||||
}
|
||||
|
||||
func (e *expressionInterfaceImpl) ASC() orderByClause {
|
||||
func (e *expressionInterfaceImpl) ASC() OrderByClause {
|
||||
return &orderByClauseImpl{expression: e.parent, ascent: true}
|
||||
}
|
||||
|
||||
func (e *expressionInterfaceImpl) DESC() orderByClause {
|
||||
func (e *expressionInterfaceImpl) DESC() OrderByClause {
|
||||
return &orderByClauseImpl{expression: e.parent, ascent: false}
|
||||
}
|
||||
|
||||
func (e *expressionInterfaceImpl) CAST_TO(dbType string) expression {
|
||||
func (e *expressionInterfaceImpl) CAST_TO(dbType string) Expression {
|
||||
return newCast(e.parent, dbType)
|
||||
}
|
||||
|
||||
|
|
@ -120,11 +120,11 @@ func (e *expressionInterfaceImpl) serializeAsOrderBy(statement statementType, ou
|
|||
|
||||
// Representation of binary operations (e.g. comparisons, arithmetic)
|
||||
type binaryOpExpression struct {
|
||||
lhs, rhs expression
|
||||
lhs, rhs Expression
|
||||
operator string
|
||||
}
|
||||
|
||||
func newBinaryExpression(lhs, rhs expression, operator string, parent ...expression) binaryOpExpression {
|
||||
func newBinaryExpression(lhs, rhs Expression, operator string) binaryOpExpression {
|
||||
binaryExpression := binaryOpExpression{
|
||||
lhs: lhs,
|
||||
rhs: rhs,
|
||||
|
|
@ -136,7 +136,7 @@ func newBinaryExpression(lhs, rhs expression, operator string, parent ...express
|
|||
|
||||
func (c *binaryOpExpression) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
if c == nil {
|
||||
return errors.New("Binary expression is nil.")
|
||||
return errors.New("Binary Expression is nil.")
|
||||
}
|
||||
if c.lhs == nil {
|
||||
return errors.Newf("nil lhs.")
|
||||
|
|
@ -168,13 +168,13 @@ func (c *binaryOpExpression) serialize(statement statementType, out *queryData,
|
|||
return nil
|
||||
}
|
||||
|
||||
// A prefix operator expression
|
||||
// A prefix operator Expression
|
||||
type prefixOpExpression struct {
|
||||
expression expression
|
||||
expression Expression
|
||||
operator string
|
||||
}
|
||||
|
||||
func newPrefixExpression(expression expression, operator string) prefixOpExpression {
|
||||
func newPrefixExpression(expression Expression, operator string) prefixOpExpression {
|
||||
prefixExpression := prefixOpExpression{
|
||||
expression: expression,
|
||||
operator: operator,
|
||||
|
|
@ -185,13 +185,13 @@ func newPrefixExpression(expression expression, operator string) prefixOpExpress
|
|||
|
||||
func (p *prefixOpExpression) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
if p == nil {
|
||||
return errors.New("Prefix expression is nil.")
|
||||
return errors.New("Prefix Expression is nil.")
|
||||
}
|
||||
|
||||
out.writeString(p.operator + " ")
|
||||
|
||||
if p.expression == nil {
|
||||
return errors.Newf("nil prefix expression.")
|
||||
return errors.Newf("nil prefix Expression.")
|
||||
}
|
||||
if err := p.expression.serialize(statement, out); err != nil {
|
||||
return err
|
||||
|
|
@ -200,13 +200,13 @@ func (p *prefixOpExpression) serialize(statement statementType, out *queryData,
|
|||
return nil
|
||||
}
|
||||
|
||||
// A postifx operator expression
|
||||
// A postifx operator Expression
|
||||
type postfixOpExpression struct {
|
||||
expression expression
|
||||
expression Expression
|
||||
operator string
|
||||
}
|
||||
|
||||
func newPostfixOpExpression(expression expression, operator string) postfixOpExpression {
|
||||
func newPostfixOpExpression(expression Expression, operator string) postfixOpExpression {
|
||||
postfixOpExpression := postfixOpExpression{
|
||||
expression: expression,
|
||||
operator: operator,
|
||||
|
|
@ -217,11 +217,11 @@ func newPostfixOpExpression(expression expression, operator string) postfixOpExp
|
|||
|
||||
func (p *postfixOpExpression) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
if p == nil {
|
||||
return errors.New("Postifx operator expression is nil.")
|
||||
return errors.New("Postifx operator Expression is nil.")
|
||||
}
|
||||
|
||||
if p.expression == nil {
|
||||
return errors.Newf("nil prefix expression.")
|
||||
return errors.Newf("nil prefix Expression.")
|
||||
}
|
||||
if err := p.expression.serialize(statement, out); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package sqlbuilder
|
|||
import "errors"
|
||||
|
||||
type expressionTable interface {
|
||||
readableTable
|
||||
ReadableTable
|
||||
|
||||
RefIntColumnName(name string) *IntegerColumn
|
||||
RefIntColumn(column column) *IntegerColumn
|
||||
|
|
@ -11,7 +11,7 @@ type expressionTable interface {
|
|||
}
|
||||
|
||||
type expressionTableImpl struct {
|
||||
statement expression
|
||||
statement Expression
|
||||
alias string
|
||||
}
|
||||
|
||||
|
|
@ -66,33 +66,33 @@ func (e *expressionTableImpl) serialize(statement statementType, out *queryData,
|
|||
}
|
||||
|
||||
// Generates a select query on the current tableName.
|
||||
func (e *expressionTableImpl) SELECT(projections ...projection) selectStatement {
|
||||
func (e *expressionTableImpl) SELECT(projections ...projection) SelectStatement {
|
||||
return newSelectStatement(e, projections)
|
||||
}
|
||||
|
||||
// Creates a inner join tableName expression using onCondition.
|
||||
func (e *expressionTableImpl) INNER_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||
// Creates a inner join tableName Expression using onCondition.
|
||||
func (e *expressionTableImpl) INNER_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable {
|
||||
return InnerJoinOn(e, table, onCondition)
|
||||
}
|
||||
|
||||
//func (s *expressionTableImpl) InnerJoinUsing(table readableTable, col1 column, col2 column) readableTable {
|
||||
//func (s *expressionTableImpl) InnerJoinUsing(table ReadableTable, col1 column, col2 column) ReadableTable {
|
||||
// return INNER_JOIN(s, table, col1.EQ(col2))
|
||||
//}
|
||||
|
||||
// Creates a left join tableName expression using onCondition.
|
||||
func (e *expressionTableImpl) LEFT_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||
// Creates a left join tableName Expression using onCondition.
|
||||
func (e *expressionTableImpl) LEFT_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable {
|
||||
return LeftJoinOn(e, table, onCondition)
|
||||
}
|
||||
|
||||
// Creates a right join tableName expression using onCondition.
|
||||
func (e *expressionTableImpl) RIGHT_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||
// Creates a right join tableName Expression using onCondition.
|
||||
func (e *expressionTableImpl) RIGHT_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable {
|
||||
return RightJoinOn(e, table, onCondition)
|
||||
}
|
||||
|
||||
func (e *expressionTableImpl) FULL_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||
func (e *expressionTableImpl) FULL_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable {
|
||||
return FullJoin(e, table, onCondition)
|
||||
}
|
||||
|
||||
func (e *expressionTableImpl) CROSS_JOIN(table readableTable) readableTable {
|
||||
func (e *expressionTableImpl) CROSS_JOIN(table ReadableTable) ReadableTable {
|
||||
return CrossJoin(e, table)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package sqlbuilder
|
|||
import "errors"
|
||||
|
||||
type FloatExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs FloatExpression) BoolExpression
|
||||
NOT_EQ(rhs FloatExpression) BoolExpression
|
||||
|
|
@ -107,10 +107,10 @@ type floatExpressionWrapper struct {
|
|||
expressionInterfaceImpl
|
||||
floatInterfaceImpl
|
||||
|
||||
expression expression
|
||||
expression Expression
|
||||
}
|
||||
|
||||
func newFloatExpressionWrap(expression expression) FloatExpression {
|
||||
func newFloatExpressionWrap(expression Expression) FloatExpression {
|
||||
floatExpressionWrap := floatExpressionWrapper{}
|
||||
|
||||
floatExpressionWrap.expression = expression
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ type funcExpressionImpl struct {
|
|||
expressionInterfaceImpl
|
||||
|
||||
name string
|
||||
expressions []expression
|
||||
expressions []Expression
|
||||
noBrackets bool
|
||||
}
|
||||
|
||||
func newFunc(name string, expressions []expression, parent expression) *funcExpressionImpl {
|
||||
func newFunc(name string, expressions []Expression, parent Expression) *funcExpressionImpl {
|
||||
funcExp := &funcExpressionImpl{
|
||||
name: name,
|
||||
expressions: expressions,
|
||||
|
|
@ -55,7 +55,7 @@ type boolFunc struct {
|
|||
boolInterfaceImpl
|
||||
}
|
||||
|
||||
func newBoolFunc(name string, expressions ...expression) BoolExpression {
|
||||
func newBoolFunc(name string, expressions ...Expression) BoolExpression {
|
||||
boolFunc := &boolFunc{}
|
||||
|
||||
boolFunc.funcExpressionImpl = *newFunc(name, expressions, boolFunc)
|
||||
|
|
@ -69,7 +69,7 @@ type floatFunc struct {
|
|||
floatInterfaceImpl
|
||||
}
|
||||
|
||||
func newFloatFunc(name string, expressions ...expression) FloatExpression {
|
||||
func newFloatFunc(name string, expressions ...Expression) FloatExpression {
|
||||
floatFunc := &floatFunc{}
|
||||
|
||||
floatFunc.funcExpressionImpl = *newFunc(name, expressions, floatFunc)
|
||||
|
|
@ -83,7 +83,7 @@ type integerFunc struct {
|
|||
integerInterfaceImpl
|
||||
}
|
||||
|
||||
func newIntegerFunc(name string, expressions ...expression) IntegerExpression {
|
||||
func newIntegerFunc(name string, expressions ...Expression) IntegerExpression {
|
||||
floatFunc := &integerFunc{}
|
||||
|
||||
floatFunc.funcExpressionImpl = *newFunc(name, expressions, floatFunc)
|
||||
|
|
@ -97,7 +97,7 @@ type stringFunc struct {
|
|||
stringInterfaceImpl
|
||||
}
|
||||
|
||||
func newStringFunc(name string, expressions ...expression) StringExpression {
|
||||
func newStringFunc(name string, expressions ...Expression) StringExpression {
|
||||
stringFunc := &stringFunc{}
|
||||
|
||||
stringFunc.funcExpressionImpl = *newFunc(name, expressions, stringFunc)
|
||||
|
|
@ -111,7 +111,7 @@ type dateFunc struct {
|
|||
dateInterfaceImpl
|
||||
}
|
||||
|
||||
func newDateFunc(name string, expressions ...expression) *dateFunc {
|
||||
func newDateFunc(name string, expressions ...Expression) *dateFunc {
|
||||
dateFunc := &dateFunc{}
|
||||
|
||||
dateFunc.funcExpressionImpl = *newFunc(name, expressions, dateFunc)
|
||||
|
|
@ -125,7 +125,7 @@ type timeFunc struct {
|
|||
timeInterfaceImpl
|
||||
}
|
||||
|
||||
func newTimeFunc(name string, expressions ...expression) *timeFunc {
|
||||
func newTimeFunc(name string, expressions ...Expression) *timeFunc {
|
||||
timeFun := &timeFunc{}
|
||||
|
||||
timeFun.funcExpressionImpl = *newFunc(name, expressions, timeFun)
|
||||
|
|
@ -139,7 +139,7 @@ type timezFunc struct {
|
|||
timezInterfaceImpl
|
||||
}
|
||||
|
||||
func newTimezFunc(name string, expressions ...expression) *timezFunc {
|
||||
func newTimezFunc(name string, expressions ...Expression) *timezFunc {
|
||||
timezFun := &timezFunc{}
|
||||
|
||||
timezFun.funcExpressionImpl = *newFunc(name, expressions, timezFun)
|
||||
|
|
@ -153,7 +153,7 @@ type timestampFunc struct {
|
|||
timestampInterfaceImpl
|
||||
}
|
||||
|
||||
func newTimestampFunc(name string, expressions ...expression) *timestampFunc {
|
||||
func newTimestampFunc(name string, expressions ...Expression) *timestampFunc {
|
||||
timestampFunc := ×tampFunc{}
|
||||
|
||||
timestampFunc.funcExpressionImpl = *newFunc(name, expressions, timestampFunc)
|
||||
|
|
@ -167,7 +167,7 @@ type timestampzFunc struct {
|
|||
timestampzInterfaceImpl
|
||||
}
|
||||
|
||||
func newTimestampzFunc(name string, expressions ...expression) *timestampzFunc {
|
||||
func newTimestampzFunc(name string, expressions ...Expression) *timestampzFunc {
|
||||
timestampzFunc := ×tampzFunc{}
|
||||
|
||||
timestampzFunc.funcExpressionImpl = *newFunc(name, expressions, timestampzFunc)
|
||||
|
|
@ -176,7 +176,7 @@ func newTimestampzFunc(name string, expressions ...expression) *timestampzFunc {
|
|||
return timestampzFunc
|
||||
}
|
||||
|
||||
func ROW(expressions ...expression) expression {
|
||||
func ROW(expressions ...Expression) Expression {
|
||||
return newFunc("ROW", expressions, nil)
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ func BOOL_OR(boolExpression BoolExpression) BoolExpression {
|
|||
return newBoolFunc("BOOL_OR", boolExpression)
|
||||
}
|
||||
|
||||
func COUNT(expression expression) IntegerExpression {
|
||||
func COUNT(expression Expression) IntegerExpression {
|
||||
return newIntegerFunc("COUNT", expression)
|
||||
}
|
||||
|
||||
|
|
@ -343,11 +343,11 @@ func CHR(integerExpression IntegerExpression) StringExpression {
|
|||
}
|
||||
|
||||
//
|
||||
//func CONCAT(expressions ...expression) StringExpression {
|
||||
//func CONCAT(expressions ...Expression) StringExpression {
|
||||
// return newStringFunc("CONCAT", expressions...)
|
||||
//}
|
||||
//
|
||||
//func CONCAT_WS(expressions ...expression) StringExpression {
|
||||
//func CONCAT_WS(expressions ...Expression) StringExpression {
|
||||
// return newStringFunc("CONCAT_WS", expressions...)
|
||||
//}
|
||||
|
||||
|
|
@ -452,7 +452,7 @@ func TO_HEX(number IntegerExpression) StringExpression {
|
|||
|
||||
//----------Data Type Formatting Functions ----------------------//
|
||||
|
||||
func TO_CHAR(expression expression, text StringExpression) StringExpression {
|
||||
func TO_CHAR(expression Expression, text StringExpression) StringExpression {
|
||||
return newStringFunc("TO_CHAR", expression, text)
|
||||
}
|
||||
|
||||
|
|
@ -538,24 +538,24 @@ func NOW() TimestampzExpression {
|
|||
|
||||
// --------------- Conditional Expressions Functions -------------//
|
||||
|
||||
func COALESCE(value expression, values ...expression) expression {
|
||||
var allValues = []expression{value}
|
||||
func COALESCE(value Expression, values ...Expression) Expression {
|
||||
var allValues = []Expression{value}
|
||||
allValues = append(allValues, values...)
|
||||
return newFunc("COALESCE", allValues, nil)
|
||||
}
|
||||
|
||||
func NULLIF(value1, value2 expression) expression {
|
||||
return newFunc("NULLIF", []expression{value1, value2}, nil)
|
||||
func NULLIF(value1, value2 Expression) Expression {
|
||||
return newFunc("NULLIF", []Expression{value1, value2}, nil)
|
||||
}
|
||||
|
||||
func GREATEST(value expression, values ...expression) expression {
|
||||
var allValues = []expression{value}
|
||||
func GREATEST(value Expression, values ...Expression) Expression {
|
||||
var allValues = []Expression{value}
|
||||
allValues = append(allValues, values...)
|
||||
return newFunc("GREATEST", allValues, nil)
|
||||
}
|
||||
|
||||
func LEAST(value expression, values ...expression) expression {
|
||||
var allValues = []expression{value}
|
||||
func LEAST(value Expression, values ...Expression) Expression {
|
||||
var allValues = []Expression{value}
|
||||
allValues = append(allValues, values...)
|
||||
return newFunc("LEAST", allValues, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,20 +9,20 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type insertStatement interface {
|
||||
type InsertStatement interface {
|
||||
Statement
|
||||
|
||||
// Add a row of values to the insert Statement.
|
||||
VALUES(values ...interface{}) insertStatement
|
||||
VALUES(values ...interface{}) InsertStatement
|
||||
// Map or stracture mapped to column names
|
||||
VALUES_MAPPING(data interface{}) insertStatement
|
||||
VALUES_MAPPING(data interface{}) InsertStatement
|
||||
|
||||
RETURNING(projections ...projection) insertStatement
|
||||
RETURNING(projections ...projection) InsertStatement
|
||||
|
||||
QUERY(selectStatement selectStatement) insertStatement
|
||||
QUERY(selectStatement SelectStatement) InsertStatement
|
||||
}
|
||||
|
||||
func newInsertStatement(t writableTable, columns ...column) insertStatement {
|
||||
func newInsertStatement(t writableTable, columns ...column) InsertStatement {
|
||||
return &insertStatementImpl{
|
||||
table: t,
|
||||
columns: columns,
|
||||
|
|
@ -33,7 +33,7 @@ type insertStatementImpl struct {
|
|||
table writableTable
|
||||
columns []column
|
||||
rows [][]clause
|
||||
query selectStatement
|
||||
query SelectStatement
|
||||
returning []projection
|
||||
|
||||
errors []string
|
||||
|
|
@ -47,8 +47,8 @@ func (u *insertStatementImpl) Execute(db execution.Db) (res sql.Result, err erro
|
|||
return Execute(u, db)
|
||||
}
|
||||
|
||||
// expression or default keyword
|
||||
func (i *insertStatementImpl) VALUES(values ...interface{}) insertStatement {
|
||||
// Expression or default keyword
|
||||
func (i *insertStatementImpl) VALUES(values ...interface{}) InsertStatement {
|
||||
if len(values) == 0 {
|
||||
return i
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ func (i *insertStatementImpl) VALUES(values ...interface{}) insertStatement {
|
|||
return i
|
||||
}
|
||||
|
||||
func (i *insertStatementImpl) VALUES_MAPPING(data interface{}) insertStatement {
|
||||
func (i *insertStatementImpl) VALUES_MAPPING(data interface{}) InsertStatement {
|
||||
if data == nil {
|
||||
i.addError("ADD method data is nil.")
|
||||
return i
|
||||
|
|
@ -105,13 +105,13 @@ func (i *insertStatementImpl) VALUES_MAPPING(data interface{}) insertStatement {
|
|||
return i
|
||||
}
|
||||
|
||||
func (i *insertStatementImpl) RETURNING(projections ...projection) insertStatement {
|
||||
func (i *insertStatementImpl) RETURNING(projections ...projection) InsertStatement {
|
||||
i.returning = defaultProjectionAliasing(projections)
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *insertStatementImpl) QUERY(selectStatement selectStatement) insertStatement {
|
||||
func (i *insertStatementImpl) QUERY(selectStatement SelectStatement) InsertStatement {
|
||||
i.query = selectStatement
|
||||
|
||||
return i
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type IntegerExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs IntegerExpression) BoolExpression
|
||||
NOT_EQ(rhs IntegerExpression) BoolExpression
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ type nullLiteral struct {
|
|||
expressionInterfaceImpl
|
||||
}
|
||||
|
||||
func newNullLiteral() expression {
|
||||
func newNullLiteral() Expression {
|
||||
nullExpression := &nullLiteral{}
|
||||
|
||||
nullExpression.expressionInterfaceImpl.parent = nullExpression
|
||||
|
|
@ -199,7 +199,7 @@ type starLiteral struct {
|
|||
expressionInterfaceImpl
|
||||
}
|
||||
|
||||
func newStarLiteral() expression {
|
||||
func newStarLiteral() Expression {
|
||||
starExpression := &starLiteral{}
|
||||
|
||||
starExpression.expressionInterfaceImpl.parent = starExpression
|
||||
|
|
@ -216,7 +216,7 @@ func (n *starLiteral) serialize(statement statementType, out *queryData, options
|
|||
|
||||
type wrap struct {
|
||||
expressionInterfaceImpl
|
||||
expressions []expression
|
||||
expressions []Expression
|
||||
}
|
||||
|
||||
func (n *wrap) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
|
|
@ -226,9 +226,28 @@ func (n *wrap) serialize(statement statementType, out *queryData, options ...ser
|
|||
return err
|
||||
}
|
||||
|
||||
func WRAP(expression ...expression) expression {
|
||||
func WRAP(expression ...Expression) Expression {
|
||||
wrap := &wrap{expressions: expression}
|
||||
wrap.expressionInterfaceImpl.parent = wrap
|
||||
|
||||
return wrap
|
||||
}
|
||||
|
||||
//---------------------------------------------------//
|
||||
|
||||
type rawExpression struct {
|
||||
expressionInterfaceImpl
|
||||
raw string
|
||||
}
|
||||
|
||||
func (n *rawExpression) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
out.writeString(n.raw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func RAW(raw string) Expression {
|
||||
rawExp := &rawExpression{raw: raw}
|
||||
rawExp.expressionInterfaceImpl.parent = rawExp
|
||||
|
||||
return rawExp
|
||||
}
|
||||
|
|
|
|||
7
sqlbuilder/literal_expression_test.go
Normal file
7
sqlbuilder/literal_expression_test.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRawExpression(t *testing.T) {
|
||||
assertExpressionSerialize(t, RAW("current_database()"), "current_database()")
|
||||
}
|
||||
|
|
@ -19,11 +19,11 @@ const (
|
|||
LOCK_ACCESS_EXCLUSIVE = "ACCESS EXCLUSIVE"
|
||||
)
|
||||
|
||||
type lockStatement interface {
|
||||
type LockStatement interface {
|
||||
Statement
|
||||
|
||||
IN(lockMode lockMode) lockStatement
|
||||
NOWAIT() lockStatement
|
||||
IN(lockMode lockMode) LockStatement
|
||||
NOWAIT() LockStatement
|
||||
}
|
||||
|
||||
type lockStatementImpl struct {
|
||||
|
|
@ -32,18 +32,18 @@ type lockStatementImpl struct {
|
|||
nowait bool
|
||||
}
|
||||
|
||||
func LOCK(tables ...tableInterface) lockStatement {
|
||||
func LOCK(tables ...tableInterface) LockStatement {
|
||||
return &lockStatementImpl{
|
||||
tables: tables,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *lockStatementImpl) IN(lockMode lockMode) lockStatement {
|
||||
func (l *lockStatementImpl) IN(lockMode lockMode) LockStatement {
|
||||
l.lockMode = lockMode
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *lockStatementImpl) NOWAIT() lockStatement {
|
||||
func (l *lockStatementImpl) NOWAIT() LockStatement {
|
||||
l.nowait = true
|
||||
return l
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,40 +12,40 @@ func NOT(expr BoolExpression) BoolExpression {
|
|||
//----------- Comparison operators ---------------//
|
||||
|
||||
// Returns a representation of "a=b"
|
||||
func EQ(lhs, rhs expression) BoolExpression {
|
||||
func EQ(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "=")
|
||||
}
|
||||
|
||||
// Returns a representation of "a!=b"
|
||||
func NOT_EQ(lhs, rhs expression) BoolExpression {
|
||||
func NOT_EQ(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "!=")
|
||||
}
|
||||
|
||||
func IS_DISTINCT_FROM(lhs, rhs expression) BoolExpression {
|
||||
func IS_DISTINCT_FROM(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "IS DISTINCT FROM")
|
||||
}
|
||||
|
||||
func IS_NOT_DISTINCT_FROM(lhs, rhs expression) BoolExpression {
|
||||
func IS_NOT_DISTINCT_FROM(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "IS NOT DISTINCT FROM")
|
||||
}
|
||||
|
||||
// Returns a representation of "a<b"
|
||||
func LT(lhs expression, rhs expression) BoolExpression {
|
||||
func LT(lhs Expression, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "<")
|
||||
}
|
||||
|
||||
// Returns a representation of "a<=b"
|
||||
func LT_EQ(lhs, rhs expression) BoolExpression {
|
||||
func LT_EQ(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "<=")
|
||||
}
|
||||
|
||||
// Returns a representation of "a>b"
|
||||
func GT(lhs, rhs expression) BoolExpression {
|
||||
func GT(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, ">")
|
||||
}
|
||||
|
||||
// Returns a representation of "a>=b"
|
||||
func GT_EQ(lhs, rhs expression) BoolExpression {
|
||||
func GT_EQ(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, ">=")
|
||||
}
|
||||
|
||||
|
|
@ -73,47 +73,47 @@ func IS_NOT_UNKNOWN(expr BoolExpression) BoolExpression {
|
|||
return newPostifxBoolExpression(expr, "IS NOT UNKNOWN")
|
||||
}
|
||||
|
||||
func And(lhs, rhs expression) BoolExpression {
|
||||
func And(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "AND")
|
||||
}
|
||||
|
||||
// Returns a representation of "c[0] OR ... OR c[n-1]" for c in clauses
|
||||
func Or(lhs, rhs expression) BoolExpression {
|
||||
func Or(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "OR")
|
||||
}
|
||||
|
||||
func Regexp(lhs, rhs expression) BoolExpression {
|
||||
func Regexp(lhs, rhs Expression) BoolExpression {
|
||||
return newBinaryBoolExpression(lhs, rhs, "REGEXP")
|
||||
}
|
||||
|
||||
func RegexpL(lhs expression, val string) BoolExpression {
|
||||
func RegexpL(lhs Expression, val string) BoolExpression {
|
||||
return Regexp(lhs, literal(val))
|
||||
}
|
||||
|
||||
func EXISTS(subQuery selectStatement) BoolExpression {
|
||||
func EXISTS(subQuery SelectStatement) BoolExpression {
|
||||
return newPrefixBoolExpression(subQuery, "EXISTS")
|
||||
}
|
||||
|
||||
// --------------- CASE operator -------------------//
|
||||
|
||||
type caseOperatorExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
WHEN(condition expression) caseOperatorExpression
|
||||
THEN(then expression) caseOperatorExpression
|
||||
ELSE(els expression) caseOperatorExpression
|
||||
WHEN(condition Expression) caseOperatorExpression
|
||||
THEN(then Expression) caseOperatorExpression
|
||||
ELSE(els Expression) caseOperatorExpression
|
||||
}
|
||||
|
||||
type caseOperatorImpl struct {
|
||||
expressionInterfaceImpl
|
||||
|
||||
expression expression
|
||||
when []expression
|
||||
then []expression
|
||||
els expression
|
||||
expression Expression
|
||||
when []Expression
|
||||
then []Expression
|
||||
els Expression
|
||||
}
|
||||
|
||||
func CASE(expression ...expression) caseOperatorExpression {
|
||||
func CASE(expression ...Expression) caseOperatorExpression {
|
||||
caseExp := &caseOperatorImpl{}
|
||||
|
||||
if len(expression) > 0 {
|
||||
|
|
@ -125,17 +125,17 @@ func CASE(expression ...expression) caseOperatorExpression {
|
|||
return caseExp
|
||||
}
|
||||
|
||||
func (c *caseOperatorImpl) WHEN(when expression) caseOperatorExpression {
|
||||
func (c *caseOperatorImpl) WHEN(when Expression) caseOperatorExpression {
|
||||
c.when = append(c.when, when)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *caseOperatorImpl) THEN(then expression) caseOperatorExpression {
|
||||
func (c *caseOperatorImpl) THEN(then Expression) caseOperatorExpression {
|
||||
c.then = append(c.then, then)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *caseOperatorImpl) ELSE(els expression) caseOperatorExpression {
|
||||
func (c *caseOperatorImpl) ELSE(els Expression) caseOperatorExpression {
|
||||
c.els = els
|
||||
|
||||
return c
|
||||
|
|
@ -143,7 +143,7 @@ func (c *caseOperatorImpl) ELSE(els expression) caseOperatorExpression {
|
|||
|
||||
func (c *caseOperatorImpl) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
if c == nil {
|
||||
return errors.New("Case expression is nil. ")
|
||||
return errors.New("Case Expression is nil. ")
|
||||
}
|
||||
|
||||
out.writeString("(CASE")
|
||||
|
|
@ -157,11 +157,11 @@ func (c *caseOperatorImpl) serialize(statement statementType, out *queryData, op
|
|||
}
|
||||
|
||||
if len(c.when) == 0 || len(c.then) == 0 {
|
||||
return errors.New("Invalid case Statement. There should be at least one when/then expression pair. ")
|
||||
return errors.New("Invalid case Statement. There should be at least one when/then Expression pair. ")
|
||||
}
|
||||
|
||||
if len(c.when) != len(c.then) {
|
||||
return errors.New("When and then expression count mismatch. ")
|
||||
return errors.New("When and then Expression count mismatch. ")
|
||||
}
|
||||
|
||||
for i, when := range c.when {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package sqlbuilder
|
|||
|
||||
import "github.com/dropbox/godropbox/errors"
|
||||
|
||||
type orderByClause interface {
|
||||
type OrderByClause interface {
|
||||
serializeAsOrderBy(statement statementType, out *queryData) error
|
||||
}
|
||||
|
||||
type orderByClauseImpl struct {
|
||||
expression expression
|
||||
expression Expression
|
||||
ascent bool
|
||||
}
|
||||
|
||||
|
|
@ -29,10 +29,10 @@ func (o *orderByClauseImpl) serializeAsOrderBy(statement statementType, out *que
|
|||
return nil
|
||||
}
|
||||
|
||||
func ASC(expression expression) orderByClause {
|
||||
func ASC(expression Expression) OrderByClause {
|
||||
return &orderByClauseImpl{expression: expression, ascent: true}
|
||||
}
|
||||
|
||||
func DESC(expression expression) orderByClause {
|
||||
func DESC(expression Expression) OrderByClause {
|
||||
return &orderByClauseImpl{expression: expression, ascent: false}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,43 +6,43 @@ import (
|
|||
"github.com/sub0zero/go-sqlbuilder/sqlbuilder/execution"
|
||||
)
|
||||
|
||||
type selectStatement interface {
|
||||
type SelectStatement interface {
|
||||
Statement
|
||||
expression
|
||||
Expression
|
||||
hasRows()
|
||||
|
||||
DISTINCT() selectStatement
|
||||
FROM(table readableTable) selectStatement
|
||||
WHERE(expression BoolExpression) selectStatement
|
||||
GROUP_BY(groupByClauses ...groupByClause) selectStatement
|
||||
HAVING(boolExpression BoolExpression) selectStatement
|
||||
ORDER_BY(orderByClauses ...orderByClause) selectStatement
|
||||
DISTINCT() SelectStatement
|
||||
FROM(table ReadableTable) SelectStatement
|
||||
WHERE(expression BoolExpression) SelectStatement
|
||||
GROUP_BY(groupByClauses ...groupByClause) SelectStatement
|
||||
HAVING(boolExpression BoolExpression) SelectStatement
|
||||
ORDER_BY(orderByClauses ...OrderByClause) SelectStatement
|
||||
|
||||
LIMIT(limit int64) selectStatement
|
||||
OFFSET(offset int64) selectStatement
|
||||
LIMIT(limit int64) SelectStatement
|
||||
OFFSET(offset int64) SelectStatement
|
||||
|
||||
FOR_UPDATE() selectStatement
|
||||
FOR_UPDATE() SelectStatement
|
||||
|
||||
AsTable(alias string) expressionTable
|
||||
}
|
||||
|
||||
func SELECT(projection ...projection) selectStatement {
|
||||
func SELECT(projection ...projection) SelectStatement {
|
||||
return newSelectStatement(nil, projection)
|
||||
}
|
||||
|
||||
// NOTE: selectStatement purposely does not implement the Table interface since
|
||||
// NOTE: SelectStatement purposely does not implement the Table interface since
|
||||
// mysql's subquery performance is horrible.
|
||||
type selectStatementImpl struct {
|
||||
expressionInterfaceImpl
|
||||
isRowsType
|
||||
|
||||
table readableTable
|
||||
table ReadableTable
|
||||
distinct bool
|
||||
projections []projection
|
||||
where BoolExpression
|
||||
groupBy []groupByClause
|
||||
having BoolExpression
|
||||
orderBy []orderByClause
|
||||
orderBy []OrderByClause
|
||||
|
||||
limit, offset int64
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ func defaultProjectionAliasing(projections []projection) []projection {
|
|||
return aliasedProjections
|
||||
}
|
||||
|
||||
func newSelectStatement(table readableTable, projections []projection) selectStatement {
|
||||
func newSelectStatement(table ReadableTable, projections []projection) SelectStatement {
|
||||
newSelect := &selectStatementImpl{
|
||||
table: table,
|
||||
projections: defaultProjectionAliasing(projections),
|
||||
|
|
@ -80,7 +80,7 @@ func newSelectStatement(table readableTable, projections []projection) selectSta
|
|||
return newSelect
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) FROM(table readableTable) selectStatement {
|
||||
func (s *selectStatementImpl) FROM(table ReadableTable) SelectStatement {
|
||||
s.table = table
|
||||
return s
|
||||
}
|
||||
|
|
@ -211,44 +211,44 @@ func (s *selectStatementImpl) AsTable(alias string) expressionTable {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) WHERE(expression BoolExpression) selectStatement {
|
||||
func (s *selectStatementImpl) WHERE(expression BoolExpression) SelectStatement {
|
||||
s.where = expression
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) GROUP_BY(groupByClauses ...groupByClause) selectStatement {
|
||||
func (s *selectStatementImpl) GROUP_BY(groupByClauses ...groupByClause) SelectStatement {
|
||||
s.groupBy = groupByClauses
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) HAVING(expression BoolExpression) selectStatement {
|
||||
func (s *selectStatementImpl) HAVING(expression BoolExpression) SelectStatement {
|
||||
s.having = expression
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) ORDER_BY(clauses ...orderByClause) selectStatement {
|
||||
func (s *selectStatementImpl) ORDER_BY(clauses ...OrderByClause) SelectStatement {
|
||||
|
||||
s.orderBy = clauses
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) OFFSET(offset int64) selectStatement {
|
||||
func (s *selectStatementImpl) OFFSET(offset int64) SelectStatement {
|
||||
s.offset = offset
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) LIMIT(limit int64) selectStatement {
|
||||
func (s *selectStatementImpl) LIMIT(limit int64) SelectStatement {
|
||||
s.limit = limit
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) DISTINCT() selectStatement {
|
||||
func (s *selectStatementImpl) DISTINCT() SelectStatement {
|
||||
s.distinct = true
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) FOR_UPDATE() selectStatement {
|
||||
func (s *selectStatementImpl) FOR_UPDATE() SelectStatement {
|
||||
s.forUpdate = true
|
||||
return s
|
||||
}
|
||||
|
|
@ -261,6 +261,6 @@ func (s *selectStatementImpl) Execute(db execution.Db) (res sql.Result, err erro
|
|||
return Execute(s, db)
|
||||
}
|
||||
|
||||
func NumExp(expression expression) FloatExpression {
|
||||
func NumExp(expression Expression) FloatExpression {
|
||||
return newFloatExpressionWrap(expression)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ import (
|
|||
"github.com/sub0zero/go-sqlbuilder/sqlbuilder/execution"
|
||||
)
|
||||
|
||||
type setStatement interface {
|
||||
type SetStatement interface {
|
||||
Statement
|
||||
expression
|
||||
Expression
|
||||
hasRows()
|
||||
|
||||
ORDER_BY(clauses ...orderByClause) setStatement
|
||||
LIMIT(limit int64) setStatement
|
||||
OFFSET(offset int64) setStatement
|
||||
ORDER_BY(clauses ...OrderByClause) SetStatement
|
||||
LIMIT(limit int64) SetStatement
|
||||
OFFSET(offset int64) SetStatement
|
||||
|
||||
AsTable(alias string) expressionTable
|
||||
}
|
||||
|
|
@ -24,27 +24,27 @@ const (
|
|||
except = "EXCEPT"
|
||||
)
|
||||
|
||||
func UNION(selects ...rowsType) setStatement {
|
||||
func UNION(selects ...rowsType) SetStatement {
|
||||
return newSetStatementImpl(union, false, selects...)
|
||||
}
|
||||
|
||||
func UNION_ALL(selects ...rowsType) setStatement {
|
||||
func UNION_ALL(selects ...rowsType) SetStatement {
|
||||
return newSetStatementImpl(union, true, selects...)
|
||||
}
|
||||
|
||||
func INTERSECT(selects ...rowsType) setStatement {
|
||||
func INTERSECT(selects ...rowsType) SetStatement {
|
||||
return newSetStatementImpl(intersect, false, selects...)
|
||||
}
|
||||
|
||||
func INTERSECT_ALL(selects ...rowsType) setStatement {
|
||||
func INTERSECT_ALL(selects ...rowsType) SetStatement {
|
||||
return newSetStatementImpl(intersect, true, selects...)
|
||||
}
|
||||
|
||||
func EXCEPT(selects ...rowsType) setStatement {
|
||||
func EXCEPT(selects ...rowsType) SetStatement {
|
||||
return newSetStatementImpl(except, false, selects...)
|
||||
}
|
||||
|
||||
func EXCEPT_ALL(selects ...rowsType) setStatement {
|
||||
func EXCEPT_ALL(selects ...rowsType) SetStatement {
|
||||
return newSetStatementImpl(except, true, selects...)
|
||||
}
|
||||
|
||||
|
|
@ -55,13 +55,13 @@ type setStatementImpl struct {
|
|||
|
||||
operator string
|
||||
selects []rowsType
|
||||
orderBy []orderByClause
|
||||
orderBy []OrderByClause
|
||||
limit, offset int64
|
||||
// True if results of the union should be deduped.
|
||||
all bool
|
||||
}
|
||||
|
||||
func newSetStatementImpl(operator string, all bool, selects ...rowsType) setStatement {
|
||||
func newSetStatementImpl(operator string, all bool, selects ...rowsType) SetStatement {
|
||||
setStatement := &setStatementImpl{
|
||||
operator: operator,
|
||||
selects: selects,
|
||||
|
|
@ -75,18 +75,18 @@ func newSetStatementImpl(operator string, all bool, selects ...rowsType) setStat
|
|||
return setStatement
|
||||
}
|
||||
|
||||
func (us *setStatementImpl) ORDER_BY(orderBy ...orderByClause) setStatement {
|
||||
func (us *setStatementImpl) ORDER_BY(orderBy ...OrderByClause) SetStatement {
|
||||
|
||||
us.orderBy = orderBy
|
||||
return us
|
||||
}
|
||||
|
||||
func (us *setStatementImpl) LIMIT(limit int64) setStatement {
|
||||
func (us *setStatementImpl) LIMIT(limit int64) SetStatement {
|
||||
us.limit = limit
|
||||
return us
|
||||
}
|
||||
|
||||
func (us *setStatementImpl) OFFSET(offset int64) setStatement {
|
||||
func (us *setStatementImpl) OFFSET(offset int64) SetStatement {
|
||||
us.offset = offset
|
||||
return us
|
||||
}
|
||||
|
|
|
|||
|
|
@ -406,7 +406,7 @@ func (s *StmtSuite) TestUnlockStatement(c *gc.C) {
|
|||
}
|
||||
|
||||
func (s *StmtSuite) TestUnionSelectStatement(c *gc.C) {
|
||||
select_queries := make([]selectStatement, 0, 3)
|
||||
select_queries := make([]SelectStatement, 0, 3)
|
||||
|
||||
select_queries = append(select_queries,
|
||||
table1.Select(table1Col1).Where(GtL(table1Col1, 123)),
|
||||
|
|
@ -428,7 +428,7 @@ func (s *StmtSuite) TestUnionSelectStatement(c *gc.C) {
|
|||
}
|
||||
|
||||
func (s *StmtSuite) TestUnionLimitWithoutOrderBy(c *gc.C) {
|
||||
select_queries := make([]selectStatement, 0, 3)
|
||||
select_queries := make([]SelectStatement, 0, 3)
|
||||
|
||||
select_queries = append(select_queries,
|
||||
table1.Select(table1Col1).Where(GtL(table1Col1, 123)).OrderBy(table1ColFloat),
|
||||
|
|
@ -448,7 +448,7 @@ func (s *StmtSuite) TestUnionLimitWithoutOrderBy(c *gc.C) {
|
|||
}
|
||||
|
||||
func (s *StmtSuite) TestUnionSelectWithMismatchedColumns(c *gc.C) {
|
||||
select_queries := make([]selectStatement, 0, 3)
|
||||
select_queries := make([]SelectStatement, 0, 3)
|
||||
|
||||
select_queries = append(select_queries,
|
||||
|
||||
|
|
@ -483,7 +483,7 @@ func (s *StmtSuite) TestComplicatedUnionSelectWithWhereStatement(c *gc.C) {
|
|||
|
||||
// tests on outer Statement: Group By, Order By, LIMIT
|
||||
// on inner Statement: AndWhere, WHERE (with AND), Order By, LIMIT
|
||||
select_queries := make([]selectStatement, 0, 3)
|
||||
select_queries := make([]SelectStatement, 0, 3)
|
||||
|
||||
// We're not trying to write a SQL parser, so we won't warn if you do something silly like
|
||||
// try to apply a where clause on more columns than you've selected in your union select
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type StringExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs StringExpression) BoolExpression
|
||||
NOT_EQ(rhs StringExpression) BoolExpression
|
||||
|
|
@ -13,7 +13,7 @@ type StringExpression interface {
|
|||
GT(rhs StringExpression) BoolExpression
|
||||
GT_EQ(rhs StringExpression) BoolExpression
|
||||
|
||||
CONCAT(rhs expression) StringExpression
|
||||
CONCAT(rhs Expression) StringExpression
|
||||
|
||||
LIKE(pattern StringExpression) BoolExpression
|
||||
NOT_LIKE(pattern StringExpression) BoolExpression
|
||||
|
|
@ -57,7 +57,7 @@ func (s *stringInterfaceImpl) LT_EQ(rhs StringExpression) BoolExpression {
|
|||
return LT_EQ(s.parent, rhs)
|
||||
}
|
||||
|
||||
func (s *stringInterfaceImpl) CONCAT(rhs expression) StringExpression {
|
||||
func (s *stringInterfaceImpl) CONCAT(rhs Expression) StringExpression {
|
||||
return newBinaryStringExpression(s.parent, rhs, "||")
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ type binaryStringExpression struct {
|
|||
binaryOpExpression
|
||||
}
|
||||
|
||||
func newBinaryStringExpression(lhs, rhs expression, operator string) StringExpression {
|
||||
func newBinaryStringExpression(lhs, rhs Expression, operator string) StringExpression {
|
||||
boolExpression := binaryStringExpression{}
|
||||
|
||||
boolExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
||||
|
|
|
|||
|
|
@ -16,35 +16,35 @@ type tableInterface interface {
|
|||
|
||||
// The sql tableName read interface. NOTE: NATURAL JOINs, and join "USING" clause
|
||||
// are not supported.
|
||||
type readableTable interface {
|
||||
type ReadableTable interface {
|
||||
tableInterface
|
||||
|
||||
// Generates a select query on the current tableName.
|
||||
SELECT(projections ...projection) selectStatement
|
||||
SELECT(projections ...projection) SelectStatement
|
||||
|
||||
// Creates a inner join tableName expression using onCondition.
|
||||
INNER_JOIN(table readableTable, onCondition BoolExpression) readableTable
|
||||
// Creates a inner join tableName Expression using onCondition.
|
||||
INNER_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable
|
||||
|
||||
// Creates a left join tableName expression using onCondition.
|
||||
LEFT_JOIN(table readableTable, onCondition BoolExpression) readableTable
|
||||
// Creates a left join tableName Expression using onCondition.
|
||||
LEFT_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable
|
||||
|
||||
// Creates a right join tableName expression using onCondition.
|
||||
RIGHT_JOIN(table readableTable, onCondition BoolExpression) readableTable
|
||||
// Creates a right join tableName Expression using onCondition.
|
||||
RIGHT_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable
|
||||
|
||||
FULL_JOIN(table readableTable, onCondition BoolExpression) readableTable
|
||||
FULL_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable
|
||||
|
||||
CROSS_JOIN(table readableTable) readableTable
|
||||
CROSS_JOIN(table ReadableTable) ReadableTable
|
||||
}
|
||||
|
||||
// The sql tableName write interface.
|
||||
type writableTable interface {
|
||||
tableInterface
|
||||
|
||||
INSERT(columns ...column) insertStatement
|
||||
UPDATE(columns ...column) updateStatement
|
||||
DELETE() deleteStatement
|
||||
INSERT(columns ...column) InsertStatement
|
||||
UPDATE(columns ...column) UpdateStatement
|
||||
DELETE() DeleteStatement
|
||||
|
||||
LOCK() lockStatement
|
||||
LOCK() LockStatement
|
||||
}
|
||||
|
||||
// Defines a physical tableName in the database that is both readable and writable.
|
||||
|
|
@ -105,7 +105,7 @@ func (t *Table) Columns() []column {
|
|||
return t.columns
|
||||
}
|
||||
|
||||
// Generates the sql string for the current tableName expression. Note: the
|
||||
// Generates the sql string for the current tableName Expression. Note: the
|
||||
// generated string may not be a valid/executable sql Statement.
|
||||
func (t *Table) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
if t == nil {
|
||||
|
|
@ -125,55 +125,55 @@ func (t *Table) serialize(statement statementType, out *queryData, options ...se
|
|||
}
|
||||
|
||||
// Generates a select query on the current tableName.
|
||||
func (t *Table) SELECT(projections ...projection) selectStatement {
|
||||
func (t *Table) SELECT(projections ...projection) SelectStatement {
|
||||
return newSelectStatement(t, projections)
|
||||
}
|
||||
|
||||
// Creates a inner join tableName expression using onCondition.
|
||||
// Creates a inner join tableName Expression using onCondition.
|
||||
func (t *Table) INNER_JOIN(
|
||||
table readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
table ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return InnerJoinOn(t, table, onCondition)
|
||||
}
|
||||
|
||||
// Creates a left join tableName expression using onCondition.
|
||||
// Creates a left join tableName Expression using onCondition.
|
||||
func (t *Table) LEFT_JOIN(
|
||||
table readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
table ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return LeftJoinOn(t, table, onCondition)
|
||||
}
|
||||
|
||||
// Creates a right join tableName expression using onCondition.
|
||||
// Creates a right join tableName Expression using onCondition.
|
||||
func (t *Table) RIGHT_JOIN(
|
||||
table readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
table ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return RightJoinOn(t, table, onCondition)
|
||||
}
|
||||
|
||||
func (t *Table) FULL_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||
func (t *Table) FULL_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable {
|
||||
return FullJoin(t, table, onCondition)
|
||||
}
|
||||
|
||||
func (t *Table) CROSS_JOIN(table readableTable) readableTable {
|
||||
func (t *Table) CROSS_JOIN(table ReadableTable) ReadableTable {
|
||||
return CrossJoin(t, table)
|
||||
}
|
||||
|
||||
func (t *Table) INSERT(columns ...column) insertStatement {
|
||||
func (t *Table) INSERT(columns ...column) InsertStatement {
|
||||
return newInsertStatement(t, columns...)
|
||||
}
|
||||
|
||||
func (t *Table) UPDATE(columns ...column) updateStatement {
|
||||
func (t *Table) UPDATE(columns ...column) UpdateStatement {
|
||||
return newUpdateStatement(t, columns)
|
||||
}
|
||||
|
||||
func (t *Table) DELETE() deleteStatement {
|
||||
func (t *Table) DELETE() DeleteStatement {
|
||||
return newDeleteStatement(t)
|
||||
}
|
||||
|
||||
func (t *Table) LOCK() lockStatement {
|
||||
func (t *Table) LOCK() LockStatement {
|
||||
return LOCK(t)
|
||||
}
|
||||
|
||||
|
|
@ -189,17 +189,17 @@ const (
|
|||
|
||||
// Join expressions are pseudo readable tables.
|
||||
type joinTable struct {
|
||||
lhs readableTable
|
||||
rhs readableTable
|
||||
lhs ReadableTable
|
||||
rhs ReadableTable
|
||||
join_type joinType
|
||||
onCondition BoolExpression
|
||||
}
|
||||
|
||||
func newJoinTable(
|
||||
lhs readableTable,
|
||||
rhs readableTable,
|
||||
lhs ReadableTable,
|
||||
rhs ReadableTable,
|
||||
join_type joinType,
|
||||
onCondition BoolExpression) readableTable {
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return &joinTable{
|
||||
lhs: lhs,
|
||||
|
|
@ -210,40 +210,40 @@ func newJoinTable(
|
|||
}
|
||||
|
||||
func InnerJoinOn(
|
||||
lhs readableTable,
|
||||
rhs readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
lhs ReadableTable,
|
||||
rhs ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return newJoinTable(lhs, rhs, INNER_JOIN, onCondition)
|
||||
}
|
||||
|
||||
func LeftJoinOn(
|
||||
lhs readableTable,
|
||||
rhs readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
lhs ReadableTable,
|
||||
rhs ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return newJoinTable(lhs, rhs, LEFT_JOIN, onCondition)
|
||||
}
|
||||
|
||||
func RightJoinOn(
|
||||
lhs readableTable,
|
||||
rhs readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
lhs ReadableTable,
|
||||
rhs ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return newJoinTable(lhs, rhs, RIGHT_JOIN, onCondition)
|
||||
}
|
||||
|
||||
func FullJoin(
|
||||
lhs readableTable,
|
||||
rhs readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
lhs ReadableTable,
|
||||
rhs ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return newJoinTable(lhs, rhs, FULL_JOIN, onCondition)
|
||||
}
|
||||
|
||||
func CrossJoin(
|
||||
lhs readableTable,
|
||||
rhs readableTable) readableTable {
|
||||
lhs ReadableTable,
|
||||
rhs ReadableTable) ReadableTable {
|
||||
|
||||
return newJoinTable(lhs, rhs, CROSS_JOIN, nil)
|
||||
}
|
||||
|
|
@ -318,35 +318,35 @@ func (t *joinTable) serialize(statement statementType, out *queryData, options .
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *joinTable) SELECT(projections ...projection) selectStatement {
|
||||
func (t *joinTable) SELECT(projections ...projection) SelectStatement {
|
||||
return newSelectStatement(t, projections)
|
||||
}
|
||||
|
||||
func (t *joinTable) INNER_JOIN(
|
||||
table readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
table ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return InnerJoinOn(t, table, onCondition)
|
||||
}
|
||||
|
||||
func (t *joinTable) LEFT_JOIN(
|
||||
table readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
table ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return LeftJoinOn(t, table, onCondition)
|
||||
}
|
||||
|
||||
func (t *joinTable) FULL_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||
func (t *joinTable) FULL_JOIN(table ReadableTable, onCondition BoolExpression) ReadableTable {
|
||||
return FullJoin(t, table, onCondition)
|
||||
}
|
||||
|
||||
func (t *joinTable) CROSS_JOIN(table readableTable) readableTable {
|
||||
func (t *joinTable) CROSS_JOIN(table ReadableTable) ReadableTable {
|
||||
return CrossJoin(t, table)
|
||||
}
|
||||
|
||||
func (t *joinTable) RIGHT_JOIN(
|
||||
table readableTable,
|
||||
onCondition BoolExpression) readableTable {
|
||||
table ReadableTable,
|
||||
onCondition BoolExpression) ReadableTable {
|
||||
|
||||
return RightJoinOn(t, table, onCondition)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ var table3 = NewTable(
|
|||
table3Col1,
|
||||
table3StrCol)
|
||||
|
||||
func assertExpressionSerialize(t *testing.T, expression expression, query string, args ...interface{}) {
|
||||
func assertExpressionSerialize(t *testing.T, expression Expression, query string, args ...interface{}) {
|
||||
out := queryData{}
|
||||
err := expression.serialize(select_statement, &out)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type TimeExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs TimeExpression) BoolExpression
|
||||
NOT_EQ(rhs TimeExpression) BoolExpression
|
||||
|
|
@ -58,7 +58,7 @@ type prefixTimeExpression struct {
|
|||
prefixOpExpression
|
||||
}
|
||||
|
||||
func newPrefixTimeExpression(operator string, expression expression) TimeExpression {
|
||||
func newPrefixTimeExpression(operator string, expression Expression) TimeExpression {
|
||||
timeExpr := prefixTimeExpression{}
|
||||
timeExpr.prefixOpExpression = newPrefixExpression(expression, operator)
|
||||
|
||||
|
|
@ -68,6 +68,6 @@ func newPrefixTimeExpression(operator string, expression expression) TimeExpress
|
|||
return &timeExpr
|
||||
}
|
||||
|
||||
func INTERVAL(interval string) expression {
|
||||
func INTERVAL(interval string) Expression {
|
||||
return newPrefixTimeExpression("INTERVAL", literal(interval))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type TimestampExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs TimestampExpression) BoolExpression
|
||||
NOT_EQ(rhs TimestampExpression) BoolExpression
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type TimestampzExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs TimestampzExpression) BoolExpression
|
||||
NOT_EQ(rhs TimestampzExpression) BoolExpression
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package sqlbuilder
|
||||
|
||||
type TimezExpression interface {
|
||||
expression
|
||||
Expression
|
||||
|
||||
EQ(rhs TimezExpression) BoolExpression
|
||||
NOT_EQ(rhs TimezExpression) BoolExpression
|
||||
|
|
@ -58,7 +58,7 @@ type prefixTimezExpression struct {
|
|||
prefixOpExpression
|
||||
}
|
||||
|
||||
func newPrefixTimezExpression(operator string, expression expression) TimezExpression {
|
||||
func newPrefixTimezExpression(operator string, expression Expression) TimezExpression {
|
||||
timeExpr := prefixTimezExpression{}
|
||||
timeExpr.prefixOpExpression = newPrefixExpression(expression, operator)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ import (
|
|||
"github.com/sub0zero/go-sqlbuilder/sqlbuilder/execution"
|
||||
)
|
||||
|
||||
type updateStatement interface {
|
||||
type UpdateStatement interface {
|
||||
Statement
|
||||
|
||||
SET(values ...interface{}) updateStatement
|
||||
WHERE(expression BoolExpression) updateStatement
|
||||
RETURNING(projections ...projection) updateStatement
|
||||
SET(values ...interface{}) UpdateStatement
|
||||
WHERE(expression BoolExpression) UpdateStatement
|
||||
RETURNING(projections ...projection) UpdateStatement
|
||||
}
|
||||
|
||||
func newUpdateStatement(table writableTable, columns []column) updateStatement {
|
||||
func newUpdateStatement(table writableTable, columns []column) UpdateStatement {
|
||||
return &updateStatementImpl{
|
||||
table: table,
|
||||
columns: columns,
|
||||
|
|
@ -29,7 +29,7 @@ type updateStatementImpl struct {
|
|||
returning []projection
|
||||
}
|
||||
|
||||
func (u *updateStatementImpl) SET(values ...interface{}) updateStatement {
|
||||
func (u *updateStatementImpl) SET(values ...interface{}) UpdateStatement {
|
||||
|
||||
for _, value := range values {
|
||||
if clause, ok := value.(clause); ok {
|
||||
|
|
@ -42,12 +42,12 @@ func (u *updateStatementImpl) SET(values ...interface{}) updateStatement {
|
|||
return u
|
||||
}
|
||||
|
||||
func (u *updateStatementImpl) WHERE(expression BoolExpression) updateStatement {
|
||||
func (u *updateStatementImpl) WHERE(expression BoolExpression) UpdateStatement {
|
||||
u.where = expression
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *updateStatementImpl) RETURNING(projections ...projection) updateStatement {
|
||||
func (u *updateStatementImpl) RETURNING(projections ...projection) UpdateStatement {
|
||||
u.returning = defaultProjectionAliasing(projections)
|
||||
return u
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/sub0zero/go-sqlbuilder/sqlbuilder/execution"
|
||||
)
|
||||
|
||||
func serializeOrderByClauseList(statement statementType, orderByClauses []orderByClause, out *queryData) error {
|
||||
func serializeOrderByClauseList(statement statementType, orderByClauses []OrderByClause, out *queryData) error {
|
||||
|
||||
for i, value := range orderByClauses {
|
||||
if i > 0 {
|
||||
|
|
@ -61,7 +61,7 @@ func serializeClauseList(statement statementType, clauses []clause, out *queryDa
|
|||
return nil
|
||||
}
|
||||
|
||||
func serializeExpressionList(statement statementType, expressions []expression, separator string, out *queryData) error {
|
||||
func serializeExpressionList(statement statementType, expressions []Expression, separator string, out *queryData) error {
|
||||
|
||||
for i, value := range expressions {
|
||||
if i > 0 {
|
||||
|
|
@ -86,7 +86,7 @@ func serializeProjectionList(statement statementType, projections []projection,
|
|||
}
|
||||
|
||||
if col == nil {
|
||||
return errors.New("projection expression is nil.")
|
||||
return errors.New("projection Expression is nil.")
|
||||
}
|
||||
|
||||
if err := col.serializeForProjection(statement, out); err != nil {
|
||||
|
|
@ -113,8 +113,8 @@ func serializeColumnList(statement statementType, columns []column, out *queryDa
|
|||
return nil
|
||||
}
|
||||
|
||||
//func stringExpressionListToExpressionList(stringExpressions []StringExpression) []expression{
|
||||
// var ret []expression
|
||||
//func stringExpressionListToExpressionList(stringExpressions []StringExpression) []Expression{
|
||||
// var ret []Expression
|
||||
//
|
||||
// for _, strExp := range stringExpressions {
|
||||
// ret = append(ret, strExp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue