Documentation
¶
Index ¶
- Variables
- func GetUrl(opts options) string
- type BatchInsert
- type ConnectionOpenStrategy
- type Logger
- type Option
- func WithAltHosts(altHosts string) Option
- func WithBlockSize(blockSize int) Option
- func WithConnectionOpenStrategy(connectionOpenStrategy ConnectionOpenStrategy) Option
- func WithDatabase(db string) Option
- func WithDebug(debug bool) Option
- func WithFlushPeriod(flushPeriod time.Duration) Option
- func WithHost(host string) Option
- func WithLogger(logger Logger) Option
- func WithMaxBatchSize(maxBatchSize int) Option
- func WithNoDelay(noDelay bool) Option
- func WithPoolSize(poolSize int) Option
- func WithReadTimeout(readTimeout int) Option
- func WithUserInfo(userName, password string) Option
- func WithWriteTimeOut(writeTimeOut int) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("batch insert is closed")
Functions ¶
Types ¶
type BatchInsert ¶
type BatchInsert struct {
// contains filtered or unexported fields
}
Example ¶
package main
import (
batchinsert "github.com/MaruHyl/go-clickhouse-batchinsert"
)
func main() {
//
createTable := `
CREATE TABLE IF NOT EXISTS test (
x UInt8
) engine=Memory`
insertSql := "INSERT INTO test (x) values (?)"
//
b, err := batchinsert.New(
insertSql,
batchinsert.WithHost("127.0.0.1:9000"),
)
if err != nil {
panic(err)
}
//
_, err = b.DB().Exec(createTable)
if err != nil {
panic(err)
}
//
_ = b.Insert(1)
_ = b.Insert(2)
_ = b.Insert(3)
//
_, err = b.DB().Exec(`DROP TABLE IF EXISTS test`)
if err != nil {
panic(err)
}
err = b.Close()
if err != nil {
panic(err)
}
}
Output:
func (*BatchInsert) Close ¶
func (b *BatchInsert) Close() error
func (*BatchInsert) DB ¶
func (b *BatchInsert) DB() *sql.DB
func (*BatchInsert) Insert ¶
func (b *BatchInsert) Insert(values ...interface{}) (err error)
func (*BatchInsert) Len ¶
func (b *BatchInsert) Len() int
type ConnectionOpenStrategy ¶
type ConnectionOpenStrategy string
const OpenStrategyInOrder ConnectionOpenStrategy = "in_order"
const OpenStrategyRandom ConnectionOpenStrategy = "random"
type Option ¶
type Option func(opt *options)
func WithAltHosts ¶
Comma separated list of single address host for load-balancing
func WithBlockSize ¶
Maximum rows in block (default is 1000000). If the rows are larger then the data will be split into several blocks to send them to the server
func WithConnectionOpenStrategy ¶
func WithConnectionOpenStrategy(connectionOpenStrategy ConnectionOpenStrategy) Option
Random/in_order (default random)
func WithFlushPeriod ¶
func WithLogger ¶
func WithMaxBatchSize ¶
func WithNoDelay ¶
Disable/enable the Nagle Algorithm for tcp socket (default is 'true' - disable)
func WithPoolSize ¶
Maximum amount of pre-allocated byte chunks used in queries (default is 100). Decrease this if you experience memory problems at the expense of more GC pressure and vice versa.