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: typecheck table names in .from() #528

Merged
merged 1 commit into from
Mar 28, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/PostgrestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default class PostgrestClient<
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
relation: ViewName
): PostgrestQueryBuilder<Schema, View, ViewName>
from(relation: string): PostgrestQueryBuilder<Schema, any, any>
/**
* Perform a query on a table or a view.
*
Expand Down
2 changes: 2 additions & 0 deletions test/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ test('throwOnError throws errors instead of returning them', async () => {
let isErrorCaught = false

try {
// @ts-expect-error: nonexistent table
await postgrest.from('missing_table').select().throwOnError()
} catch (error) {
expect(error).toMatchInlineSnapshot(
Expand All @@ -642,6 +643,7 @@ test('throwOnError throws errors instead of returning them', async () => {

test('throwOnError throws errors which include stack', async () => {
try {
// @ts-expect-error: nonexistent table
await postgrest.from('does_not_exist').select().throwOnError()
} catch (err) {
expect(err instanceof Error).toBe(true)
Expand Down
1 change: 1 addition & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
// table invalid type
{
expectError(postgrest.from(42))
expectError(postgrest.from('nonexistent_table'))
}

// `null` can't be used with `.eq()`
Expand Down