clickhouse

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BETWEEN    = "BETWEEN"
	NOTBETWEEN = "NOT BETWEEN"
	IN         = "IN"
	NOTIN      = "NOT IN"
	AND        = "AND"
	OR         = "OR"
	ISNULL     = "IS NULL"
	ISNOTNULL  = "IS NOT NULL"
	EQUAL      = "="
	NOTEQUAL   = "!="
	LIKE       = "LIKE"
	JOIN       = "JOIN"
	INNERJOIN  = "INNER JOIN"
	LEFTJOIN   = "LEFT JOIN"
	RIGHTJOIN  = "RIGHT JOIN"
	UNION      = "UNION"
	UNIONALL   = "UNION ALL"
	DESC       = "DESC"
	ASC        = "ASC"
)

Variables

This section is empty.

Functions

func SetTrace

func SetTrace(t bool)

Types

type Config

type Config struct {
	Username     string //账号 root
	Password     string //密码
	Host         string //host localhost
	Port         string //端口 3306
	Database     string //默认连接数据库
	ReadTimeout  int
	WriteTimeout int
	LoadBalance  string //负载均衡
}

Config 数据库配置

func (*Config) URI

func (config *Config) URI() string

URI 构造数据库连接

type Connection

type Connection interface {
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	NewQuery(ctx context.Context) *QueryBuilder
	GetLastSql() Sql
	LastSql(query string, args ...interface{})
}

Connection 链接

type DbError

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

func NewDBError

func NewDBError(msg string, sql Sql) DbError

func (DbError) Error

func (e DbError) Error() string

type Epr

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

func NewEpr

func NewEpr(value string) Epr

func (Epr) ToString

func (e Epr) ToString() string

type Grammar

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

Grammar sql 语法

func (Grammar) Delete

func (g Grammar) Delete() string

func (Grammar) Insert

func (g Grammar) Insert() string

func (Grammar) InsertUpdate

func (g Grammar) InsertUpdate() string

func (Grammar) Replace

func (g Grammar) Replace() string

func (Grammar) Select

func (g Grammar) Select() string

Select 构造select

func (Grammar) ToSql

func (g Grammar) ToSql() string

func (Grammar) Update

func (g Grammar) Update() string

type Proxy

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

Proxy 代理

func NewProxy

func NewProxy() *Proxy

NewProxy 代理池

func (*Proxy) NameSpace

func (proxy *Proxy) NameSpace(group string) *QueryDb

NameSpace 获取分组

func (*Proxy) SetNameSpace

func (proxy *Proxy) SetNameSpace(group string, client *QueryDb)

SetNameSpace 设置组

type QueryBuilder

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

QueryBuilder 查询构造器

func (*QueryBuilder) Between

func (query *QueryBuilder) Between(column string, value1 interface{}, value2 interface{}) *QueryBuilder

Between 构造Between

func (*QueryBuilder) Count

func (query *QueryBuilder) Count() (int64, error)

Count

func (*QueryBuilder) Delete

func (query *QueryBuilder) Delete() (int64, error)

Delete .

func (*QueryBuilder) DeleteSQL

func (query *QueryBuilder) DeleteSQL() string

DeleteSQL .

func (*QueryBuilder) Distinct

func (query *QueryBuilder) Distinct() *QueryBuilder

Distinct .

func (*QueryBuilder) Equal

func (query *QueryBuilder) Equal(column string, value interface{}) *QueryBuilder

Equal 构造等于

func (*QueryBuilder) Exec

func (query *QueryBuilder) Exec(sql string, args ...interface{}) (int64, error)

Exec 原始SQl语句执行

func (*QueryBuilder) ExecSQL

func (query *QueryBuilder) ExecSQL(sql string, args ...interface{}) string

Exec 原始SQl语句执行

func (*QueryBuilder) GroupBy

func (query *QueryBuilder) GroupBy(groups ...string) *QueryBuilder

GroupBy .

func (*QueryBuilder) In

func (query *QueryBuilder) In(column string, value ...interface{}) *QueryBuilder

In 构造 in语句

func (*QueryBuilder) InnerJoin

func (query *QueryBuilder) InnerJoin(tablename string, on string) *QueryBuilder

func (*QueryBuilder) Insert

func (query *QueryBuilder) Insert(data interface{}) (int64, error)

Insert 插入数据

func (*QueryBuilder) InsertSQL

func (query *QueryBuilder) InsertSQL(data interface{}) string

InsertSQL 获取SQL语句

func (*QueryBuilder) InsertUpdate

func (query *QueryBuilder) InsertUpdate(insert interface{}, update interface{}) (int64, error)

InsertUpdate

func (*QueryBuilder) InsertUpdateSQL

func (query *QueryBuilder) InsertUpdateSQL(insert interface{}, update interface{}) string

InsertUpdate

func (*QueryBuilder) IsNULL

func (query *QueryBuilder) IsNULL(column string) *QueryBuilder

IsNULL .

func (*QueryBuilder) IsNotNULL

func (query *QueryBuilder) IsNotNULL(column string) *QueryBuilder

IsNotNULL .

func (*QueryBuilder) Join

func (query *QueryBuilder) Join(tablename string, on string) *QueryBuilder

Join .

func (*QueryBuilder) LeftJoin

func (query *QueryBuilder) LeftJoin(tablename string, on string) *QueryBuilder

LeftJoin .

func (*QueryBuilder) Like

func (query *QueryBuilder) Like(column string, value interface{}) *QueryBuilder

Like .

func (*QueryBuilder) Limit

func (query *QueryBuilder) Limit(limit int64) *QueryBuilder

Limit .

func (*QueryBuilder) MultiInsert

func (query *QueryBuilder) MultiInsert(datas ...interface{}) (int64, error)

MultiInsert 批量插入

func (*QueryBuilder) MultiInsertSQL

func (query *QueryBuilder) MultiInsertSQL(datas ...interface{}) string

MultiInsertSQL 批量插入

func (*QueryBuilder) NotBetween

func (query *QueryBuilder) NotBetween(column string, value1 interface{}, value2 interface{}) *QueryBuilder

NotBetween 构造不Not Between

func (*QueryBuilder) NotEqual

func (query *QueryBuilder) NotEqual(column string, value interface{}) *QueryBuilder

NotEqual 构造不等于

func (*QueryBuilder) NotIn

func (query *QueryBuilder) NotIn(column string, value ...interface{}) *QueryBuilder

NotIn .

func (*QueryBuilder) NotOrBetween

func (query *QueryBuilder) NotOrBetween(column string, value1 interface{}, value2 interface{}) *QueryBuilder

NotOrBetween 构造 Not Between OR Not Between

func (*QueryBuilder) Offset

func (query *QueryBuilder) Offset(offset int64) *QueryBuilder

Offset .

func (*QueryBuilder) OrBetween

func (query *QueryBuilder) OrBetween(column string, value1 interface{}, value2 interface{}) *QueryBuilder

OrBetween 构造 或者 Between

func (*QueryBuilder) OrEqual

func (query *QueryBuilder) OrEqual(column string, value interface{}) *QueryBuilder

OrEqual 构造或者等于

func (*QueryBuilder) OrIn

func (query *QueryBuilder) OrIn(column string, value ...interface{}) *QueryBuilder

OrIn orin语句

func (*QueryBuilder) OrIsNULL

func (query *QueryBuilder) OrIsNULL(column string) *QueryBuilder

OrIsNULL .

func (*QueryBuilder) OrIsNotNULL

func (query *QueryBuilder) OrIsNotNULL(column string) *QueryBuilder

OrIsNotNULL .

func (*QueryBuilder) OrLike

func (query *QueryBuilder) OrLike(column string, value interface{}) *QueryBuilder

OrLike .

func (*QueryBuilder) OrNotEqual

func (query *QueryBuilder) OrNotEqual(column string, value interface{}) *QueryBuilder

OrNotEqual 构造或者不等于

func (*QueryBuilder) OrNotIn

func (query *QueryBuilder) OrNotIn(column string, value ...interface{}) *QueryBuilder

OrNotIn .

func (*QueryBuilder) OrWhere

func (query *QueryBuilder) OrWhere(column string, value ...interface{}) *QueryBuilder

OrWhere 构造OR条件

func (*QueryBuilder) OrderBy

func (query *QueryBuilder) OrderBy(column string, direction string) *QueryBuilder

OrderBy .

func (*QueryBuilder) QueryRow

func (query *QueryBuilder) QueryRow(sql string, args ...interface{}) *Row

func (*QueryBuilder) QueryRowSQL

func (query *QueryBuilder) QueryRowSQL(sql string, args ...interface{}) string

func (*QueryBuilder) QueryRows

func (query *QueryBuilder) QueryRows(sql string, args ...interface{}) *Rows

func (*QueryBuilder) QueryRowsSQL

func (query *QueryBuilder) QueryRowsSQL(sql string, args ...interface{}) string

func (*QueryBuilder) Replace

func (query *QueryBuilder) Replace(datas ...interface{}) (int64, error)

Replace 替换

func (*QueryBuilder) ReplaceSQL

func (query *QueryBuilder) ReplaceSQL(datas ...interface{}) string

ReplaceSQL 替换

func (*QueryBuilder) RightJoin

func (query *QueryBuilder) RightJoin(tablename string, on string) *QueryBuilder

RightJoin .

func (*QueryBuilder) Row

func (query *QueryBuilder) Row() *Row

GetRow 获取一条记录

func (*QueryBuilder) RowSQL

func (query *QueryBuilder) RowSQL() string

func (*QueryBuilder) Rows

func (query *QueryBuilder) Rows() *Rows

