All Projects → leprosus → golang-clickhouse

leprosus / golang-clickhouse

Licence: GPL-3.0 license
Golang Yandex ClickHouse connector

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to golang-clickhouse

db-migrator.go
DB migrations. CLI and Golang
Stars: ✭ 13 (-59.37%)
Mutual labels:  clickhouse
Proton
High performance Pinba server
Stars: ✭ 27 (-15.62%)
Mutual labels:  clickhouse
clickhouse hadoop
Import data from clickhouse to hadoop with pure SQL
Stars: ✭ 26 (-18.75%)
Mutual labels:  clickhouse
openreplay
📺 OpenReplay is developer-friendly, open-source session replay.
Stars: ✭ 6,131 (+19059.38%)
Mutual labels:  clickhouse
trickster
Open Source HTTP Reverse Proxy Cache and Time Series Dashboard Accelerator
Stars: ✭ 1,753 (+5378.13%)
Mutual labels:  clickhouse
onelinerhub
2.5k code solutions with clear explanation @ onelinerhub.com
Stars: ✭ 645 (+1915.63%)
Mutual labels:  clickhouse
fense
Fense is a database proxy written in Java, which can connect DB of different engines at the same time. The key features are: authority management, query cache, audit security, current limiting fuse, onesql and so on
Stars: ✭ 22 (-31.25%)
Mutual labels:  clickhouse
dbt-clickhouse
The Clickhouse plugin for dbt (data build tool)
Stars: ✭ 77 (+140.63%)
Mutual labels:  clickhouse
clickhouse-ast-parser
AST parser and visitor for ClickHouse SQL
Stars: ✭ 60 (+87.5%)
Mutual labels:  clickhouse
dbal-clickhouse
Doctrine DBAL driver for ClickHouse database
Stars: ✭ 77 (+140.63%)
Mutual labels:  clickhouse
uptrace
Open source APM: OpenTelemetry traces, metrics, and logs
Stars: ✭ 1,187 (+3609.38%)
Mutual labels:  clickhouse
ClickHouseMigrator
Help to migrate data to ClickHouse, create database and table auto.
Stars: ✭ 58 (+81.25%)
Mutual labels:  clickhouse
awesome-clickhouse
A curated list of awesome ClickHouse software.
Stars: ✭ 71 (+121.88%)
Mutual labels:  clickhouse
chtable
Grafana's table plugin for ClickHouse
Stars: ✭ 26 (-18.75%)
Mutual labels:  clickhouse
vulkn
Love your Data. Love the Environment. Love VULKИ.
Stars: ✭ 43 (+34.38%)
Mutual labels:  clickhouse
yabr.os
Чтение скобочного формата файлов 1С (oscript)
Stars: ✭ 33 (+3.13%)
Mutual labels:  clickhouse
appmetrica-logsapi-loader
A tool for automatic data loading from AppMetrica LogsAPI into (local) ClickHouse
Stars: ✭ 18 (-43.75%)
Mutual labels:  clickhouse
chclient
Fast http client for SELECT queries in clickhouse
Stars: ✭ 44 (+37.5%)
Mutual labels:  clickhouse
radondb-clickhouse-kubernetes
Open Source,High Availability Cluster,based on ClickHouse
Stars: ✭ 54 (+68.75%)
Mutual labels:  clickhouse
cds
Data syncing in golang for ClickHouse.
Stars: ✭ 839 (+2521.88%)
Mutual labels:  clickhouse

Golang Clickhouse connector

Create new connection

package main

import (
	ch "github.com/leprosus/golang-clickhouse"
)

var (
    user = "clickhouse.user"
    pass = "clickhouse.pass"
    host = "clickhouse.host"
    port = 8123
)

func init(){
    conn := ch.New(host, port, user, pass)
    
    // Also you can preset maximum memory usage limit to execute one query
    conn.MaxMemoryUsage(4 * clickhouse.GigaByte)
}

Query rows

conn := ch.New(host, port, user, pass)

iter, err := conn.Fetch("SELECT `database`, `name`, `engine` FROM system.tables")
if err != nil {
    panic(err)
}

