forked from ClickHouse/clickhouse-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
write_column.go
55 lines (48 loc) · 1.27 KB
/
write_column.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package clickhouse
import (
"database/sql"
"database/sql/driver"
"time"
"github.com/kshvakov/clickhouse/lib/data"
"github.com/kshvakov/clickhouse/lib/types"
)
// Interface for Clickhouse driver
type Clickhouse interface {
Block() (*data.Block, error)
Prepare(query string) (driver.Stmt, error)
Begin() (driver.Tx, error)
Commit() error
Rollback() error
Close() error
WriteBlock(block *data.Block) error
}
// Interface for Block allowing writes to individual columns
type ColumnWriter interface {
WriteDate(c int, v time.Time) error
WriteDateTime(c int, v time.Time) error
WriteUInt8(c int, v uint8) error
WriteUInt16(c int, v uint16) error
WriteUInt32(c int, v uint32) error
WriteUInt64(c int, v uint64) error
WriteFloat32(c int, v float32) error
WriteFloat64(c int, v float64) error
WriteBytes(c int, v []byte) error
WriteArray(c int, v *types.Array) error
WriteString(c int, v string) error
WriteFixedString(c int, v []byte) error
}
func OpenDirect(dsn string) (Clickhouse, error) {
return open(dsn)
}
func (ch *clickhouse) Block() (*data.Block, error) {
if ch.block == nil {
return nil, sql.ErrTxDone
}
return ch.block, nil
}
func (ch *clickhouse) WriteBlock(block *data.Block) error {
if block == nil {
return sql.ErrTxDone
}
return ch.writeBlock(block)
}