Two questions relating to implicit ordering. I can obviously verify in code but I;m asking about this from a let's document the guarantee POV, partly so we don't accidentally change the behaviour:
Is there an implicit ordering to a collection, such as by insert time or key? For example when a live query doesn't have an orderBy. If so, does this work across synced and optimistic state?
Say I have a base collection that's ordered and then I derive a new collection / live query from it:
const { collection: orderedTodos } = useLiveQuery((query) =>
query
.from({ todo: todoCollection })
.orderBy(({ todo }) => todo.inserted_at, 'asc')
)
const { data: pendingTodos } = useLiveQuery((query) =>
query
.from({ todo: orderedTodos })
.where(({ todo }) => eq(todo.completed, false))
)
Is the second collection guaranteed to be in the same order as the first?
If there is not orderBy in the query, there is no implicit order - it's essentially random.
(Technically, it likely in insertion order, but that's a side effect with zero guarantee)