Hey! :wave: In realtime, specifying the primary ke...
# supabase-kt
n
Hey! 👋 In realtime, specifying the primary key of the listened table is needed. 1. Why is this a need? 2. How can a multi-column PK be passed?
Is something like this correct?
Copy code
.selectAsFlow<PubAdmin>(
    PrimaryKey("pub_admin") { it.user + it.pub },
    filter = FilterOperation("user", FilterOperator.EQ, userId)
)
j
The primary key is used for local caching because realtime doesn't send over all the rows matching the filter on a database update. You specify two things with this parameter: 1. the actual column name like "product_id" which is used for the DELETE event and 2. a producer to get the value of the primary key once the updated object has been serialized. As of now, there is no way to pass a multi-column PK. It may be possible though if you add the possibility to provide a list of primary keys and use a concatinated string of all primary keys as the key for the cache?
n
Sorry, I didn’t come back to you.
It may be possible though if you add
You mean to add this in the SDK, right?
j
Yes.
n
I’ll take a look 🙂, thanks!
j
Yea I think its best to have the base method with a list of primary keys and all other existing methods are just overloads calling
selectAsFlow(listOf(primaryKey))
. With that, there are no big breaking changes needed
n
That sounds like a good strategy 🙂. Let me open a PR with it.