where method

QueryBuilder where(
  1. String column, {
  2. Object? equals,
  3. Object? notEquals,
  4. Object? greaterThan,
  5. Object? lessThan,
  6. Object? greaterThanOrEqual,
  7. Object? lessThanOrEqual,
  8. String? like,
  9. List<Object?>? whereIn,
  10. bool isNull = false,
  11. bool isNotNull = false,
})

Adds a WHERE condition. Pass exactly one named argument per call.

.where('age', greaterThan: 18)
.where('email', like: '%@corp.com')
.where('role', whereIn: ['admin', 'editor'])
.where('deleted_at', isNull: true)

Implementation

QueryBuilder where(
  String column, {
  Object? equals,
  Object? notEquals,
  Object? greaterThan,
  Object? lessThan,
  Object? greaterThanOrEqual,
  Object? lessThanOrEqual,
  String? like,
  List<Object?>? whereIn,
  bool isNull = false,
  bool isNotNull = false,
}) {
  if (isNull) {
    _conditions.add(_Condition(column, 'IS NULL', null));
  } else if (isNotNull) {
    _conditions.add(_Condition(column, 'IS NOT NULL', null));
  } else if (equals != null) {
    _conditions.add(_Condition(column, '=', equals));
  } else if (notEquals != null) {
    _conditions.add(_Condition(column, '!=', notEquals));
  } else if (greaterThan != null) {
    _conditions.add(_Condition(column, '>', greaterThan));
  } else if (lessThan != null) {
    _conditions.add(_Condition(column, '<', lessThan));
  } else if (greaterThanOrEqual != null) {
    _conditions.add(_Condition(column, '>=', greaterThanOrEqual));
  } else if (lessThanOrEqual != null) {
    _conditions.add(_Condition(column, '<=', lessThanOrEqual));
  } else if (like != null) {
    _conditions.add(_Condition(column, 'LIKE', like));
  } else if (whereIn != null) {
    if (whereIn.isEmpty) {
      throw ArgumentError.value(
        whereIn,
        'whereIn',
        'whereIn list must not be empty — an empty IN () clause is invalid SQL',
      );
    }
    _conditions.add(_Condition(column, 'IN', whereIn));
  }
  return this;
}