Skip to content

Allow injecting generated database types into client #90

Description

@MrDizzystick

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions