Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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