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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

IsraelOrtuno
Copy link

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 request for n3-supabase pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 3706aea

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.

None yet

1 participant