for iter.Next() {
    result := iter.Result

    database, _ := result.String("database")
    name, _ := result.String("name")
    engine, _ := result.String("engine")

    println(database, country, engine)
}

Execute insert

conn := ch.New(host, port, user, pass)

query := fmt.Sprintf("INSERT INTO db.table (SomeFiled) VALUES ('%s')", "Some value")
conn.Exec(query)

Preset you own logging

ch.Debug(func(message string) {
    log.Printf("DEBUG: %s\n", message)
})

ch.Info(func(message string) {
    log.Printf("INFO: %s\n", message)
}

ch.Info(func(message string) {
    log.Printf("WARN: %s\n", message)
}

ch.Error(func(message string) {
    log.Printf("ERROR: %s\n", message)
}

ch.Fatal(func(message string) {
    log.Printf("FATAL: %s\n", message)
}}

Values escaping

value := "Here	is tab. This is line comment --"
escaped := clickhouse.Escape(value)
fmt.Print(escaped) //Here\tis tab. This is line comment \-\-

List all methods

Connection

  • clickhouse.New(host, port, user, pass) - creates connection
  • conn.Attempts(attempts, wait) - sets amount of attempts and time awaiting after fail request (wait in seconds)
  • conn.MaxMemoryUsage(limit) - sets maximum memory usage per query (limit in bytes)
  • conn.MaxRequests(limit) - sets maximum requests at the same time
  • conn.ConnectTimeout(timeout) - sets connection timeout (timeout in seconds)
  • conn.SendTimeout(timeout) - sets send timeout (timeout in seconds)
  • conn.ReceiveTimeout(timeout) - sets receive timeout (timeout in seconds)
  • conn.Compression(flag) - sets response compression

Logging

  • clickhouse.Debug(func(message string)) - sets custom logger for debug
  • clickhouse.Info(func(message string)) - sets custom logger for info
  • clickhouse.Warn(func(message string)) - sets custom logger for warn
  • clickhouse.Error(func(message string)) - sets custom logger for error
  • clickhouse.Fatal(func(message string)) - sets custom logger for fatal

Fetching

  • conn.Fetch(query) - executes, fetches query and returns iterator and error
  • conn.ForcedFetch(query) - executes, fetches query and returns iterator and error without requests limits
  • conn.FetchOne(query) - executes, fetches query and returns first result and error
  • conn.ForcedFetchOne(query) - executes, fetches query and returns first result and error without requests limits
  • conn.Exec(query) - executes query and returns error
  • conn.ForcedExec(query) - executes query and returns error without requests limits
  • conn.InsertBatch(query) - inserts batch data from file into database.table table with TabSeparated, TabSeparatedWithNames, CSV, CSVWithNames format

Iterator

  • iter.Next() - checks if has more data
  • iter.Err() - returns error if exist or nil
  • iter.Result() - returns result
  • iter.Close() - closes data stream

Result

  • result.Columns() - returns columns list
  • result.Exist("FieldName") - returns true if field is exist or false
  • result.String("FieldName") - returns string value and error
  • result.Bytes("FieldName") - returns bytes slice value and error
  • result.Bool("FieldName") - returns boolean value and error
  • result.UInt8("FieldName") - returns unsigned int8 value and error
  • result.UInt16("FieldName") - returns unsigned int16 value and error
  • result.UInt32("FieldName") - returns unsigned int32 value and error
  • result.UInt64("FieldName") - returns unsigned int64 value and error
  • result.Int8("FieldName") - returns int8 value and error
  • result.Int16("FieldName") - returns int16 value and error
  • result.Int32("FieldName") - returns int32 value and error
  • result.Int64("FieldName") - returns int64 value and error
  • result.Float32("FieldName") - returns float32 value and error
  • result.Float64("FieldName") - returns float64 value and error
  • result.Date("FieldName") - parses data YYYY-MM-DD and returns time value and error
  • result.DateTime("FieldName") - parses data YYYY-MM-DD HH:MM:SS and returns time value and error

Escaping

  • clickhouse.Escape("ValueToEscape") - escapes special symbols
  • clickhouse.Unescape("ValueToUndoEscaping") - undoes escaping of special symbols
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].