Is it possible to get paginated data and filter it...
# supabase-kt
m
Is it possible to get paginated data and filter it or sort it using a foreign key? I was trying it, it works without pagination but as soon as I add pagination it stops working.
j
Can you share your code?
m
I have something similar to this, supabase.getAll is something custom that I have to make things easier. This call works without pagination but with pagination I can't use filter or sort with the populated data.
Copy code
// Dto
@Serializable
data class SampleDto(
    val id: String,
    @SerialName("other_id_data")
    val other: OtherDto? = null,
)

// Call
fun getColumns() =
    Columns.raw(COLUMNS_VALUE)
const val COLUMNS_VALUE = "*, other_id_data: other_id(*)"

supabase.getAll(
    page = page,
    limit = limit,
    columns = SampleDto.getColumns(),
) {
    filter {
        gte(
            "other_id_data.date",
            Clock.System.now().toLocalDateTime(TimeZone.UTC).date,
        )
    }
}
j
How does the
getAll
method look?
m
Hmmm maybe having
filter
after
range
can fix this? Did you manage to reproduce it
Copy code
suspend inline fun <reified T : Any> SupabaseDataSource<T>.getAll(
    page: Long,
    limit: Int = 10,
    columns: Columns = Columns.ALL,
    crossinline filter: @PostgrestFilterDSL PostgrestRequestBuilder.() -> Unit = {},
) = handleErrors {
    postgrestBuilder
        .select(
            columns = columns,
            request = {
                filter()

                val from = (page - 1) * limit
                val to = page * limit - 1

                range(
                    from = from,
                    to = to,
                )
            },
        )
        .decodeList<T>()
}
j
I just tried something similar with a filter including a foreign key and it works as expected. Do you get no data at all when using
range
?
m