sqlWhereBy function

String sqlWhereBy(
  1. Map<String, dynamic> whereValues, [
  2. String? append
])

Returns the where criteria (without where) by anding whereValues.

Note: if a value in whereValues is null, it will generate foo is null. If a value is not, it will generate !=. Example, "foo": not(null) => foo is not null. "foo": not(123) => foo != 123.

Implementation

String sqlWhereBy(Map<String, dynamic> whereValues, [String? append]) {
  final where = StringBuffer();
  bool first = true;
  whereValues.forEach((name, value) {
    if (first) first = false;
    else where.write(' and ');

    where..write('"')..write(name);

    bool negate;
    if (negate = value is Not) value = value.value;

    if (value != null) {
      where.write('"');
      if (negate) where.write('!');
      where..write('=')..write(_pool!.typeConverter.encode(value, null));
    } else {
      where.write('" is ');
      if (negate) where.write("not ");
      where.write('null');
    }
  });

  if (append != null)
    where..write(' ')..write(append);
  return where.toString();
}