Skip to content

Commit 82d1548

Browse files
committed
feat: query parser: add types for count
Closes #447, #479.
1 parent bcbd0f4 commit 82d1548

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/select-query-parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ type ConstructFieldDefinition<
156156
: Field extends { name: string; original: string }
157157
? Field['original'] extends keyof Row
158158
? { [K in Field['name']]: Row[Field['original']] }
159+
: Field['original'] extends 'count'
160+
? { count: number }
159161
: SelectQueryError<`Referencing missing column \`${Field['original']}\``>
160162
: Record<string, unknown>
161163

test/index.test-d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
5454
expectError(postgrest.from('updatable_view').update({ non_updatable_column: 0 }))
5555
}
5656

57+
// `count` in embedded resource
58+
{
59+
const { data, error } = await postgrest.from('messages').select('message, users(count)').single()
60+
if (error) {
61+
throw new Error(error.message)
62+
}
63+
// TODO: more accurate type with correct cardinality.
64+
expectType<{ message: string | null; users: { count: number } | null }>(data)
65+
}
66+
5767
// spread resource with single column in select query
5868
{
5969
const { data, error } = await postgrest

0 commit comments

Comments
 (0)