Strictly type Integer and Real expressions.
This commit is contained in:
parent
7f5ba98819
commit
2b6288d317
32 changed files with 640 additions and 547 deletions
|
|
@ -33,8 +33,8 @@ func (c ColumnInfo) SqlBuilderColumnType() string {
|
||||||
case "USER-DEFINED", "text", "character", "character varying", "bytea", "uuid",
|
case "USER-DEFINED", "text", "character", "character varying", "bytea", "uuid",
|
||||||
"tsvector", "bit", "bit varying", "money", "json", "jsonb", "xml", "point", "interval", "line", "ARRAY":
|
"tsvector", "bit", "bit varying", "money", "json", "jsonb", "xml", "point", "interval", "line", "ARRAY":
|
||||||
return "StringColumn"
|
return "StringColumn"
|
||||||
case "real", "numeric", "double precision":
|
case "real", "numeric", "decimal", "double precision":
|
||||||
return "NumericColumn"
|
return "FloatColumn"
|
||||||
default:
|
default:
|
||||||
fmt.Println("Unknown sql type: " + c.DataType + ", using string column instead for sql builder.")
|
fmt.Println("Unknown sql type: " + c.DataType + ", using string column instead for sql builder.")
|
||||||
return "StringColumn"
|
return "StringColumn"
|
||||||
|
|
@ -62,7 +62,7 @@ func (c ColumnInfo) GoBaseType() string {
|
||||||
return "string"
|
return "string"
|
||||||
case "real":
|
case "real":
|
||||||
return "float32"
|
return "float32"
|
||||||
case "numeric", "double precision":
|
case "numeric", "decimal", "double precision":
|
||||||
return "float64"
|
return "float64"
|
||||||
case "uuid":
|
case "uuid":
|
||||||
return "uuid.UUID"
|
return "uuid.UUID"
|
||||||
|
|
|
||||||
|
|
@ -1,73 +1,73 @@
|
||||||
package sqlbuilder
|
package sqlbuilder
|
||||||
|
|
||||||
type boolExpression interface {
|
type BoolExpression interface {
|
||||||
expression
|
expression
|
||||||
|
|
||||||
EQ(expression boolExpression) boolExpression
|
EQ(expression BoolExpression) BoolExpression
|
||||||
NOT_EQ(expression boolExpression) boolExpression
|
NOT_EQ(expression BoolExpression) BoolExpression
|
||||||
IS_DISTINCT_FROM(rhs boolExpression) boolExpression
|
IS_DISTINCT_FROM(rhs BoolExpression) BoolExpression
|
||||||
IS_NOT_DISTINCT_FROM(rhs boolExpression) boolExpression
|
IS_NOT_DISTINCT_FROM(rhs BoolExpression) BoolExpression
|
||||||
|
|
||||||
IS_TRUE() boolExpression
|
IS_TRUE() BoolExpression
|
||||||
IS_NOT_TRUE() boolExpression
|
IS_NOT_TRUE() BoolExpression
|
||||||
IS_FALSE() boolExpression
|
IS_FALSE() BoolExpression
|
||||||
IS_NOT_FALSE() boolExpression
|
IS_NOT_FALSE() BoolExpression
|
||||||
IS_UNKNOWN() boolExpression
|
IS_UNKNOWN() BoolExpression
|
||||||
IS_NOT_UNKNOWN() boolExpression
|
IS_NOT_UNKNOWN() BoolExpression
|
||||||
|
|
||||||
AND(expression boolExpression) boolExpression
|
AND(expression BoolExpression) BoolExpression
|
||||||
OR(expression boolExpression) boolExpression
|
OR(expression BoolExpression) BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type boolInterfaceImpl struct {
|
type boolInterfaceImpl struct {
|
||||||
parent boolExpression
|
parent BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) EQ(expression boolExpression) boolExpression {
|
func (b *boolInterfaceImpl) EQ(expression BoolExpression) BoolExpression {
|
||||||
return EQ(b.parent, expression)
|
return EQ(b.parent, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) NOT_EQ(expression boolExpression) boolExpression {
|
func (b *boolInterfaceImpl) NOT_EQ(expression BoolExpression) BoolExpression {
|
||||||
return NOT_EQ(b.parent, expression)
|
return NOT_EQ(b.parent, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_DISTINCT_FROM(rhs boolExpression) boolExpression {
|
func (b *boolInterfaceImpl) IS_DISTINCT_FROM(rhs BoolExpression) BoolExpression {
|
||||||
return IS_DISTINCT_FROM(b.parent, rhs)
|
return IS_DISTINCT_FROM(b.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs boolExpression) boolExpression {
|
func (b *boolInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs BoolExpression) BoolExpression {
|
||||||
return IS_NOT_DISTINCT_FROM(b.parent, rhs)
|
return IS_NOT_DISTINCT_FROM(b.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) AND(expression boolExpression) boolExpression {
|
func (b *boolInterfaceImpl) AND(expression BoolExpression) BoolExpression {
|
||||||
return And(b.parent, expression)
|
return And(b.parent, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) OR(expression boolExpression) boolExpression {
|
func (b *boolInterfaceImpl) OR(expression BoolExpression) BoolExpression {
|
||||||
return Or(b.parent, expression)
|
return Or(b.parent, expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_TRUE() boolExpression {
|
func (b *boolInterfaceImpl) IS_TRUE() BoolExpression {
|
||||||
return IS_TRUE(b.parent)
|
return IS_TRUE(b.parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_NOT_TRUE() boolExpression {
|
func (b *boolInterfaceImpl) IS_NOT_TRUE() BoolExpression {
|
||||||
return IS_NOT_TRUE(b.parent)
|
return IS_NOT_TRUE(b.parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_FALSE() boolExpression {
|
func (b *boolInterfaceImpl) IS_FALSE() BoolExpression {
|
||||||
return IS_FALSE(b.parent)
|
return IS_FALSE(b.parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_NOT_FALSE() boolExpression {
|
func (b *boolInterfaceImpl) IS_NOT_FALSE() BoolExpression {
|
||||||
return IS_NOT_FALSE(b.parent)
|
return IS_NOT_FALSE(b.parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_UNKNOWN() boolExpression {
|
func (b *boolInterfaceImpl) IS_UNKNOWN() BoolExpression {
|
||||||
return IS_UNKNOWN(b.parent)
|
return IS_UNKNOWN(b.parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *boolInterfaceImpl) IS_NOT_UNKNOWN() boolExpression {
|
func (b *boolInterfaceImpl) IS_NOT_UNKNOWN() BoolExpression {
|
||||||
return IS_NOT_UNKNOWN(b.parent)
|
return IS_NOT_UNKNOWN(b.parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ type binaryBoolExpression struct {
|
||||||
binaryOpExpression
|
binaryOpExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBinaryBoolExpression(lhs, rhs expression, operator string) boolExpression {
|
func newBinaryBoolExpression(lhs, rhs expression, operator string) BoolExpression {
|
||||||
boolExpression := binaryBoolExpression{}
|
boolExpression := binaryBoolExpression{}
|
||||||
|
|
||||||
boolExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
boolExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
||||||
|
|
@ -97,7 +97,7 @@ type prefixBoolExpression struct {
|
||||||
prefixOpExpression
|
prefixOpExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPrefixBoolExpression(expression expression, operator string) boolExpression {
|
func newPrefixBoolExpression(expression expression, operator string) BoolExpression {
|
||||||
exp := prefixBoolExpression{}
|
exp := prefixBoolExpression{}
|
||||||
exp.prefixOpExpression = newPrefixExpression(expression, operator)
|
exp.prefixOpExpression = newPrefixExpression(expression, operator)
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ type postfixBoolOpExpression struct {
|
||||||
postfixOpExpression
|
postfixOpExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPostifxBoolExpression(expression expression, operator string) boolExpression {
|
func newPostifxBoolExpression(expression expression, operator string) BoolExpression {
|
||||||
exp := postfixBoolOpExpression{}
|
exp := postfixBoolOpExpression{}
|
||||||
exp.postfixOpExpression = newPostfixOpExpression(expression, operator)
|
exp.postfixOpExpression = newPostfixOpExpression(expression, operator)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,25 +18,24 @@ func NewBoolColumn(name string, nullable NullableColumn) *BoolColumn {
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------//
|
//------------------------------------------------------//
|
||||||
type NumericColumn struct {
|
type FloatColumn struct {
|
||||||
numericInterfaceImpl
|
floatInterfaceImpl
|
||||||
baseColumn
|
baseColumn
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNumericColumn(name string, nullable NullableColumn) *NumericColumn {
|
func NewFloatColumn(name string, nullable NullableColumn) *FloatColumn {
|
||||||
|
|
||||||
numericColumn := &NumericColumn{}
|
floatColumn := &FloatColumn{}
|
||||||
|
|
||||||
numericColumn.numericInterfaceImpl.parent = numericColumn
|
floatColumn.floatInterfaceImpl.parent = floatColumn
|
||||||
|
|
||||||
numericColumn.baseColumn = newBaseColumn(name, nullable, "", numericColumn)
|
floatColumn.baseColumn = newBaseColumn(name, nullable, "", floatColumn)
|
||||||
|
|
||||||
return numericColumn
|
return floatColumn
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------//
|
//------------------------------------------------------//
|
||||||
type IntegerColumn struct {
|
type IntegerColumn struct {
|
||||||
numericInterfaceImpl
|
|
||||||
integerInterfaceImpl
|
integerInterfaceImpl
|
||||||
|
|
||||||
baseColumn
|
baseColumn
|
||||||
|
|
@ -47,7 +46,6 @@ type IntegerColumn struct {
|
||||||
func NewIntegerColumn(name string, nullable NullableColumn) *IntegerColumn {
|
func NewIntegerColumn(name string, nullable NullableColumn) *IntegerColumn {
|
||||||
integerColumn := &IntegerColumn{}
|
integerColumn := &IntegerColumn{}
|
||||||
|
|
||||||
integerColumn.numericInterfaceImpl.parent = integerColumn
|
|
||||||
integerColumn.integerInterfaceImpl.parent = integerColumn
|
integerColumn.integerInterfaceImpl.parent = integerColumn
|
||||||
|
|
||||||
integerColumn.baseColumn = newBaseColumn(name, nullable, "", integerColumn)
|
integerColumn.baseColumn = newBaseColumn(name, nullable, "", integerColumn)
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ func TestNewIntColumn(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewNumericColumnColumn(t *testing.T) {
|
func TestNewNumericColumnColumn(t *testing.T) {
|
||||||
numericColumn := NewNumericColumn("col", Nullable)
|
numericColumn := NewFloatColumn("col", Nullable)
|
||||||
|
|
||||||
out := queryData{}
|
out := queryData{}
|
||||||
err := numericColumn.serialize(select_statement, &out)
|
err := numericColumn.serialize(select_statement, &out)
|
||||||
|
|
|
||||||
|
|
@ -3,49 +3,49 @@ package sqlbuilder
|
||||||
type DateExpression interface {
|
type DateExpression interface {
|
||||||
expression
|
expression
|
||||||
|
|
||||||
EQ(rhs DateExpression) boolExpression
|
EQ(rhs DateExpression) BoolExpression
|
||||||
NOT_EQ(rhs DateExpression) boolExpression
|
NOT_EQ(rhs DateExpression) BoolExpression
|
||||||
IS_DISTINCT_FROM(rhs DateExpression) boolExpression
|
IS_DISTINCT_FROM(rhs DateExpression) BoolExpression
|
||||||
IS_NOT_DISTINCT_FROM(rhs DateExpression) boolExpression
|
IS_NOT_DISTINCT_FROM(rhs DateExpression) BoolExpression
|
||||||
|
|
||||||
LT(rhs DateExpression) boolExpression
|
LT(rhs DateExpression) BoolExpression
|
||||||
LT_EQ(rhs DateExpression) boolExpression
|
LT_EQ(rhs DateExpression) BoolExpression
|
||||||
GT(rhs DateExpression) boolExpression
|
GT(rhs DateExpression) BoolExpression
|
||||||
GT_EQ(rhs DateExpression) boolExpression
|
GT_EQ(rhs DateExpression) BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type dateInterfaceImpl struct {
|
type dateInterfaceImpl struct {
|
||||||
parent DateExpression
|
parent DateExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) EQ(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) EQ(rhs DateExpression) BoolExpression {
|
||||||
return EQ(t.parent, rhs)
|
return EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) NOT_EQ(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) NOT_EQ(rhs DateExpression) BoolExpression {
|
||||||
return NOT_EQ(t.parent, rhs)
|
return NOT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) IS_DISTINCT_FROM(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) IS_DISTINCT_FROM(rhs DateExpression) BoolExpression {
|
||||||
return IS_DISTINCT_FROM(t.parent, rhs)
|
return IS_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs DateExpression) BoolExpression {
|
||||||
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) LT(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) LT(rhs DateExpression) BoolExpression {
|
||||||
return LT(t.parent, rhs)
|
return LT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) LT_EQ(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) LT_EQ(rhs DateExpression) BoolExpression {
|
||||||
return LT_EQ(t.parent, rhs)
|
return LT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) GT(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) GT(rhs DateExpression) BoolExpression {
|
||||||
return GT(t.parent, rhs)
|
return GT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *dateInterfaceImpl) GT_EQ(rhs DateExpression) boolExpression {
|
func (t *dateInterfaceImpl) GT_EQ(rhs DateExpression) BoolExpression {
|
||||||
return GT_EQ(t.parent, rhs)
|
return GT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
type deleteStatement interface {
|
type deleteStatement interface {
|
||||||
Statement
|
Statement
|
||||||
|
|
||||||
WHERE(expression boolExpression) deleteStatement
|
WHERE(expression BoolExpression) deleteStatement
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDeleteStatement(table writableTable) deleteStatement {
|
func newDeleteStatement(table writableTable) deleteStatement {
|
||||||
|
|
@ -20,10 +20,10 @@ func newDeleteStatement(table writableTable) deleteStatement {
|
||||||
|
|
||||||
type deleteStatementImpl struct {
|
type deleteStatementImpl struct {
|
||||||
table writableTable
|
table writableTable
|
||||||
where boolExpression
|
where BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *deleteStatementImpl) WHERE(expression boolExpression) deleteStatement {
|
func (d *deleteStatementImpl) WHERE(expression BoolExpression) deleteStatement {
|
||||||
d.where = expression
|
d.where = expression
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -612,7 +612,7 @@ func newScanType(columnType *sql.ColumnType) reflect.Type {
|
||||||
return nullStringType
|
return nullStringType
|
||||||
case "FLOAT4":
|
case "FLOAT4":
|
||||||
return nullFloatType
|
return nullFloatType
|
||||||
case "FLOAT8", "NUMERIC":
|
case "FLOAT8", "NUMERIC", "DECIMAL":
|
||||||
return nullFloat64Type
|
return nullFloat64Type
|
||||||
case "BOOL":
|
case "BOOL":
|
||||||
return nullBoolType
|
return nullBoolType
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ type expression interface {
|
||||||
groupByClause
|
groupByClause
|
||||||
orderByClause
|
orderByClause
|
||||||
|
|
||||||
IS_NULL() boolExpression
|
IS_NULL() BoolExpression
|
||||||
IS_NOT_NULL() boolExpression
|
IS_NOT_NULL() BoolExpression
|
||||||
|
|
||||||
IN(subQuery selectStatement) boolExpression
|
IN(subQuery selectStatement) BoolExpression
|
||||||
NOT_IN(subQuery selectStatement) boolExpression
|
NOT_IN(subQuery selectStatement) BoolExpression
|
||||||
|
|
||||||
AS(alias string) projection
|
AS(alias string) projection
|
||||||
|
|
||||||
|
|
@ -27,19 +27,19 @@ type expressionInterfaceImpl struct {
|
||||||
parent expression
|
parent expression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *expressionInterfaceImpl) IS_NULL() boolExpression {
|
func (e *expressionInterfaceImpl) IS_NULL() BoolExpression {
|
||||||
return newPostifxBoolExpression(e.parent, "IS NULL")
|
return newPostifxBoolExpression(e.parent, "IS NULL")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *expressionInterfaceImpl) IS_NOT_NULL() boolExpression {
|
func (e *expressionInterfaceImpl) IS_NOT_NULL() BoolExpression {
|
||||||
return newPostifxBoolExpression(e.parent, "IS NOT NULL")
|
return newPostifxBoolExpression(e.parent, "IS NOT NULL")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *expressionInterfaceImpl) IN(subQuery selectStatement) boolExpression {
|
func (e *expressionInterfaceImpl) IN(subQuery selectStatement) BoolExpression {
|
||||||
return newBinaryBoolExpression(e.parent, subQuery, "IN")
|
return newBinaryBoolExpression(e.parent, subQuery, "IN")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *expressionInterfaceImpl) NOT_IN(subQuery selectStatement) boolExpression {
|
func (e *expressionInterfaceImpl) NOT_IN(subQuery selectStatement) BoolExpression {
|
||||||
return newBinaryBoolExpression(e.parent, subQuery, "NOT IN")
|
return newBinaryBoolExpression(e.parent, subQuery, "NOT IN")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ func isSimpleOperand(expression expression) bool {
|
||||||
if _, ok := expression.(column); ok {
|
if _, ok := expression.(column); ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if _, ok := expression.(*numericFunc); ok {
|
if _, ok := expression.(*floatFunc); ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ func (s *ExprSuite) TestRegexExpr(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ExprSuite) TestAndExpr(c *gc.C) {
|
func (s *ExprSuite) TestAndExpr(c *gc.C) {
|
||||||
expr := And(EqL(table1Col1, 1), EqL(table1Col2, 2), EqL(table1Col3, 3))
|
expr := And(EqL(table1Col1, 1), EqL(table1ColFloat, 2), EqL(table1Col3, 3))
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ func (s *ExprSuite) TestAndExpr(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ExprSuite) TestOrExpr(c *gc.C) {
|
func (s *ExprSuite) TestOrExpr(c *gc.C) {
|
||||||
expr := Or(EqL(table1Col1, 1), EqL(table1Col2, 2), EqL(table1Col3, 3))
|
expr := Or(EqL(table1Col1, 1), EqL(table1ColFloat, 2), EqL(table1Col3, 3))
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
|
@ -331,7 +331,7 @@ func (s *ExprSuite) TestSqlFuncExprEmptyArgList(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ExprSuite) TestSqlFuncExprNonEmptyArgList(c *gc.C) {
|
func (s *ExprSuite) TestSqlFuncExprNonEmptyArgList(c *gc.C) {
|
||||||
expr := SqlFunc("add", table1Col1, table1Col2)
|
expr := SqlFunc("add", table1Col1, table1ColFloat)
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func (e *expressionTableImpl) SELECT(projections ...projection) selectStatement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a inner join tableName expression using onCondition.
|
// Creates a inner join tableName expression using onCondition.
|
||||||
func (e *expressionTableImpl) INNER_JOIN(table readableTable, onCondition boolExpression) readableTable {
|
func (e *expressionTableImpl) INNER_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||||
return InnerJoinOn(e, table, onCondition)
|
return InnerJoinOn(e, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,16 +80,16 @@ func (e *expressionTableImpl) INNER_JOIN(table readableTable, onCondition boolEx
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Creates a left join tableName expression using onCondition.
|
// Creates a left join tableName expression using onCondition.
|
||||||
func (e *expressionTableImpl) LEFT_JOIN(table readableTable, onCondition boolExpression) readableTable {
|
func (e *expressionTableImpl) LEFT_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||||
return LeftJoinOn(e, table, onCondition)
|
return LeftJoinOn(e, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a right join tableName expression using onCondition.
|
// Creates a right join tableName expression using onCondition.
|
||||||
func (e *expressionTableImpl) RIGHT_JOIN(table readableTable, onCondition boolExpression) readableTable {
|
func (e *expressionTableImpl) RIGHT_JOIN(table readableTable, onCondition BoolExpression) readableTable {
|
||||||
return RightJoinOn(e, table, onCondition)
|
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)
|
return FullJoin(e, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
123
sqlbuilder/float_expression.go
Normal file
123
sqlbuilder/float_expression.go
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
package sqlbuilder
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
type FloatExpression interface {
|
||||||
|
expression
|
||||||
|
|
||||||
|
EQ(rhs FloatExpression) BoolExpression
|
||||||
|
NOT_EQ(rhs FloatExpression) BoolExpression
|
||||||
|
IS_DISTINCT_FROM(rhs FloatExpression) BoolExpression
|
||||||
|
IS_NOT_DISTINCT_FROM(rhs FloatExpression) BoolExpression
|
||||||
|
|
||||||
|
LT(rhs FloatExpression) BoolExpression
|
||||||
|
LT_EQ(rhs FloatExpression) BoolExpression
|
||||||
|
GT(rhs FloatExpression) BoolExpression
|
||||||
|
GT_EQ(rhs FloatExpression) BoolExpression
|
||||||
|
|
||||||
|
ADD(rhs FloatExpression) FloatExpression
|
||||||
|
SUB(rhs FloatExpression) FloatExpression
|
||||||
|
MUL(rhs FloatExpression) FloatExpression
|
||||||
|
DIV(rhs FloatExpression) FloatExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
type floatInterfaceImpl struct {
|
||||||
|
parent FloatExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) EQ(rhs FloatExpression) BoolExpression {
|
||||||
|
return EQ(n.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) NOT_EQ(rhs FloatExpression) BoolExpression {
|
||||||
|
return NOT_EQ(n.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) IS_DISTINCT_FROM(rhs FloatExpression) BoolExpression {
|
||||||
|
return IS_DISTINCT_FROM(n.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs FloatExpression) BoolExpression {
|
||||||
|
return IS_NOT_DISTINCT_FROM(n.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) GT(rhs FloatExpression) BoolExpression {
|
||||||
|
return GT(n.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) GT_EQ(rhs FloatExpression) BoolExpression {
|
||||||
|
return GT_EQ(n.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) LT(expression FloatExpression) BoolExpression {
|
||||||
|
return LT(n.parent, expression)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) LT_EQ(expression FloatExpression) BoolExpression {
|
||||||
|
return LT_EQ(n.parent, expression)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) ADD(expression FloatExpression) FloatExpression {
|
||||||
|
return newBinaryFloatExpression(n.parent, expression, "+")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) SUB(expression FloatExpression) FloatExpression {
|
||||||
|
return newBinaryFloatExpression(n.parent, expression, "-")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) MUL(expression FloatExpression) FloatExpression {
|
||||||
|
return newBinaryFloatExpression(n.parent, expression, "*")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatInterfaceImpl) DIV(expression FloatExpression) FloatExpression {
|
||||||
|
return newBinaryFloatExpression(n.parent, expression, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------//
|
||||||
|
type binaryFloatExpression struct {
|
||||||
|
expressionInterfaceImpl
|
||||||
|
floatInterfaceImpl
|
||||||
|
|
||||||
|
binaryOpExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBinaryFloatExpression(lhs, rhs FloatExpression, operator string) FloatExpression {
|
||||||
|
floatExpression := binaryFloatExpression{}
|
||||||
|
|
||||||
|
floatExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
||||||
|
|
||||||
|
floatExpression.expressionInterfaceImpl.parent = &floatExpression
|
||||||
|
floatExpression.floatInterfaceImpl.parent = &floatExpression
|
||||||
|
|
||||||
|
return &floatExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
////---------------------------------------------------//
|
||||||
|
type floatExpressionWrapper struct {
|
||||||
|
expressionInterfaceImpl
|
||||||
|
floatInterfaceImpl
|
||||||
|
|
||||||
|
expression expression
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFloatExpressionWrap(expression expression) FloatExpression {
|
||||||
|
floatExpressionWrap := floatExpressionWrapper{}
|
||||||
|
|
||||||
|
floatExpressionWrap.expression = expression
|
||||||
|
|
||||||
|
floatExpressionWrap.expressionInterfaceImpl.parent = &floatExpressionWrap
|
||||||
|
floatExpressionWrap.floatInterfaceImpl.parent = &floatExpressionWrap
|
||||||
|
|
||||||
|
return &floatExpressionWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *floatExpressionWrapper) serialize(statement statementType, out *queryData) error {
|
||||||
|
if n == nil {
|
||||||
|
return errors.New("Float expression wrapper is nil. ")
|
||||||
|
}
|
||||||
|
//out.writeString("(")
|
||||||
|
err := n.expression.serialize(statement, out)
|
||||||
|
//out.writeString(")")
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
@ -5,34 +5,34 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNumericEQColumn(t *testing.T) {
|
func TestFloatExpressionEQColumn(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.EQ(table2Col3)), "table1.col1 = table2.col3")
|
assert.Equal(t, getTestSerialize(t, table1Col1.EQ(table2Col3)), "table1.col1 = table2.col3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericEQInt(t *testing.T) {
|
func TestFloatExpressionEQInt(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.EQ(Int(11))), "table1.col1 = $1")
|
assert.Equal(t, getTestSerialize(t, table1Col1.EQ(Int(11))), "table1.col1 = $1")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericEQFloat(t *testing.T) {
|
func TestFloatExpressionEQFloat(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.EQ(Float(22.333))), "table1.col1 = $1")
|
assert.Equal(t, getTestSerialize(t, table1Col1.EQ(Int(22))), "table1.col1 = $1")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericNOT_EQ(t *testing.T) {
|
func TestFloatExpressionNOT_EQ(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.NOT_EQ(table2Col3)), "table1.col1 != table2.col3")
|
assert.Equal(t, getTestSerialize(t, table1Col1.NOT_EQ(table2Col3)), "table1.col1 != table2.col3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericGT(t *testing.T) {
|
func TestFloatExpressionGT(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.GT(table2Col3)), "table1.col1 > table2.col3")
|
assert.Equal(t, getTestSerialize(t, table1Col1.GT(table2Col3)), "table1.col1 > table2.col3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericGT_EQ(t *testing.T) {
|
func TestFloatExpressionGT_EQ(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.GT_EQ(table2Col3)), "table1.col1 >= table2.col3")
|
assert.Equal(t, getTestSerialize(t, table1Col1.GT_EQ(table2Col3)), "table1.col1 >= table2.col3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericLT(t *testing.T) {
|
func TestFloatExpressionLT(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.LT(table2Col3)), "table1.col1 < table2.col3")
|
assert.Equal(t, getTestSerialize(t, table1Col1.LT(table2Col3)), "table1.col1 < table2.col3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumericLT_EQ(t *testing.T) {
|
func TestFloatExpressionLT_EQ(t *testing.T) {
|
||||||
assert.Equal(t, getTestSerialize(t, table1Col1.LT_EQ(table2Col3)), "table1.col1 <= table2.col3")
|
assert.Equal(t, getTestSerialize(t, table1Col1.LT_EQ(table2Col3)), "table1.col1 <= table2.col3")
|
||||||
}
|
}
|
||||||
|
|
@ -44,126 +44,58 @@ func (f *funcExpressionImpl) serialize(statement statementType, out *queryData)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type numericFunc struct {
|
// ------------------- FLOAT FUNCTIONS --------------------------//
|
||||||
|
|
||||||
|
type floatFunc struct {
|
||||||
funcExpressionImpl
|
funcExpressionImpl
|
||||||
numericInterfaceImpl
|
floatInterfaceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNumericFunc(name string, expressions ...expression) numericExpression {
|
func newFloatFunc(name string, expressions ...expression) FloatExpression {
|
||||||
numericFunc := &numericFunc{}
|
floatFunc := &floatFunc{}
|
||||||
|
|
||||||
numericFunc.funcExpressionImpl = *newFunc(name, expressions, numericFunc)
|
floatFunc.funcExpressionImpl = *newFunc(name, expressions, floatFunc)
|
||||||
numericFunc.numericInterfaceImpl.parent = numericFunc
|
floatFunc.floatInterfaceImpl.parent = floatFunc
|
||||||
|
|
||||||
return numericFunc
|
return floatFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func COUNT(expression numericExpression) numericExpression {
|
func COUNTf(floatExpression FloatExpression) FloatExpression {
|
||||||
return NewNumericFunc("COUNT", expression)
|
return newFloatFunc("COUNT", floatExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MAX(expression numericExpression) numericExpression {
|
func MAXf(floatExpression FloatExpression) FloatExpression {
|
||||||
return NewNumericFunc("MAX", expression)
|
return newFloatFunc("MAX", floatExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SUM(expression numericExpression) numericExpression {
|
func SUMf(floatExpression FloatExpression) FloatExpression {
|
||||||
return NewNumericFunc("SUM", expression)
|
return newFloatFunc("SUM", floatExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
type caseInterface interface {
|
// ------------------- FLOAT FUNCTIONS --------------------------//
|
||||||
expression
|
|
||||||
|
|
||||||
WHEN(condition expression) caseInterface
|
type integerFunc struct {
|
||||||
THEN(then expression) caseInterface
|
funcExpressionImpl
|
||||||
ELSE(els expression) caseInterface
|
integerInterfaceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
type caseExpression struct {
|
func newIntegerFunc(name string, expressions ...expression) IntegerExpression {
|
||||||
expressionInterfaceImpl
|
floatFunc := &integerFunc{}
|
||||||
|
|
||||||
expression expression
|
floatFunc.funcExpressionImpl = *newFunc(name, expressions, floatFunc)
|
||||||
when []expression
|
floatFunc.integerInterfaceImpl.parent = floatFunc
|
||||||
then []expression
|
|
||||||
els expression
|
return floatFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func CASE(expression ...expression) caseInterface {
|
func COUNTi(integerExpression IntegerExpression) IntegerExpression {
|
||||||
caseExp := &caseExpression{}
|
return newIntegerFunc("COUNT", integerExpression)
|
||||||
|
|
||||||
if len(expression) == 1 {
|
|
||||||
caseExp.expression = expression[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
caseExp.expressionInterfaceImpl.parent = caseExp
|
func MAXi(integerExpression IntegerExpression) IntegerExpression {
|
||||||
|
return newIntegerFunc("MAX", integerExpression)
|
||||||
return caseExp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *caseExpression) WHEN(when expression) caseInterface {
|
func SUMi(integerExpression IntegerExpression) IntegerExpression {
|
||||||
c.when = append(c.when, when)
|
return newIntegerFunc("SUM", integerExpression)
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *caseExpression) THEN(then expression) caseInterface {
|
|
||||||
c.then = append(c.then, then)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *caseExpression) ELSE(els expression) caseInterface {
|
|
||||||
c.els = els
|
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *caseExpression) serialize(statement statementType, out *queryData) error {
|
|
||||||
if c == nil {
|
|
||||||
return errors.New("Case expression is nil. ")
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeString("(CASE")
|
|
||||||
|
|
||||||
if c.expression != nil {
|
|
||||||
err := c.expression.serialize(statement, out)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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. ")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(c.when) != len(c.then) {
|
|
||||||
return errors.New("When and then expression count mismatch. ")
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, when := range c.when {
|
|
||||||
out.writeString("WHEN")
|
|
||||||
err := when.serialize(statement, out)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeString("THEN")
|
|
||||||
err = c.then[i].serialize(statement, out)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.els != nil {
|
|
||||||
out.writeString("ELSE")
|
|
||||||
err := c.els.serialize(statement, out)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeString("END)")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func TestInsertNoRow(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertColumnLengthMismatch(t *testing.T) {
|
func TestInsertColumnLengthMismatch(t *testing.T) {
|
||||||
_, _, err := table1.INSERT(table1Col1, table1Col2).VALUES(nil).Sql()
|
_, _, err := table1.INSERT(table1Col1, table1ColFloat).VALUES(nil).Sql()
|
||||||
|
|
||||||
//fmt.Println(err)
|
//fmt.Println(err)
|
||||||
assert.Assert(t, err != nil)
|
assert.Assert(t, err != nil)
|
||||||
|
|
@ -66,7 +66,7 @@ INSERT INTO db.table1 (colTime) VALUES
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertMultipleValues(t *testing.T) {
|
func TestInsertMultipleValues(t *testing.T) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2, table1Col3)
|
stmt := table1.INSERT(table1Col1, table1ColFloat, table1Col3)
|
||||||
stmt.VALUES(1, 2, 3)
|
stmt.VALUES(1, 2, 3)
|
||||||
|
|
||||||
sql, _, err := stmt.Sql()
|
sql, _, err := stmt.Sql()
|
||||||
|
|
@ -75,7 +75,7 @@ func TestInsertMultipleValues(t *testing.T) {
|
||||||
fmt.Println(sql)
|
fmt.Println(sql)
|
||||||
|
|
||||||
expectedSql := `
|
expectedSql := `
|
||||||
INSERT INTO db.table1 (col1,col2,col3) VALUES
|
INSERT INTO db.table1 (col1,colFloat,col3) VALUES
|
||||||
($1, $2, $3);
|
($1, $2, $3);
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ INSERT INTO db.table1 (col1,col2,col3) VALUES
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertMultipleRows(t *testing.T) {
|
func TestInsertMultipleRows(t *testing.T) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2).
|
stmt := table1.INSERT(table1Col1, table1ColFloat).
|
||||||
VALUES(1, 2).
|
VALUES(1, 2).
|
||||||
VALUES(11, 22).
|
VALUES(11, 22).
|
||||||
VALUES(111, 222)
|
VALUES(111, 222)
|
||||||
|
|
@ -94,7 +94,7 @@ func TestInsertMultipleRows(t *testing.T) {
|
||||||
fmt.Println(sql)
|
fmt.Println(sql)
|
||||||
|
|
||||||
expectedSql := `
|
expectedSql := `
|
||||||
INSERT INTO db.table1 (col1,col2) VALUES
|
INSERT INTO db.table1 (col1,colFloat) VALUES
|
||||||
($1, $2),
|
($1, $2),
|
||||||
($3, $4),
|
($3, $4),
|
||||||
($5, $6);
|
($5, $6);
|
||||||
|
|
@ -106,15 +106,15 @@ INSERT INTO db.table1 (col1,col2) VALUES
|
||||||
func TestInsertValuesFromModel(t *testing.T) {
|
func TestInsertValuesFromModel(t *testing.T) {
|
||||||
type Table1Model struct {
|
type Table1Model struct {
|
||||||
Col1 int
|
Col1 int
|
||||||
Col2 string
|
ColFloat float64
|
||||||
}
|
}
|
||||||
|
|
||||||
toInsert := Table1Model{
|
toInsert := Table1Model{
|
||||||
Col1: 1,
|
Col1: 1,
|
||||||
Col2: "one",
|
ColFloat: 1.11,
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2).
|
stmt := table1.INSERT(table1Col1, table1ColFloat).
|
||||||
VALUES_MAPPING(toInsert)
|
VALUES_MAPPING(toInsert)
|
||||||
|
|
||||||
sql, _, err := stmt.Sql()
|
sql, _, err := stmt.Sql()
|
||||||
|
|
@ -124,7 +124,7 @@ func TestInsertValuesFromModel(t *testing.T) {
|
||||||
fmt.Println(sql)
|
fmt.Println(sql)
|
||||||
|
|
||||||
assert.Equal(t, sql, `
|
assert.Equal(t, sql, `
|
||||||
INSERT INTO db.table1 (col1,col2) VALUES
|
INSERT INTO db.table1 (col1,colFloat) VALUES
|
||||||
($1, $2);
|
($1, $2);
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +140,7 @@ func TestInsertValuesFromModelColumnMismatch(t *testing.T) {
|
||||||
Col2: "one",
|
Col2: "one",
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2).
|
stmt := table1.INSERT(table1Col1, table1ColFloat).
|
||||||
VALUES_MAPPING(toInsert)
|
VALUES_MAPPING(toInsert)
|
||||||
|
|
||||||
_, _, err := stmt.Sql()
|
_, _, err := stmt.Sql()
|
||||||
|
|
@ -162,7 +162,7 @@ func TestInsertQuery(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertDefaultValue(t *testing.T) {
|
func TestInsertDefaultValue(t *testing.T) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2).
|
stmt := table1.INSERT(table1Col1, table1ColFloat).
|
||||||
VALUES(DEFAULT, "two")
|
VALUES(DEFAULT, "two")
|
||||||
|
|
||||||
stmtStr, _, err := stmt.Sql()
|
stmtStr, _, err := stmt.Sql()
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,109 @@
|
||||||
package sqlbuilder
|
package sqlbuilder
|
||||||
|
|
||||||
type integerExpression interface {
|
type IntegerExpression interface {
|
||||||
numericExpression
|
expression
|
||||||
|
|
||||||
BitAnd(expression integerExpression) integerExpression
|
EQ(rhs IntegerExpression) BoolExpression
|
||||||
BitOr(expression integerExpression) integerExpression
|
NOT_EQ(rhs IntegerExpression) BoolExpression
|
||||||
BitXor(expression integerExpression) integerExpression
|
IS_DISTINCT_FROM(rhs IntegerExpression) BoolExpression
|
||||||
BitNot() integerExpression
|
IS_NOT_DISTINCT_FROM(rhs IntegerExpression) BoolExpression
|
||||||
|
|
||||||
|
LT(rhs IntegerExpression) BoolExpression
|
||||||
|
LT_EQ(rhs IntegerExpression) BoolExpression
|
||||||
|
GT(rhs IntegerExpression) BoolExpression
|
||||||
|
GT_EQ(rhs IntegerExpression) BoolExpression
|
||||||
|
|
||||||
|
ADD(rhs IntegerExpression) IntegerExpression
|
||||||
|
SUB(rhs IntegerExpression) IntegerExpression
|
||||||
|
MUL(rhs IntegerExpression) IntegerExpression
|
||||||
|
DIV(rhs IntegerExpression) IntegerExpression
|
||||||
|
|
||||||
|
BitAnd(expression IntegerExpression) IntegerExpression
|
||||||
|
BitOr(expression IntegerExpression) IntegerExpression
|
||||||
|
BitXor(expression IntegerExpression) IntegerExpression
|
||||||
|
BitNot() IntegerExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type integerInterfaceImpl struct {
|
type integerInterfaceImpl struct {
|
||||||
parent integerExpression
|
parent IntegerExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *integerInterfaceImpl) BitAnd(expression integerExpression) integerExpression {
|
func (i *integerInterfaceImpl) EQ(rhs IntegerExpression) BoolExpression {
|
||||||
|
return EQ(i.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) NOT_EQ(rhs IntegerExpression) BoolExpression {
|
||||||
|
return NOT_EQ(i.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) IS_DISTINCT_FROM(rhs IntegerExpression) BoolExpression {
|
||||||
|
return IS_DISTINCT_FROM(i.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs IntegerExpression) BoolExpression {
|
||||||
|
return IS_NOT_DISTINCT_FROM(i.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) GT(rhs IntegerExpression) BoolExpression {
|
||||||
|
return GT(i.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) GT_EQ(rhs IntegerExpression) BoolExpression {
|
||||||
|
return GT_EQ(i.parent, rhs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) LT(expression IntegerExpression) BoolExpression {
|
||||||
|
return LT(i.parent, expression)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) LT_EQ(expression IntegerExpression) BoolExpression {
|
||||||
|
return LT_EQ(i.parent, expression)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) ADD(expression IntegerExpression) IntegerExpression {
|
||||||
|
return NewBinaryIntegerExpression(i.parent, expression, "+")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) SUB(expression IntegerExpression) IntegerExpression {
|
||||||
|
return NewBinaryIntegerExpression(i.parent, expression, "-")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) MUL(expression IntegerExpression) IntegerExpression {
|
||||||
|
return NewBinaryIntegerExpression(i.parent, expression, "*")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) DIV(expression IntegerExpression) IntegerExpression {
|
||||||
|
return NewBinaryIntegerExpression(i.parent, expression, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *integerInterfaceImpl) BitAnd(expression IntegerExpression) IntegerExpression {
|
||||||
return NewBinaryIntegerExpression(i.parent, expression, "&")
|
return NewBinaryIntegerExpression(i.parent, expression, "&")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *integerInterfaceImpl) BitOr(expression integerExpression) integerExpression {
|
func (i *integerInterfaceImpl) BitOr(expression IntegerExpression) IntegerExpression {
|
||||||
return NewBinaryIntegerExpression(i.parent, expression, "|")
|
return NewBinaryIntegerExpression(i.parent, expression, "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *integerInterfaceImpl) BitXor(expression integerExpression) integerExpression {
|
func (i *integerInterfaceImpl) BitXor(expression IntegerExpression) IntegerExpression {
|
||||||
return NewBinaryIntegerExpression(i.parent, expression, "#")
|
return NewBinaryIntegerExpression(i.parent, expression, "#")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *integerInterfaceImpl) BitNot() integerExpression {
|
func (i *integerInterfaceImpl) BitNot() IntegerExpression {
|
||||||
return NewPrefixIntegerExpression(i.parent, " ~")
|
return NewPrefixIntegerOpExpression(i.parent, "~")
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------//
|
//---------------------------------------------------//
|
||||||
type binaryIntegerExpression struct {
|
type binaryIntegerExpression struct {
|
||||||
expressionInterfaceImpl
|
expressionInterfaceImpl
|
||||||
numericInterfaceImpl
|
|
||||||
integerInterfaceImpl
|
integerInterfaceImpl
|
||||||
|
|
||||||
binaryOpExpression
|
binaryOpExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBinaryIntegerExpression(lhs, rhs integerExpression, operator string) integerExpression {
|
func NewBinaryIntegerExpression(lhs, rhs IntegerExpression, operator string) IntegerExpression {
|
||||||
integerExpression := binaryIntegerExpression{}
|
integerExpression := binaryIntegerExpression{}
|
||||||
|
|
||||||
integerExpression.expressionInterfaceImpl.parent = &integerExpression
|
integerExpression.expressionInterfaceImpl.parent = &integerExpression
|
||||||
integerExpression.numericInterfaceImpl.parent = &integerExpression
|
|
||||||
integerExpression.integerInterfaceImpl.parent = &integerExpression
|
integerExpression.integerInterfaceImpl.parent = &integerExpression
|
||||||
|
|
||||||
integerExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
integerExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
||||||
|
|
@ -51,20 +112,18 @@ func NewBinaryIntegerExpression(lhs, rhs integerExpression, operator string) int
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------//
|
//---------------------------------------------------//
|
||||||
type prefixIntegerExpression struct {
|
type prefixIntegerOpExpression struct {
|
||||||
expressionInterfaceImpl
|
expressionInterfaceImpl
|
||||||
numericInterfaceImpl
|
|
||||||
integerInterfaceImpl
|
integerInterfaceImpl
|
||||||
|
|
||||||
prefixOpExpression
|
prefixOpExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPrefixIntegerExpression(expression integerExpression, operator string) integerExpression {
|
func NewPrefixIntegerOpExpression(expression IntegerExpression, operator string) IntegerExpression {
|
||||||
integerExpression := prefixIntegerExpression{}
|
integerExpression := prefixIntegerOpExpression{}
|
||||||
integerExpression.prefixOpExpression = newPrefixExpression(expression, operator)
|
integerExpression.prefixOpExpression = newPrefixExpression(expression, operator)
|
||||||
|
|
||||||
integerExpression.expressionInterfaceImpl.parent = &integerExpression
|
integerExpression.expressionInterfaceImpl.parent = &integerExpression
|
||||||
integerExpression.numericInterfaceImpl.parent = &integerExpression
|
|
||||||
integerExpression.integerInterfaceImpl.parent = &integerExpression
|
integerExpression.integerInterfaceImpl.parent = &integerExpression
|
||||||
|
|
||||||
return &integerExpression
|
return &integerExpression
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,18 @@ func (l literalExpression) serialize(statement statementType, out *queryData) er
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type numLiteralExpression struct {
|
type integerLiteralExpression struct {
|
||||||
literalExpression
|
literalExpression
|
||||||
numericInterfaceImpl
|
integerInterfaceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
func Int(value int) numericExpression {
|
func Int(value int) IntegerExpression {
|
||||||
numLiteral := &numLiteralExpression{}
|
numLiteral := &integerLiteralExpression{}
|
||||||
|
|
||||||
numLiteral.literalExpression = *Literal(value)
|
numLiteral.literalExpression = *Literal(value)
|
||||||
numLiteral.literalExpression.parent = numLiteral
|
|
||||||
|
|
||||||
numLiteral.numericInterfaceImpl.parent = numLiteral
|
numLiteral.literalExpression.parent = numLiteral
|
||||||
|
numLiteral.integerInterfaceImpl.parent = numLiteral
|
||||||
|
|
||||||
return numLiteral
|
return numLiteral
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ type boolLiteralExpression struct {
|
||||||
literalExpression
|
literalExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func Bool(value bool) boolExpression {
|
func Bool(value bool) BoolExpression {
|
||||||
boolLiteralExpression := boolLiteralExpression{}
|
boolLiteralExpression := boolLiteralExpression{}
|
||||||
|
|
||||||
boolLiteralExpression.literalExpression = *Literal(value)
|
boolLiteralExpression.literalExpression = *Literal(value)
|
||||||
|
|
@ -53,18 +53,18 @@ func Bool(value bool) boolExpression {
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------//
|
//---------------------------------------------------//
|
||||||
type numericLiteral struct {
|
type floatLiteral struct {
|
||||||
numericInterfaceImpl
|
floatInterfaceImpl
|
||||||
literalExpression
|
literalExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func Float(value float64) numericExpression {
|
func Float(value float64) FloatExpression {
|
||||||
numericLiteral := numericLiteral{}
|
floatLiteral := floatLiteral{}
|
||||||
numericLiteral.literalExpression = *Literal(value)
|
floatLiteral.literalExpression = *Literal(value)
|
||||||
|
|
||||||
numericLiteral.numericInterfaceImpl.parent = &numericLiteral
|
floatLiteral.floatInterfaceImpl.parent = &floatLiteral
|
||||||
|
|
||||||
return &numericLiteral
|
return &floatLiteral
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------//
|
//---------------------------------------------------//
|
||||||
|
|
|
||||||
|
|
@ -1,123 +0,0 @@
|
||||||
package sqlbuilder
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
type numericExpression interface {
|
|
||||||
expression
|
|
||||||
|
|
||||||
EQ(rhs numericExpression) boolExpression
|
|
||||||
NOT_EQ(rhs numericExpression) boolExpression
|
|
||||||
IS_DISTINCT_FROM(rhs numericExpression) boolExpression
|
|
||||||
IS_NOT_DISTINCT_FROM(rhs numericExpression) boolExpression
|
|
||||||
|
|
||||||
LT(rhs numericExpression) boolExpression
|
|
||||||
LT_EQ(rhs numericExpression) boolExpression
|
|
||||||
GT(rhs numericExpression) boolExpression
|
|
||||||
GT_EQ(rhs numericExpression) boolExpression
|
|
||||||
|
|
||||||
ADD(rhs numericExpression) numericExpression
|
|
||||||
SUB(rhs numericExpression) numericExpression
|
|
||||||
MUL(rhs numericExpression) numericExpression
|
|
||||||
DIV(rhs numericExpression) numericExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
type numericInterfaceImpl struct {
|
|
||||||
parent numericExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) EQ(rhs numericExpression) boolExpression {
|
|
||||||
return EQ(n.parent, rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) NOT_EQ(rhs numericExpression) boolExpression {
|
|
||||||
return NOT_EQ(n.parent, rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) IS_DISTINCT_FROM(rhs numericExpression) boolExpression {
|
|
||||||
return IS_DISTINCT_FROM(n.parent, rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs numericExpression) boolExpression {
|
|
||||||
return IS_NOT_DISTINCT_FROM(n.parent, rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) GT(rhs numericExpression) boolExpression {
|
|
||||||
return GT(n.parent, rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) GT_EQ(rhs numericExpression) boolExpression {
|
|
||||||
return GT_EQ(n.parent, rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) LT(expression numericExpression) boolExpression {
|
|
||||||
return LT(n.parent, expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) LT_EQ(expression numericExpression) boolExpression {
|
|
||||||
return LT_EQ(n.parent, expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) ADD(expression numericExpression) numericExpression {
|
|
||||||
return newBinaryNumericExpression(n.parent, expression, "+")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) SUB(expression numericExpression) numericExpression {
|
|
||||||
return newBinaryNumericExpression(n.parent, expression, "-")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) MUL(expression numericExpression) numericExpression {
|
|
||||||
return newBinaryNumericExpression(n.parent, expression, "*")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericInterfaceImpl) DIV(expression numericExpression) numericExpression {
|
|
||||||
return newBinaryNumericExpression(n.parent, expression, "/")
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------//
|
|
||||||
type binaryNumericExpression struct {
|
|
||||||
expressionInterfaceImpl
|
|
||||||
numericInterfaceImpl
|
|
||||||
|
|
||||||
binaryOpExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
func newBinaryNumericExpression(lhs, rhs expression, operator string) numericExpression {
|
|
||||||
numericExpression := binaryNumericExpression{}
|
|
||||||
|
|
||||||
numericExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
|
|
||||||
|
|
||||||
numericExpression.expressionInterfaceImpl.parent = &numericExpression
|
|
||||||
numericExpression.numericInterfaceImpl.parent = &numericExpression
|
|
||||||
|
|
||||||
return &numericExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------//
|
|
||||||
type numericExpressionWrapper struct {
|
|
||||||
expressionInterfaceImpl
|
|
||||||
numericInterfaceImpl
|
|
||||||
|
|
||||||
expression expression
|
|
||||||
}
|
|
||||||
|
|
||||||
func newNumericExpressionWrap(expression expression) numericExpression {
|
|
||||||
numericExpressionWrap := numericExpressionWrapper{}
|
|
||||||
|
|
||||||
numericExpressionWrap.expression = expression
|
|
||||||
|
|
||||||
numericExpressionWrap.expressionInterfaceImpl.parent = &numericExpressionWrap
|
|
||||||
numericExpressionWrap.numericInterfaceImpl.parent = &numericExpressionWrap
|
|
||||||
|
|
||||||
return &numericExpressionWrap
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *numericExpressionWrapper) serialize(statement statementType, out *queryData) error {
|
|
||||||
if n == nil {
|
|
||||||
return errors.New("Numeric expression wrapper is nil. ")
|
|
||||||
}
|
|
||||||
//out.writeString("(")
|
|
||||||
err := n.expression.serialize(statement, out)
|
|
||||||
//out.writeString(")")
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
@ -1,101 +1,203 @@
|
||||||
package sqlbuilder
|
package sqlbuilder
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
//----------- Logical operators ---------------//
|
//----------- Logical operators ---------------//
|
||||||
|
|
||||||
// Returns a representation of "not expr"
|
// Returns a representation of "not expr"
|
||||||
func NOT(expr boolExpression) boolExpression {
|
func NOT(expr BoolExpression) BoolExpression {
|
||||||
return newPrefixBoolExpression(expr, "NOT")
|
return newPrefixBoolExpression(expr, "NOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------- Comparison operators ---------------//
|
//----------- Comparison operators ---------------//
|
||||||
|
|
||||||
// Returns a representation of "a=b"
|
// Returns a representation of "a=b"
|
||||||
func EQ(lhs, rhs expression) boolExpression {
|
func EQ(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, "=")
|
return newBinaryBoolExpression(lhs, rhs, "=")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a representation of "a!=b"
|
// Returns a representation of "a!=b"
|
||||||
func NOT_EQ(lhs, rhs expression) boolExpression {
|
func NOT_EQ(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, "!=")
|
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")
|
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")
|
return newBinaryBoolExpression(lhs, rhs, "IS NOT DISTINCT FROM")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a representation of "a<b"
|
// Returns a representation of "a<b"
|
||||||
func LT(lhs expression, rhs expression) boolExpression {
|
func LT(lhs expression, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, "<")
|
return newBinaryBoolExpression(lhs, rhs, "<")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a representation of "a<=b"
|
// Returns a representation of "a<=b"
|
||||||
func LT_EQ(lhs, rhs expression) boolExpression {
|
func LT_EQ(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, "<=")
|
return newBinaryBoolExpression(lhs, rhs, "<=")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a representation of "a>b"
|
// Returns a representation of "a>b"
|
||||||
func GT(lhs, rhs expression) boolExpression {
|
func GT(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, ">")
|
return newBinaryBoolExpression(lhs, rhs, ">")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a representation of "a>=b"
|
// Returns a representation of "a>=b"
|
||||||
func GT_EQ(lhs, rhs expression) boolExpression {
|
func GT_EQ(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, ">=")
|
return newBinaryBoolExpression(lhs, rhs, ">=")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IS_TRUE(expr boolExpression) boolExpression {
|
func IS_TRUE(expr BoolExpression) BoolExpression {
|
||||||
return newPostifxBoolExpression(expr, "IS TRUE")
|
return newPostifxBoolExpression(expr, "IS TRUE")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IS_NOT_TRUE(expr boolExpression) boolExpression {
|
func IS_NOT_TRUE(expr BoolExpression) BoolExpression {
|
||||||
return newPostifxBoolExpression(expr, "IS NOT TRUE")
|
return newPostifxBoolExpression(expr, "IS NOT TRUE")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IS_FALSE(expr boolExpression) boolExpression {
|
func IS_FALSE(expr BoolExpression) BoolExpression {
|
||||||
return newPostifxBoolExpression(expr, "IS FALSE")
|
return newPostifxBoolExpression(expr, "IS FALSE")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IS_NOT_FALSE(expr boolExpression) boolExpression {
|
func IS_NOT_FALSE(expr BoolExpression) BoolExpression {
|
||||||
return newPostifxBoolExpression(expr, "IS NOT FALSE")
|
return newPostifxBoolExpression(expr, "IS NOT FALSE")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IS_UNKNOWN(expr boolExpression) boolExpression {
|
func IS_UNKNOWN(expr BoolExpression) BoolExpression {
|
||||||
return newPostifxBoolExpression(expr, "IS UNKNOWN")
|
return newPostifxBoolExpression(expr, "IS UNKNOWN")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IS_NOT_UNKNOWN(expr boolExpression) boolExpression {
|
func IS_NOT_UNKNOWN(expr BoolExpression) BoolExpression {
|
||||||
return newPostifxBoolExpression(expr, "IS NOT UNKNOWN")
|
return newPostifxBoolExpression(expr, "IS NOT UNKNOWN")
|
||||||
}
|
}
|
||||||
|
|
||||||
func And(lhs, rhs expression) boolExpression {
|
func And(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, "AND")
|
return newBinaryBoolExpression(lhs, rhs, "AND")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a representation of "c[0] OR ... OR c[n-1]" for c in clauses
|
// 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")
|
return newBinaryBoolExpression(lhs, rhs, "OR")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Like(lhs, rhs expression) boolExpression {
|
func Like(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, "LIKE")
|
return newBinaryBoolExpression(lhs, rhs, "LIKE")
|
||||||
}
|
}
|
||||||
|
|
||||||
func LikeL(lhs expression, val string) boolExpression {
|
func LikeL(lhs expression, val string) BoolExpression {
|
||||||
return Like(lhs, Literal(val))
|
return Like(lhs, Literal(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Regexp(lhs, rhs expression) boolExpression {
|
func Regexp(lhs, rhs expression) BoolExpression {
|
||||||
return newBinaryBoolExpression(lhs, rhs, "REGEXP")
|
return newBinaryBoolExpression(lhs, rhs, "REGEXP")
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegexpL(lhs expression, val string) boolExpression {
|
func RegexpL(lhs expression, val string) BoolExpression {
|
||||||
return Regexp(lhs, Literal(val))
|
return Regexp(lhs, Literal(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
func EXISTS(subQuery selectStatement) boolExpression {
|
func EXISTS(subQuery selectStatement) BoolExpression {
|
||||||
return newPrefixBoolExpression(subQuery, "EXISTS")
|
return newPrefixBoolExpression(subQuery, "EXISTS")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------- CASE operator -------------------//
|
||||||
|
|
||||||
|
type caseOperatorExpression interface {
|
||||||
|
expression
|
||||||
|
|
||||||
|
WHEN(condition expression) caseOperatorExpression
|
||||||
|
THEN(then expression) caseOperatorExpression
|
||||||
|
ELSE(els expression) caseOperatorExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
type caseOperatorImpl struct {
|
||||||
|
expressionInterfaceImpl
|
||||||
|
|
||||||
|
expression expression
|
||||||
|
when []expression
|
||||||
|
then []expression
|
||||||
|
els expression
|
||||||
|
}
|
||||||
|
|
||||||
|
func CASE(expression ...expression) caseOperatorExpression {
|
||||||
|
caseExp := &caseOperatorImpl{}
|
||||||
|
|
||||||
|
if len(expression) == 1 {
|
||||||
|
caseExp.expression = expression[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
caseExp.expressionInterfaceImpl.parent = caseExp
|
||||||
|
|
||||||
|
return caseExp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *caseOperatorImpl) WHEN(when expression) caseOperatorExpression {
|
||||||
|
c.when = append(c.when, when)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *caseOperatorImpl) THEN(then expression) caseOperatorExpression {
|
||||||
|
c.then = append(c.then, then)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *caseOperatorImpl) ELSE(els expression) caseOperatorExpression {
|
||||||
|
c.els = els
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *caseOperatorImpl) serialize(statement statementType, out *queryData) error {
|
||||||
|
if c == nil {
|
||||||
|
return errors.New("Case expression is nil. ")
|
||||||
|
}
|
||||||
|
|
||||||
|
out.writeString("(CASE")
|
||||||
|
|
||||||
|
if c.expression != nil {
|
||||||
|
err := c.expression.serialize(statement, out)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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. ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(c.when) != len(c.then) {
|
||||||
|
return errors.New("When and then expression count mismatch. ")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, when := range c.when {
|
||||||
|
out.writeString("WHEN")
|
||||||
|
err := when.serialize(statement, out)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
out.writeString("THEN")
|
||||||
|
err = c.then[i].serialize(statement, out)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.els != nil {
|
||||||
|
out.writeString("ELSE")
|
||||||
|
err := c.els.serialize(statement, out)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out.writeString("END)")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,9 @@ type selectStatement interface {
|
||||||
|
|
||||||
DISTINCT() selectStatement
|
DISTINCT() selectStatement
|
||||||
FROM(table readableTable) selectStatement
|
FROM(table readableTable) selectStatement
|
||||||
WHERE(expression boolExpression) selectStatement
|
WHERE(expression BoolExpression) selectStatement
|
||||||
GROUP_BY(groupByClauses ...groupByClause) selectStatement
|
GROUP_BY(groupByClauses ...groupByClause) selectStatement
|
||||||
HAVING(boolExpression boolExpression) selectStatement
|
HAVING(boolExpression BoolExpression) selectStatement
|
||||||
ORDER_BY(orderByClauses ...orderByClause) selectStatement
|
ORDER_BY(orderByClauses ...orderByClause) selectStatement
|
||||||
|
|
||||||
LIMIT(limit int64) selectStatement
|
LIMIT(limit int64) selectStatement
|
||||||
|
|
@ -39,9 +39,9 @@ type selectStatementImpl struct {
|
||||||
table readableTable
|
table readableTable
|
||||||
distinct bool
|
distinct bool
|
||||||
projections []projection
|
projections []projection
|
||||||
where boolExpression
|
where BoolExpression
|
||||||
groupBy []groupByClause
|
groupBy []groupByClause
|
||||||
having boolExpression
|
having BoolExpression
|
||||||
orderBy []orderByClause
|
orderBy []orderByClause
|
||||||
|
|
||||||
limit, offset int64
|
limit, offset int64
|
||||||
|
|
@ -217,7 +217,7 @@ func (s *selectStatementImpl) AsTable(alias string) expressionTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selectStatementImpl) WHERE(expression boolExpression) selectStatement {
|
func (s *selectStatementImpl) WHERE(expression BoolExpression) selectStatement {
|
||||||
s.where = expression
|
s.where = expression
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +227,7 @@ func (s *selectStatementImpl) GROUP_BY(groupByClauses ...groupByClause) selectSt
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selectStatementImpl) HAVING(expression boolExpression) selectStatement {
|
func (s *selectStatementImpl) HAVING(expression BoolExpression) selectStatement {
|
||||||
s.having = expression
|
s.having = expression
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
@ -267,6 +267,6 @@ func (s *selectStatementImpl) Execute(db execution.Db) (res sql.Result, err erro
|
||||||
return Execute(s, db)
|
return Execute(s, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NumExp(expression expression) numericExpression {
|
func NumExp(expression expression) FloatExpression {
|
||||||
return newNumericExpressionWrap(expression)
|
return newFloatExpressionWrap(expression)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func (s *StmtSuite) TestSelectSingleColumn(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestSelectMultiColumns(c *gc.C) {
|
func (s *StmtSuite) TestSelectMultiColumns(c *gc.C) {
|
||||||
sql, err := table1.Select(table1Col1, table1Col2).String()
|
sql, err := table1.Select(table1Col1, table1ColFloat).String()
|
||||||
|
|
||||||
c.Assert(err, gc.IsNil)
|
c.Assert(err, gc.IsNil)
|
||||||
c.Assert(
|
c.Assert(
|
||||||
|
|
@ -130,9 +130,9 @@ func (s *StmtSuite) TestSelectLimitWithOffset(c *gc.C) {
|
||||||
func (s *StmtSuite) TestSelectGroupBy(c *gc.C) {
|
func (s *StmtSuite) TestSelectGroupBy(c *gc.C) {
|
||||||
q := table1.Select(
|
q := table1.Select(
|
||||||
table1Col1,
|
table1Col1,
|
||||||
table1Col2,
|
table1ColFloat,
|
||||||
Alias("total", SqlFunc("sum", table1Col3)))
|
Alias("total", SqlFunc("sum", table1Col3)))
|
||||||
q.GroupBy(table1Col1, table1Col2)
|
q.GroupBy(table1Col1, table1ColFloat)
|
||||||
sql, err := q.String()
|
sql, err := q.String()
|
||||||
|
|
||||||
c.Assert(err, gc.IsNil)
|
c.Assert(err, gc.IsNil)
|
||||||
|
|
@ -145,7 +145,7 @@ func (s *StmtSuite) TestSelectGroupBy(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestSelectSingleOrderBy(c *gc.C) {
|
func (s *StmtSuite) TestSelectSingleOrderBy(c *gc.C) {
|
||||||
q := table1.Select(table1Col1, table1Col2).OrderBy(table1Col2)
|
q := table1.Select(table1Col1, table1ColFloat).OrderBy(table1ColFloat)
|
||||||
sql, err := q.String()
|
sql, err := q.String()
|
||||||
|
|
||||||
c.Assert(err, gc.IsNil)
|
c.Assert(err, gc.IsNil)
|
||||||
|
|
@ -157,7 +157,7 @@ func (s *StmtSuite) TestSelectSingleOrderBy(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestSelectOrderByAsc(c *gc.C) {
|
func (s *StmtSuite) TestSelectOrderByAsc(c *gc.C) {
|
||||||
q := table1.Select(table1Col1, table1Col2).OrderBy(ASC(table1Col2))
|
q := table1.Select(table1Col1, table1ColFloat).OrderBy(ASC(table1ColFloat))
|
||||||
sql, err := q.String()
|
sql, err := q.String()
|
||||||
|
|
||||||
c.Assert(err, gc.IsNil)
|
c.Assert(err, gc.IsNil)
|
||||||
|
|
@ -169,7 +169,7 @@ func (s *StmtSuite) TestSelectOrderByAsc(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestSelectOrderByDesc(c *gc.C) {
|
func (s *StmtSuite) TestSelectOrderByDesc(c *gc.C) {
|
||||||
q := table1.Select(table1Col1, table1Col2).OrderBy(DESC(table1Col2))
|
q := table1.Select(table1Col1, table1ColFloat).OrderBy(DESC(table1ColFloat))
|
||||||
sql, err := q.String()
|
sql, err := q.String()
|
||||||
|
|
||||||
c.Assert(err, gc.IsNil)
|
c.Assert(err, gc.IsNil)
|
||||||
|
|
@ -181,8 +181,8 @@ func (s *StmtSuite) TestSelectOrderByDesc(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestSelectMultiOrderBy(c *gc.C) {
|
func (s *StmtSuite) TestSelectMultiOrderBy(c *gc.C) {
|
||||||
q := table1.Select(table1Col1, table1Col2)
|
q := table1.Select(table1Col1, table1ColFloat)
|
||||||
q.OrderBy(table1Col2, table1Col1)
|
q.OrderBy(table1ColFloat, table1Col1)
|
||||||
sql, err := q.String()
|
sql, err := q.String()
|
||||||
|
|
||||||
c.Assert(err, gc.IsNil)
|
c.Assert(err, gc.IsNil)
|
||||||
|
|
@ -249,7 +249,7 @@ func (s *StmtSuite) TestInsertNoRow(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestInsertColumnLengthMismatch(c *gc.C) {
|
func (s *StmtSuite) TestInsertColumnLengthMismatch(c *gc.C) {
|
||||||
_, err := table1.INSERT(table1Col1, table1Col2).Add(nil).String()
|
_, err := table1.INSERT(table1Col1, table1ColFloat).Add(nil).String()
|
||||||
|
|
||||||
c.Assert(err, gc.NotNil)
|
c.Assert(err, gc.NotNil)
|
||||||
}
|
}
|
||||||
|
|
@ -301,7 +301,7 @@ func (s *StmtSuite) TestInsertIgnore(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestInsertMultipleValues(c *gc.C) {
|
func (s *StmtSuite) TestInsertMultipleValues(c *gc.C) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2, table1Col3)
|
stmt := table1.INSERT(table1Col1, table1ColFloat, table1Col3)
|
||||||
stmt.Add(Literal(1), Literal(2), Literal(3))
|
stmt.Add(Literal(1), Literal(2), Literal(3))
|
||||||
|
|
||||||
sql, err := stmt.String()
|
sql, err := stmt.String()
|
||||||
|
|
@ -316,7 +316,7 @@ func (s *StmtSuite) TestInsertMultipleValues(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestInsertMultipleRows(c *gc.C) {
|
func (s *StmtSuite) TestInsertMultipleRows(c *gc.C) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2)
|
stmt := table1.INSERT(table1Col1, table1ColFloat)
|
||||||
stmt.Add(Literal(1), Literal(2))
|
stmt.Add(Literal(1), Literal(2))
|
||||||
stmt.Add(Literal(11), Literal(22))
|
stmt.Add(Literal(11), Literal(22))
|
||||||
stmt.Add(Literal(111), Literal(222))
|
stmt.Add(Literal(111), Literal(222))
|
||||||
|
|
@ -333,7 +333,7 @@ func (s *StmtSuite) TestInsertMultipleRows(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestOnDuplicateKeyUpdateNilCol(c *gc.C) {
|
func (s *StmtSuite) TestOnDuplicateKeyUpdateNilCol(c *gc.C) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2)
|
stmt := table1.INSERT(table1Col1, table1ColFloat)
|
||||||
stmt.Add(Literal(1), Literal(2))
|
stmt.Add(Literal(1), Literal(2))
|
||||||
stmt.AddOnDuplicateKeyUpdate(nil, Literal(3))
|
stmt.AddOnDuplicateKeyUpdate(nil, Literal(3))
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ func (s *StmtSuite) TestOnDuplicateKeyUpdateNilCol(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestOnDuplicateKeyUpdateNilExpr(c *gc.C) {
|
func (s *StmtSuite) TestOnDuplicateKeyUpdateNilExpr(c *gc.C) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2)
|
stmt := table1.INSERT(table1Col1, table1ColFloat)
|
||||||
stmt.Add(Literal(1), Literal(2))
|
stmt.Add(Literal(1), Literal(2))
|
||||||
stmt.AddOnDuplicateKeyUpdate(table1Col1, nil)
|
stmt.AddOnDuplicateKeyUpdate(table1Col1, nil)
|
||||||
|
|
||||||
|
|
@ -351,7 +351,7 @@ func (s *StmtSuite) TestOnDuplicateKeyUpdateNilExpr(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestOnDuplicateKeyUpdateSingle(c *gc.C) {
|
func (s *StmtSuite) TestOnDuplicateKeyUpdateSingle(c *gc.C) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2)
|
stmt := table1.INSERT(table1Col1, table1ColFloat)
|
||||||
stmt.Add(Literal(1), Literal(2))
|
stmt.Add(Literal(1), Literal(2))
|
||||||
stmt.AddOnDuplicateKeyUpdate(table1Col3, Literal(3))
|
stmt.AddOnDuplicateKeyUpdate(table1Col3, Literal(3))
|
||||||
|
|
||||||
|
|
@ -368,10 +368,10 @@ func (s *StmtSuite) TestOnDuplicateKeyUpdateSingle(c *gc.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StmtSuite) TestOnDuplicateKeyUpdateMulti(c *gc.C) {
|
func (s *StmtSuite) TestOnDuplicateKeyUpdateMulti(c *gc.C) {
|
||||||
stmt := table1.INSERT(table1Col1, table1Col2)
|
stmt := table1.INSERT(table1Col1, table1ColFloat)
|
||||||
stmt.Add(Literal(1), Literal(2))
|
stmt.Add(Literal(1), Literal(2))
|
||||||
stmt.AddOnDuplicateKeyUpdate(table1Col3, Literal(3))
|
stmt.AddOnDuplicateKeyUpdate(table1Col3, Literal(3))
|
||||||
stmt.AddOnDuplicateKeyUpdate(table1Col2, Literal(4))
|
stmt.AddOnDuplicateKeyUpdate(table1ColFloat, Literal(4))
|
||||||
|
|
||||||
sql, err := stmt.String()
|
sql, err := stmt.String()
|
||||||
c.Assert(err, gc.IsNil)
|
c.Assert(err, gc.IsNil)
|
||||||
|
|
@ -431,7 +431,7 @@ func (s *StmtSuite) TestUnionLimitWithoutOrderBy(c *gc.C) {
|
||||||
select_queries := make([]selectStatement, 0, 3)
|
select_queries := make([]selectStatement, 0, 3)
|
||||||
|
|
||||||
select_queries = append(select_queries,
|
select_queries = append(select_queries,
|
||||||
table1.Select(table1Col1).Where(GtL(table1Col1, 123)).OrderBy(table1Col2),
|
table1.Select(table1Col1).Where(GtL(table1Col1, 123)).OrderBy(table1ColFloat),
|
||||||
table1.Select(table1Col1).Where(GtL(table1Col1, 456)),
|
table1.Select(table1Col1).Where(GtL(table1Col1, 456)),
|
||||||
table1.Select(table1Col1).Where(LtL(table1Col1, 23)),
|
table1.Select(table1Col1).Where(LtL(table1Col1, 23)),
|
||||||
)
|
)
|
||||||
|
|
@ -454,7 +454,7 @@ func (s *StmtSuite) TestUnionSelectWithMismatchedColumns(c *gc.C) {
|
||||||
|
|
||||||
table1.Select(
|
table1.Select(
|
||||||
table1Col1,
|
table1Col1,
|
||||||
table1Col2,
|
table1ColFloat,
|
||||||
table1Col3,
|
table1Col3,
|
||||||
table1ColTime).AndWhere(GtL(table1Col1, 123)).AndWhere(LtL(table1Col1, 321)),
|
table1ColTime).AndWhere(GtL(table1Col1, 123)).AndWhere(LtL(table1Col1, 321)),
|
||||||
table1.Select(table1Col1).Where(And(GtL(table1Col1, 123), LtL(table1Col1, 321))),
|
table1.Select(table1Col1).Where(And(GtL(table1Col1, 123), LtL(table1Col1, 321))),
|
||||||
|
|
|
||||||
|
|
@ -3,49 +3,49 @@ package sqlbuilder
|
||||||
type stringExpression interface {
|
type stringExpression interface {
|
||||||
expression
|
expression
|
||||||
|
|
||||||
EQ(rhs stringExpression) boolExpression
|
EQ(rhs stringExpression) BoolExpression
|
||||||
NOT_EQ(rhs stringExpression) boolExpression
|
NOT_EQ(rhs stringExpression) BoolExpression
|
||||||
IS_DISTINCT_FROM(rhs stringExpression) boolExpression
|
IS_DISTINCT_FROM(rhs stringExpression) BoolExpression
|
||||||
IS_NOT_DISTINCT_FROM(rhs stringExpression) boolExpression
|
IS_NOT_DISTINCT_FROM(rhs stringExpression) BoolExpression
|
||||||
|
|
||||||
LT(rhs stringExpression) boolExpression
|
LT(rhs stringExpression) BoolExpression
|
||||||
LT_EQ(rhs stringExpression) boolExpression
|
LT_EQ(rhs stringExpression) BoolExpression
|
||||||
GT(rhs stringExpression) boolExpression
|
GT(rhs stringExpression) BoolExpression
|
||||||
GT_EQ(rhs stringExpression) boolExpression
|
GT_EQ(rhs stringExpression) BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type stringInterfaceImpl struct {
|
type stringInterfaceImpl struct {
|
||||||
parent stringExpression
|
parent stringExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) EQ(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) EQ(rhs stringExpression) BoolExpression {
|
||||||
return EQ(s.parent, rhs)
|
return EQ(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) NOT_EQ(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) NOT_EQ(rhs stringExpression) BoolExpression {
|
||||||
return NOT_EQ(s.parent, rhs)
|
return NOT_EQ(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) IS_DISTINCT_FROM(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) IS_DISTINCT_FROM(rhs stringExpression) BoolExpression {
|
||||||
return IS_DISTINCT_FROM(s.parent, rhs)
|
return IS_DISTINCT_FROM(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs stringExpression) BoolExpression {
|
||||||
return IS_NOT_DISTINCT_FROM(s.parent, rhs)
|
return IS_NOT_DISTINCT_FROM(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) GT(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) GT(rhs stringExpression) BoolExpression {
|
||||||
return GT(s.parent, rhs)
|
return GT(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) GT_EQ(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) GT_EQ(rhs stringExpression) BoolExpression {
|
||||||
return GT_EQ(s.parent, rhs)
|
return GT_EQ(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) LT(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) LT(rhs stringExpression) BoolExpression {
|
||||||
return LT(s.parent, rhs)
|
return LT(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringInterfaceImpl) LT_EQ(rhs stringExpression) boolExpression {
|
func (s *stringInterfaceImpl) LT_EQ(rhs stringExpression) BoolExpression {
|
||||||
return LT_EQ(s.parent, rhs)
|
return LT_EQ(s.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@ type readableTable interface {
|
||||||
SELECT(projections ...projection) selectStatement
|
SELECT(projections ...projection) selectStatement
|
||||||
|
|
||||||
// Creates a inner join tableName expression using onCondition.
|
// Creates a inner join tableName expression using onCondition.
|
||||||
INNER_JOIN(table readableTable, onCondition boolExpression) readableTable
|
INNER_JOIN(table readableTable, onCondition BoolExpression) readableTable
|
||||||
|
|
||||||
// Creates a left join tableName expression using onCondition.
|
// Creates a left join tableName expression using onCondition.
|
||||||
LEFT_JOIN(table readableTable, onCondition boolExpression) readableTable
|
LEFT_JOIN(table readableTable, onCondition BoolExpression) readableTable
|
||||||
|
|
||||||
// Creates a right join tableName expression using onCondition.
|
// Creates a right join tableName expression using onCondition.
|
||||||
RIGHT_JOIN(table readableTable, onCondition boolExpression) readableTable
|
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
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ func (t *Table) SELECT(projections ...projection) selectStatement {
|
||||||
// Creates a inner join tableName expression using onCondition.
|
// Creates a inner join tableName expression using onCondition.
|
||||||
func (t *Table) INNER_JOIN(
|
func (t *Table) INNER_JOIN(
|
||||||
table readableTable,
|
table readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return InnerJoinOn(t, table, onCondition)
|
return InnerJoinOn(t, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +140,7 @@ func (t *Table) INNER_JOIN(
|
||||||
// Creates a left join tableName expression using onCondition.
|
// Creates a left join tableName expression using onCondition.
|
||||||
func (t *Table) LEFT_JOIN(
|
func (t *Table) LEFT_JOIN(
|
||||||
table readableTable,
|
table readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return LeftJoinOn(t, table, onCondition)
|
return LeftJoinOn(t, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
@ -148,12 +148,12 @@ func (t *Table) LEFT_JOIN(
|
||||||
// Creates a right join tableName expression using onCondition.
|
// Creates a right join tableName expression using onCondition.
|
||||||
func (t *Table) RIGHT_JOIN(
|
func (t *Table) RIGHT_JOIN(
|
||||||
table readableTable,
|
table readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return RightJoinOn(t, table, onCondition)
|
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)
|
return FullJoin(t, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,14 +192,14 @@ type joinTable struct {
|
||||||
lhs readableTable
|
lhs readableTable
|
||||||
rhs readableTable
|
rhs readableTable
|
||||||
join_type joinType
|
join_type joinType
|
||||||
onCondition boolExpression
|
onCondition BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func newJoinTable(
|
func newJoinTable(
|
||||||
lhs readableTable,
|
lhs readableTable,
|
||||||
rhs readableTable,
|
rhs readableTable,
|
||||||
join_type joinType,
|
join_type joinType,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return &joinTable{
|
return &joinTable{
|
||||||
lhs: lhs,
|
lhs: lhs,
|
||||||
|
|
@ -212,7 +212,7 @@ func newJoinTable(
|
||||||
func InnerJoinOn(
|
func InnerJoinOn(
|
||||||
lhs readableTable,
|
lhs readableTable,
|
||||||
rhs readableTable,
|
rhs readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return newJoinTable(lhs, rhs, INNER_JOIN, onCondition)
|
return newJoinTable(lhs, rhs, INNER_JOIN, onCondition)
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +220,7 @@ func InnerJoinOn(
|
||||||
func LeftJoinOn(
|
func LeftJoinOn(
|
||||||
lhs readableTable,
|
lhs readableTable,
|
||||||
rhs readableTable,
|
rhs readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return newJoinTable(lhs, rhs, LEFT_JOIN, onCondition)
|
return newJoinTable(lhs, rhs, LEFT_JOIN, onCondition)
|
||||||
}
|
}
|
||||||
|
|
@ -228,7 +228,7 @@ func LeftJoinOn(
|
||||||
func RightJoinOn(
|
func RightJoinOn(
|
||||||
lhs readableTable,
|
lhs readableTable,
|
||||||
rhs readableTable,
|
rhs readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return newJoinTable(lhs, rhs, RIGHT_JOIN, onCondition)
|
return newJoinTable(lhs, rhs, RIGHT_JOIN, onCondition)
|
||||||
}
|
}
|
||||||
|
|
@ -236,7 +236,7 @@ func RightJoinOn(
|
||||||
func FullJoin(
|
func FullJoin(
|
||||||
lhs readableTable,
|
lhs readableTable,
|
||||||
rhs readableTable,
|
rhs readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return newJoinTable(lhs, rhs, FULL_JOIN, onCondition)
|
return newJoinTable(lhs, rhs, FULL_JOIN, onCondition)
|
||||||
}
|
}
|
||||||
|
|
@ -324,19 +324,19 @@ func (t *joinTable) SELECT(projections ...projection) selectStatement {
|
||||||
|
|
||||||
func (t *joinTable) INNER_JOIN(
|
func (t *joinTable) INNER_JOIN(
|
||||||
table readableTable,
|
table readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return InnerJoinOn(t, table, onCondition)
|
return InnerJoinOn(t, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *joinTable) LEFT_JOIN(
|
func (t *joinTable) LEFT_JOIN(
|
||||||
table readableTable,
|
table readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return LeftJoinOn(t, table, onCondition)
|
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)
|
return FullJoin(t, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,7 +346,7 @@ func (t *joinTable) CROSS_JOIN(table readableTable) readableTable {
|
||||||
|
|
||||||
func (t *joinTable) RIGHT_JOIN(
|
func (t *joinTable) RIGHT_JOIN(
|
||||||
table readableTable,
|
table readableTable,
|
||||||
onCondition boolExpression) readableTable {
|
onCondition BoolExpression) readableTable {
|
||||||
|
|
||||||
return RightJoinOn(t, table, onCondition)
|
return RightJoinOn(t, table, onCondition)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func (s *TableSuite) TestBasicColumns(c *gc.C) {
|
||||||
|
|
||||||
c.Assert(len(cols), gc.Equals, 4)
|
c.Assert(len(cols), gc.Equals, 4)
|
||||||
c.Assert(cols[0], gc.Equals, table1Col1)
|
c.Assert(cols[0], gc.Equals, table1Col1)
|
||||||
c.Assert(cols[1], gc.Equals, table1Col2)
|
c.Assert(cols[1], gc.Equals, table1ColFloat)
|
||||||
c.Assert(cols[2], gc.Equals, table1Col3)
|
c.Assert(cols[2], gc.Equals, table1Col3)
|
||||||
c.Assert(cols[3], gc.Equals, table1ColTime)
|
c.Assert(cols[3], gc.Equals, table1ColTime)
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +126,7 @@ func (s *TableSuite) TestRightJoin(c *gc.C) {
|
||||||
// cols := join.Columns()
|
// cols := join.Columns()
|
||||||
// c.Assert(len(cols), gc.Equals, 6)
|
// c.Assert(len(cols), gc.Equals, 6)
|
||||||
// c.Assert(cols[0], gc.Equals, table1Col1)
|
// c.Assert(cols[0], gc.Equals, table1Col1)
|
||||||
// c.Assert(cols[1], gc.Equals, table1Col2)
|
// c.Assert(cols[1], gc.Equals, table1ColFloat)
|
||||||
// c.Assert(cols[2], gc.Equals, table1Col3)
|
// c.Assert(cols[2], gc.Equals, table1Col3)
|
||||||
// c.Assert(cols[3], gc.Equals, table1ColTime)
|
// c.Assert(cols[3], gc.Equals, table1ColTime)
|
||||||
// c.Assert(cols[4], gc.Equals, table2Col3)
|
// c.Assert(cols[4], gc.Equals, table2Col3)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var table1Col1 = NewIntegerColumn("col1", Nullable)
|
var table1Col1 = NewIntegerColumn("col1", Nullable)
|
||||||
var table1Col2 = NewIntegerColumn("col2", Nullable)
|
var table1ColFloat = NewFloatColumn("colFloat", Nullable)
|
||||||
var table1Col3 = NewIntegerColumn("col3", Nullable)
|
var table1Col3 = NewIntegerColumn("col3", Nullable)
|
||||||
var table1ColTime = NewTimeColumn("colTime", Nullable)
|
var table1ColTime = NewTimeColumn("colTime", Nullable)
|
||||||
var table1ColBool = NewBoolColumn("colBool", Nullable)
|
var table1ColBool = NewBoolColumn("colBool", Nullable)
|
||||||
|
|
@ -15,7 +15,7 @@ var table1 = NewTable(
|
||||||
"db",
|
"db",
|
||||||
"table1",
|
"table1",
|
||||||
table1Col1,
|
table1Col1,
|
||||||
table1Col2,
|
table1ColFloat,
|
||||||
table1Col3,
|
table1Col3,
|
||||||
table1ColTime,
|
table1ColTime,
|
||||||
table1ColBool)
|
table1ColBool)
|
||||||
|
|
|
||||||
|
|
@ -3,50 +3,50 @@ package sqlbuilder
|
||||||
type timeExpression interface {
|
type timeExpression interface {
|
||||||
expression
|
expression
|
||||||
|
|
||||||
EQ(rhs timeExpression) boolExpression
|
EQ(rhs timeExpression) BoolExpression
|
||||||
NOT_EQ(rhs timeExpression) boolExpression
|
NOT_EQ(rhs timeExpression) BoolExpression
|
||||||
IS_DISTINCT_FROM(rhs timeExpression) boolExpression
|
IS_DISTINCT_FROM(rhs timeExpression) BoolExpression
|
||||||
IS_NOT_DISTINCT_FROM(rhs timeExpression) boolExpression
|
IS_NOT_DISTINCT_FROM(rhs timeExpression) BoolExpression
|
||||||
|
|
||||||
LT(rhs timeExpression) boolExpression
|
LT(rhs timeExpression) BoolExpression
|
||||||
LT_EQ(rhs timeExpression) boolExpression
|
LT_EQ(rhs timeExpression) BoolExpression
|
||||||
GT(rhs timeExpression) boolExpression
|
GT(rhs timeExpression) BoolExpression
|
||||||
GT_EQ(rhs timeExpression) boolExpression
|
GT_EQ(rhs timeExpression) BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type timeInterfaceImpl struct {
|
type timeInterfaceImpl struct {
|
||||||
parent timeExpression
|
parent timeExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) EQ(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) EQ(rhs timeExpression) BoolExpression {
|
||||||
return EQ(t.parent, rhs)
|
return EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) NOT_EQ(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) NOT_EQ(rhs timeExpression) BoolExpression {
|
||||||
return NOT_EQ(t.parent, rhs)
|
return NOT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) IS_DISTINCT_FROM(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) IS_DISTINCT_FROM(rhs timeExpression) BoolExpression {
|
||||||
return IS_DISTINCT_FROM(t.parent, rhs)
|
return IS_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs timeExpression) BoolExpression {
|
||||||
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) LT(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) LT(rhs timeExpression) BoolExpression {
|
||||||
return LT(t.parent, rhs)
|
return LT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) LT_EQ(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) LT_EQ(rhs timeExpression) BoolExpression {
|
||||||
return LT_EQ(t.parent, rhs)
|
return LT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) GT(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) GT(rhs timeExpression) BoolExpression {
|
||||||
return GT(t.parent, rhs)
|
return GT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timeInterfaceImpl) GT_EQ(rhs timeExpression) boolExpression {
|
func (t *timeInterfaceImpl) GT_EQ(rhs timeExpression) BoolExpression {
|
||||||
return GT_EQ(t.parent, rhs)
|
return GT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,49 +3,49 @@ package sqlbuilder
|
||||||
type TimestampExpression interface {
|
type TimestampExpression interface {
|
||||||
expression
|
expression
|
||||||
|
|
||||||
EQ(rhs TimestampExpression) boolExpression
|
EQ(rhs TimestampExpression) BoolExpression
|
||||||
NOT_EQ(rhs TimestampExpression) boolExpression
|
NOT_EQ(rhs TimestampExpression) BoolExpression
|
||||||
IS_DISTINCT_FROM(rhs TimestampExpression) boolExpression
|
IS_DISTINCT_FROM(rhs TimestampExpression) BoolExpression
|
||||||
IS_NOT_DISTINCT_FROM(rhs TimestampExpression) boolExpression
|
IS_NOT_DISTINCT_FROM(rhs TimestampExpression) BoolExpression
|
||||||
|
|
||||||
LT(rhs TimestampExpression) boolExpression
|
LT(rhs TimestampExpression) BoolExpression
|
||||||
LT_EQ(rhs TimestampExpression) boolExpression
|
LT_EQ(rhs TimestampExpression) BoolExpression
|
||||||
GT(rhs TimestampExpression) boolExpression
|
GT(rhs TimestampExpression) BoolExpression
|
||||||
GT_EQ(rhs TimestampExpression) boolExpression
|
GT_EQ(rhs TimestampExpression) BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type timestampInterfaceImpl struct {
|
type timestampInterfaceImpl struct {
|
||||||
parent TimestampExpression
|
parent TimestampExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) EQ(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) EQ(rhs TimestampExpression) BoolExpression {
|
||||||
return EQ(t.parent, rhs)
|
return EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) NOT_EQ(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) NOT_EQ(rhs TimestampExpression) BoolExpression {
|
||||||
return NOT_EQ(t.parent, rhs)
|
return NOT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) IS_DISTINCT_FROM(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) IS_DISTINCT_FROM(rhs TimestampExpression) BoolExpression {
|
||||||
return IS_DISTINCT_FROM(t.parent, rhs)
|
return IS_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs TimestampExpression) BoolExpression {
|
||||||
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) LT(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) LT(rhs TimestampExpression) BoolExpression {
|
||||||
return LT(t.parent, rhs)
|
return LT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) LT_EQ(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) LT_EQ(rhs TimestampExpression) BoolExpression {
|
||||||
return LT_EQ(t.parent, rhs)
|
return LT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) GT(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) GT(rhs TimestampExpression) BoolExpression {
|
||||||
return GT(t.parent, rhs)
|
return GT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampInterfaceImpl) GT_EQ(rhs TimestampExpression) boolExpression {
|
func (t *timestampInterfaceImpl) GT_EQ(rhs TimestampExpression) BoolExpression {
|
||||||
return GT_EQ(t.parent, rhs)
|
return GT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,49 +3,49 @@ package sqlbuilder
|
||||||
type TimestampzExpression interface {
|
type TimestampzExpression interface {
|
||||||
expression
|
expression
|
||||||
|
|
||||||
EQ(rhs TimestampzExpression) boolExpression
|
EQ(rhs TimestampzExpression) BoolExpression
|
||||||
NOT_EQ(rhs TimestampzExpression) boolExpression
|
NOT_EQ(rhs TimestampzExpression) BoolExpression
|
||||||
IS_DISTINCT_FROM(rhs TimestampzExpression) boolExpression
|
IS_DISTINCT_FROM(rhs TimestampzExpression) BoolExpression
|
||||||
IS_NOT_DISTINCT_FROM(rhs TimestampzExpression) boolExpression
|
IS_NOT_DISTINCT_FROM(rhs TimestampzExpression) BoolExpression
|
||||||
|
|
||||||
LT(rhs TimestampzExpression) boolExpression
|
LT(rhs TimestampzExpression) BoolExpression
|
||||||
LT_EQ(rhs TimestampzExpression) boolExpression
|
LT_EQ(rhs TimestampzExpression) BoolExpression
|
||||||
GT(rhs TimestampzExpression) boolExpression
|
GT(rhs TimestampzExpression) BoolExpression
|
||||||
GT_EQ(rhs TimestampzExpression) boolExpression
|
GT_EQ(rhs TimestampzExpression) BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type timestampzInterfaceImpl struct {
|
type timestampzInterfaceImpl struct {
|
||||||
parent TimestampzExpression
|
parent TimestampzExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) EQ(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) EQ(rhs TimestampzExpression) BoolExpression {
|
||||||
return EQ(t.parent, rhs)
|
return EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) NOT_EQ(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) NOT_EQ(rhs TimestampzExpression) BoolExpression {
|
||||||
return NOT_EQ(t.parent, rhs)
|
return NOT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) IS_DISTINCT_FROM(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) IS_DISTINCT_FROM(rhs TimestampzExpression) BoolExpression {
|
||||||
return IS_DISTINCT_FROM(t.parent, rhs)
|
return IS_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs TimestampzExpression) BoolExpression {
|
||||||
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) LT(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) LT(rhs TimestampzExpression) BoolExpression {
|
||||||
return LT(t.parent, rhs)
|
return LT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) LT_EQ(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) LT_EQ(rhs TimestampzExpression) BoolExpression {
|
||||||
return LT_EQ(t.parent, rhs)
|
return LT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) GT(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) GT(rhs TimestampzExpression) BoolExpression {
|
||||||
return GT(t.parent, rhs)
|
return GT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timestampzInterfaceImpl) GT_EQ(rhs TimestampzExpression) boolExpression {
|
func (t *timestampzInterfaceImpl) GT_EQ(rhs TimestampzExpression) BoolExpression {
|
||||||
return GT_EQ(t.parent, rhs)
|
return GT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,50 +3,50 @@ package sqlbuilder
|
||||||
type timezExpression interface {
|
type timezExpression interface {
|
||||||
expression
|
expression
|
||||||
|
|
||||||
EQ(rhs timezExpression) boolExpression
|
EQ(rhs timezExpression) BoolExpression
|
||||||
NOT_EQ(rhs timezExpression) boolExpression
|
NOT_EQ(rhs timezExpression) BoolExpression
|
||||||
IS_DISTINCT_FROM(rhs timezExpression) boolExpression
|
IS_DISTINCT_FROM(rhs timezExpression) BoolExpression
|
||||||
IS_NOT_DISTINCT_FROM(rhs timezExpression) boolExpression
|
IS_NOT_DISTINCT_FROM(rhs timezExpression) BoolExpression
|
||||||
|
|
||||||
LT(rhs timezExpression) boolExpression
|
LT(rhs timezExpression) BoolExpression
|
||||||
LT_EQ(rhs timezExpression) boolExpression
|
LT_EQ(rhs timezExpression) BoolExpression
|
||||||
GT(rhs timezExpression) boolExpression
|
GT(rhs timezExpression) BoolExpression
|
||||||
GT_EQ(rhs timezExpression) boolExpression
|
GT_EQ(rhs timezExpression) BoolExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
type timezInterfaceImpl struct {
|
type timezInterfaceImpl struct {
|
||||||
parent timezExpression
|
parent timezExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) EQ(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) EQ(rhs timezExpression) BoolExpression {
|
||||||
return EQ(t.parent, rhs)
|
return EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) NOT_EQ(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) NOT_EQ(rhs timezExpression) BoolExpression {
|
||||||
return NOT_EQ(t.parent, rhs)
|
return NOT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) IS_DISTINCT_FROM(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) IS_DISTINCT_FROM(rhs timezExpression) BoolExpression {
|
||||||
return IS_DISTINCT_FROM(t.parent, rhs)
|
return IS_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs timezExpression) BoolExpression {
|
||||||
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
return IS_NOT_DISTINCT_FROM(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) LT(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) LT(rhs timezExpression) BoolExpression {
|
||||||
return LT(t.parent, rhs)
|
return LT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) LT_EQ(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) LT_EQ(rhs timezExpression) BoolExpression {
|
||||||
return LT_EQ(t.parent, rhs)
|
return LT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) GT(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) GT(rhs timezExpression) BoolExpression {
|
||||||
return GT(t.parent, rhs)
|
return GT(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *timezInterfaceImpl) GT_EQ(rhs timezExpression) boolExpression {
|
func (t *timezInterfaceImpl) GT_EQ(rhs timezExpression) BoolExpression {
|
||||||
return GT_EQ(t.parent, rhs)
|
return GT_EQ(t.parent, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ type updateStatement interface {
|
||||||
Statement
|
Statement
|
||||||
|
|
||||||
SET(values ...interface{}) updateStatement
|
SET(values ...interface{}) updateStatement
|
||||||
WHERE(expression boolExpression) updateStatement
|
WHERE(expression BoolExpression) updateStatement
|
||||||
RETURNING(projections ...projection) updateStatement
|
RETURNING(projections ...projection) updateStatement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ type updateStatementImpl struct {
|
||||||
table writableTable
|
table writableTable
|
||||||
columns []column
|
columns []column
|
||||||
updateValues []clause
|
updateValues []clause
|
||||||
where boolExpression
|
where BoolExpression
|
||||||
returning []projection
|
returning []projection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ func (u *updateStatementImpl) SET(values ...interface{}) updateStatement {
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *updateStatementImpl) WHERE(expression boolExpression) updateStatement {
|
func (u *updateStatementImpl) WHERE(expression BoolExpression) updateStatement {
|
||||||
u.where = expression
|
u.where = expression
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ import (
|
||||||
//
|
//
|
||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
stmt := table1.UPDATE(table1Col1, table1Col2).
|
stmt := table1.UPDATE(table1Col1, table1ColFloat).
|
||||||
SET(table1.SELECT(table1Col2, table2Col3)).
|
SET(table1.SELECT(table1ColFloat, table2Col3)).
|
||||||
WHERE(table1Col1.EQ(Int(2))).
|
WHERE(table1Col1.EQ(Int(2))).
|
||||||
RETURNING(table1Col1)
|
RETURNING(table1Col1)
|
||||||
|
|
||||||
|
|
@ -23,8 +23,8 @@ func TestUpdate(t *testing.T) {
|
||||||
fmt.Println(stmtStr)
|
fmt.Println(stmtStr)
|
||||||
|
|
||||||
assert.Equal(t, stmtStr, `
|
assert.Equal(t, stmtStr, `
|
||||||
UPDATE db.table1 SET (col1,col2) = (
|
UPDATE db.table1 SET (col1,colFloat) = (
|
||||||
SELECT table1.col2 AS "table1.col2",
|
SELECT table1.colFloat AS "table1.colFloat",
|
||||||
table2.col3 AS "table2.col3"
|
table2.col3 AS "table2.col3"
|
||||||
FROM db.table1
|
FROM db.table1
|
||||||
)
|
)
|
||||||
|
|
@ -53,7 +53,7 @@ RETURNING table1.col1 AS "table1.col1";
|
||||||
//
|
//
|
||||||
//func (s *StmtSuite) TestUpdateSingleValue(c *gc.C) {
|
//func (s *StmtSuite) TestUpdateSingleValue(c *gc.C) {
|
||||||
// stmt := table1.UPDATE().SET(table1Col1, Literal(1))
|
// stmt := table1.UPDATE().SET(table1Col1, Literal(1))
|
||||||
// stmt.WHERE(EqString(table1Col2, 2))
|
// stmt.WHERE(EqString(table1ColFloat, 2))
|
||||||
// sql, err := stmt.String()
|
// sql, err := stmt.String()
|
||||||
// c.Assert(err, gc.IsNil)
|
// c.Assert(err, gc.IsNil)
|
||||||
//
|
//
|
||||||
|
|
@ -65,7 +65,7 @@ RETURNING table1.col1 AS "table1.col1";
|
||||||
//
|
//
|
||||||
//func (s *StmtSuite) TestUpdateUsingDeferredLookupColumns(c *gc.C) {
|
//func (s *StmtSuite) TestUpdateUsingDeferredLookupColumns(c *gc.C) {
|
||||||
// stmt := table1.UPDATE().SET(table1.C("col1"), Literal(1))
|
// stmt := table1.UPDATE().SET(table1.C("col1"), Literal(1))
|
||||||
// stmt.WHERE(EqString(table1Col2, 2))
|
// stmt.WHERE(EqString(table1ColFloat, 2))
|
||||||
// sql, err := stmt.String()
|
// sql, err := stmt.String()
|
||||||
// c.Assert(err, gc.IsNil)
|
// c.Assert(err, gc.IsNil)
|
||||||
//
|
//
|
||||||
|
|
@ -78,8 +78,8 @@ RETURNING table1.col1 AS "table1.col1";
|
||||||
//func (s *StmtSuite) TestUpdateMultiValues(c *gc.C) {
|
//func (s *StmtSuite) TestUpdateMultiValues(c *gc.C) {
|
||||||
// stmt := table1.UPDATE()
|
// stmt := table1.UPDATE()
|
||||||
// stmt.SET(table1Col1, Literal(1))
|
// stmt.SET(table1Col1, Literal(1))
|
||||||
// stmt.SET(table1Col2, Literal(2))
|
// stmt.SET(table1ColFloat, Literal(2))
|
||||||
// stmt.WHERE(EqString(table1Col2, 3))
|
// stmt.WHERE(EqString(table1ColFloat, 3))
|
||||||
// sql, err := stmt.String()
|
// sql, err := stmt.String()
|
||||||
// c.Assert(err, gc.IsNil)
|
// c.Assert(err, gc.IsNil)
|
||||||
//
|
//
|
||||||
|
|
@ -93,8 +93,8 @@ RETURNING table1.col1 AS "table1.col1";
|
||||||
//
|
//
|
||||||
//func (s *StmtSuite) TestUpdateWithOrderBy(c *gc.C) {
|
//func (s *StmtSuite) TestUpdateWithOrderBy(c *gc.C) {
|
||||||
// stmt := table1.UPDATE().SET(table1Col1, Literal(1))
|
// stmt := table1.UPDATE().SET(table1Col1, Literal(1))
|
||||||
// stmt.WHERE(EqString(table1Col2, 2))
|
// stmt.WHERE(EqString(table1ColFloat, 2))
|
||||||
// stmt.ORDER_BY(table1Col2)
|
// stmt.ORDER_BY(table1ColFloat)
|
||||||
// sql, err := stmt.String()
|
// sql, err := stmt.String()
|
||||||
// c.Assert(err, gc.IsNil)
|
// c.Assert(err, gc.IsNil)
|
||||||
//
|
//
|
||||||
|
|
@ -109,7 +109,7 @@ RETURNING table1.col1 AS "table1.col1";
|
||||||
//
|
//
|
||||||
//func (s *StmtSuite) TestUpdateWithLimit(c *gc.C) {
|
//func (s *StmtSuite) TestUpdateWithLimit(c *gc.C) {
|
||||||
// stmt := table1.UPDATE().SET(table1Col1, Literal(1))
|
// stmt := table1.UPDATE().SET(table1Col1, Literal(1))
|
||||||
// stmt.WHERE(EqString(table1Col2, 2))
|
// stmt.WHERE(EqString(table1ColFloat, 2))
|
||||||
// stmt.LIMIT(5)
|
// stmt.LIMIT(5)
|
||||||
// sql, err := stmt.String()
|
// sql, err := stmt.String()
|
||||||
// c.Assert(err, gc.IsNil)
|
// c.Assert(err, gc.IsNil)
|
||||||
|
|
|
||||||
|
|
@ -612,7 +612,7 @@ LIMIT 1000;
|
||||||
f1 := Film.AS("f1")
|
f1 := Film.AS("f1")
|
||||||
f2 := Film.AS("f2")
|
f2 := Film.AS("f2")
|
||||||
|
|
||||||
f1.FilmID.EQ(Float(11))
|
f1.FilmID.EQ(Int(11))
|
||||||
|
|
||||||
query := f1.
|
query := f1.
|
||||||
INNER_JOIN(f2, f1.FilmID.NOT_EQ(f2.FilmID).AND(f1.Length.EQ(f2.Length))).
|
INNER_JOIN(f2, f1.FilmID.NOT_EQ(f2.FilmID).AND(f1.Length.EQ(f2.Length))).
|
||||||
|
|
@ -770,7 +770,9 @@ func TestSelectFunctions(t *testing.T) {
|
||||||
SELECT MAX(film.rental_rate) AS "max_film_rate"
|
SELECT MAX(film.rental_rate) AS "max_film_rate"
|
||||||
FROM dvds.film;
|
FROM dvds.film;
|
||||||
`
|
`
|
||||||
query := Film.SELECT(MAX(Film.RentalRate).AS("max_film_rate"))
|
query := Film.SELECT(
|
||||||
|
MAXf(Film.RentalRate).AS("max_film_rate"),
|
||||||
|
)
|
||||||
|
|
||||||
assertQuery(t, query, expectedQuery)
|
assertQuery(t, query, expectedQuery)
|
||||||
|
|
||||||
|
|
@ -807,7 +809,7 @@ WHERE film.rental_rate = (
|
||||||
ORDER BY film.film_id ASC;
|
ORDER BY film.film_id ASC;
|
||||||
`
|
`
|
||||||
|
|
||||||
maxFilmRentalRate := NumExp(Film.SELECT(MAX(Film.RentalRate)))
|
maxFilmRentalRate := NumExp(Film.SELECT(MAXf(Film.RentalRate)))
|
||||||
|
|
||||||
query := Film.
|
query := Film.
|
||||||
SELECT(Film.AllColumns).
|
SELECT(Film.AllColumns).
|
||||||
|
|
@ -855,17 +857,17 @@ ORDER BY SUM(payment.amount) ASC;
|
||||||
customersPaymentQuery := Payment.
|
customersPaymentQuery := Payment.
|
||||||
SELECT(
|
SELECT(
|
||||||
Payment.CustomerID.AS("customer_payment_sum.customer_id"),
|
Payment.CustomerID.AS("customer_payment_sum.customer_id"),
|
||||||
SUM(Payment.Amount).AS("customer_payment_sum.amount_sum"),
|
SUMf(Payment.Amount).AS("customer_payment_sum.amount_sum"),
|
||||||
).
|
).
|
||||||
GROUP_BY(Payment.CustomerID).
|
GROUP_BY(Payment.CustomerID).
|
||||||
ORDER_BY(
|
ORDER_BY(
|
||||||
SUM(Payment.Amount).ASC(),
|
SUMf(Payment.Amount).ASC(),
|
||||||
).
|
).
|
||||||
HAVING(
|
HAVING(
|
||||||
SUM(Payment.Amount).GT(Int(100)),
|
SUMf(Payment.Amount).GT(Float(100)),
|
||||||
)
|
)
|
||||||
|
|
||||||
assertQuery(t, customersPaymentQuery, expectedSql, 100)
|
assertQuery(t, customersPaymentQuery, expectedSql, float64(100))
|
||||||
|
|
||||||
type CustomerPaymentSum struct {
|
type CustomerPaymentSum struct {
|
||||||
CustomerID int16
|
CustomerID int16
|
||||||
|
|
@ -911,7 +913,7 @@ ORDER BY customer_payment_sum.amount_sum ASC;
|
||||||
customersPaymentSubQuery := Payment.
|
customersPaymentSubQuery := Payment.
|
||||||
SELECT(
|
SELECT(
|
||||||
Payment.CustomerID,
|
Payment.CustomerID,
|
||||||
SUM(Payment.Amount).AS("amount_sum"),
|
SUMf(Payment.Amount).AS("amount_sum"),
|
||||||
).
|
).
|
||||||
GROUP_BY(Payment.CustomerID)
|
GROUP_BY(Payment.CustomerID)
|
||||||
|
|
||||||
|
|
@ -1024,10 +1026,10 @@ OFFSET 20;
|
||||||
query := UNION_ALL(
|
query := UNION_ALL(
|
||||||
Payment.
|
Payment.
|
||||||
SELECT(Payment.PaymentID.AS("payment.payment_id"), Payment.Amount).
|
SELECT(Payment.PaymentID.AS("payment.payment_id"), Payment.Amount).
|
||||||
WHERE(Payment.Amount.LT_EQ(Int(100))),
|
WHERE(Payment.Amount.LT_EQ(Float(100))),
|
||||||
Payment.
|
Payment.
|
||||||
SELECT(Payment.PaymentID, Payment.Amount).
|
SELECT(Payment.PaymentID, Payment.Amount).
|
||||||
WHERE(Payment.Amount.GT_EQ(Int(200))),
|
WHERE(Payment.Amount.GT_EQ(Float(200))),
|
||||||
).
|
).
|
||||||
ORDER_BY(RefColumn("payment.payment_id").ASC(), Payment.Amount.DESC()).
|
ORDER_BY(RefColumn("payment.payment_id").ASC(), Payment.Amount.DESC()).
|
||||||
LIMIT(10).
|
LIMIT(10).
|
||||||
|
|
@ -1036,7 +1038,7 @@ OFFSET 20;
|
||||||
queryStr, _, _ := query.Sql()
|
queryStr, _, _ := query.Sql()
|
||||||
|
|
||||||
fmt.Println("-" + queryStr + "-")
|
fmt.Println("-" + queryStr + "-")
|
||||||
assertQuery(t, query, expectedQuery, int(100), int(200), int64(10), int64(20))
|
assertQuery(t, query, expectedQuery, float64(100), float64(200), int64(10), int64(20))
|
||||||
|
|
||||||
dest := []model.Payment{}
|
dest := []model.Payment{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,29 +91,29 @@ func TestBoolOperators(t *testing.T) {
|
||||||
func TestNumericOperators(t *testing.T) {
|
func TestNumericOperators(t *testing.T) {
|
||||||
query := AllTypes.SELECT(
|
query := AllTypes.SELECT(
|
||||||
AllTypes.Numeric.EQ(AllTypes.Numeric),
|
AllTypes.Numeric.EQ(AllTypes.Numeric),
|
||||||
AllTypes.Decimal.EQ(Int(12)),
|
AllTypes.Decimal.EQ(Float(12)),
|
||||||
AllTypes.Real.EQ(Float(12.12)),
|
AllTypes.Real.EQ(Float(12.12)),
|
||||||
AllTypes.Smallint.NOT_EQ(AllTypes.Real),
|
//AllTypes.Smallint.NOT_EQ(AllTypes.Real),
|
||||||
AllTypes.Integer.NOT_EQ(Int(12)),
|
AllTypes.Integer.NOT_EQ(Int(12)),
|
||||||
AllTypes.Bigint.NOT_EQ(Float(12)),
|
AllTypes.Bigint.NOT_EQ(Int(12)),
|
||||||
AllTypes.Numeric.IS_DISTINCT_FROM(AllTypes.Numeric),
|
AllTypes.Numeric.IS_DISTINCT_FROM(AllTypes.Numeric),
|
||||||
AllTypes.Decimal.IS_DISTINCT_FROM(Int(12)),
|
AllTypes.Decimal.IS_DISTINCT_FROM(Float(12)),
|
||||||
AllTypes.Real.IS_DISTINCT_FROM(Float(12.12)),
|
AllTypes.Real.IS_DISTINCT_FROM(Float(12.12)),
|
||||||
AllTypes.Numeric.IS_NOT_DISTINCT_FROM(AllTypes.Numeric),
|
AllTypes.Numeric.IS_NOT_DISTINCT_FROM(AllTypes.Numeric),
|
||||||
AllTypes.Decimal.IS_NOT_DISTINCT_FROM(Int(12)),
|
AllTypes.Decimal.IS_NOT_DISTINCT_FROM(Float(12)),
|
||||||
AllTypes.Real.IS_NOT_DISTINCT_FROM(Float(12.12)),
|
AllTypes.Real.IS_NOT_DISTINCT_FROM(Float(12.12)),
|
||||||
AllTypes.Numeric.LT(AllTypes.Integer),
|
//AllTypes.Numeric.LT(AllTypes.Integer),
|
||||||
AllTypes.Numeric.LT(Int(124)),
|
AllTypes.Numeric.LT(Float(124)),
|
||||||
AllTypes.Numeric.LT(Float(34.56)),
|
AllTypes.Numeric.LT(Float(34.56)),
|
||||||
AllTypes.Smallint.LT_EQ(AllTypes.Numeric),
|
//AllTypes.Smallint.LT_EQ(AllTypes.Numeric),
|
||||||
AllTypes.Integer.LT_EQ(Int(45)),
|
AllTypes.Integer.LT_EQ(Int(45)),
|
||||||
AllTypes.Bigint.LT_EQ(Float(65)),
|
AllTypes.Bigint.LT_EQ(Int(65)),
|
||||||
AllTypes.Numeric.GT(AllTypes.Smallint),
|
//AllTypes.Numeric.GT(AllTypes.Smallint),
|
||||||
AllTypes.Numeric.GT(Int(124)),
|
AllTypes.Numeric.GT(Float(124)),
|
||||||
AllTypes.Numeric.GT(Float(34.56)),
|
AllTypes.Numeric.GT(Float(34.56)),
|
||||||
AllTypes.Smallint.GT_EQ(AllTypes.Numeric),
|
//AllTypes.Smallint.GT_EQ(AllTypes.Numeric),
|
||||||
AllTypes.Integer.GT_EQ(Int(45)),
|
AllTypes.Integer.GT_EQ(Int(45)),
|
||||||
AllTypes.Bigint.GT_EQ(Float(65)),
|
AllTypes.Bigint.GT_EQ(Int(65)),
|
||||||
)
|
)
|
||||||
|
|
||||||
fmt.Println(query.DebugSql())
|
fmt.Println(query.DebugSql())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue