Skip to content
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

how to select with order by #21

Open
jiayuxiaochaoren opened this issue Jul 7, 2023 · 2 comments
Open

how to select with order by #21

jiayuxiaochaoren opened this issue Jul 7, 2023 · 2 comments

Comments

@jiayuxiaochaoren
Copy link

I want to get latest record,but i don't know how to query to meet such needs.

@whoiscarlo
Copy link
Contributor

So there is a way to do this. If you look at this file on line 343:

func (b *SelectRequestBuilder) OrderBy(column, direction string) *SelectRequestBuilder {
	b.params.Set("order", column+"."+direction)
	return b
}

The way it would be used is:

var results []interface{}
client := supa.CreateClient(supabase_url, supabase_key)
err := client.DB.From(tableName).Select("*").OrderBy("name", "asc").ExecuteWithContext(ctx, &results)

log.Info("results", results)

However, this addition hasn't been added to the latest tags/ releases of postgres-go so you currently can't do it until @nedpals adds the new tag.


I did push this PR though, so that the function would work this way since the order parameter is just a binary function at the end of the day.

If accepted the function would work like this:

var results []interface{}
client := supa.CreateClient(supabase_url, supabase_key)
// true for ascend
// false for descend
err := client.DB.From(tableName).Select("*").OrderBy("name", true).ExecuteWithContext(ctx, &results)

log.Info("results", results)
``

@Yongtae723
Copy link

So in conclusion, we can not use OrderBy, can we?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants