Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: query parser: add types for count #498

Merged
merged 1 commit into from
Mar 3, 2024
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
Loading