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 ClickHouse guide for usage examples, table design, and setup instructions.
import { clickhouseTarget } from '@subsquid/pipes/targets/clickhouse'

clickhouseTarget

clickhouseTarget<T>({
  client: ClickHouseClient,
  onStart?: (ctx: { store: ClickhouseStore; logger: Logger }) => unknown | Promise<unknown>,
  onData: (ctx: { store: ClickhouseStore; data: T; ctx: Ctx }) => unknown | Promise<unknown>,
  onRollback?: (ctx: {
    type: 'offset_check' | 'blockchain_fork'
    store: ClickhouseStore
    safeCursor: BlockCursor
    /** @deprecated Use `safeCursor` instead. */
    cursor: BlockCursor
  }) => unknown | Promise<unknown>,
  settings?: Settings,
})
ParameterRequiredDescription
clientYesClient from @clickhouse/client.
onStartNoRuns once before processing starts. Use for table creation or other setup.
onDataYesCalled for each batch.
onRollbackNoCalled on startup ('offset_check') and on each fork ('blockchain_fork').
settingsNoConfiguration for the internal cursor state table. See Settings below.
Settings:
FieldDefaultDescription
databaseClient’s configured databaseClickHouse database for the state table.
table'sync'Name of the state table.
id'stream'Stream identifier within the state table.
maxRows10000Maximum rows retained per stream id in the state table.

ClickhouseStore methods

MethodDescription
store.insert(params)Queues an insert. Non-blocking — returns a Promise but need not be awaited inside onData; inserts are flushed when the target closes.
store.query(params)Passthrough to client.query().
store.command(params)Passthrough to client.command().
store.removeAllRows({ tables, where, params? })Cancels rows matching where by re-inserting them with sign = -1. Requires CollapsingMergeTree.
store.removeAllRowsByQuery({ table, query, params? })Like removeAllRows, but uses a custom SELECT to identify the rows to cancel.
store.executeFiles(dir)Executes all .sql files found in dir.