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: automatically pass database typings to clients #366

Merged
merged 3 commits into from
Jul 5, 2024

Conversation

IsraelOrtuno
Copy link
Contributor

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • 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:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

Copy link

netlify bot commented May 8, 2024

Deploy Preview for n3-supabase canceled.

Name Link
🔨 Latest commit b1044e4
🔍 Latest deploy log https://app.netlify.com/sites/n3-supabase/deploys/6687cef1b7f2da0008ff05f2

@ifzm
Copy link

ifzm commented Jul 5, 2024

Looking forward to merging :)

Copy link
Collaborator

@larbish larbish left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR @IsraelOrtuno. I was waiting for an upstream fix to merge this big PR and merge all other fixes and features. That's why it took time to merge 🙏

@larbish larbish merged commit 132307a into nuxt-modules:main Jul 5, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants