supabase-community / postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
https://supabase.io
Apache License 2.0
170 stars 27 forks source link

Select from table fails #9

Closed txbrown closed 3 years ago

txbrown commented 3 years ago

Bug report

Describe the bug

Following the test example and the supabase-js example in the documentation I am not able to fetch data using the From().Select() chain and an error is returned in the response body instead of the err value itself.

The json response looks like:

{"message":"no Route matched with those values"}

To Reproduce

        type User struct {
        id string
    }

        var (
            headers = map[string]string{"Authorization": fmt.Sprintf("Bearer %s", serverconf.Supabase.Key)}
            schema  = "public"
        )

        var serverconf := utils.NewServerConfig()

        supabaseClient := postgrest.NewClient(serverconf.Supabase.URL, schema, headers)

        res, err := r.client.From("users").Select("*", "", false).Eq("email", email).Execute()

    if err := json.Unmarshal(res, &result); err != nil {
        panic(err)
    }

Expected behavior

Expected to have a valid user response and no error. Also expected error to be returned in err variable but instead it's nil.

yusufpapurcu commented 3 years ago

Can you check your supabase url? Your url must something like this: https://github.com/supabase/postgrest-go/issues/3#issuecomment-854105015

txbrown commented 3 years ago

@yusufpapurcu thanks, that helped. however I still get no api key found error too. Would you be able to point me to documentation where I can read about these endpoints and how to communicate with the api e.g. with curl or insomnia for example?

yusufpapurcu commented 3 years ago

Actually there is no referance that I can mention. I learned using API from debugging JS library. So we are working on other libraries (goTrue-Storage-Realtime) for provide support them in golang.

yusufpapurcu commented 3 years ago

For now you can get api-key from js library's user object and you can use it.

txbrown commented 3 years ago

I see. having had a look I also noticed that the headers need to be like

    headers  = map[string]string{"apikey": "<supaba_api_key>"}

Now the requests go through! However getting errors for non existing public relations "public.users does not exist".

I'll keep trying to reverse-engineer it for my needs and if I find useful things to document I'll report back. Thanks!

intabulas commented 3 years ago

@txbrown Regarding returning an error. I did just submit PR #11 for Execute() to actually return errors when there are any