Skip to content

Commit

Permalink
fix: issue where .range() not respecting the offset given. (#722)
Browse files Browse the repository at this point in the history
* add more cases for range

* fix: range properly starts from the given offset
  • Loading branch information
dshukertjr committed Nov 22, 2023
1 parent 60a2515 commit e3541a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/postgrest/lib/src/postgrest_builder.dart
Expand Up @@ -317,18 +317,19 @@ class PostgrestBuilder<T, S, R> implements Future<T> {
///
/// [url] may be used to update based on a different url than the current one
Uri appendSearchParams(String key, String value, [Uri? url]) {
final searchParams = Map<String, dynamic>.from(_url.queryParametersAll);
final searchParams =
Map<String, dynamic>.from((url ?? _url).queryParametersAll);
searchParams[key] = [...searchParams[key] ?? [], value];
return (url ?? _url).replace(queryParameters: searchParams);
}

/// Get new Uri with overridden queryParams
///
/// [url] may be used to update based on a different url than the current one
Uri overrideSearchParams(String key, String value, [Uri? url]) {
Uri overrideSearchParams(String key, String value) {
final searchParams = Map<String, dynamic>.from(_url.queryParametersAll);
searchParams[key] = value;
return (url ?? _url).replace(queryParameters: searchParams);
return _url.replace(queryParameters: searchParams);
}

@override
Expand Down
4 changes: 3 additions & 1 deletion packages/postgrest/test/transforms_test.dart
Expand Up @@ -143,10 +143,12 @@ void main() {

test('range', () async {
const from = 1;
const to = 3;
const to = 2;
final res = await postgrest.from('users').select().range(from, to);
//from -1 so that the index is included
expect(res.length, to - (from - 1));
expect(res[0]['username'], 'kiwicopple');
expect(res[1]['username'], 'awailas');
});

test('range 1-1', () async {
Expand Down

0 comments on commit e3541a4

Please sign in to comment.