Skip to content

Commit d66aaab

Browse files
authored
fix: enable filtering and tranformation on count with head (supabase#768)
* fix: enable filtering and tranformation on count with head * modify test
1 parent 7daba8d commit d66aaab

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/postgrest/lib/src/postgrest_query_builder.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ class PostgrestQueryBuilder<T> extends RawPostgrestBuilder<T, T, T> {
250250
/// ```dart
251251
/// int count = await supabase.from('users').count();
252252
/// ```
253-
RawPostgrestBuilder<int, int, int> count(
254-
[CountOption option = CountOption.exact]) {
255-
return _copyWithType(
253+
PostgrestFilterBuilder<int> count([CountOption option = CountOption.exact]) {
254+
return PostgrestFilterBuilder<int>(_copyWithType(
256255
method: METHOD_HEAD,
257256
count: option,
258-
);
257+
));
259258
}
260259
}

packages/postgrest/test/basic_test.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,29 @@ void main() {
283283
await postgrest.from('users').select('*').head();
284284
});
285285

286+
test('count with head: true, filters', () async {
287+
final int count = await postgrest
288+
.from('users')
289+
.count(CountOption.exact)
290+
.eq('status', 'ONLINE');
291+
expect(count, 3);
292+
});
293+
286294
test('select with head:true, count: exact', () async {
287-
final res = await postgrest.from('users').count(CountOption.exact);
295+
final int res = await postgrest.from('users').count(CountOption.exact);
288296
expect(res, 4);
289297
});
290298

291299
test('select with count: planned', () async {
292300
final res =
293301
await postgrest.from('users').select('*').count(CountOption.planned);
294-
expect(res.count, isNotNull);
302+
final int count = res.count;
303+
expect(count, isNotNull);
295304
});
296305

297306
test('select with head:true, count: estimated', () async {
298-
final res = await postgrest.from('users').count(CountOption.estimated);
307+
final int res =
308+
await postgrest.from('users').count(CountOption.estimated);
299309
expect(res, isA<int>());
300310
});
301311

0 commit comments

Comments
 (0)