Skip to content

Add TypeScript type for PostgREST View in from() method #1

@Waffle0823

Description

@Waffle0823

TODO: Support PostgREST Views in TypeScript from() method

Goal

Enable type-safe usage of PostgreSQL VIEWs in supabase.from() by adding a View generic type, similar to how Table is handled.

Tasks

  • Extend Schema['Views'] to include all relevant database views.
  • Add ViewName generic constrained to keyof Schema['Views'].
  • Add View generic to represent the selected view's row structure.
  • Update from() overloads to accept view names and infer View['Row'] type.
  • Add unit tests to verify type inference for view selections.
  • Update documentation/examples for type-safe view usage.

Example

supabase
  .from<'active_users'>()
  .select('id, email') // correctly infers { id: number; email: string }[]

Notes

  • Views are read-only in most cases; consider handling insert, update, delete appropriately.
  • Ensure backward compatibility with existing table handling.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions