Data Type Formatting Functions.
This commit is contained in:
parent
938c01b9b2
commit
fcd3596780
2 changed files with 68 additions and 13 deletions
|
|
@ -86,6 +86,20 @@ func newStringFunc(name string, expressions ...expression) StringExpression {
|
||||||
return stringFunc
|
return stringFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type dateFunc struct {
|
||||||
|
funcExpressionImpl
|
||||||
|
dateInterfaceImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDateFunc(name string, expressions ...expression) DateExpression {
|
||||||
|
dateFunc := &dateFunc{}
|
||||||
|
|
||||||
|
dateFunc.funcExpressionImpl = *newFunc(name, expressions, dateFunc)
|
||||||
|
dateFunc.dateInterfaceImpl.parent = dateFunc
|
||||||
|
|
||||||
|
return dateFunc
|
||||||
|
}
|
||||||
|
|
||||||
type boolFunc struct {
|
type boolFunc struct {
|
||||||
funcExpressionImpl
|
funcExpressionImpl
|
||||||
boolInterfaceImpl
|
boolInterfaceImpl
|
||||||
|
|
@ -100,6 +114,20 @@ func newBoolFunc(name string, expressions ...expression) BoolExpression {
|
||||||
return boolFunc
|
return boolFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type timestampzFunc struct {
|
||||||
|
funcExpressionImpl
|
||||||
|
timestampzInterfaceImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTimestampzFunc(name string, expressions ...expression) TimestampzExpression {
|
||||||
|
timestampzFunc := ×tampzFunc{}
|
||||||
|
|
||||||
|
timestampzFunc.funcExpressionImpl = *newFunc(name, expressions, timestampzFunc)
|
||||||
|
timestampzFunc.timestampzInterfaceImpl.parent = timestampzFunc
|
||||||
|
|
||||||
|
return timestampzFunc
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------ Mathematical functions ---------------//
|
// ------------------ Mathematical functions ---------------//
|
||||||
|
|
||||||
func ABSf(floatExpression FloatExpression) FloatExpression {
|
func ABSf(floatExpression FloatExpression) FloatExpression {
|
||||||
|
|
@ -336,3 +364,21 @@ func TO_ASCII(str StringExpression, encoding ...StringExpression) StringExpressi
|
||||||
func TO_HEX(number IntegerExpression) StringExpression {
|
func TO_HEX(number IntegerExpression) StringExpression {
|
||||||
return newStringFunc("TO_HEX", number)
|
return newStringFunc("TO_HEX", number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------Data Type Formatting Functions ----------------------//
|
||||||
|
|
||||||
|
func TO_CHAR(expression expression, text StringExpression) StringExpression {
|
||||||
|
return newStringFunc("TO_CHAR", expression, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TO_DATE(dateStr, format StringExpression) DateExpression {
|
||||||
|
return newDateFunc("TO_DATE", dateStr, format)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TO_NUMBER(floatStr, format StringExpression) FloatExpression {
|
||||||
|
return newFloatFunc("TO_NUMBER", floatStr, format)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TO_TIMESTAMP(timestampzStr, format StringExpression) TimestampzExpression {
|
||||||
|
return newTimestampzFunc("TO_TIMESTAMP", timestampzStr, format)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,28 @@ func TestAllTypesSelect(t *testing.T) {
|
||||||
assert.DeepEqual(t, dest[1], allTypesRow1)
|
assert.DeepEqual(t, dest[1], allTypesRow1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExpressionOperators(t *testing.T) {
|
||||||
|
query := AllTypes.SELECT(
|
||||||
|
AllTypes.Integer.IS_NULL(),
|
||||||
|
AllTypes.Timestamp.IS_NOT_NULL(),
|
||||||
|
|
||||||
|
TO_CHAR(AllTypes.Timestamp, String("HH12:MI:SS")),
|
||||||
|
TO_CHAR(AllTypes.Integer, String("999")),
|
||||||
|
TO_CHAR(AllTypes.DoublePrecision, String("999D9")),
|
||||||
|
TO_CHAR(AllTypes.Numeric, String("999D99S")),
|
||||||
|
|
||||||
|
TO_DATE(String("05 Dec 2000"), String("DD Mon YYYY")),
|
||||||
|
TO_NUMBER(String("12,454"), String("99G999D9S")),
|
||||||
|
TO_TIMESTAMP(String("05 Dec 2000"), String("DD Mon YYYY")),
|
||||||
|
)
|
||||||
|
|
||||||
|
fmt.Println(query.DebugSql())
|
||||||
|
|
||||||
|
err := query.Query(db, &struct{}{})
|
||||||
|
|
||||||
|
assert.NilError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestStringOperators(t *testing.T) {
|
func TestStringOperators(t *testing.T) {
|
||||||
query := AllTypes.SELECT(
|
query := AllTypes.SELECT(
|
||||||
AllTypes.Text.EQ(AllTypes.Character),
|
AllTypes.Text.EQ(AllTypes.Character),
|
||||||
|
|
@ -87,19 +109,6 @@ func TestStringOperators(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExpressionOperators(t *testing.T) {
|
|
||||||
query := AllTypes.SELECT(
|
|
||||||
AllTypes.Integer.IS_NULL(),
|
|
||||||
AllTypes.Timestamp.IS_NOT_NULL(),
|
|
||||||
)
|
|
||||||
|
|
||||||
fmt.Println(query.DebugSql())
|
|
||||||
|
|
||||||
err := query.Query(db, &struct{}{})
|
|
||||||
|
|
||||||
assert.NilError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBoolOperators(t *testing.T) {
|
func TestBoolOperators(t *testing.T) {
|
||||||
query := AllTypes.SELECT(
|
query := AllTypes.SELECT(
|
||||||
AllTypes.Boolean.EQ(AllTypes.BooleanPtr),
|
AllTypes.Boolean.EQ(AllTypes.BooleanPtr),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue