getStrSeek method

  1. @protected
String getStrSeek(
  1. QueryDirection direction, {
  2. required bool first,
})

Returns a WHERE clause condition for query seek-based pagination.

Implementation

@protected
String getStrSeek(QueryDirection direction, {required bool first}) {
  Sql? noNulls;
  if (order.isNotEmpty)
    noNulls = order
        .map((var o) => o.sql.parens().isNotEqual(SqlL(null)))
        .reduce((var v, var e) => v & e);
  if (first) ////
    return noNulls != null ? noNulls.str : "1";
  bool forward = direction == QueryDirection.forward;
  bool distinctionRowId = distinction == QueryDistinction.rowid;
  SqlI id = SqlI(distinctionRowId ? columnRowId : columnKeyId);
  Sql seek = forward ? id > Sql.raw(":0") : id < Sql.raw(":0");
  for (int i = order.length - 1; i >= 0; --i) {
    Sql x = order[i].sql.parens();
    Sql p = Sql.raw(":${i + 1}");
    bool ascending = order[i].sorting == QuerySorting.ascending;
    if ((ascending && forward) || (!ascending && !forward))
      seek = (x >= p) & ((x > p) | seek);
    else
      seek = (x <= p) & ((x < p) | seek);
  }
  return (noNulls != null ? noNulls & seek : seek).str;
}