A Go tool that automatically generates Go struct models from your ClickHouse database schema.
- Generates Go structs with proper type mappings for ClickHouse columns
- Handles enums, nullable types, arrays, and complex ClickHouse types
- Includes JSON, database, and validation tags
- Optimized for financial/trading data with decimal precision
- Supports aggregate functions and materialized views
go install github.com/sxlgg/clickhouse-go-models@latestOr clone and build:
git clone https://github.com/sxlgg/clickhouse-go-models
cd clickhouse-go-models
go build -o clickhouse-go-models- Create a
.envfile with your ClickHouse connection details - Run the generator:
# Generate models to default location
./clickhouse-go-models
# Custom output file and package
./clickhouse-go-models --output models/db.go --package db
# Dry run to see output without writing file
./clickhouse-go-models --dry-run --verboseCopy env.sample to .env and configure your ClickHouse connection:
cp env.sample .envThe generator will create Go structs like:
type Trade struct {
ID uint64 `json:"id" ch:"id" db:"id"`
Amount decimal.Decimal `json:"amount" ch:"amount" db:"amount" validate:"gte=0"`
Price decimal.Decimal `json:"price" ch:"price" db:"price" validate:"gte=0"`
Timestamp time.Time `json:"timestamp" ch:"timestamp" db:"timestamp"`
}