defineDatasource() function with schema definitions, table engines, and ingestion configurations.
Basic Datasource
Here’s a simple datasource definition:Schema Definition
Schemas are defined using thet.* type validators, which map to ClickHouse column types:
String Types
Numeric Types
Date and Time Types
Complex Types
Type Modifiers
All type validators support modifiers:Table Engines
The SDK supports all major ClickHouse table engines through theengine helper:
MergeTree (Default)
The most universal engine for high-load analytics:ReplacingMergeTree
Removes duplicate rows during background merges:SummingMergeTree
Sums numeric columns during background merges:AggregatingMergeTree
For incremental aggregation with AggregateFunction columns:CollapsingMergeTree
For collapsing state/cancel row pairs:VersionedCollapsingMergeTree
Collapsing with versioning for out-of-order events:External Data Ingestion
Kafka
Consume data from Kafka topics:~/workspace/source/src/schema/datasource.ts:64-75
S3
Import data from S3 buckets:~/workspace/source/src/schema/datasource.ts:78-89
GCS
Import data from Google Cloud Storage:~/workspace/source/src/schema/datasource.ts:92-103
Aggregate Functions
For materialized views with AggregatingMergeTree:~/workspace/source/src/schema/types.ts:392-424
Column Definitions
For advanced column configurations, use thecolumn() helper:
~/workspace/source/src/schema/datasource.ts:317-325
Secondary Indexes
Add secondary indexes for faster filtering:~/workspace/source/src/schema/datasource.ts:106-118
JSON Path Generation
By default, the SDK generates JSON path expressions for all columns. Disable this for datasources that are targets of materialized views:Schema Evolution
For incompatible schema changes, use a forward query:~/workspace/source/src/schema/datasource.ts:140-144
Related Resources
Pipes
Learn how to transform and query datasource data
Type Inference
Extract TypeScript types from datasources
Connections
External data connections (Kafka, S3, GCS)
Type Validators
Complete reference of t.* validators