nedpals / supabase-go

Unofficial Supabase client library for Go.
https://pkg.go.dev/github.com/nedpals/supabase-go
MIT License
362 stars 69 forks source link

rpc error #15

Open rehacktive opened 1 year ago

rehacktive commented 1 year ago

Hello, I've tried to use the client rpc call with something like:

client.DB.Rpc("search",....)

but I get the error:

Post "/rpc/public/search": unsupported protocol scheme ""

I think there's an issue with the baseURL in the client maybe? can you help? thanks

JeffWelder commented 1 year ago

I'm getting the same issue here.

whoiscarlo commented 8 months ago

Any updates on this?

whoiscarlo commented 8 months ago

Alright created a fix for this issue PR.

The problem was that the Rpc() method on line 64 in the file client.go found in postgrest-go/pkg/client.go is failing because the http.NewRequest function isn't given the full REST_URL to the supabase project. Currently it's getting /rpc/[function_name], when it should be https://$SUPABASE_URL/rest/v1/rpc/[function_name].

As a temporary solution until the PR is accepted you can overwrite the file $HOME/go/pkg/mod/github.com/nedpals/postgrest-go@[latest_version]/pkg/client.go and replace line 64 with:

url := c.Transport.baseURL.String() + "/rpc/" + f
req, err := http.NewRequest("POST", url, bytes.NewBuffer(b))

Cheers!

whoiscarlo commented 8 months ago

Updated the PR again because I ran into http.bodyEOFSignal errors when the Postgres function is more complex.

Also, I rewrote the Rpc method to work similar to the From method, this way users can determined what data type they get back, if they are expecting something.

whoiscarlo commented 8 months ago

The PR has been accepted but the new tag hasn't been released so it won't work until then