Skip to content

Querying Indexed Data

View as Markdown

Use this page when the indexer is already writing rows and you want to consume them from your app or internal tooling.

Export the stream tables from your schema package, then query them with Drizzle like any other app table.

import { desc, eq } from "drizzle-orm";
import { db } from "./db";
import { tokenAccountsTable, tokenTransferEvents } from "./schema";
const recentTransfers = await db
.select()
.from(tokenTransferEvents)
.where(eq(tokenTransferEvents.dest, "ta..."))
.orderBy(desc(tokenTransferEvents.slot))
.limit(20);
const ownerBalances = await db
.select()
.from(tokenAccountsTable)
.where(eq(tokenAccountsTable.owner, "ta..."));

Direct queries are a good fit when:

  • the backend route is internal to your app
  • the query needs joins across multiple indexed tables
  • you need auth, aggregation, or business-specific response shapes
  • the result shape should evolve with your product rather than with stream definitions

For most apps:

  1. query tables directly inside the backend for core product endpoints
  2. wrap common queries in small repository functions
  3. keep auth, aggregation, and response shaping in application code