forked from supabase/postgrest-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example for erroneous TypeScript types when using non-"count" agg…
…regate functions
- Loading branch information
1 parent
7c3dd21
commit a91b000
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { expectType } from 'tsd' | ||
import { PostgrestClient } from '../src/index' | ||
import { Database } from './types' | ||
|
||
const REST_URL = 'http://localhost:3000' | ||
const postgrest = new PostgrestClient<Database>(REST_URL) | ||
|
||
// query for field of top-level resource => succeeds | ||
{ | ||
const { data, error } = await postgrest.from('messages').select('numeric_value').single() | ||
if (error) throw new Error(error.message) | ||
expectType<{ numeric_value: number }>(data) | ||
} | ||
|
||
// `sum` on top-level resource => fails | ||
{ | ||
// => const data: SelectQueryError<"Referencing missing column `sum`"> | null | ||
const { data, error } = await postgrest.from('messages').select('numeric_value.sum()').single() | ||
if (error) throw new Error(error.message) | ||
expectType<{ sum: number }>(data) | ||
} | ||
|
||
// `min` and `max` on top-level resource => fails | ||
{ | ||
// => const data: SelectQueryError<"Referencing missing column `max`"> | null | ||
const { data, error } = await postgrest | ||
.from('messages') | ||
.select('numeric_value.min(), numeric_value.max()') | ||
.single() | ||
if (error) throw new Error(error.message) | ||
expectType<{ min: number; max: number }>(data) | ||
} | ||
|
||
// `sum` on embedded resource => fails | ||
{ | ||
// => users: SelectQueryError<"Referencing missing column `sum`"> | null | ||
const { data, error } = await postgrest | ||
.from('messages') | ||
.select('message, users(numeric_value.sum())') | ||
.single() | ||
if (error) { | ||
throw new Error(error.message) | ||
} | ||
expectType<{ message: string | null; users: { sum: number } | null }>(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters