buildPaginated method
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
''';
});
}