Skip to content

Allow injecting generated database types into client #90

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

Closed
MrDizzystick opened this issue Oct 20, 2022 · 0 comments
Closed

Allow injecting generated database types into client #90

MrDizzystick opened this issue Oct 20, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@MrDizzystick
Copy link

Describe the solution you'd like

The ability to pass in database types to the Supabase client, as shown in the docs here: https://supabase.com/docs/reference/javascript/typescript-support

Example of how it might be used:

import { Database } from 'lib/database.types.ts'

const client = useSupabaseClient<Database>()

const { data: book } = await client
  .from('books')  // TypeScript is aware of all the table names.
  .select()
  .eq('id', id)
  .single();

const { title, author, publish_date, created_at, updated_at } = book  // TypeScript is aware of all columns for that table.

Describe alternatives you've considered

It seems to work for the composables if I change the "useSupabaseClient" signature to <T>(): SupabaseClient<T> and use the type further down like this:

if (!nuxtApp._supabaseClient || recreateClient) {
  nuxtApp._supabaseClient = createClient<T>(url, key, options)
}

I'm not sure how to handle setting the types when the "supabase.client.ts" and "supabase.server.ts" plugins load, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant