Kotlin: Fetch data

Perform a SELECT query on the table or view.

Examples

Getting your data

val city = supabase.postgrest["cities"].select().decodeSingle<City>()

Selecting specific columns

val city = supabase.postgrest["cities"].select(columns = Columns.list("id, name")).decodeSingle<City>()

Query foreign tables

val country = supabase.postgrest["countries"]
            .select(
                columns = Columns.raw(
                                """
                                id,
                                name,
                                cities (
                                    id,
                                    name
                                )
                                """)
            )
            .decodeSingle<Country>()

Query the same foreign table multiple times

val message = supabase.postgrest["messages"]
            .select(columns = Columns.raw(
                              """
                              content,
                              from: sender_id(name),
                              to: receiver_id(name)
                              """))
            .decodeSingle<Message>()

Querying with count option

val count = supabase.postgrest["countries"]
            .select(head = true, count = Count.EXACT)
            .count()!!

Querying JSON data

val user = supabase.postgrest["users"]
            .select(columns = Columns.raw(
                            """
                            id, name
                            address->city
                            """)
            .decodeSingle<User>()