Skip to content

Commit

Permalink
feat: query parser: add types for count (#498)
Browse files Browse the repository at this point in the history
Closes #447, #479.
  • Loading branch information
bnjmnt4n committed Mar 3, 2024
1 parent 14910bf commit 5ea5163
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/select-query-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ type ConstructFieldDefinition<
: Field extends { name: string; original: string }
? Field['original'] extends keyof Row
? { [K in Field['name']]: Row[Field['original']] }
: Field['original'] extends 'count'
? { count: number }
: SelectQueryError<`Referencing missing column \`${Field['original']}\``>
: Record<string, unknown>

Expand Down
9 changes: 9 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
expectType<{ message: string | null }>(data)
}

// `count` in embedded resource
{
const { data, error } = await postgrest.from('messages').select('message, users(count)').single()
if (error) {
throw new Error(error.message)
}
expectType<{ message: string | null; users: { count: number } | null }>(data)
}

// json accessor in select query
{
const { data, error } = await postgrest
Expand Down

0 comments on commit 5ea5163

Please sign in to comment.