supabase
supabase copied to clipboard
feat: automatically pass database typings to clients
Types of changes
- [ ] Bug fix (a non-breaking change which fixes an issue)
- [x] New feature (a non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Description
This PR aims to automatically pass Supabase database generated types to the clients to get autocompletion and type-safe results when querying the database. By default it will try to locate the database typings ~/types/database.types.ts
.
This can be configured:
defineNuxtConfig({
supabase: {
types: './path/to/types/file' // or false to disable this behaviour
}
})
Types could be overwritten too:
import type { Database } from '~/other'
const client = useSupabaseClient<Database>()
What it does under the hood is to basically map type Database
to what is found in that file (if exists) as this type is always passed to the clients. If not, it will generate a default type Database = unknown
so the clients still get a type. It's my first working with auto-generated TypeScript so not sure if it's the way to go but works pretty nice. Open to any suggestions of how this should be made.
Resolves what motivated @ozum to submit this PR #160 and also this issue #150
Checklist:
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes (if not applicable, please state why)