jet/bool_expression.go

160 lines
4.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
//BoolExpression interface
type BoolExpression interface {
2019-06-04 12:10:23 +02:00
Expression
2019-03-31 09:17:28 +02:00
2019-06-27 19:55:21 +02:00
// Check if this expression is equal to rhs
EQ(rhs BoolExpression) BoolExpression
// Check if this expression is not equal to rhs
NOT_EQ(rhs BoolExpression) BoolExpression
// Check if this expression is distinct to rhs
IS_DISTINCT_FROM(rhs BoolExpression) BoolExpression
2019-06-27 19:55:21 +02:00
// Check if this expression is not distinct to rhs
IS_NOT_DISTINCT_FROM(rhs BoolExpression) BoolExpression
2019-03-31 14:07:58 +02:00
2019-06-27 19:55:21 +02:00
// Check if this expression is true
IS_TRUE() BoolExpression
2019-06-27 19:55:21 +02:00
// Check if this expression is not true
IS_NOT_TRUE() BoolExpression
2019-06-27 19:55:21 +02:00
// Check if this expression is false
IS_FALSE() BoolExpression
2019-06-27 19:55:21 +02:00
// Check if this expression is not false
IS_NOT_FALSE() BoolExpression
2019-06-27 19:55:21 +02:00
// Check if this expression is unknown
IS_UNKNOWN() BoolExpression
2019-06-27 19:55:21 +02:00
// Check if this expression is not unknown
IS_NOT_UNKNOWN() BoolExpression
2019-05-29 14:03:38 +02:00
2019-06-27 19:55:21 +02:00
// expression AND operator rhs
AND(rhs BoolExpression) BoolExpression
// expression OR operator rhs
OR(rhs BoolExpression) BoolExpression
2019-03-31 09:17:28 +02:00
}
type boolInterfaceImpl struct {
parent BoolExpression
2019-03-31 09:17:28 +02:00
}
func (b *boolInterfaceImpl) EQ(expression BoolExpression) BoolExpression {
2019-06-27 19:55:21 +02:00
return eq(b.parent, expression)
2019-03-31 14:07:58 +02:00
}
func (b *boolInterfaceImpl) NOT_EQ(expression BoolExpression) BoolExpression {
2019-06-27 19:55:21 +02:00
return notEq(b.parent, expression)
2019-03-31 14:07:58 +02:00
}
func (b *boolInterfaceImpl) IS_DISTINCT_FROM(rhs BoolExpression) BoolExpression {
2019-06-27 19:55:21 +02:00
return isDistinctFrom(b.parent, rhs)
}
func (b *boolInterfaceImpl) IS_NOT_DISTINCT_FROM(rhs BoolExpression) BoolExpression {
2019-06-27 19:55:21 +02:00
return isNotDistinctFrom(b.parent, rhs)
}
func (b *boolInterfaceImpl) AND(expression BoolExpression) BoolExpression {
2019-07-15 13:06:06 +02:00
return newBinaryBoolOperator(b.parent, expression, "AND")
2019-03-31 09:17:28 +02:00
}
func (b *boolInterfaceImpl) OR(expression BoolExpression) BoolExpression {
2019-07-15 13:06:06 +02:00
return newBinaryBoolOperator(b.parent, expression, "OR")
2019-03-31 09:17:28 +02:00
}
2019-05-29 14:03:38 +02:00
func (b *boolInterfaceImpl) IS_TRUE() BoolExpression {
2019-06-05 17:15:20 +02:00
return newPostifxBoolExpression(b.parent, "IS TRUE")
2019-03-31 09:17:28 +02:00
}
func (b *boolInterfaceImpl) IS_NOT_TRUE() BoolExpression {
2019-06-05 17:15:20 +02:00
return newPostifxBoolExpression(b.parent, "IS NOT TRUE")
2019-03-31 09:17:28 +02:00
}
func (b *boolInterfaceImpl) IS_FALSE() BoolExpression {
2019-06-05 17:15:20 +02:00
return newPostifxBoolExpression(b.parent, "IS FALSE")
2019-03-31 09:17:28 +02:00
}
func (b *boolInterfaceImpl) IS_NOT_FALSE() BoolExpression {
2019-06-05 17:15:20 +02:00
return newPostifxBoolExpression(b.parent, "IS NOT FALSE")
2019-05-29 14:03:38 +02:00
}
2019-03-31 09:17:28 +02:00
func (b *boolInterfaceImpl) IS_UNKNOWN() BoolExpression {
2019-06-05 17:15:20 +02:00
return newPostifxBoolExpression(b.parent, "IS UNKNOWN")
2019-05-29 14:03:38 +02:00
}
2019-03-31 09:17:28 +02:00
func (b *boolInterfaceImpl) IS_NOT_UNKNOWN() BoolExpression {
2019-06-05 17:15:20 +02:00
return newPostifxBoolExpression(b.parent, "IS NOT UNKNOWN")
2019-03-31 09:17:28 +02:00
}
//---------------------------------------------------//
type binaryBoolExpression struct {
2019-03-31 14:07:58 +02:00
expressionInterfaceImpl
2019-03-31 09:17:28 +02:00
boolInterfaceImpl
2019-05-29 14:03:38 +02:00
binaryOpExpression
2019-03-31 09:17:28 +02:00
}
2019-07-15 13:06:06 +02:00
func newBinaryBoolOperator(lhs, rhs Expression, operator string) BoolExpression {
2019-03-31 09:17:28 +02:00
boolExpression := binaryBoolExpression{}
2019-05-29 14:03:38 +02:00
boolExpression.binaryOpExpression = newBinaryExpression(lhs, rhs, operator)
2019-03-31 14:07:58 +02:00
boolExpression.expressionInterfaceImpl.parent = &boolExpression
2019-03-31 09:17:28 +02:00
boolExpression.boolInterfaceImpl.parent = &boolExpression
return &boolExpression
}
//---------------------------------------------------//
type prefixBoolExpression struct {
2019-03-31 14:07:58 +02:00
expressionInterfaceImpl
2019-03-31 09:17:28 +02:00
boolInterfaceImpl
2019-05-29 14:03:38 +02:00
prefixOpExpression
2019-03-31 09:17:28 +02:00
}
2019-07-15 13:06:06 +02:00
func newPrefixBoolOperator(expression Expression, operator string) BoolExpression {
2019-05-29 14:03:38 +02:00
exp := prefixBoolExpression{}
exp.prefixOpExpression = newPrefixExpression(expression, operator)
2019-03-31 09:17:28 +02:00
2019-05-29 14:03:38 +02:00
exp.expressionInterfaceImpl.parent = &exp
exp.boolInterfaceImpl.parent = &exp
2019-05-29 14:03:38 +02:00
return &exp
}
2019-05-29 14:03:38 +02:00
//---------------------------------------------------//
type postfixBoolOpExpression struct {
expressionInterfaceImpl
boolInterfaceImpl
2019-05-29 14:03:38 +02:00
postfixOpExpression
}
2019-06-04 12:10:23 +02:00
func newPostifxBoolExpression(expression Expression, operator string) BoolExpression {
2019-05-29 14:03:38 +02:00
exp := postfixBoolOpExpression{}
exp.postfixOpExpression = newPostfixOpExpression(expression, operator)
2019-05-29 14:03:38 +02:00
exp.expressionInterfaceImpl.parent = &exp
exp.boolInterfaceImpl.parent = &exp
2019-05-29 14:03:38 +02:00
return &exp
}
2019-06-07 14:23:14 +02:00
//---------------------------------------------------//
type boolExpressionWrapper struct {
boolInterfaceImpl
Expression
}
func newBoolExpressionWrap(expression Expression) BoolExpression {
boolExpressionWrap := boolExpressionWrapper{Expression: expression}
boolExpressionWrap.boolInterfaceImpl.parent = &boolExpressionWrap
return &boolExpressionWrap
}
2019-07-18 17:43:11 +02:00
// BoolExp is bool expression wrapper around arbitrary expression.
// Allows go compiler to see any expression as bool expression.
// Does not add sql cast to generated sql builder output.
2019-06-07 14:23:14 +02:00
func BoolExp(expression Expression) BoolExpression {
return newBoolExpressionWrap(expression)
}