stream_insert to update causes the row to disappear.

I’m using the generated table gen live and I’m trying to update a row in the table. The documentation says to use stream_insert to update but when I pass in the updated db row it causes the row to disappear. The workaround is to use stream_delete |> stream_insert.

Am I doing something wrong?

Thank you,

Is the id the same? Stream uses this to identify the part to replace/delete/insert.

It should be. I’m using the ID passed back to query the DB and update. Then used the same object as input into the insert. If doesn’t match what is already in the table then the stream_delete() wouldn’t be able to remove it?

Below is the code I’m using as a work around. Ideally I won’t need to use stream_delete.

 |> stream_delete(:checkins, checkin)
 |> stream_insert(:checkins, checkin)

That’s unexpected… could you show a bit more code?

From reading the stream_insert/4 docs, you should only need to chain together stream_delete and stream_insert when you want to simultaneously update and move an existing streamed resource to the top of the streamed collection.

# get existing song
song = get_song!(id)

# update in place
socket |> stream_insert(:songs, song) # or
socket |> stream_insert(:songs, song, at: -1)

# update and move to top of streamed collection
socket |> stream_insert(:songs, song, at: 0)

# update and move to bottom of streamed collection
|> stream_delete(:songs, song)
|> stream_insert(:songs, song, at: -1)