clickhouse_go

package module
v0.0.0-...-a3c3a25 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2019 License: MIT Imports: 13 Imported by: 0

README

clickhouse-go

An orm framework for ClickHouse

install

go get -u github.com/kshvakov/clickhouse

Example

package main

import (
	"fmt"
	orm "github.com/brz233/clickhouse-go"
	"log"
)

func main() {
	engine, err := orm.NewEngine("clickhouse", "tcp://127.0.0.1:9000")
	if err != nil {
		log.Fatal(err)
	}

	_, err = engine.Exec("CREATE DATABASE demo")
	if err != nil {
		log.Fatal(err)
	}

	_, err = engine.Exec("CREATE TABLE demo.table01 (`id` Int64, `name` String) ENGINE = Memory")
	if err != nil {
		log.Fatal(err)
	}

	insertItem := []*struct{
		Id   int64  `db:"id"`
		Name string `db:"name"`
	}{
		{1, "abc"},
		{2, "cde"},
		{3, "fgh"},
	}

	err = engine.Table("demo.table01").Insert(insertItem)
	if err != nil {
		log.Fatal(err)
	}

	var Item = []*struct {
		Id   int64  `db:"id"`
		Name string `db:"name"`
	}{}

	err = engine.Table("xfail.test").Find(&Item)
	if err != nil {
		log.Fatal(err)
	}

	for _, value := range Item {
		fmt.Println(value.Id, value.Name)
	}
}

Documentation

Index

Constants

View Source
const (
	Plus         = "plus"
	Minus        = "minus"
	Multiply     = "multiply"
	Divide       = "divide"
	IntDiv       = "intDiv"
	IntDivOrZero = "intDivOrZero"
	Modulo       = "modulo"
	Negate       = "negate"
	Abs          = "abs"
	Gcd          = "gcd"
	Lcm          = "lcm"
)

Arithmetic functions

For all arithmetic functions, the result type is calculated as the smallest number type that the result fits in, if there is such a type. The minimum is taken simultaneously based on the number of bits, whether it is signed, and whether it floats. If there are not enough bits, the highest bit type is taken.

View Source
const (
	BitAnd = "bitAnd"
	//bitOr(a, b)
	BitOr = "bitOr"
	//bitXor(a, b)
	BitXor = "bitXor"
	//bitNot(a)
	BitNot = "bitNot"
	//bitShiftLeft(a, b)
	BitShiftLeft = "bitShiftLeft"
	//bitShiftRight(a, b)
	BitShiftRight = "bitShiftRight"
	//bitRotateLeft(a, b)
	BitRotateLeft = "bitRotateLeft"
	//bitRotateRight(a, b)
	BitRotateRight = "bitRotateRight"
	//bitTest(a, b)
	BitTest = "bitTest"
	//bitTestAll(a, b)
	BitTestAll = "bitTestAll"
	//bitTestAny(a, b)
	BitTestAny = "bitTestAny"
)

Bit functions

View Source
const (
	Hex             = "hex"
	Unhex           = "unhex"
	UUIDStringToNum = "UUIDStringToNum"
	UUIDNumToString = "UUIDNumToString"
	BitmaskToList   = "bitmaskToList"
	BitmaskToArray  = "bitmaskToArray"
)

Encoding functions

View Source
const (
	E        = "e"
	Pi       = "pi"
	Exp      = "exp"
	Log      = "log"
	Ln       = "ln"
	Exp2     = "exp2"
	Log2     = "log2"
	Exp10    = "exp10"
	Log10    = "log10"
	Sqrt     = "sqrt"
	Cbrt     = "cbrt"
	Erf      = "erf"
	Erfc     = "erfc"
	Lgamma   = "lgamma"
	Tgamma   = "tgamma"
	Sin      = "sin"
	Cos      = "cos"
	Tan      = "tan"
	Asin     = "asin"
	Acos     = "acos"
	Atan     = "atan"
	Pow      = "pow"
	Power    = "power"
	IntExp2  = "intExp2"
	IntExp10 = "intExp10"
)

Variables

View Source
var (
	ErrorWithoutPrepare = errors.New("error: prepare is false")

	ErrorWithoutStmt = errors.New("error: stmt is nil")

	ErrParamsType = errors.New("error: param type error")

	ErrTableNotFound = errors.New("error: table not found")

	ErrNotSupportInsertType = errors.New("error: not support type")

	ErrNotSupportFindType = errors.New("error: not support type")
)

Functions

func Alias

func Alias(funcStr, alias string) string

func Use

func Use(funcName string, args ...interface{}) (funcStr string, err error)

Types

type Engine

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

func Default

func Default(dataSourceName string) (engine *Engine, err error)

Default retuen the clickhouse engine

func NewEngine

func NewEngine(driverName, dataSourceName string) (engine *Engine, err error)

func (*Engine) Column

func (engine *Engine) Column(columns ...string) *Session

func (*Engine) Exec

func (engine *Engine) Exec(query string, args ...interface{}) (sql.Result, error)

func (*Engine) GroupBy

func (engine *Engine) GroupBy(groupBys ...string) *Session

func (*Engine) Having

func (engine *Engine) Having(pred string, rest ...interface{}) *Session

func (*Engine) Join

func (engine *Engine) Join(join string, rest ...interface{}) *Session

func (*Engine) LeftJoin

func (engine *Engine) LeftJoin(join string, rest ...interface{}) *Session

func (*Engine) Limit

func (engine *Engine) Limit(limit int64, offset ...int64) *Session

func (*Engine) NewSession

func (engine *Engine) NewSession() *Session

func (*Engine) NotFromTable

func (engine *Engine) NotFromTable() *Session

NotFromTable 如果使用函数生成,不从表中读取数据

func (*Engine) Options

func (engine *Engine) Options(options ...string) *Session

func (*Engine) Order

func (engine *Engine) Order(orderBys ...string) *Session

func (*Engine) RightJoin

func (engine *Engine) RightJoin(join string, rest ...interface{}) *Session

func (*Engine) Table

func (engine *Engine) Table(name string) *Session

func (*Engine) UseFunc

func (engine *Engine) UseFunc(funcName, alias string, args ...interface{}) *Session

func (*Engine) Values

func (engine *Engine) Values(values ...interface{}) *Session

func (*Engine) Where

func (engine *Engine) Where(pred string, args ...interface{}) *Session

type Session

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

func (*Session) Clone

func (session *Session) Clone() *Session

func (*Session) Close

func (session *Session) Close()

Close release the connection from pool

func (*Session) Column

func (session *Session) Column(columns ...string) *Session

func (*Session) DB

func (session *Session) DB() *sqlx.DB

func (*Session) Exec

func (session *Session) Exec(query string, args ...interface{}) (sql.Result, error)

func (*Session) Find

func (session *Session) Find(obj interface{}) (err error)

Find 查询

func (*Session) FindWithSql

func (session *Session) FindWithSql(obj interface{}, query string, args ...interface{}) (err error)

FindWithSql 使用定义的sql去查询结果

func (*Session) GenFindSQL

func (session *Session) GenFindSQL(obj interface{}) *Session

GenFindSQL 生成查询使用的代码

func (*Session) GenInsertSQL

func (session *Session) GenInsertSQL(obj interface{}) *Session

func (*Session) GetBySQL

func (session *Session) GetBySQL(dest interface{}, query string, args ...interface{}) (err error)

func (*Session) GroupBy

func (session *Session) GroupBy(groupBys ...string) *Session

func (*Session) Having

func (session *Session) Having(pred string, rest ...interface{}) *Session

func (*Session) ID

func (session *Session) ID(id uint64) *Session

func (*Session) Init

func (session *Session) Init()

func (*Session) Insert

func (session *Session) Insert(bean interface{}) (err error)

func (*Session) Join

func (session *Session) Join(join string, rest ...interface{}) *Session

func (*Session) LeftJoin

func (session *Session) LeftJoin(join string, rest ...interface{}) *Session

func (*Session) Limit

func (session *Session) Limit(limit int64, offset ...int64) *Session

func (*Session) NotFromTable

func (session *Session) NotFromTable() *Session

NotFromTable 如果使用函数生成,不从表中读取数据

func (*Session) Options

func (session *Session) Options(options ...string) *Session

func (*Session) Order

func (session *Session) Order(orderBys ...string) *Session

func (*Session) RightJoin

func (session *Session) RightJoin(join string, rest ...interface{}) *Session

func (*Session) SelectBySQL

func (session *Session) SelectBySQL(dest interface{}, query string, args ...interface{}) (err error)

func (*Session) Table

func (session *Session) Table(from string) *Session

func (*Session) ToSql

func (session *Session) ToSql() (sql string)

获取SQL

func (*Session) UseFunc

func (session *Session) UseFunc(funcName, alias string, args ...interface{}) *Session

func (*Session) Values

func (session *Session) Values(values ...interface{}) *Session

func (*Session) Where

func (session *Session) Where(pred string, args ...interface{}) *Session

Jump to

Keyboard shortcuts

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