Skip to content

How do I use generated database types? #150

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
gergely-xyz opened this issue Feb 5, 2023 · 5 comments
Closed

How do I use generated database types? #150

gergely-xyz opened this issue Feb 5, 2023 · 5 comments
Labels
question Further information is requested Stale

Comments

@gergely-xyz
Copy link

I would like to use the types generated with the supabase cli. #90 was closed as completed so I'm assuming this is possible, but I can't seem to make it work.

I've generated the types of my database:
supabase gen types typescript --linked > supabase/schema.ts

And added the following to my nuxt.config.ts:

import { Database } from './supabase/schema'
export default defineNuxtConfig({
// ...
  supabase: {
    client: {
      db: {
        schema: Database,
      },
    },
  },
// ...
}

The documentation references this for available options.
I expected type hints to show up as shown here.

@gergely-xyz gergely-xyz added the question Further information is requested label Feb 5, 2023
@tomvoet
Copy link

tomvoet commented Feb 10, 2023

Hi,
you just need to add the Database interface as the type parameter in the angle brackets '<>'.

const supabase = useSupabaseClient<Database>();

This should probably do the trick :)

@ozum
Copy link

ozum commented Feb 25, 2023

It would be a better DX if we can add this to the module configuration to be automatically used for every useSupabaseClient call.

export default defineNuxtConfig({
  // ...
  supabase: {
    types: "~/types/database"
  }
}

Just for this purpose, I also created a PR (#160) to make auto imports optional, so I can create my own composable which adds types and reexports the client.

/composables/useSupaClient.ts

import type { Database } from "~/types/database";
export default () => useSupabaseClient<Database>();

Currently, I have to use a different name, because auto imported composables overwrite the local composables with same name.

Problem is, other developers may not know that there is a useSupaClient composable and use by mistake auto imported useSupabaseClient composable.

@ozum ozum mentioned this issue Feb 25, 2023
6 tasks
@zernonia
Copy link

zernonia commented Mar 3, 2023

I agree that adding types in config will improve DX by a huge factor. I wouldn't want to keep importing the same types over and over again in components/composables.

Copy link

github-actions bot commented May 6, 2025

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label May 6, 2025
Copy link

github-actions bot commented Jun 5, 2025

This issue was closed because it has been stalled for 30 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

4 participants