clickhouse

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 9 Imported by: 0

README

ClickHouse CLI

Go Reference Go Report Card

A standalone ClickHouse interactive CLI client for Go applications.

Features

  • 🚀 Full ClickHouse SQL support
  • 📊 Vertical/Horizontal display modes
  • ⏱️ Query timing
  • 💾 Connection pooling
  • 🎯 System tables support
  • 📈 Optimized for analytical queries

Installation

go get github.com/binrchq/clickhouse-cli

Quick Start

package main

import (
    "log"
    "os"
    
    clickhousecli "github.com/binrchq/clickhouse-cli"
)

func main() {
    cli := clickhousecli.NewCLI(
        os.Stdin,
        "localhost",
        9000,
        "default",
        "password",
        "default",
    )
    
    if err := cli.Connect(); err != nil {
        log.Fatal(err)
    }
    defer cli.Close()
    
    if err := cli.Start(); err != nil {
        log.Fatal(err)
    }
}

Supported Commands

SQL Commands
  • SELECT - Query (with complex analytics support)
  • INSERT - Insert data
  • CREATE TABLE - Create table
  • DROP TABLE - Delete table
  • OPTIMIZE TABLE - Optimize table
System Tables
SELECT * FROM system.databases
SELECT * FROM system.tables
SELECT * FROM system.processes
SELECT * FROM system.query_log
Special Commands
  • USE <database> - Switch database
  • SHOW DATABASES - List databases
  • SHOW TABLES - List tables
  • DESCRIBE TABLE - Describe table
  • help - Show help
  • timing - Toggle timing
  • vertical - Toggle vertical output

Requirements

  • Go 1.21 or higher
  • ClickHouse 20.3 or higher

Dependencies

License

MIT License - see LICENSE file for details.

Author

Maintained by binrc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

CLI ClickHouse 交互式命令行客户端

func NewCLI

func NewCLI(term Terminal, host string, port int, username, password, database string) *CLI

NewCLI 创建新的 ClickHouse CLI 实例

func NewCLIWithConfig added in v0.1.1

func NewCLIWithConfig(term Terminal, config *Config) *CLI

NewCLIWithConfig 使用配置创建 ClickHouse CLI 实例

func (*CLI) Close

func (c *CLI) Close() error

Close 关闭数据库连接

func (*CLI) Connect

func (c *CLI) Connect() error

Connect 连接到 ClickHouse

func (*CLI) Start

func (c *CLI) Start() error

Start 启动交互式命令行

type Config added in v0.1.1

type Config struct {
	Host            string
	Port            int
	Username        string
	Password        string
	Database        string
	Secure          bool          // 使用 TLS
	SkipVerify      bool          // 跳过 TLS 验证
	DialTimeout     time.Duration // 连接超时
	ReadTimeout     time.Duration // 读超时
	WriteTimeout    time.Duration // 写超时
	MaxOpenConns    int           // 最大打开连接数
	MaxIdleConns    int           // 最大空闲连接数
	ConnMaxLifetime time.Duration // 连接最大生命周期
	Compression     string        // 压缩方式: lz4, zstd, none
	// 其他参数
	Params map[string]string
}

Config ClickHouse 连接配置

type ReadWriteCloser added in v0.1.1

type ReadWriteCloser struct {
	io.ReadWriter
}

ReadWriteCloser wraps io.ReadWriter to add a no-op Close method

func (*ReadWriteCloser) Close added in v0.1.1

func (rwc *ReadWriteCloser) Close() error

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader 从终端读取输入(使用 readline 以支持SSH session)

func NewReader

func NewReader(term io.ReadWriter) *Reader

NewReader 创建新的 Reader

func (*Reader) Close

func (r *Reader) Close() error

Close 关闭读取器

func (*Reader) ReadLine

func (r *Reader) ReadLine() (string, error)

ReadLine 读取一行输入

func (*Reader) SetPrompt added in v0.1.1

func (r *Reader) SetPrompt(prompt string)

SetPrompt 设置提示符

type ServerInfo

type ServerInfo struct {
	Version   string
	Uptime    int64
	BuildType string
}

ServerInfo ClickHouse 服务器信息

type Terminal

type Terminal interface {
	io.Reader
	io.Writer
}

Terminal 终端接口,用于输入输出

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL