Skip to main content

Documentation Index

Fetch the complete documentation index at: https://beta.docs.sqd.dev/llms.txt

Use this file to discover all available pages before exploring further.

See the Postgres via Drizzle guide for usage examples and setup instructions.
import { drizzleTarget } from '@subsquid/pipes/targets/drizzle/node-postgres'

drizzleTarget

drizzleTarget<T>({
  db: NodePgDatabase,
  tables: Table[] | Record<string, Table>,
  onStart?: (ctx: { db: NodePgDatabase }) => Promise<unknown>,
  onData: (ctx: { tx: Transaction; data: T; ctx: Ctx }) => Promise<unknown>,
  onBeforeRollback?: (ctx: { tx: Transaction; cursor: BlockCursor }) => Promise<unknown> | unknown,
  onAfterRollback?: (ctx: { tx: Transaction; cursor: BlockCursor }) => Promise<unknown> | unknown,
  settings?: {
    state?: StateOptions
    transaction?: {
      isolationLevel?: 'read uncommitted' | 'read committed' | 'repeatable read' | 'serializable'
    }
  },
})
ParameterRequiredDescription
dbYesDrizzle NodePgDatabase instance. Must expose $client (a pg Pool or Client).
tablesYesTables tracked for automatic fork rollback. All tables written to in onData must appear here.
onStartNoRuns once before processing starts. Receives { db }.
onDataYesCalled for each batch inside a serializable transaction.
onBeforeRollbackNoCalled inside the rollback transaction before snapshots are replayed.
onAfterRollbackNoCalled inside the rollback transaction after snapshots are replayed.
settings.stateNoConfiguration for the internal cursor state table. See StateOptions below.
settings.transaction.isolationLevelNoTransaction isolation level. Defaults to 'serializable'.
StateOptions:
FieldDefaultDescription
schema'public'PostgreSQL schema for the state table.
table'sync'Name of the state table.
id'stream'Stream identifier within the state table.
unfinalizedBlocksRetention1000Number of unfinalized blocks retained in state for rollback purposes.

batchForInsert

import { batchForInsert } from '@subsquid/pipes/targets/drizzle/node-postgres'
function batchForInsert<T>(data: readonly T[], size?: number): Generator<T[]>
Splits an array into chunks that fit within PostgreSQL’s 32,767-parameter limit. Chunk size is Math.floor(32767 / columnsPerRecord) by default. Pass size to set a smaller cap; values exceeding the computed maximum are silently clamped. chunk is a deprecated alias for batchForInsert.