GetRows 获取多条记录

func (*QueryBuilder) RowsSQL

func (query *QueryBuilder) RowsSQL() string

func (*QueryBuilder) Select

func (query *QueryBuilder) Select(columns ...string) *QueryBuilder

Select 查询字段

func (*QueryBuilder) Skip

func (query *QueryBuilder) Skip(offset int64) *QueryBuilder

Skip .

func (*QueryBuilder) Table

func (query *QueryBuilder) Table(tablename ...string) *QueryBuilder

Table 设置操作的表名称

func (*QueryBuilder) ToSql

func (query *QueryBuilder) ToSql(method string) string

ToSql 输出SQL语句

func (*QueryBuilder) Union

func (query *QueryBuilder) Union(unions ...QueryBuilder) *QueryBuilder

Union .

func (*QueryBuilder) UnionAll

func (query *QueryBuilder) UnionAll(unions ...QueryBuilder) *QueryBuilder

UnionAll .

func (*QueryBuilder) UnionLimit

func (query *QueryBuilder) UnionLimit(limit int64) *QueryBuilder

UnionLimit .

func (*QueryBuilder) UnionOffset

func (query *QueryBuilder) UnionOffset(offset int64) *QueryBuilder

UnionOffset .

func (*QueryBuilder) UnionOrderBy

func (query *QueryBuilder) UnionOrderBy(column string, direction string) *QueryBuilder

UnionOrderBy .

func (*QueryBuilder) Update

func (query *QueryBuilder) Update(data interface{}) (int64, error)

Update 更新

func (*QueryBuilder) UpdateSQL

func (query *QueryBuilder) UpdateSQL(data interface{}) string

UpdateSQL 更新

func (*QueryBuilder) Where

func (query *QueryBuilder) Where(column string, value ...interface{}) *QueryBuilder

Where 构造条件语句

type QueryDb

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

QueryDb mysql 配置

func New

func New(config *Config) *QueryDb

New 新连接

func (*QueryDb) Begin

func (querydb *QueryDb) Begin() (*QueryTx, error)

Begin 开启一个事务

func (*QueryDb) Exec

func (querydb *QueryDb) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Exec 复用执行语句

func (*QueryDb) GetLastSql

func (querydb *QueryDb) GetLastSql() Sql

GetLastSql 获取sql语句

func (*QueryDb) LastSql

func (querydb *QueryDb) LastSql(query string, args ...interface{})

func (*QueryDb) NewQuery

func (querydb *QueryDb) NewQuery(ctx context.Context) *QueryBuilder

NewQuery 生成一个新的查询构造器

func (*QueryDb) Query

func (querydb *QueryDb) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Query 复用查询语句

type QueryTx

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

QueryTx 事务

func (*QueryTx) Commit

func (querytx *QueryTx) Commit() error

Commit 事务提交

func (*QueryTx) Exec

func (querytx *QueryTx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Exec 复用执行语句

func (*QueryTx) GetLastSql

func (querytx *QueryTx) GetLastSql() Sql

GetLastSql 获取sql语句

func (*QueryTx) LastSql

func (querytx *QueryTx) LastSql(query string, args ...interface{})

func (*QueryTx) NewQuery

func (querytx *QueryTx) NewQuery(ctx context.Context) *QueryBuilder

NewQuery 生成一个新的查询构造器

func (*QueryTx) Query

func (querytx *QueryTx) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Query 复用查询语句

func (*QueryTx) Rollback

func (querytx *QueryTx) Rollback() error

Rollback 事务回滚

type Row

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

Row 获取记录

func (*Row) ToArray

func (r *Row) ToArray() (result []string, err error)

ToArray get Array

func (*Row) ToInterface

func (r *Row) ToInterface() (result map[string]interface{}, err error)

func (*Row) ToMap

func (r *Row) ToMap() (result map[string]string, err error)

ToMap get Map

func (*Row) ToStruct

func (r *Row) ToStruct(st interface{}) error

ToStruct get Struct

type Rows

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

Rows get data

func (*Rows) ToArray

func (r *Rows) ToArray() (data [][]string, err error)

ToArray get Array

func (*Rows) ToInterface

func (r *Rows) ToInterface() (data []map[string]interface{}, err error)

[]map[interface{}]interface{}

func (*Rows) ToMap

func (r *Rows) ToMap() (data []map[string]string, err error)

ToMap get Map

func (*Rows) ToStruct

func (r *Rows) ToStruct(st interface{}) error

ToStruct get Struct

type Sql

type Sql struct {
	Sql      string
	Args     []interface{}
	CostTime time.Duration
}

Sql sql语句

func (Sql) ToJson

func (sql Sql) ToJson() string

ToJson sql语句转出json

func (Sql) ToString

func (sqlRaw Sql) ToString() string

ToString sql语句转出string

Jump to

Keyboard shortcuts

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