0

For supabase 1 there was open-api to generate types for typescript which is pretty clear: https://supabase.com/docs/guides/api/generating-types npx openapi-typescript https://your-project.supabase.co/rest/v1/?apikey=your-anon-key --output types/supabase.ts

But I am not able to use them with supabase rc 2. enter image description here

So I assume I need to follow the new documentation, but there is no description of how to do it. There is only one for local DB. Plus I found --db-url flag but not more info regarding that.

https://supabase.com/docs/reference/javascript/next/typescript-support

I have tried this command: npx supabase gen types typescript --db-url https://your-project.supabase.co > src/database.types.ts, but I am getting error: Error: URL is not a valid Supabase connection string.

Thank you for help

Dawe
  • 562
  • 1
  • 9
  • 19

1 Answers1

1

for --db-url use the connection string shown under /settings/database, I used the node version. It should look something like

postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres
Andrew Smith
  • 1,224
  • 6
  • 9
HotCustard
  • 11
  • 1
  • 1
  • This moved me to the next step, thank you. It run that command, but I am getting error: `Error: error running container` – Dawe Oct 08 '22 at 20:23
  • It seems that I have issue with connecting to database via uri. I am getting error: ```failed: Connection refused. Is the server running on that host and accepting TCP/IP connections?``` – Dawe Oct 09 '22 at 10:54
  • @Dawe You need to be using your own project reference and not the one posted in HotCustard's example. You also need to have docker running on your computer as it's a requirement for the types generation code. – Andrew Smith Oct 09 '22 at 14:27
  • @AndrewSmith I have all of this, and of course, I am using my project URL. Docker is running - have docker desktop. I also used it to get types from local DB (I just pulled schema to local via supabase-cli), but it is not much comfortable – Dawe Oct 09 '22 at 18:08
  • @Dawe Sounds like your --db-url is pointing to a locally hosted version, but the local version is not running. You can point to the supabase hosted version and bypass needing a local version. If you want it generating from local then you will need to work out what the correct connection string should be based on your local setup. – HotCustard Oct 10 '22 at 07:30
  • @HotCustard --db-url gets remote url (which I get on my project at supabase.com). For local URL I use `supabase gen types typescript --local` this command, which works correctly. – Dawe Oct 10 '22 at 07:34