forked from mailru/go-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
45 lines (35 loc) · 883 Bytes
/
types.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
package clickhouse
import (
"database/sql/driver"
"strconv"
"time"
)
// Array wraps slice or array into driver.Valuer interface to allow pass through it from database/sql
func Array(v interface{}) driver.Valuer {
return array{v: v}
}
// Date returns date for t
func Date(t time.Time) driver.Valuer {
return date(t)
}
// UInt64 returns date for t
func UInt64(u uint64) driver.Valuer {
return bigUint64(u)
}
type array struct {
v interface{}
}
// Value implements driver.Valuer
func (a array) Value() (driver.Value, error) {
return textEncode.Encode(a)
}
type date time.Time
// Value implements driver.Valuer
func (d date) Value() (driver.Value, error) {
return []byte(formatDate(time.Time(d))), nil
}
type bigUint64 uint64
// Value implements driver.Valuer
func (u bigUint64) Value() (driver.Value, error) {
return []byte(strconv.FormatUint(uint64(u), 10)), nil
}