jet/internal/jet/string_expression.go

106 lines
3.5 KiB
Go
Raw Normal View History

2019-06-21 13:56:57 +02:00
package jet
2019-07-18 17:43:11 +02:00
// StringExpression interface
type StringExpression interface {
2019-06-04 12:10:23 +02:00
Expression
EQ(rhs StringExpression) BoolExpression
NOT_EQ(rhs StringExpression) BoolExpression
IS_DISTINCT_FROM(rhs StringExpression) BoolExpression
IS_NOT_DISTINCT_FROM(rhs StringExpression) BoolExpression
LT(rhs StringExpression) BoolExpression
LT_EQ(rhs StringExpression) BoolExpression
GT(rhs StringExpression) BoolExpression
GT_EQ(rhs StringExpression) BoolExpression
2019-06-04 12:10:23 +02:00
CONCAT(rhs Expression) StringExpression
LIKE(pattern StringExpression) BoolExpression
NOT_LIKE(pattern StringExpression) BoolExpression
2019-08-15 11:10:02 +02:00
REGEXP_LIKE(pattern StringExpression, caseSensitive ...bool) BoolExpression
NOT_REGEXP_LIKE(pattern StringExpression, caseSensitive ...bool) BoolExpression
}
type stringInterfaceImpl struct {
parent StringExpression
}
func (s *stringInterfaceImpl) EQ(rhs StringExpression) BoolExpression {
return Eq(s.parent, rhs)
}
func (s *stringInterfaceImpl) NOT_EQ(rhs StringExpression) BoolExpression {
return NotEq(s.parent, rhs)
}
func (s *stringInterfaceImpl) IS_DISTINCT_FROM(rhs StringExpression) BoolExpression {
return IsDistinctFrom(s.parent, rhs)
}
func (s *stringInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs StringExpression) BoolExpression {
return IsNotDistinctFrom(s.parent, rhs)
}
func (s *stringInterfaceImpl) GT(rhs StringExpression) BoolExpression {
return Gt(s.parent, rhs)
}
2019-04-04 13:07:21 +02:00
func (s *stringInterfaceImpl) GT_EQ(rhs StringExpression) BoolExpression {
return GtEq(s.parent, rhs)
2019-05-29 14:03:38 +02:00
}
func (s *stringInterfaceImpl) LT(rhs StringExpression) BoolExpression {
return Lt(s.parent, rhs)
2019-05-29 14:03:38 +02:00
}
func (s *stringInterfaceImpl) LT_EQ(rhs StringExpression) BoolExpression {
return LtEq(s.parent, rhs)
2019-04-04 13:07:21 +02:00
}
2019-06-04 12:10:23 +02:00
func (s *stringInterfaceImpl) CONCAT(rhs Expression) StringExpression {
return newBinaryStringOperatorExpression(s.parent, rhs, StringConcatOperator)
}
func (s *stringInterfaceImpl) LIKE(pattern StringExpression) BoolExpression {
return newBinaryBoolOperatorExpression(s.parent, pattern, "LIKE")
}
func (s *stringInterfaceImpl) NOT_LIKE(pattern StringExpression) BoolExpression {
return newBinaryBoolOperatorExpression(s.parent, pattern, "NOT LIKE")
}
2019-08-15 11:10:02 +02:00
func (s *stringInterfaceImpl) REGEXP_LIKE(pattern StringExpression, caseSensitive ...bool) BoolExpression {
return newBinaryBoolOperatorExpression(s.parent, pattern, StringRegexpLikeOperator, Bool(len(caseSensitive) > 0 && caseSensitive[0]))
2019-08-15 11:10:02 +02:00
}
func (s *stringInterfaceImpl) NOT_REGEXP_LIKE(pattern StringExpression, caseSensitive ...bool) BoolExpression {
return newBinaryBoolOperatorExpression(s.parent, pattern, StringNotRegexpLikeOperator, Bool(len(caseSensitive) > 0 && caseSensitive[0]))
}
//---------------------------------------------------//
func newBinaryStringOperatorExpression(lhs, rhs Expression, operator string) StringExpression {
return StringExp(NewBinaryOperatorExpression(lhs, rhs, operator))
}
2019-06-07 14:23:14 +02:00
//---------------------------------------------------//
type stringExpressionWrapper struct {
stringInterfaceImpl
Expression
}
func newStringExpressionWrap(expression Expression) StringExpression {
stringExpressionWrap := stringExpressionWrapper{Expression: expression}
stringExpressionWrap.stringInterfaceImpl.parent = &stringExpressionWrap
return &stringExpressionWrap
}
2019-07-18 17:43:11 +02:00
// StringExp is string expression wrapper around arbitrary expression.
// Allows go compiler to see any expression as string expression.
// Does not add sql cast to generated sql builder output.
2019-06-07 14:23:14 +02:00
func StringExp(expression Expression) StringExpression {
return newStringExpressionWrap(expression)
}