Skip to content

Commit

Permalink
fix: typings
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Sep 9, 2022
1 parent b2028cd commit eff88f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/SupabaseClient.ts
Expand Up @@ -151,10 +151,13 @@ export default class SupabaseClient<
from<
TableName extends string & keyof Schema['Tables'],
Table extends Schema['Tables'][TableName]
>(table: TableName): PostgrestQueryBuilder<Table>
from(table: string): PostgrestQueryBuilder<any>
from(table: string): PostgrestQueryBuilder<any> {
return this.rest.from(table)
>(relation: TableName): PostgrestQueryBuilder<Table>
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
relation: ViewName
): PostgrestQueryBuilder<View>
from(relation: string): PostgrestQueryBuilder<any>
from(relation: string): PostgrestQueryBuilder<any> {
return this.rest.from(relation)
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/lib/types.ts
Expand Up @@ -59,12 +59,25 @@ export type GenericTable = {
Update: Record<string, unknown>
}

export type GenericUpdatableView = {
Row: Record<string, unknown>
Insert: Record<string, unknown>
Update: Record<string, unknown>
}

export type GenericNonUpdatableView = {
Row: Record<string, unknown>
}

export type GenericView = GenericUpdatableView | GenericNonUpdatableView

export type GenericFunction = {
Args: Record<string, unknown>
Returns: unknown
}

export type GenericSchema = {
Tables: Record<string, GenericTable>
Views: Record<string, GenericView>
Functions: Record<string, GenericFunction>
}

3 comments on commit eff88f9

@drewbietron
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why, but compared to rc.9 I am no longer getting type inference with the client in this version.

rc.9
client.from('' // type inferred for my tables in database types)

rc.10
client.from('' // no table values pop up)

@soedirgo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drewbietron you might just need to regenerate your types - it needs the additional Views.

@drewbietron
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @soedirgo!

Please sign in to comment.