discontinuedPackage connect_database has been discontinued.

buildPaginated method

Future<Result<String>> buildPaginated(
  1. String tableName, {
  2. required String orderBy,
  3. int page = 1,
  4. int pageSize = 100,
  5. int maxLobSize = 4000,
  6. bool withNoLock = false,
})

Generates a paginated SELECT (Requires SQL Server 2012+). orderBy is required for pagination.

Implementation

Future<Result<String>> buildPaginated(
  String tableName, {
  required String orderBy,
  int page = 1,
  int pageSize = 100,
  int maxLobSize = 4000,
  bool withNoLock = false,
}) async {
  return (await getSafeColumns(tableName, maxLobSize: maxLobSize))
      .map((cols) {
    final offset = (page - 1) * pageSize;
    return '''
      SELECT $cols
      FROM $tableName${withNoLock ? ' WITH (NOLOCK)' : ''}
      ORDER BY $orderBy
      OFFSET $offset ROWS FETCH NEXT $pageSize ROWS ONLY
    ''';
  });
}