Move nullIf into expression class

This commit is contained in:
Simon Binder 2022-12-14 20:47:45 +01:00
parent 41395abe3f
commit 87d0ca3c4e
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 5 additions and 8 deletions

View File

@ -165,6 +165,11 @@ abstract class Expression<D extends Object> implements FunctionParameter {
return FunctionCallExpression<T>('IIF', [predicate, this, ifFalse]); return FunctionCallExpression<T>('IIF', [predicate, this, ifFalse]);
} }
/// Returns `null` if [matcher] is equal to this expression, `this` otherwise.
Expression<D> nullIf(Expression<D> matcher) {
return FunctionCallExpression('NULLIF', [this, matcher]);
}
/// Writes this expression into the [GenerationContext], assuming that there's /// Writes this expression into the [GenerationContext], assuming that there's
/// an outer expression with [precedence]. If the [Expression.precedence] of /// an outer expression with [precedence]. If the [Expression.precedence] of
/// `this` expression is lower, it will be wrap}ped in /// `this` expression is lower, it will be wrap}ped in

View File

@ -36,14 +36,6 @@ Expression<T> ifNull<T extends Object>(
return FunctionCallExpression<T>('IFNULL', [first, second]); return FunctionCallExpression<T>('IFNULL', [first, second]);
} }
/// Extension defines the `nullIf` members.
extension SqlNullIf on Expression {
/// Returns null if both [matcher] matches this expression.
Expression nullIf(Expression matcher) {
return FunctionCallExpression('NULLIF', [this, matcher]);
}
}
class _NullCheck extends Expression<bool> { class _NullCheck extends Expression<bool> {
final Expression _inner; final Expression _inner;
final bool _isNull; final bool _isNull;