Querying Indexed Data
Use this page when the indexer is already writing rows and you want to consume them from your app or internal tooling.
Direct Table Queries
Section titled “Direct Table Queries”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..."));When To Query Tables Directly
Section titled “When To Query Tables Directly”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
Practical Recommendation
Section titled “Practical Recommendation”For most apps:
- query tables directly inside the backend for core product endpoints
- wrap common queries in small repository functions
- keep auth, aggregation, and response shaping in application code