TanStackT
TanStack6mo ago
5 replies
hurt-tomato

is a live query collection just an alias for a regular collection?

maybe im overthinking this. say i have
const usersCollection = createCollection(
  queryCollectionOptions({
    id: "users",

and want to imperatively, outside of react, get a user.
// Assuming this is correct
usersCollection.get(id)

and i want to alias a view of this query. in react-query i would use the select callback. the docs (https://tanstack.com/db/latest/docs/guides/live-queries) say to use live query to alias
const activeUsers = createCollection(liveQueryCollectionOptions({
  query: (q) =>
    q
      .from({ user: usersCollection })
      .where(({ user }) => eq(user.active, true))
      .select(({ user }) => ({
        id: user.id,
        name: user.name,
        email: user.email,
      }))
}))

but it doesn't say what usersCollection is this scenario. so i'm assuming it is a regular createCollection(queryCollectionOptions({. I guess I'm not understanding the difference in these two types and their compatibility.
TanStack DB Live Queries TanStack DB provides a powerful, type-safe query system that allows you to fetch, filter, transform, and aggregate data from collections using a SQL-like fluent API. All queri...
Was this page helpful?