Skip to content

Qu: is it correct to assume implicit order preservation? #317

@thruflo

Description

@thruflo

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:

  1. 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?

  2. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions