Giter Club home page Giter Club logo

ch_pool's Introduction

golang clickhouse connection pool

click house connection package

    github.com/jmoiron/sqlx

install

go get -u github.com/juelite/ch_pool

use

  • init click house pool
var (
	chPool *ChPool
	err error
)

func init() {
	dsn := "tcp://192.168.1.50:9000?database=big_data&read_timeout=3600&write_timeout=3600&alt_hosts=192.168.1.51:9000,192.168.1.52:9000"
	
	chPool, err = NewChPool(10, 100, 1800, func() (db *sqlx.DB, e error) {
		return sqlx.Open("clickhouse", dsn)
	})
	if err != nil {
		log.Println(err.Error())
		panic(err)
	} else {
		log.Printf("click house连接成功!%s\n", dsn)
	}
}
  • business logic use click house connect
func main() {
    conn, err := chPool.GetConn()
    if err != nil {
        return
    }
    defer chPool.Release(conn)

    sql := "select column1, column2 from database.table limit 1"

    rows, err := chConn.Query(sql)

    // todo handle error
    // todo deal return data
}

ch_pool's People

Contributors

juelite avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

isgasho

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.