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

Refactor Postgrest syntax and implementation #353

Merged
merged 17 commits into from
Nov 22, 2023

Conversation

jan-tennert
Copy link
Collaborator

@jan-tennert jan-tennert commented Nov 20, 2023

What kind of change does this PR introduce?

Feature (closes #352 and #342)

What is the old behavior?

The old syntax looks something like this:

val city = City(name = "The Shire", countryId = 554)
supabase.postgrest["cities"].insert(city, returning = Returning.MINIMAL)
supabase.postgrest["countries"].update(newCity, returning = Returning.REPRESENTATION, count = Count.EXACT) {
   eq("id", 1)
}

What is the new behavior?

This PR refactors the Postgrest syntax. All parameters in the query methods (insert, update, delete etc.) have been moved to the new request builder. Here is an example (this is just to show all methods, you'll most likely not use all of them together):

val result = supabase.postgrest["message"].update(newMessage) { //you can also use supabase.from("message")
    select()
    count(Count.ESTIMATED)
    single()
    order("user_id", Order.ASCENDING, referencedTable = "users")
    csv()
    geojson()
    explain(analyze = true)
    filter {
        eq("id", 1)
    }
}
println(result.data)
println(result.decodeSingle<Message>())
println(result.countOrNull())
println(result.headers)

Additional context

Add any other context or screenshots.

@jan-tennert jan-tennert added enhancement New feature or request postgrest labels Nov 20, 2023
@jan-tennert jan-tennert self-assigned this Nov 20, 2023
@dshukertjr
Copy link
Member

Love the new syntax! Thanks for this update!

@jan-tennert jan-tennert marked this pull request as ready for review November 20, 2023 17:51
@jan-tennert jan-tennert changed the title Postgrest refactor Refactor Postgrest syntax and implementation Nov 20, 2023
@jan-tennert jan-tennert merged commit d827fab into development Nov 22, 2023
@jan-tennert jan-tennert deleted the postgrest-refactor branch November 22, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request postgrest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants