Skip to content

feat: automatically pass database typings to clients#366

Merged
larbish merged 3 commits into
nuxt-modules:mainfrom
IsraelOrtuno:main
Jul 5, 2024
Merged

feat: automatically pass database typings to clients#366
larbish merged 3 commits into
nuxt-modules:mainfrom
IsraelOrtuno:main

Conversation

@IsraelOrtuno

Copy link
Copy Markdown
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)

@netlify

netlify Bot commented May 8, 2024

Copy link
Copy Markdown

Deploy Preview for n3-supabase canceled.

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

@ifzm

ifzm commented Jul 5, 2024

Copy link
Copy Markdown

Looking forward to merging :)

@larbish larbish left a comment

Copy link
Copy Markdown
Member

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 🙏

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