Support for quoted identifiers.
This commit is contained in:
parent
7fc99ac997
commit
d9ffa86453
27 changed files with 268671 additions and 318 deletions
|
|
@ -6,41 +6,41 @@ import (
|
|||
|
||||
func TestBoolExpressionEQ(t *testing.T) {
|
||||
assertClauseSerializeErr(t, table1ColBool.EQ(nil), "nil rhs")
|
||||
assertClauseSerialize(t, table1ColBool.EQ(table2ColBool), "(table1.colBool = table2.colBool)")
|
||||
assertClauseSerialize(t, table1ColBool.EQ(Bool(true)), "(table1.colBool = $1)", true)
|
||||
assertClauseSerialize(t, table1ColBool.EQ(table2ColBool), "(table1.col_bool = table2.col_bool)")
|
||||
assertClauseSerialize(t, table1ColBool.EQ(Bool(true)), "(table1.col_bool = $1)", true)
|
||||
}
|
||||
|
||||
func TestBoolExpressionNOT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColBool.NOT_EQ(table2ColBool), "(table1.colBool != table2.colBool)")
|
||||
assertClauseSerialize(t, table1ColBool.NOT_EQ(Bool(true)), "(table1.colBool != $1)", true)
|
||||
assertClauseSerialize(t, table1ColBool.NOT_EQ(table2ColBool), "(table1.col_bool != table2.col_bool)")
|
||||
assertClauseSerialize(t, table1ColBool.NOT_EQ(Bool(true)), "(table1.col_bool != $1)", true)
|
||||
}
|
||||
|
||||
func TestBoolExpressionIS_TRUE(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColBool.IS_TRUE(), "table1.colBool IS TRUE")
|
||||
assertClauseSerialize(t, table1ColBool.IS_TRUE(), "table1.col_bool IS TRUE")
|
||||
assertClauseSerialize(t, (Int(2).EQ(table1ColInt)).IS_TRUE(),
|
||||
`($1 = table1.colInt) IS TRUE`, int64(2))
|
||||
`($1 = table1.col_int) IS TRUE`, int64(2))
|
||||
assertClauseSerialize(t, (Int(2).EQ(table1ColInt)).IS_TRUE().AND(Int(4).EQ(table2ColInt)),
|
||||
`(($1 = table1.colInt) IS TRUE AND ($2 = table2.colInt))`, int64(2), int64(4))
|
||||
`(($1 = table1.col_int) IS TRUE AND ($2 = table2.col_int))`, int64(2), int64(4))
|
||||
}
|
||||
|
||||
func TestBoolExpressionIS_NOT_TRUE(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColBool.IS_NOT_TRUE(), "table1.colBool IS NOT TRUE")
|
||||
assertClauseSerialize(t, table1ColBool.IS_NOT_TRUE(), "table1.col_bool IS NOT TRUE")
|
||||
}
|
||||
|
||||
func TestBoolExpressionIS_FALSE(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColBool.IS_FALSE(), "table1.colBool IS FALSE")
|
||||
assertClauseSerialize(t, table1ColBool.IS_FALSE(), "table1.col_bool IS FALSE")
|
||||
}
|
||||
|
||||
func TestBoolExpressionIS_NOT_FALSE(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColBool.IS_NOT_FALSE(), "table1.colBool IS NOT FALSE")
|
||||
assertClauseSerialize(t, table1ColBool.IS_NOT_FALSE(), "table1.col_bool IS NOT FALSE")
|
||||
}
|
||||
|
||||
func TestBoolExpressionIS_UNKNOWN(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColBool.IS_UNKNOWN(), "table1.colBool IS UNKNOWN")
|
||||
assertClauseSerialize(t, table1ColBool.IS_UNKNOWN(), "table1.col_bool IS UNKNOWN")
|
||||
}
|
||||
|
||||
func TestBoolExpressionIS_NOT_UNKNOWN(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColBool.IS_NOT_UNKNOWN(), "table1.colBool IS NOT UNKNOWN")
|
||||
assertClauseSerialize(t, table1ColBool.IS_NOT_UNKNOWN(), "table1.col_bool IS NOT UNKNOWN")
|
||||
}
|
||||
|
||||
func TestBinaryBoolExpression(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -154,6 +154,16 @@ func (q *queryData) writeString(str string) {
|
|||
q.write([]byte(str))
|
||||
}
|
||||
|
||||
func (q *queryData) writeIdentifier(name string) {
|
||||
quoteWrap := name != strings.ToLower(name) || strings.Contains(name, ".")
|
||||
|
||||
if quoteWrap {
|
||||
q.writeString(`"` + name + `"`)
|
||||
} else {
|
||||
q.writeString(name)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *queryData) writeByte(b byte) {
|
||||
q.write([]byte{b})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,6 @@
|
|||
|
||||
package sqlbuilder
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type column interface {
|
||||
Name() string
|
||||
TableName() string
|
||||
|
|
@ -60,15 +56,7 @@ func (c *columnImpl) defaultAlias() string {
|
|||
func (c *columnImpl) serializeForOrderBy(statement statementType, out *queryData) error {
|
||||
if statement == set_statement {
|
||||
// set Statement (UNION, EXCEPT ...) can reference only select projections in order by clause
|
||||
columnRef := ""
|
||||
|
||||
if c.tableName != "" {
|
||||
columnRef += c.tableName + "."
|
||||
}
|
||||
|
||||
columnRef += c.name
|
||||
|
||||
out.writeString(`"` + columnRef + `"`)
|
||||
out.writeString(`"` + c.defaultAlias() + `"`) //always quote
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -90,25 +78,12 @@ func (c columnImpl) serializeForProjection(statement statementType, out *queryDa
|
|||
|
||||
func (c columnImpl) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
||||
|
||||
columnRef := ""
|
||||
|
||||
if c.tableName != "" {
|
||||
columnRef += c.tableName + "."
|
||||
out.writeIdentifier(c.tableName)
|
||||
out.writeByte('.')
|
||||
}
|
||||
|
||||
wrapColumnName := strings.Contains(c.name, ".")
|
||||
|
||||
if wrapColumnName {
|
||||
columnRef += `"`
|
||||
}
|
||||
|
||||
columnRef += c.name
|
||||
|
||||
if wrapColumnName {
|
||||
columnRef += `"`
|
||||
}
|
||||
|
||||
out.writeString(columnRef)
|
||||
out.writeIdentifier(c.name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,38 +8,38 @@ var subQuery = table1.SELECT(table1ColFloat, table1ColInt).AsTable("sub_query")
|
|||
|
||||
func TestNewBoolColumn(t *testing.T) {
|
||||
boolColumn := BoolColumn("colBool").From(subQuery)
|
||||
assertClauseSerialize(t, boolColumn, "sub_query.colBool")
|
||||
assertClauseSerialize(t, boolColumn.EQ(Bool(true)), "(sub_query.colBool = $1)", true)
|
||||
assertProjectionSerialize(t, boolColumn, `sub_query.colBool AS "sub_query.colBool"`)
|
||||
assertClauseSerialize(t, boolColumn, `sub_query."colBool"`)
|
||||
assertClauseSerialize(t, boolColumn.EQ(Bool(true)), `(sub_query."colBool" = $1)`, true)
|
||||
assertProjectionSerialize(t, boolColumn, `sub_query."colBool" AS "sub_query.colBool"`)
|
||||
|
||||
boolColumn2 := table1ColBool.From(subQuery)
|
||||
assertClauseSerialize(t, boolColumn2, `sub_query."table1.colBool"`)
|
||||
assertClauseSerialize(t, boolColumn2.EQ(Bool(true)), `(sub_query."table1.colBool" = $1)`, true)
|
||||
assertProjectionSerialize(t, boolColumn2, `sub_query."table1.colBool" AS "sub_query.table1.colBool"`)
|
||||
assertClauseSerialize(t, boolColumn2, `sub_query."table1.col_bool"`)
|
||||
assertClauseSerialize(t, boolColumn2.EQ(Bool(true)), `(sub_query."table1.col_bool" = $1)`, true)
|
||||
assertProjectionSerialize(t, boolColumn2, `sub_query."table1.col_bool" AS "sub_query.table1.col_bool"`)
|
||||
}
|
||||
|
||||
func TestNewIntColumn(t *testing.T) {
|
||||
intColumn := IntegerColumn("colInt").From(subQuery)
|
||||
assertClauseSerialize(t, intColumn, "sub_query.colInt")
|
||||
assertClauseSerialize(t, intColumn.EQ(Int(12)), "(sub_query.colInt = $1)", int64(12))
|
||||
assertProjectionSerialize(t, intColumn, `sub_query.colInt AS "sub_query.colInt"`)
|
||||
intColumn := IntegerColumn("col_int").From(subQuery)
|
||||
assertClauseSerialize(t, intColumn, "sub_query.col_int")
|
||||
assertClauseSerialize(t, intColumn.EQ(Int(12)), "(sub_query.col_int = $1)", int64(12))
|
||||
assertProjectionSerialize(t, intColumn, `sub_query.col_int AS "sub_query.col_int"`)
|
||||
|
||||
intColumn2 := table1ColInt.From(subQuery)
|
||||
assertClauseSerialize(t, intColumn2, `sub_query."table1.colInt"`)
|
||||
assertClauseSerialize(t, intColumn2.EQ(Int(14)), `(sub_query."table1.colInt" = $1)`, int64(14))
|
||||
assertProjectionSerialize(t, intColumn2, `sub_query."table1.colInt" AS "sub_query.table1.colInt"`)
|
||||
assertClauseSerialize(t, intColumn2, `sub_query."table1.col_int"`)
|
||||
assertClauseSerialize(t, intColumn2.EQ(Int(14)), `(sub_query."table1.col_int" = $1)`, int64(14))
|
||||
assertProjectionSerialize(t, intColumn2, `sub_query."table1.col_int" AS "sub_query.table1.col_int"`)
|
||||
|
||||
}
|
||||
|
||||
func TestNewFloatColumnColumn(t *testing.T) {
|
||||
floatColumn := FloatColumn("colFloat").From(subQuery)
|
||||
assertClauseSerialize(t, floatColumn, "sub_query.colFloat")
|
||||
assertClauseSerialize(t, floatColumn.EQ(Float(1.11)), "(sub_query.colFloat = $1)", float64(1.11))
|
||||
assertProjectionSerialize(t, floatColumn, `sub_query.colFloat AS "sub_query.colFloat"`)
|
||||
floatColumn := FloatColumn("col_float").From(subQuery)
|
||||
assertClauseSerialize(t, floatColumn, "sub_query.col_float")
|
||||
assertClauseSerialize(t, floatColumn.EQ(Float(1.11)), "(sub_query.col_float = $1)", float64(1.11))
|
||||
assertProjectionSerialize(t, floatColumn, `sub_query.col_float AS "sub_query.col_float"`)
|
||||
|
||||
floatColumn2 := table1ColFloat.From(subQuery)
|
||||
assertClauseSerialize(t, floatColumn2, `sub_query."table1.colFloat"`)
|
||||
assertClauseSerialize(t, floatColumn2.EQ(Float(2.22)), `(sub_query."table1.colFloat" = $1)`, float64(2.22))
|
||||
assertProjectionSerialize(t, floatColumn2, `sub_query."table1.colFloat" AS "sub_query.table1.colFloat"`)
|
||||
assertClauseSerialize(t, floatColumn2, `sub_query."table1.col_float"`)
|
||||
assertClauseSerialize(t, floatColumn2.EQ(Float(2.22)), `(sub_query."table1.col_float" = $1)`, float64(2.22))
|
||||
assertProjectionSerialize(t, floatColumn2, `sub_query."table1.col_float" AS "sub_query.table1.col_float"`)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ func mapRowToSlice(scanContext *scanContext, groupKey string, slicePtrValue refl
|
|||
index := 0
|
||||
if structField != nil {
|
||||
tableName, columnName := getRefTableNameFrom(structField)
|
||||
index = getIndex(scanContext.columnNames, tableName+"."+columnName)
|
||||
index = scanContext.columnIndex(tableName, columnName)
|
||||
|
||||
if index < 0 {
|
||||
return
|
||||
|
|
@ -197,7 +197,7 @@ func getGroupKey(scanContext *scanContext, structType reflect.Type, structField
|
|||
tableName, _ := getRefTableNameFrom(structField)
|
||||
|
||||
if tableName == "" {
|
||||
tableName = snaker.CamelToSnake(structType.Name())
|
||||
tableName = structType.Name()
|
||||
}
|
||||
|
||||
groupKeys := []string{}
|
||||
|
|
@ -222,15 +222,8 @@ func getGroupKey(scanContext *scanContext, structType reflect.Type, structField
|
|||
}
|
||||
} else if tagInfo(field.Tag.Get("sql")).isPrimaryKey {
|
||||
fieldName := field.Name
|
||||
columnName := tableName + "." + snaker.CamelToSnake(fieldName)
|
||||
|
||||
index := getIndex(scanContext.columnNames, columnName)
|
||||
|
||||
if index < 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
cellValue := scanContext.rowElem(index)
|
||||
cellValue := scanContext.getCellValue(tableName, fieldName)
|
||||
subKey := valueToString(cellValue)
|
||||
|
||||
if subKey != "" {
|
||||
|
|
@ -360,7 +353,7 @@ func getRefTableNameFrom(structField *reflect.StructField) (table, column string
|
|||
}
|
||||
|
||||
if !structField.Anonymous {
|
||||
return snaker.CamelToSnake(structField.Name), ""
|
||||
return structField.Name, ""
|
||||
}
|
||||
|
||||
fieldType := indirectType(structField.Type)
|
||||
|
|
@ -369,7 +362,7 @@ func getRefTableNameFrom(structField *reflect.StructField) (table, column string
|
|||
fieldType = fieldType.Elem()
|
||||
}
|
||||
|
||||
return snaker.CamelToSnake(fieldType.Name()), ""
|
||||
return fieldType.Name(), ""
|
||||
}
|
||||
|
||||
func mapRowToStruct(scanContext *scanContext, groupKey string, structPtrValue reflect.Value, structField *reflect.StructField) (updated bool, err error) {
|
||||
|
|
@ -379,7 +372,7 @@ func mapRowToStruct(scanContext *scanContext, groupKey string, structPtrValue re
|
|||
tableName, _ := getRefTableNameFrom(structField)
|
||||
|
||||
if tableName == "" {
|
||||
tableName = snaker.CamelToSnake(structType.Name())
|
||||
tableName = structType.Name()
|
||||
}
|
||||
|
||||
for i := 0; i < structType.NumField(); i++ {
|
||||
|
|
@ -389,7 +382,7 @@ func mapRowToStruct(scanContext *scanContext, groupKey string, structPtrValue re
|
|||
fieldName := field.Name
|
||||
|
||||
if scannerValue, ok := implementsScanner(fieldValue); ok {
|
||||
cellValue := getCellValue(scanContext, tableName, fieldName)
|
||||
cellValue := scanContext.getCellValue(tableName, fieldName)
|
||||
|
||||
if cellValue == nil {
|
||||
continue
|
||||
|
|
@ -407,7 +400,7 @@ func mapRowToStruct(scanContext *scanContext, groupKey string, structPtrValue re
|
|||
}
|
||||
updated = true
|
||||
} else if isGoBaseType(field.Type) {
|
||||
cellValue := getCellValue(scanContext, tableName, fieldName)
|
||||
cellValue := scanContext.getCellValue(tableName, fieldName)
|
||||
|
||||
if cellValue != nil {
|
||||
updated = true
|
||||
|
|
@ -458,24 +451,6 @@ func implementsScanner(value reflect.Value) (reflect.Value, bool) {
|
|||
return value, false
|
||||
}
|
||||
|
||||
func getCellValue(scanContext *scanContext, tableName, fieldName string) interface{} {
|
||||
columnName := ""
|
||||
|
||||
if tableName == "" {
|
||||
columnName = snaker.CamelToSnake(fieldName)
|
||||
} else {
|
||||
columnName = tableName + "." + snaker.CamelToSnake(fieldName)
|
||||
}
|
||||
|
||||
index := getIndex(scanContext.columnNames, columnName)
|
||||
|
||||
if index < 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return scanContext.rowElem(index)
|
||||
}
|
||||
|
||||
func valueToString(val interface{}) string {
|
||||
if val == nil {
|
||||
return ""
|
||||
|
|
@ -546,16 +521,6 @@ func setReflectValue(source, destination reflect.Value) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getIndex(list []string, text string) int {
|
||||
for i, str := range list {
|
||||
if str == text {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
func createScanValue(columnTypes []*sql.ColumnType) []interface{} {
|
||||
values := make([]interface{}, len(columnTypes))
|
||||
|
||||
|
|
@ -610,9 +575,10 @@ type scanContext struct {
|
|||
rowNum int
|
||||
columnNames []string
|
||||
|
||||
row []interface{}
|
||||
uniqueObjectsMap map[string]int
|
||||
groupKeyMap map[string]string
|
||||
row []interface{}
|
||||
uniqueObjectsMap map[string]int
|
||||
groupKeyMap map[string]string
|
||||
columnNameIndexMap map[string]int
|
||||
}
|
||||
|
||||
func newScanContext(rows *sql.Rows) (*scanContext, error) {
|
||||
|
|
@ -628,14 +594,67 @@ func newScanContext(rows *sql.Rows) (*scanContext, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
columnNameIndexMap := map[string]int{}
|
||||
|
||||
for i, columnName := range columnNames {
|
||||
columnNameIndexMap[strings.ToLower(columnName)] = i
|
||||
}
|
||||
|
||||
return &scanContext{
|
||||
row: createScanValue(columnTypes),
|
||||
columnNames: columnNames,
|
||||
uniqueObjectsMap: make(map[string]int),
|
||||
groupKeyMap: make(map[string]string),
|
||||
row: createScanValue(columnTypes),
|
||||
columnNames: columnNames,
|
||||
uniqueObjectsMap: make(map[string]int),
|
||||
groupKeyMap: make(map[string]string),
|
||||
columnNameIndexMap: columnNameIndexMap,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *scanContext) columnIndex(structName, fieldName string) int {
|
||||
if structName == "" {
|
||||
name := strings.ToLower(fieldName)
|
||||
if i, ok := s.columnNameIndexMap[name]; ok {
|
||||
return i
|
||||
}
|
||||
|
||||
name = strings.ToLower(snaker.CamelToSnake(fieldName))
|
||||
if i, ok := s.columnNameIndexMap[name]; ok {
|
||||
return i
|
||||
}
|
||||
} else {
|
||||
name := strings.ToLower(structName + "." + fieldName)
|
||||
if i, ok := s.columnNameIndexMap[name]; ok {
|
||||
return i
|
||||
}
|
||||
|
||||
name = strings.ToLower(structName + "." + snaker.CamelToSnake(fieldName))
|
||||
if i, ok := s.columnNameIndexMap[name]; ok {
|
||||
return i
|
||||
}
|
||||
|
||||
name = strings.ToLower(snaker.CamelToSnake(structName) + "." + fieldName)
|
||||
if i, ok := s.columnNameIndexMap[name]; ok {
|
||||
return i
|
||||
}
|
||||
|
||||
name = strings.ToLower(snaker.CamelToSnake(structName) + "." + snaker.CamelToSnake(fieldName))
|
||||
if i, ok := s.columnNameIndexMap[name]; ok {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
func (s *scanContext) getCellValue(tableName, fieldName string) interface{} {
|
||||
index := s.columnIndex(tableName, fieldName)
|
||||
|
||||
if index < 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return s.rowElem(index)
|
||||
}
|
||||
|
||||
func (s *scanContext) rowElem(index int) interface{} {
|
||||
|
||||
valuer, ok := s.row[index].(driver.Valuer)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ func (c *binaryOpExpression) serialize(statement statementType, out *queryData,
|
|||
return err
|
||||
}
|
||||
|
||||
out.writeString(" " + c.operator + " ")
|
||||
out.writeString(c.operator)
|
||||
|
||||
if err := c.rhs.serialize(statement, out); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func (e *expressionTableImpl) serialize(statement statementType, out *queryData,
|
|||
}
|
||||
|
||||
out.writeString("AS")
|
||||
out.writeString(e.alias)
|
||||
out.writeIdentifier(e.alias)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,68 +5,68 @@ import (
|
|||
)
|
||||
|
||||
func TestFloatExpressionEQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.EQ(table2ColFloat), "(table1.colFloat = table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.EQ(Float(2.11)), "(table1.colFloat = $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.EQ(table2ColFloat), "(table1.col_float = table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.EQ(Float(2.11)), "(table1.col_float = $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionNOT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.NOT_EQ(table2ColFloat), "(table1.colFloat != table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.NOT_EQ(Float(2.11)), "(table1.colFloat != $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.NOT_EQ(table2ColFloat), "(table1.col_float != table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.NOT_EQ(Float(2.11)), "(table1.col_float != $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionGT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.GT(table2ColFloat), "(table1.colFloat > table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.GT(Float(2.11)), "(table1.colFloat > $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.GT(table2ColFloat), "(table1.col_float > table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.GT(Float(2.11)), "(table1.col_float > $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionGT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.GT_EQ(table2ColFloat), "(table1.colFloat >= table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.GT_EQ(Float(2.11)), "(table1.colFloat >= $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.GT_EQ(table2ColFloat), "(table1.col_float >= table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.GT_EQ(Float(2.11)), "(table1.col_float >= $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionLT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.LT(table2ColFloat), "(table1.colFloat < table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.LT(Float(2.11)), "(table1.colFloat < $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.LT(table2ColFloat), "(table1.col_float < table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.LT(Float(2.11)), "(table1.col_float < $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionLT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.LT_EQ(table2ColFloat), "(table1.colFloat <= table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.LT_EQ(Float(2.11)), "(table1.colFloat <= $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.LT_EQ(table2ColFloat), "(table1.col_float <= table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.LT_EQ(Float(2.11)), "(table1.col_float <= $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionADD(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.ADD(table2ColFloat), "(table1.colFloat + table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.ADD(Float(2.11)), "(table1.colFloat + $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.ADD(table2ColFloat), "(table1.col_float + table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.ADD(Float(2.11)), "(table1.col_float + $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionSUB(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.SUB(table2ColFloat), "(table1.colFloat - table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.SUB(Float(2.11)), "(table1.colFloat - $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.SUB(table2ColFloat), "(table1.col_float - table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.SUB(Float(2.11)), "(table1.col_float - $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionMUL(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.MUL(table2ColFloat), "(table1.colFloat * table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.MUL(Float(2.11)), "(table1.colFloat * $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.MUL(table2ColFloat), "(table1.col_float * table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.MUL(Float(2.11)), "(table1.col_float * $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionDIV(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.DIV(table2ColFloat), "(table1.colFloat / table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.DIV(Float(2.11)), "(table1.colFloat / $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.DIV(table2ColFloat), "(table1.col_float / table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.DIV(Float(2.11)), "(table1.col_float / $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionMOD(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.MOD(table2ColFloat), "(table1.colFloat % table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.MOD(Float(2.11)), "(table1.colFloat % $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.MOD(table2ColFloat), "(table1.col_float % table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.MOD(Float(2.11)), "(table1.col_float % $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExpressionPOW(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColFloat.POW(table2ColFloat), "(table1.colFloat ^ table2.colFloat)")
|
||||
assertClauseSerialize(t, table1ColFloat.POW(Float(2.11)), "(table1.colFloat ^ $1)", float64(2.11))
|
||||
assertClauseSerialize(t, table1ColFloat.POW(table2ColFloat), "(table1.col_float ^ table2.col_float)")
|
||||
assertClauseSerialize(t, table1ColFloat.POW(Float(2.11)), "(table1.col_float ^ $1)", float64(2.11))
|
||||
}
|
||||
|
||||
func TestFloatExp(t *testing.T) {
|
||||
assertClauseSerialize(t, FloatExp(table1ColInt), "table1.colInt")
|
||||
assertClauseSerialize(t, FloatExp(table1ColInt.ADD(table3ColInt)), "(table1.colInt + table3.colInt)")
|
||||
assertClauseSerialize(t, FloatExp(table1ColInt), "table1.col_int")
|
||||
assertClauseSerialize(t, FloatExp(table1ColInt.ADD(table3ColInt)), "(table1.col_int + table3.col_int)")
|
||||
assertClauseSerialize(t, FloatExp(table1ColInt.ADD(table3ColInt)).ADD(Float(11.11)),
|
||||
"((table1.colInt + table3.colInt) + $1)", float64(11.11))
|
||||
"((table1.col_int + table3.col_int) + $1)", float64(11.11))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,168 +7,168 @@ import (
|
|||
|
||||
func TestFuncAVG(t *testing.T) {
|
||||
t.Run("float", func(t *testing.T) {
|
||||
assertClauseSerialize(t, AVGf(table1ColFloat), "AVG(table1.colFloat)")
|
||||
assertClauseSerialize(t, AVGf(table1ColFloat), "AVG(table1.col_float)")
|
||||
})
|
||||
|
||||
t.Run("integer", func(t *testing.T) {
|
||||
assertClauseSerialize(t, AVGi(table1ColInt), "AVG(table1.colInt)")
|
||||
assertClauseSerialize(t, AVGi(table1ColInt), "AVG(table1.col_int)")
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuncBIT_AND(t *testing.T) {
|
||||
assertClauseSerialize(t, BIT_AND(table1ColInt), "BIT_AND(table1.colInt)")
|
||||
assertClauseSerialize(t, BIT_AND(table1ColInt), "BIT_AND(table1.col_int)")
|
||||
}
|
||||
|
||||
func TestFuncBIT_OR(t *testing.T) {
|
||||
assertClauseSerialize(t, BIT_OR(table1ColInt), "BIT_OR(table1.colInt)")
|
||||
assertClauseSerialize(t, BIT_OR(table1ColInt), "BIT_OR(table1.col_int)")
|
||||
}
|
||||
|
||||
func TestFuncBOOL_AND(t *testing.T) {
|
||||
assertClauseSerialize(t, BOOL_AND(table1ColBool), "BOOL_AND(table1.colBool)")
|
||||
assertClauseSerialize(t, BOOL_AND(table1ColBool), "BOOL_AND(table1.col_bool)")
|
||||
}
|
||||
|
||||
func TestFuncBOOL_OR(t *testing.T) {
|
||||
assertClauseSerialize(t, BOOL_OR(table1ColBool), "BOOL_OR(table1.colBool)")
|
||||
assertClauseSerialize(t, BOOL_OR(table1ColBool), "BOOL_OR(table1.col_bool)")
|
||||
}
|
||||
|
||||
func TestFuncEVERY(t *testing.T) {
|
||||
assertClauseSerialize(t, EVERY(table1ColBool), "EVERY(table1.colBool)")
|
||||
assertClauseSerialize(t, EVERY(table1ColBool), "EVERY(table1.col_bool)")
|
||||
}
|
||||
|
||||
func TestFuncMIN(t *testing.T) {
|
||||
t.Run("float", func(t *testing.T) {
|
||||
assertClauseSerialize(t, MINf(table1ColFloat), "MIN(table1.colFloat)")
|
||||
assertClauseSerialize(t, MINf(table1ColFloat), "MIN(table1.col_float)")
|
||||
})
|
||||
|
||||
t.Run("integer", func(t *testing.T) {
|
||||
assertClauseSerialize(t, MINi(table1ColInt), "MIN(table1.colInt)")
|
||||
assertClauseSerialize(t, MINi(table1ColInt), "MIN(table1.col_int)")
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuncMAX(t *testing.T) {
|
||||
t.Run("float", func(t *testing.T) {
|
||||
assertClauseSerialize(t, MAXf(table1ColFloat), "MAX(table1.colFloat)")
|
||||
assertClauseSerialize(t, MAXf(table1ColFloat), "MAX(table1.col_float)")
|
||||
assertClauseSerialize(t, MAXf(Float(11.2222)), "MAX($1)", float64(11.2222))
|
||||
})
|
||||
|
||||
t.Run("integer", func(t *testing.T) {
|
||||
assertClauseSerialize(t, MAXi(table1ColInt), "MAX(table1.colInt)")
|
||||
assertClauseSerialize(t, MAXi(table1ColInt), "MAX(table1.col_int)")
|
||||
assertClauseSerialize(t, MAXi(Int(11)), "MAX($1)", int64(11))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuncSUM(t *testing.T) {
|
||||
t.Run("float", func(t *testing.T) {
|
||||
assertClauseSerialize(t, SUMf(table1ColFloat), "SUM(table1.colFloat)")
|
||||
assertClauseSerialize(t, SUMf(table1ColFloat), "SUM(table1.col_float)")
|
||||
assertClauseSerialize(t, SUMf(Float(11.2222)), "SUM($1)", float64(11.2222))
|
||||
})
|
||||
|
||||
t.Run("integer", func(t *testing.T) {
|
||||
assertClauseSerialize(t, SUMi(table1ColInt), "SUM(table1.colInt)")
|
||||
assertClauseSerialize(t, SUMi(table1ColInt), "SUM(table1.col_int)")
|
||||
assertClauseSerialize(t, SUMi(Int(11)), "SUM($1)", int64(11))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuncCOUNT(t *testing.T) {
|
||||
assertClauseSerialize(t, COUNT(STAR), "COUNT(*)")
|
||||
assertClauseSerialize(t, COUNT(table1ColFloat), "COUNT(table1.colFloat)")
|
||||
assertClauseSerialize(t, COUNT(table1ColFloat), "COUNT(table1.col_float)")
|
||||
assertClauseSerialize(t, COUNT(Float(11.2222)), "COUNT($1)", float64(11.2222))
|
||||
}
|
||||
|
||||
func TestFuncABS(t *testing.T) {
|
||||
t.Run("float", func(t *testing.T) {
|
||||
assertClauseSerialize(t, ABSf(table1ColFloat), "ABS(table1.colFloat)")
|
||||
assertClauseSerialize(t, ABSf(table1ColFloat), "ABS(table1.col_float)")
|
||||
assertClauseSerialize(t, ABSf(Float(11.2222)), "ABS($1)", float64(11.2222))
|
||||
})
|
||||
|
||||
t.Run("integer", func(t *testing.T) {
|
||||
assertClauseSerialize(t, ABSi(table1ColInt), "ABS(table1.colInt)")
|
||||
assertClauseSerialize(t, ABSi(table1ColInt), "ABS(table1.col_int)")
|
||||
assertClauseSerialize(t, ABSi(Int(11)), "ABS($1)", int64(11))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuncSQRT(t *testing.T) {
|
||||
t.Run("float", func(t *testing.T) {
|
||||
assertClauseSerialize(t, SQRTf(table1ColFloat), "SQRT(table1.colFloat)")
|
||||
assertClauseSerialize(t, SQRTf(table1ColFloat), "SQRT(table1.col_float)")
|
||||
assertClauseSerialize(t, SQRTf(Float(11.2222)), "SQRT($1)", float64(11.2222))
|
||||
})
|
||||
|
||||
t.Run("integer", func(t *testing.T) {
|
||||
assertClauseSerialize(t, SQRTi(table1ColInt), "SQRT(table1.colInt)")
|
||||
assertClauseSerialize(t, SQRTi(table1ColInt), "SQRT(table1.col_int)")
|
||||
assertClauseSerialize(t, SQRTi(Int(11)), "SQRT($1)", int64(11))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuncCBRT(t *testing.T) {
|
||||
t.Run("float", func(t *testing.T) {
|
||||
assertClauseSerialize(t, CBRTf(table1ColFloat), "CBRT(table1.colFloat)")
|
||||
assertClauseSerialize(t, CBRTf(table1ColFloat), "CBRT(table1.col_float)")
|
||||
assertClauseSerialize(t, CBRTf(Float(11.2222)), "CBRT($1)", float64(11.2222))
|
||||
})
|
||||
|
||||
t.Run("integer", func(t *testing.T) {
|
||||
assertClauseSerialize(t, CBRTi(table1ColInt), "CBRT(table1.colInt)")
|
||||
assertClauseSerialize(t, CBRTi(table1ColInt), "CBRT(table1.col_int)")
|
||||
assertClauseSerialize(t, CBRTi(Int(11)), "CBRT($1)", int64(11))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuncCEIL(t *testing.T) {
|
||||
assertClauseSerialize(t, CEIL(table1ColFloat), "CEIL(table1.colFloat)")
|
||||
assertClauseSerialize(t, CEIL(table1ColFloat), "CEIL(table1.col_float)")
|
||||
assertClauseSerialize(t, CEIL(Float(11.2222)), "CEIL($1)", float64(11.2222))
|
||||
}
|
||||
|
||||
func TestFuncFLOOR(t *testing.T) {
|
||||
assertClauseSerialize(t, FLOOR(table1ColFloat), "FLOOR(table1.colFloat)")
|
||||
assertClauseSerialize(t, FLOOR(table1ColFloat), "FLOOR(table1.col_float)")
|
||||
assertClauseSerialize(t, FLOOR(Float(11.2222)), "FLOOR($1)", float64(11.2222))
|
||||
}
|
||||
|
||||
func TestFuncROUND(t *testing.T) {
|
||||
assertClauseSerialize(t, ROUND(table1ColFloat), "ROUND(table1.colFloat)")
|
||||
assertClauseSerialize(t, ROUND(table1ColFloat), "ROUND(table1.col_float)")
|
||||
assertClauseSerialize(t, ROUND(Float(11.2222)), "ROUND($1)", float64(11.2222))
|
||||
|
||||
assertClauseSerialize(t, ROUND(table1ColFloat, Int(2)), "ROUND(table1.colFloat, $1)", int64(2))
|
||||
assertClauseSerialize(t, ROUND(table1ColFloat, Int(2)), "ROUND(table1.col_float, $1)", int64(2))
|
||||
assertClauseSerialize(t, ROUND(Float(11.2222), Int(1)), "ROUND($1, $2)", float64(11.2222), int64(1))
|
||||
}
|
||||
|
||||
func TestFuncSIGN(t *testing.T) {
|
||||
assertClauseSerialize(t, SIGN(table1ColFloat), "SIGN(table1.colFloat)")
|
||||
assertClauseSerialize(t, SIGN(table1ColFloat), "SIGN(table1.col_float)")
|
||||
assertClauseSerialize(t, SIGN(Float(11.2222)), "SIGN($1)", float64(11.2222))
|
||||
}
|
||||
|
||||
func TestFuncTRUNC(t *testing.T) {
|
||||
assertClauseSerialize(t, TRUNC(table1ColFloat), "TRUNC(table1.colFloat)")
|
||||
assertClauseSerialize(t, TRUNC(table1ColFloat), "TRUNC(table1.col_float)")
|
||||
assertClauseSerialize(t, TRUNC(Float(11.2222)), "TRUNC($1)", float64(11.2222))
|
||||
|
||||
assertClauseSerialize(t, TRUNC(table1ColFloat, Int(2)), "TRUNC(table1.colFloat, $1)", int64(2))
|
||||
assertClauseSerialize(t, TRUNC(table1ColFloat, Int(2)), "TRUNC(table1.col_float, $1)", int64(2))
|
||||
assertClauseSerialize(t, TRUNC(Float(11.2222), Int(1)), "TRUNC($1, $2)", float64(11.2222), int64(1))
|
||||
}
|
||||
|
||||
func TestFuncLN(t *testing.T) {
|
||||
assertClauseSerialize(t, LN(table1ColFloat), "LN(table1.colFloat)")
|
||||
assertClauseSerialize(t, LN(table1ColFloat), "LN(table1.col_float)")
|
||||
assertClauseSerialize(t, LN(Float(11.2222)), "LN($1)", float64(11.2222))
|
||||
}
|
||||
|
||||
func TestFuncLOG(t *testing.T) {
|
||||
assertClauseSerialize(t, LOG(table1ColFloat), "LOG(table1.colFloat)")
|
||||
assertClauseSerialize(t, LOG(table1ColFloat), "LOG(table1.col_float)")
|
||||
assertClauseSerialize(t, LOG(Float(11.2222)), "LOG($1)", float64(11.2222))
|
||||
}
|
||||
|
||||
func TestFuncCOALESCE(t *testing.T) {
|
||||
assertClauseSerialize(t, COALESCE(table1ColFloat), "COALESCE(table1.colFloat)")
|
||||
assertClauseSerialize(t, COALESCE(table1ColFloat), "COALESCE(table1.col_float)")
|
||||
assertClauseSerialize(t, COALESCE(Float(11.2222), NULL, String("str")), "COALESCE($1, NULL, $2)", float64(11.2222), "str")
|
||||
}
|
||||
|
||||
func TestFuncNULLIF(t *testing.T) {
|
||||
assertClauseSerialize(t, NULLIF(table1ColFloat, table2ColInt), "NULLIF(table1.colFloat, table2.colInt)")
|
||||
assertClauseSerialize(t, NULLIF(table1ColFloat, table2ColInt), "NULLIF(table1.col_float, table2.col_int)")
|
||||
assertClauseSerialize(t, NULLIF(Float(11.2222), NULL), "NULLIF($1, NULL)", float64(11.2222))
|
||||
}
|
||||
|
||||
func TestFuncGREATEST(t *testing.T) {
|
||||
assertClauseSerialize(t, GREATEST(table1ColFloat), "GREATEST(table1.colFloat)")
|
||||
assertClauseSerialize(t, GREATEST(table1ColFloat), "GREATEST(table1.col_float)")
|
||||
assertClauseSerialize(t, GREATEST(Float(11.2222), NULL, String("str")), "GREATEST($1, NULL, $2)", float64(11.2222), "str")
|
||||
}
|
||||
|
||||
func TestFuncLEAST(t *testing.T) {
|
||||
assertClauseSerialize(t, LEAST(table1ColFloat), "LEAST(table1.colFloat)")
|
||||
assertClauseSerialize(t, LEAST(table1ColFloat), "LEAST(table1.col_float)")
|
||||
assertClauseSerialize(t, LEAST(Float(11.2222), NULL, String("str")), "LEAST($1, NULL, $2)", float64(11.2222), "str")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func TestInsertWithColumnList(t *testing.T) {
|
|||
columnList := ColumnList{table3ColInt, table3StrCol}
|
||||
|
||||
assertStatement(t, table3.INSERT(columnList).VALUES(1, 3), `
|
||||
INSERT INTO db.table3 (colInt, col2) VALUES
|
||||
INSERT INTO db.table3 (col_int, col2) VALUES
|
||||
($1, $2);
|
||||
`, 1, 3)
|
||||
}
|
||||
|
|
@ -39,14 +39,14 @@ func TestInsertDate(t *testing.T) {
|
|||
date := time.Date(1999, 1, 2, 3, 4, 5, 0, time.UTC)
|
||||
|
||||
assertStatement(t, table1.INSERT(table1ColTime).VALUES(date), `
|
||||
INSERT INTO db.table1 (colTime) VALUES
|
||||
INSERT INTO db.table1 (col_time) VALUES
|
||||
($1);
|
||||
`, date)
|
||||
}
|
||||
|
||||
func TestInsertMultipleValues(t *testing.T) {
|
||||
assertStatement(t, table1.INSERT(table1Col1, table1ColFloat, table1Col3).VALUES(1, 2, 3), `
|
||||
INSERT INTO db.table1 (col1, colFloat, col3) VALUES
|
||||
INSERT INTO db.table1 (col1, col_float, col3) VALUES
|
||||
($1, $2, $3);
|
||||
`, 1, 2, 3)
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ func TestInsertMultipleRows(t *testing.T) {
|
|||
VALUES(111, 222)
|
||||
|
||||
assertStatement(t, stmt, `
|
||||
INSERT INTO db.table1 (col1, colFloat) VALUES
|
||||
INSERT INTO db.table1 (col1, col_float) VALUES
|
||||
($1, $2),
|
||||
($3, $4),
|
||||
($5, $6);
|
||||
|
|
@ -83,7 +83,7 @@ func TestInsertValuesFromModel(t *testing.T) {
|
|||
USING(&toInsert)
|
||||
|
||||
expectedSql := `
|
||||
INSERT INTO db.table1 (col1, colFloat) VALUES
|
||||
INSERT INTO db.table1 (col1, col_float) VALUES
|
||||
($1, $2),
|
||||
($3, $4);
|
||||
`
|
||||
|
|
@ -140,7 +140,7 @@ func TestInsertDefaultValue(t *testing.T) {
|
|||
VALUES(DEFAULT, "two")
|
||||
|
||||
var expectedSql = `
|
||||
INSERT INTO db.table1 (col1, colFloat) VALUES
|
||||
INSERT INTO db.table1 (col1, col_float) VALUES
|
||||
(DEFAULT, $1);
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -5,77 +5,77 @@ import (
|
|||
)
|
||||
|
||||
func TestIntegerExpressionEQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.EQ(table2ColInt), "(table1.colInt = table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.EQ(Int(11)), "(table1.colInt = $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.EQ(table2ColInt), "(table1.col_int = table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.EQ(Int(11)), "(table1.col_int = $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionNOT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.NOT_EQ(table2ColInt), "(table1.colInt != table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.NOT_EQ(Int(11)), "(table1.colInt != $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.NOT_EQ(table2ColInt), "(table1.col_int != table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.NOT_EQ(Int(11)), "(table1.col_int != $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionGT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.GT(table2ColInt), "(table1.colInt > table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.GT(Int(11)), "(table1.colInt > $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.GT(table2ColInt), "(table1.col_int > table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.GT(Int(11)), "(table1.col_int > $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionGT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.GT_EQ(table2ColInt), "(table1.colInt >= table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.GT_EQ(Int(11)), "(table1.colInt >= $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.GT_EQ(table2ColInt), "(table1.col_int >= table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.GT_EQ(Int(11)), "(table1.col_int >= $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionLT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.LT(table2ColInt), "(table1.colInt < table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.LT(Int(11)), "(table1.colInt < $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.LT(table2ColInt), "(table1.col_int < table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.LT(Int(11)), "(table1.col_int < $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionLT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.LT_EQ(table2ColInt), "(table1.colInt <= table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.LT_EQ(Int(11)), "(table1.colInt <= $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.LT_EQ(table2ColInt), "(table1.col_int <= table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.LT_EQ(Int(11)), "(table1.col_int <= $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionADD(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.ADD(table2ColInt), "(table1.colInt + table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.ADD(Int(11)), "(table1.colInt + $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.ADD(table2ColInt), "(table1.col_int + table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.ADD(Int(11)), "(table1.col_int + $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionSUB(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.SUB(table2ColInt), "(table1.colInt - table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.SUB(Int(11)), "(table1.colInt - $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.SUB(table2ColInt), "(table1.col_int - table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.SUB(Int(11)), "(table1.col_int - $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionMUL(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.MUL(table2ColInt), "(table1.colInt * table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.MUL(Int(11)), "(table1.colInt * $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.MUL(table2ColInt), "(table1.col_int * table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.MUL(Int(11)), "(table1.col_int * $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntegerExpressionDIV(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.DIV(table2ColInt), "(table1.colInt / table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.DIV(Int(11)), "(table1.colInt / $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.DIV(table2ColInt), "(table1.col_int / table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.DIV(Int(11)), "(table1.col_int / $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntExpressionMOD(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.MOD(table2ColInt), "(table1.colInt % table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.MOD(Int(11)), "(table1.colInt % $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.MOD(table2ColInt), "(table1.col_int % table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.MOD(Int(11)), "(table1.col_int % $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntExpressionPOW(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.POW(table2ColInt), "(table1.colInt ^ table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.POW(Int(11)), "(table1.colInt ^ $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.POW(table2ColInt), "(table1.col_int ^ table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.POW(Int(11)), "(table1.col_int ^ $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntExpressionBIT_SHIFT_LEFT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_LEFT(table2ColInt), "(table1.colInt << table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_LEFT(Int(11)), "(table1.colInt << $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_LEFT(table2ColInt), "(table1.col_int << table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_LEFT(Int(11)), "(table1.col_int << $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntExpressionBIT_SHIFT_RIGHT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_RIGHT(table2ColInt), "(table1.colInt >> table2.colInt)")
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_RIGHT(Int(11)), "(table1.colInt >> $1)", int64(11))
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_RIGHT(table2ColInt), "(table1.col_int >> table2.col_int)")
|
||||
assertClauseSerialize(t, table1ColInt.BIT_SHIFT_RIGHT(Int(11)), "(table1.col_int >> $1)", int64(11))
|
||||
}
|
||||
|
||||
func TestIntExpressionIntExp(t *testing.T) {
|
||||
assertClauseSerialize(t, IntExp(table1ColFloat), "table1.colFloat")
|
||||
assertClauseSerialize(t, IntExp(table1ColFloat), "table1.col_float")
|
||||
assertClauseSerialize(t, IntExp(table1ColFloat.ADD(table2ColFloat)).ADD(Int(11)),
|
||||
"((table1.colFloat + table2.colFloat) + $1)", int64(11))
|
||||
"((table1.col_float + table2.col_float) + $1)", int64(11))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ func (o *orderByClauseImpl) serializeForOrderBy(statement statementType, out *qu
|
|||
}
|
||||
|
||||
if o.ascent {
|
||||
out.writeString(" ASC")
|
||||
out.writeString("ASC")
|
||||
} else {
|
||||
out.writeString(" DESC")
|
||||
out.writeString("DESC")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -10,89 +10,89 @@ func TestSelectColumnList(t *testing.T) {
|
|||
columnList := ColumnList{table2ColInt, table2ColFloat, table3ColInt}
|
||||
|
||||
assertStatement(t, SELECT(columnList).FROM(table2), `
|
||||
SELECT table2.colInt AS "table2.colInt",
|
||||
table2.colFloat AS "table2.colFloat",
|
||||
table3.colInt AS "table3.colInt"
|
||||
SELECT table2.col_int AS "table2.col_int",
|
||||
table2.col_float AS "table2.col_float",
|
||||
table3.col_int AS "table3.col_int"
|
||||
FROM db.table2;
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSelectDistinct(t *testing.T) {
|
||||
assertStatement(t, SELECT(table1ColBool).DISTINCT(), `
|
||||
SELECT DISTINCT table1.colBool AS "table1.colBool";
|
||||
SELECT DISTINCT table1.col_bool AS "table1.col_bool";
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSelectFrom(t *testing.T) {
|
||||
assertStatement(t, SELECT(table1ColInt, table2ColFloat).FROM(table1), `
|
||||
SELECT table1.colInt AS "table1.colInt",
|
||||
table2.colFloat AS "table2.colFloat"
|
||||
SELECT table1.col_int AS "table1.col_int",
|
||||
table2.col_float AS "table2.col_float"
|
||||
FROM db.table1;
|
||||
`)
|
||||
assertStatement(t, SELECT(table1ColInt, table2ColFloat).FROM(table1.INNER_JOIN(table2, table1ColInt.EQ(table2ColInt))), `
|
||||
SELECT table1.colInt AS "table1.colInt",
|
||||
table2.colFloat AS "table2.colFloat"
|
||||
SELECT table1.col_int AS "table1.col_int",
|
||||
table2.col_float AS "table2.col_float"
|
||||
FROM db.table1
|
||||
INNER JOIN db.table2 ON (table1.colInt = table2.colInt);
|
||||
INNER JOIN db.table2 ON (table1.col_int = table2.col_int);
|
||||
`)
|
||||
assertStatement(t, table1.INNER_JOIN(table2, table1ColInt.EQ(table2ColInt)).SELECT(table1ColInt, table2ColFloat), `
|
||||
SELECT table1.colInt AS "table1.colInt",
|
||||
table2.colFloat AS "table2.colFloat"
|
||||
SELECT table1.col_int AS "table1.col_int",
|
||||
table2.col_float AS "table2.col_float"
|
||||
FROM db.table1
|
||||
INNER JOIN db.table2 ON (table1.colInt = table2.colInt);
|
||||
INNER JOIN db.table2 ON (table1.col_int = table2.col_int);
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSelectWhere(t *testing.T) {
|
||||
assertStatement(t, SELECT(table1ColInt).FROM(table1).WHERE(Bool(true)), `
|
||||
SELECT table1.colInt AS "table1.colInt"
|
||||
SELECT table1.col_int AS "table1.col_int"
|
||||
FROM db.table1
|
||||
WHERE $1;
|
||||
`, true)
|
||||
assertStatement(t, SELECT(table1ColInt).FROM(table1).WHERE(table1ColInt.GT_EQ(Int(10))), `
|
||||
SELECT table1.colInt AS "table1.colInt"
|
||||
SELECT table1.col_int AS "table1.col_int"
|
||||
FROM db.table1
|
||||
WHERE table1.colInt >= $1;
|
||||
WHERE table1.col_int >= $1;
|
||||
`, int64(10))
|
||||
}
|
||||
|
||||
func TestSelectGroupBy(t *testing.T) {
|
||||
assertStatement(t, SELECT(table2ColInt).FROM(table2).GROUP_BY(table2ColFloat), `
|
||||
SELECT table2.colInt AS "table2.colInt"
|
||||
SELECT table2.col_int AS "table2.col_int"
|
||||
FROM db.table2
|
||||
GROUP BY table2.colFloat;
|
||||
GROUP BY table2.col_float;
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSelectHaving(t *testing.T) {
|
||||
assertStatement(t, SELECT(table3ColInt).FROM(table3).HAVING(table1ColBool.EQ(Bool(true))), `
|
||||
SELECT table3.colInt AS "table3.colInt"
|
||||
SELECT table3.col_int AS "table3.col_int"
|
||||
FROM db.table3
|
||||
HAVING table1.colBool = $1;
|
||||
HAVING table1.col_bool = $1;
|
||||
`, true)
|
||||
}
|
||||
|
||||
func TestSelectOrderBy(t *testing.T) {
|
||||
assertStatement(t, SELECT(table2ColFloat).FROM(table2).ORDER_BY(table2ColInt.DESC()), `
|
||||
SELECT table2.colFloat AS "table2.colFloat"
|
||||
SELECT table2.col_float AS "table2.col_float"
|
||||
FROM db.table2
|
||||
ORDER BY table2.colInt DESC;
|
||||
ORDER BY table2.col_int DESC;
|
||||
`)
|
||||
assertStatement(t, SELECT(table2ColFloat).FROM(table2).ORDER_BY(table2ColInt.DESC(), table2ColInt.ASC()), `
|
||||
SELECT table2.colFloat AS "table2.colFloat"
|
||||
SELECT table2.col_float AS "table2.col_float"
|
||||
FROM db.table2
|
||||
ORDER BY table2.colInt DESC, table2.colInt ASC;
|
||||
ORDER BY table2.col_int DESC, table2.col_int ASC;
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSelectLimitOffset(t *testing.T) {
|
||||
assertStatement(t, SELECT(table2ColInt).FROM(table2).LIMIT(10), `
|
||||
SELECT table2.colInt AS "table2.colInt"
|
||||
SELECT table2.col_int AS "table2.col_int"
|
||||
FROM db.table2
|
||||
LIMIT $1;
|
||||
`, int64(10))
|
||||
assertStatement(t, SELECT(table2ColInt).FROM(table2).LIMIT(10).OFFSET(2), `
|
||||
SELECT table2.colInt AS "table2.colInt"
|
||||
SELECT table2.col_int AS "table2.col_int"
|
||||
FROM db.table2
|
||||
LIMIT $1
|
||||
OFFSET $2;
|
||||
|
|
@ -101,23 +101,23 @@ OFFSET $2;
|
|||
|
||||
func TestSelectLock(t *testing.T) {
|
||||
assertStatement(t, SELECT(table1ColBool).FROM(table1).FOR(UPDATE()), `
|
||||
SELECT table1.colBool AS "table1.colBool"
|
||||
SELECT table1.col_bool AS "table1.col_bool"
|
||||
FROM db.table1
|
||||
FOR UPDATE;
|
||||
`)
|
||||
assertStatement(t, SELECT(table1ColBool).FROM(table1).FOR(SHARE().NOWAIT()), `
|
||||
SELECT table1.colBool AS "table1.colBool"
|
||||
SELECT table1.col_bool AS "table1.col_bool"
|
||||
FROM db.table1
|
||||
FOR SHARE NOWAIT;
|
||||
`)
|
||||
|
||||
assertStatement(t, SELECT(table1ColBool).FROM(table1).FOR(KEY_SHARE().NOWAIT()), `
|
||||
SELECT table1.colBool AS "table1.colBool"
|
||||
SELECT table1.col_bool AS "table1.col_bool"
|
||||
FROM db.table1
|
||||
FOR KEY SHARE NOWAIT;
|
||||
`)
|
||||
assertStatement(t, SELECT(table1ColBool).FROM(table1).FOR(NO_KEY_UPDATE().SKIP_LOCKED()), `
|
||||
SELECT table1.colBool AS "table1.colBool"
|
||||
SELECT table1.col_bool AS "table1.col_bool"
|
||||
FROM db.table1
|
||||
FOR NO KEY UPDATE SKIP LOCKED;
|
||||
`)
|
||||
|
|
|
|||
|
|
@ -6,67 +6,67 @@ import (
|
|||
|
||||
func TestStringEQ(t *testing.T) {
|
||||
exp := table3StrCol.EQ(table2ColStr)
|
||||
assertClauseSerialize(t, exp, "(table3.col2 = table2.colStr)")
|
||||
assertClauseSerialize(t, exp, "(table3.col2 = table2.col_str)")
|
||||
exp = table3StrCol.EQ(String("JOHN"))
|
||||
assertClauseSerialize(t, exp, "(table3.col2 = $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringNOT_EQ(t *testing.T) {
|
||||
exp := table3StrCol.NOT_EQ(table2ColStr)
|
||||
assertClauseSerialize(t, exp, "(table3.col2 != table2.colStr)")
|
||||
assertClauseSerialize(t, exp, "(table3.col2 != table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.NOT_EQ(String("JOHN")), "(table3.col2 != $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringGT(t *testing.T) {
|
||||
exp := table3StrCol.GT(table2ColStr)
|
||||
assertClauseSerialize(t, exp, "(table3.col2 > table2.colStr)")
|
||||
assertClauseSerialize(t, exp, "(table3.col2 > table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.GT(String("JOHN")), "(table3.col2 > $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringGT_EQ(t *testing.T) {
|
||||
exp := table3StrCol.GT_EQ(table2ColStr)
|
||||
assertClauseSerialize(t, exp, "(table3.col2 >= table2.colStr)")
|
||||
assertClauseSerialize(t, exp, "(table3.col2 >= table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.GT_EQ(String("JOHN")), "(table3.col2 >= $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringLT(t *testing.T) {
|
||||
exp := table3StrCol.LT(table2ColStr)
|
||||
assertClauseSerialize(t, exp, "(table3.col2 < table2.colStr)")
|
||||
assertClauseSerialize(t, exp, "(table3.col2 < table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.LT(String("JOHN")), "(table3.col2 < $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringLT_EQ(t *testing.T) {
|
||||
exp := table3StrCol.LT_EQ(table2ColStr)
|
||||
assertClauseSerialize(t, exp, "(table3.col2 <= table2.colStr)")
|
||||
assertClauseSerialize(t, exp, "(table3.col2 <= table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.LT_EQ(String("JOHN")), "(table3.col2 <= $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringCONCAT(t *testing.T) {
|
||||
assertClauseSerialize(t, table3StrCol.CONCAT(table2ColStr), "(table3.col2 || table2.colStr)")
|
||||
assertClauseSerialize(t, table3StrCol.CONCAT(table2ColStr), "(table3.col2 || table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.CONCAT(String("JOHN")), "(table3.col2 || $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringLIKE(t *testing.T) {
|
||||
assertClauseSerialize(t, table3StrCol.LIKE(table2ColStr), "(table3.col2 LIKE table2.colStr)")
|
||||
assertClauseSerialize(t, table3StrCol.LIKE(table2ColStr), "(table3.col2 LIKE table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.LIKE(String("JOHN")), "(table3.col2 LIKE $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringNOT_LIKE(t *testing.T) {
|
||||
assertClauseSerialize(t, table3StrCol.NOT_LIKE(table2ColStr), "(table3.col2 NOT LIKE table2.colStr)")
|
||||
assertClauseSerialize(t, table3StrCol.NOT_LIKE(table2ColStr), "(table3.col2 NOT LIKE table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.NOT_LIKE(String("JOHN")), "(table3.col2 NOT LIKE $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringSIMILAR_TO(t *testing.T) {
|
||||
assertClauseSerialize(t, table3StrCol.SIMILAR_TO(table2ColStr), "(table3.col2 SIMILAR TO table2.colStr)")
|
||||
assertClauseSerialize(t, table3StrCol.SIMILAR_TO(table2ColStr), "(table3.col2 SIMILAR TO table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.SIMILAR_TO(String("JOHN")), "(table3.col2 SIMILAR TO $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringNOT_SIMILAR_TO(t *testing.T) {
|
||||
assertClauseSerialize(t, table3StrCol.NOT_SIMILAR_TO(table2ColStr), "(table3.col2 NOT SIMILAR TO table2.colStr)")
|
||||
assertClauseSerialize(t, table3StrCol.NOT_SIMILAR_TO(table2ColStr), "(table3.col2 NOT SIMILAR TO table2.col_str)")
|
||||
assertClauseSerialize(t, table3StrCol.NOT_SIMILAR_TO(String("JOHN")), "(table3.col2 NOT SIMILAR TO $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringExp(t *testing.T) {
|
||||
assertClauseSerialize(t, StringExp(table2ColFloat), "table2.colFloat")
|
||||
assertClauseSerialize(t, StringExp(table2ColFloat).NOT_LIKE(String("abc")), "(table2.colFloat NOT LIKE $1)", "abc")
|
||||
assertClauseSerialize(t, StringExp(table2ColFloat), "table2.col_float")
|
||||
assertClauseSerialize(t, StringExp(table2ColFloat).NOT_LIKE(String("abc")), "(table2.col_float NOT LIKE $1)", "abc")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,13 +160,13 @@ func (t *tableImpl) serialize(statement statementType, out *queryData, options .
|
|||
return errors.New("tableImpl is nil. ")
|
||||
}
|
||||
|
||||
out.writeString(t.schemaName)
|
||||
out.writeIdentifier(t.schemaName)
|
||||
out.writeString(".")
|
||||
out.writeString(t.TableName())
|
||||
out.writeIdentifier(t.name)
|
||||
|
||||
if len(t.alias) > 0 {
|
||||
out.writeString(" AS ")
|
||||
out.writeString(t.alias)
|
||||
out.writeString("AS")
|
||||
out.writeIdentifier(t.alias)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -15,76 +15,76 @@ func TestINNER_JOIN(t *testing.T) {
|
|||
assertClauseSerialize(t, table1.
|
||||
INNER_JOIN(table2, table1ColInt.EQ(table2ColInt)),
|
||||
`db.table1
|
||||
INNER JOIN db.table2 ON (table1.colInt = table2.colInt)`)
|
||||
INNER JOIN db.table2 ON (table1.col_int = table2.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
INNER_JOIN(table2, table1ColInt.EQ(table2ColInt)).
|
||||
INNER_JOIN(table3, table1ColInt.EQ(table3ColInt)),
|
||||
`db.table1
|
||||
INNER JOIN db.table2 ON (table1.colInt = table2.colInt)
|
||||
INNER JOIN db.table3 ON (table1.colInt = table3.colInt)`)
|
||||
INNER JOIN db.table2 ON (table1.col_int = table2.col_int)
|
||||
INNER JOIN db.table3 ON (table1.col_int = table3.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
INNER_JOIN(table2, table1ColInt.EQ(Int(1))).
|
||||
INNER_JOIN(table3, table1ColInt.EQ(Int(2))),
|
||||
`db.table1
|
||||
INNER JOIN db.table2 ON (table1.colInt = $1)
|
||||
INNER JOIN db.table3 ON (table1.colInt = $2)`, int64(1), int64(2))
|
||||
INNER JOIN db.table2 ON (table1.col_int = $1)
|
||||
INNER JOIN db.table3 ON (table1.col_int = $2)`, int64(1), int64(2))
|
||||
}
|
||||
|
||||
func TestLEFT_JOIN(t *testing.T) {
|
||||
assertClauseSerialize(t, table1.
|
||||
LEFT_JOIN(table2, table1ColInt.EQ(table2ColInt)),
|
||||
`db.table1
|
||||
LEFT JOIN db.table2 ON (table1.colInt = table2.colInt)`)
|
||||
LEFT JOIN db.table2 ON (table1.col_int = table2.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
LEFT_JOIN(table2, table1ColInt.EQ(table2ColInt)).
|
||||
LEFT_JOIN(table3, table1ColInt.EQ(table3ColInt)),
|
||||
`db.table1
|
||||
LEFT JOIN db.table2 ON (table1.colInt = table2.colInt)
|
||||
LEFT JOIN db.table3 ON (table1.colInt = table3.colInt)`)
|
||||
LEFT JOIN db.table2 ON (table1.col_int = table2.col_int)
|
||||
LEFT JOIN db.table3 ON (table1.col_int = table3.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
LEFT_JOIN(table2, table1ColInt.EQ(Int(1))).
|
||||
LEFT_JOIN(table3, table1ColInt.EQ(Int(2))),
|
||||
`db.table1
|
||||
LEFT JOIN db.table2 ON (table1.colInt = $1)
|
||||
LEFT JOIN db.table3 ON (table1.colInt = $2)`, int64(1), int64(2))
|
||||
LEFT JOIN db.table2 ON (table1.col_int = $1)
|
||||
LEFT JOIN db.table3 ON (table1.col_int = $2)`, int64(1), int64(2))
|
||||
}
|
||||
|
||||
func TestRIGHT_JOIN(t *testing.T) {
|
||||
assertClauseSerialize(t, table1.
|
||||
RIGHT_JOIN(table2, table1ColInt.EQ(table2ColInt)),
|
||||
`db.table1
|
||||
RIGHT JOIN db.table2 ON (table1.colInt = table2.colInt)`)
|
||||
RIGHT JOIN db.table2 ON (table1.col_int = table2.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
RIGHT_JOIN(table2, table1ColInt.EQ(table2ColInt)).
|
||||
RIGHT_JOIN(table3, table1ColInt.EQ(table3ColInt)),
|
||||
`db.table1
|
||||
RIGHT JOIN db.table2 ON (table1.colInt = table2.colInt)
|
||||
RIGHT JOIN db.table3 ON (table1.colInt = table3.colInt)`)
|
||||
RIGHT JOIN db.table2 ON (table1.col_int = table2.col_int)
|
||||
RIGHT JOIN db.table3 ON (table1.col_int = table3.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
RIGHT_JOIN(table2, table1ColInt.EQ(Int(1))).
|
||||
RIGHT_JOIN(table3, table1ColInt.EQ(Int(2))),
|
||||
`db.table1
|
||||
RIGHT JOIN db.table2 ON (table1.colInt = $1)
|
||||
RIGHT JOIN db.table3 ON (table1.colInt = $2)`, int64(1), int64(2))
|
||||
RIGHT JOIN db.table2 ON (table1.col_int = $1)
|
||||
RIGHT JOIN db.table3 ON (table1.col_int = $2)`, int64(1), int64(2))
|
||||
}
|
||||
|
||||
func TestFULL_JOIN(t *testing.T) {
|
||||
assertClauseSerialize(t, table1.
|
||||
FULL_JOIN(table2, table1ColInt.EQ(table2ColInt)),
|
||||
`db.table1
|
||||
FULL JOIN db.table2 ON (table1.colInt = table2.colInt)`)
|
||||
FULL JOIN db.table2 ON (table1.col_int = table2.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
FULL_JOIN(table2, table1ColInt.EQ(table2ColInt)).
|
||||
FULL_JOIN(table3, table1ColInt.EQ(table3ColInt)),
|
||||
`db.table1
|
||||
FULL JOIN db.table2 ON (table1.colInt = table2.colInt)
|
||||
FULL JOIN db.table3 ON (table1.colInt = table3.colInt)`)
|
||||
FULL JOIN db.table2 ON (table1.col_int = table2.col_int)
|
||||
FULL JOIN db.table3 ON (table1.col_int = table3.col_int)`)
|
||||
assertClauseSerialize(t, table1.
|
||||
FULL_JOIN(table2, table1ColInt.EQ(Int(1))).
|
||||
FULL_JOIN(table3, table1ColInt.EQ(Int(2))),
|
||||
`db.table1
|
||||
FULL JOIN db.table2 ON (table1.colInt = $1)
|
||||
FULL JOIN db.table3 ON (table1.colInt = $2)`, int64(1), int64(2))
|
||||
FULL JOIN db.table2 ON (table1.col_int = $1)
|
||||
FULL JOIN db.table3 ON (table1.col_int = $2)`, int64(1), int64(2))
|
||||
}
|
||||
|
||||
func TestCROSS_JOIN(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import (
|
|||
)
|
||||
|
||||
var table1Col1 = IntegerColumn("col1")
|
||||
var table1ColInt = IntegerColumn("colInt")
|
||||
var table1ColFloat = FloatColumn("colFloat")
|
||||
var table1ColInt = IntegerColumn("col_int")
|
||||
var table1ColFloat = FloatColumn("col_float")
|
||||
var table1Col3 = IntegerColumn("col3")
|
||||
var table1ColTime = TimeColumn("colTime")
|
||||
var table1ColBool = BoolColumn("colBool")
|
||||
var table1ColTime = TimeColumn("col_time")
|
||||
var table1ColBool = BoolColumn("col_bool")
|
||||
|
||||
var table1 = NewTable(
|
||||
"db",
|
||||
|
|
@ -24,11 +24,11 @@ var table1 = NewTable(
|
|||
|
||||
var table2Col3 = IntegerColumn("col3")
|
||||
var table2Col4 = IntegerColumn("col4")
|
||||
var table2ColInt = IntegerColumn("colInt")
|
||||
var table2ColFloat = FloatColumn("colFloat")
|
||||
var table2ColStr = StringColumn("colStr")
|
||||
var table2ColBool = BoolColumn("colBool")
|
||||
var table2ColTime = TimeColumn("colTime")
|
||||
var table2ColInt = IntegerColumn("col_int")
|
||||
var table2ColFloat = FloatColumn("col_float")
|
||||
var table2ColStr = StringColumn("col_str")
|
||||
var table2ColBool = BoolColumn("col_bool")
|
||||
var table2ColTime = TimeColumn("col_time")
|
||||
|
||||
var table2 = NewTable(
|
||||
"db",
|
||||
|
|
@ -42,7 +42,7 @@ var table2 = NewTable(
|
|||
table2ColTime)
|
||||
|
||||
var table3Col1 = IntegerColumn("col1")
|
||||
var table3ColInt = IntegerColumn("colInt")
|
||||
var table3ColInt = IntegerColumn("col_int")
|
||||
var table3StrCol = StringColumn("col2")
|
||||
var table3 = NewTable(
|
||||
"db",
|
||||
|
|
|
|||
|
|
@ -5,37 +5,37 @@ import (
|
|||
)
|
||||
|
||||
func TestTimeExpressionEQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColTime.EQ(table2ColTime), "(table1.colTime = table2.colTime)")
|
||||
assertClauseSerialize(t, table1ColTime.EQ(Time(10, 20, 0, 0)), "(table1.colTime = $1::time without time zone)", "10:20:00.000")
|
||||
assertClauseSerialize(t, table1ColTime.EQ(table2ColTime), "(table1.col_time = table2.col_time)")
|
||||
assertClauseSerialize(t, table1ColTime.EQ(Time(10, 20, 0, 0)), "(table1.col_time = $1::time without time zone)", "10:20:00.000")
|
||||
}
|
||||
|
||||
func TestTimeExpressionNOT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColTime.NOT_EQ(table2ColTime), "(table1.colTime != table2.colTime)")
|
||||
assertClauseSerialize(t, table1ColTime.NOT_EQ(Time(10, 20, 0, 0)), "(table1.colTime != $1::time without time zone)", "10:20:00.000")
|
||||
assertClauseSerialize(t, table1ColTime.NOT_EQ(table2ColTime), "(table1.col_time != table2.col_time)")
|
||||
assertClauseSerialize(t, table1ColTime.NOT_EQ(Time(10, 20, 0, 0)), "(table1.col_time != $1::time without time zone)", "10:20:00.000")
|
||||
}
|
||||
|
||||
func TestTimeExpressionLT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColTime.LT(table2ColTime), "(table1.colTime < table2.colTime)")
|
||||
assertClauseSerialize(t, table1ColTime.LT(Time(10, 20, 0, 0)), "(table1.colTime < $1::time without time zone)", "10:20:00.000")
|
||||
assertClauseSerialize(t, table1ColTime.LT(table2ColTime), "(table1.col_time < table2.col_time)")
|
||||
assertClauseSerialize(t, table1ColTime.LT(Time(10, 20, 0, 0)), "(table1.col_time < $1::time without time zone)", "10:20:00.000")
|
||||
}
|
||||
|
||||
func TestTimeExpressionLT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColTime.LT_EQ(table2ColTime), "(table1.colTime <= table2.colTime)")
|
||||
assertClauseSerialize(t, table1ColTime.LT_EQ(Time(10, 20, 0, 0)), "(table1.colTime <= $1::time without time zone)", "10:20:00.000")
|
||||
assertClauseSerialize(t, table1ColTime.LT_EQ(table2ColTime), "(table1.col_time <= table2.col_time)")
|
||||
assertClauseSerialize(t, table1ColTime.LT_EQ(Time(10, 20, 0, 0)), "(table1.col_time <= $1::time without time zone)", "10:20:00.000")
|
||||
}
|
||||
|
||||
func TestTimeExpressionGT(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColTime.GT(table2ColTime), "(table1.colTime > table2.colTime)")
|
||||
assertClauseSerialize(t, table1ColTime.GT(Time(10, 20, 0, 0)), "(table1.colTime > $1::time without time zone)", "10:20:00.000")
|
||||
assertClauseSerialize(t, table1ColTime.GT(table2ColTime), "(table1.col_time > table2.col_time)")
|
||||
assertClauseSerialize(t, table1ColTime.GT(Time(10, 20, 0, 0)), "(table1.col_time > $1::time without time zone)", "10:20:00.000")
|
||||
}
|
||||
|
||||
func TestTimeExpressionGT_EQ(t *testing.T) {
|
||||
assertClauseSerialize(t, table1ColTime.GT_EQ(table2ColTime), "(table1.colTime >= table2.colTime)")
|
||||
assertClauseSerialize(t, table1ColTime.GT_EQ(Time(10, 20, 0, 0)), "(table1.colTime >= $1::time without time zone)", "10:20:00.000")
|
||||
assertClauseSerialize(t, table1ColTime.GT_EQ(table2ColTime), "(table1.col_time >= table2.col_time)")
|
||||
assertClauseSerialize(t, table1ColTime.GT_EQ(Time(10, 20, 0, 0)), "(table1.col_time >= $1::time without time zone)", "10:20:00.000")
|
||||
}
|
||||
|
||||
func TestTimeExp(t *testing.T) {
|
||||
assertClauseSerialize(t, TimeExp(table1ColFloat), "table1.colFloat")
|
||||
assertClauseSerialize(t, TimeExp(table1ColFloat), "table1.col_float")
|
||||
assertClauseSerialize(t, TimeExp(table1ColFloat).LT(Time(1, 1, 1, 1)),
|
||||
"(table1.colFloat < $1::time without time zone)", string("01:01:01.001"))
|
||||
"(table1.col_float < $1::time without time zone)", string("01:01:01.001"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import (
|
|||
func TestUpdateWithOneValue(t *testing.T) {
|
||||
expectedSql := `
|
||||
UPDATE db.table1
|
||||
SET colInt = $1
|
||||
WHERE table1.colInt >= $2;
|
||||
SET col_int = $1
|
||||
WHERE table1.col_int >= $2;
|
||||
`
|
||||
stmt := table1.UPDATE(table1ColInt).
|
||||
SET(1).
|
||||
|
|
@ -20,8 +20,8 @@ WHERE table1.colInt >= $2;
|
|||
func TestUpdateWithValues(t *testing.T) {
|
||||
expectedSql := `
|
||||
UPDATE db.table1
|
||||
SET (colInt, colFloat) = ($1, $2)
|
||||
WHERE table1.colInt >= $3;
|
||||
SET (col_int, col_float) = ($1, $2)
|
||||
WHERE table1.col_int >= $3;
|
||||
`
|
||||
stmt := table1.UPDATE(table1ColInt, table1ColFloat).
|
||||
SET(1, 22.2).
|
||||
|
|
@ -33,8 +33,8 @@ WHERE table1.colInt >= $3;
|
|||
func TestUpdateOneColumnWithSelect(t *testing.T) {
|
||||
expectedSql := `
|
||||
UPDATE db.table1
|
||||
SET colFloat = (
|
||||
SELECT table1.colFloat AS "table1.colFloat"
|
||||
SET col_float = (
|
||||
SELECT table1.col_float AS "table1.col_float"
|
||||
FROM db.table1
|
||||
)
|
||||
WHERE table1.col1 = $1
|
||||
|
|
@ -54,8 +54,8 @@ RETURNING table1.col1 AS "table1.col1";
|
|||
func TestUpdateColumnsWithSelect(t *testing.T) {
|
||||
expectedSql := `
|
||||
UPDATE db.table1
|
||||
SET (col1, colFloat) = (
|
||||
SELECT table1.colFloat AS "table1.colFloat",
|
||||
SET (col1, col_float) = (
|
||||
SELECT table1.col_float AS "table1.col_float",
|
||||
table2.col3 AS "table2.col3"
|
||||
FROM db.table1
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue