Skip to content

sxlgg/clickhouse-go-models

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ClickHouse Logo

ClickHouse Go Models

A Go tool that automatically generates Go struct models from your ClickHouse database schema.

Features

  • 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

Installation

go install github.com/sxlgg/clickhouse-go-models@latest

Or clone and build:

git clone https://github.com/sxlgg/clickhouse-go-models
cd clickhouse-go-models
go build -o clickhouse-go-models

Usage

  1. Create a .env file with your ClickHouse connection details
  2. 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 --verbose

Environment Configuration

Copy env.sample to .env and configure your ClickHouse connection:

cp env.sample .env

The 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"`
}

About

๐Ÿ—๏ธ Generate Go struct models from ClickHouse database schema with proper type mappings, tags, and enum support.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages