clickhouse_orm

package module
v0.0.0-...-3a04f63 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 12 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)
	}
}

Thanks

Documentation

Index

Constants

View Source
const (
	BIFPlus         = "plus"         //plus(a, b), a + b operator
	BIFMinus        = "minus"        //minus(a, b), a - b operator
	BIFMultiply     = "multiply"     //multiply(a, b), a * b operator
	BIFDivide       = "divide"       //divide(a, b), a / b operator
	BIFIntDiv       = "intDiv"       //intDiv(a, b)
	BIFIntDivOrZero = "intDivOrZero" //intDivOrZero(a, b)
	BIFModulo       = "modulo"       //modulo(a, b), a % b operator
	BIFNegate       = "negate"       //negate(a), -a operator
	BIFAbs          = "abs"          //abs(a) {#arithm_func-abs}
	BIFGcd          = "gcd"          //gcd(a, b)
	BIFLcm          = "lcm"          //lcm(a, b)
)

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 (
	BIFEmpty               = "empty"               //empty
	BIFNotEmpty            = "notEmpty"            //notEmpty
	BIFLength              = "length"              //length
	BIFEmptyArrayUInt8     = "emptyArrayUInt8"     //emptyArrayUInt8
	BIFEmptyArrayUInt16    = "emptyArrayUInt16"    //emptyArrayUInt16
	BIFEmptyArrayUInt32    = "emptyArrayUInt32"    //emptyArrayUInt32
	BIFEmptyArrayUInt64    = "emptyArrayUInt64"    //emptyArrayUInt64
	BIFEmptyArrayInt8      = "emptyArrayInt8"      //emptyArrayInt8
	BIFEmptyArrayInt16     = "emptyArrayInt16"     //emptyArrayInt16
	BIFEmptyArrayInt32     = "emptyArrayInt32"     //emptyArrayInt32
	BIFEmptyArrayInt64     = "emptyArrayInt64"     //emptyArrayInt64
	BIFEmptyArrayFloat32   = "emptyArrayFloat32"   //emptyArrayFloat32
	BIFEmptyArrayFloat64   = "emptyArrayFloat64"   //emptyArrayFloat64
	BIFEmptyArrayDate      = "emptyArrayDate"      //emptyArrayDate
	BIFEmptyArrayDateTime  = "emptyArrayDateTime"  //emptyArrayDateTime
	BIFEmptyArrayString    = "emptyArrayString"    //emptyArrayString
	BIFEmptyArrayToSingle  = "emptyArrayToSingle"  //emptyArrayToSingle
	BIFRange               = "range"               //range(N)
	BIFArray               = "array"               //array(x1, ...), operator [x1, ...]
	BIFArrayConcat         = "arrayConcat"         //arrayConcat(arrays)
	BIFArrayElement        = "arrayElement"        //arrayElement(arr, n), operator arr[n]
	BIFHas                 = "has"                 //has(arr, elem)
	BIFHasAll              = "hasAll"              //hasAll(set, subset)
	BIFHasAny              = "hasAny"              //hasAny(array1, array2)
	BIFIndexOf             = "indexOf"             //indexOf(arr, x)
	BIFCountEqual          = "countEqual"          //countEqual(arr, x)
	BIFArrayEnumerate      = "arrayEnumerate"      //arrayEnumerate(arr)
	BIFArrayEnumerateUniq  = "arrayEnumerateUniq"  //arrayEnumerateUniq(arr, ...)
	BIFArrayPopBack        = "arrayPopBack"        //arrayPopBack(array)
	BIFArrayPopFront       = "arrayPopFront"       //arrayPopFront(array)
	BIFArrayPushBack       = "arrayPushBack"       //arrayPushBack(array, single_value)
	BIFArrayPushFront      = "arrayPushFront"      //arrayPushFront(array, single_value)
	BIFArrayResize         = "arrayResize"         //arrayResize(array, size[, extender])
	BIFArraySlice          = "arraySlice"          //arraySlice(array, offset[, length])
	BIFArraySort           = "arraySort"           //arraySort([func,] arr, ...)
	BIFArrayReverseSort    = "arrayReverseSort"    //arrayReverseSort([func,] arr, ...)
	BIFArrayUniq           = "arrayUniq"           //arrayUniq(arr, ...)
	BIFArrayJoin           = "arrayJoin"           //arrayJoin(arr):SELECT arrayJoin([1, 2, 3] AS src) AS dst, 'Hello', src
	BIFArrayDifference     = "arrayDifference"     //arrayDifference(arr)
	BIFArrayDistinct       = "arrayDistinct"       //arrayDistinct(arr)
	BIFArrayEnumerateDense = "arrayEnumerateDense" //arrayEnumerateDense(arr)
	BIFArrayIntersect      = "arrayIntersect"      //arrayIntersect(arr)
	BIFArrayReduce         = "arrayReduce"         //arrayReduce(agg_func, arr1, ...)
	BIFArrayReverse        = "arrayReverse"        //arrayReverse(arr)
)

Functions for working with arrays

View Source
const (
	BIFBitAnd         = "bitAnd"         //bitAnd(a, b)
	BIFBitOr          = "bitOr"          //bitOr(a, b)
	BIFBitXor         = "bitXor"         //bitXor(a, b)
	BIFBitNot         = "bitNot"         //bitNot(a)
	BIFBitShiftLeft   = "bitShiftLeft"   //bitShiftLeft(a, b)
	BIFBitShiftRight  = "bitShiftRight"  //bitShiftRight(a, b)
	BIFBitRotateLeft  = "bitRotateLeft"  //bitRotateLeft(a, b)
	BIFBitRotateRight = "bitRotateRight" //bitRotateRight(a, b)
	BIFBitTest        = "bitTest"        //bitTest(a, b)
	BIFBitTestAll     = "bitTestAll"     //bitTestAll(a, b)
	BIFBitTestAny     = "bitTestAny"     //bitTestAny(a, b)
)

Bit functions

View Source
const (
	BIFHex             = "hex"
	BIFUnhex           = "unhex"
	BIFUUIDStringToNum = "UUIDStringToNum"
	BIFUUIDNumToString = "UUIDNumToString"
	BIFBitmaskToList   = "bitmaskToList"
	BIFBitmaskToArray  = "bitmaskToArray"
)

Encoding functions

View Source
const (
	BIFE        = "e"
	BIFPi       = "pi"
	BIFExp      = "exp"
	BIFLog      = "log"
	BIFLn       = "ln"
	BIFExp2     = "exp2"
	BIFLog2     = "log2"
	BIFExp10    = "exp10"
	BIFLog10    = "log10"
	BIFSqrt     = "sqrt"
	BIFCbrt     = "cbrt"
	BIFErf      = "erf"
	BIFErfc     = "erfc"
	BIFLgamma   = "lgamma"
	BIFTgamma   = "tgamma"
	BIFSin      = "sin"
	BIFCos      = "cos"
	BIFTan      = "tan"
	BIFAsin     = "asin"
	BIFAcos     = "acos"
	BIFAtan     = "atan"
	BIFPow      = "pow"
	BIFPower    = "power"
	BIFIntExp2  = "intExp2"
	BIFIntExp10 = "intExp10"
)
View Source
const (
	BIFProtocol                       = "protocol"                       //protocol,Returns the protocol. Examples: http, ftp, mailto, magnet...
	BIFDomain                         = "domain"                         //domain,Gets the domain. Cut scheme with size less than 16 bytes.
	BIFDomainWithoutWWW               = "domainWithoutWWW"               //domainWithoutWWW
	BIFTopLevelDomain                 = "topLevelDomain"                 //topLevelDomain
	BIFFirstSignificantSubdomain      = "firstSignificantSubdomain"      //firstSignificantSubdomain
	BIFCutToFirstSignificantSubdomain = "cutToFirstSignificantSubdomain" //cutToFirstSignificantSubdomain
	BIFPath                           = "path"                           //path
	BIFPathFull                       = "pathFull"                       //pathFull
	BIFQueryString                    = "queryString"                    //queryString
	BIFFragment                       = "fragment"                       //fragment
	BIFURLHierarchy                   = "URLHierarchy"                   //URLHierarchy(URL)
	BIFURLPathHierarchy               = "URLPathHierarchy"               //URLPathHierarchy(URL)
	BIFDecodeURLComponent             = "decodeURLComponent"             //decodeURLComponent(URL)
	BIFCutWWW                         = "cutWWW"                         //cutWWW
	BIFCutQueryString                 = "cutQueryString"                 //cutQueryString
	BIFCutFragment                    = "cutFragment"                    //cutFragment
	BIFCutQueryStringAndFragment      = "cutQueryStringAndFragment"      //cutQueryStringAndFragment
	BIFCutURLParameter                = "cutURLParameter"                //cutURLParameter(URL, name)
)

Functions for working with URLs

View Source
const (
	BIFGenerateUUIDv4 = "generateUUIDv4" //generateUUIDv4()
	BIFToUUID         = "toUUID"         //toUUID(String)

)

Functions for working with UUID

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")

	ErrOnlySupportPtr = errors.New("must pass a pointer, not a value, to StructScan destination")

	ErrNotSupportNilPtr = errors.New("nil pointer passed to StructScan destination")
)

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)

NewEngine

func (*Engine) Column

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

func (*Engine) ColumnValue

func (engine *Engine) ColumnValue(columns []string, elemBean interface{}) ([]interface{}, error)

func (*Engine) DB

func (engine *Engine) DB() *sqlx.DB

func (*Engine) Exec

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

Exec

func (*Engine) FindWithSql

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

FindWithSql

func (*Engine) GetColumns

func (engine *Engine) GetColumns(bean interface{}) []string

func (*Engine) GetWithSQL

func (engine *Engine) GetWithSQL(dest interface{}, query string, args ...interface{}) (err error)

GetWithSQL

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

NewSession

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) 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) ColumnValue

func (session *Session) ColumnValue(columns []string, elemBean interface{}) ([]interface{}, error)

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) GetColumns

func (session *Session) GetColumns(bean interface{}) []string

func (*Session) GetWithSQL

func (session *Session) GetWithSQL(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) InsertCHMulti

func (session *Session) InsertCHMulti(bean interface{}, args [][]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) 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