forked from mailru/go-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
42 lines (35 loc) · 846 Bytes
/
helpers.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
package clickhouse
import (
"bytes"
"net/http"
"strings"
"time"
)
var (
escaper = strings.NewReplacer(`\`, `\\`, `'`, `\'`)
dateFormat = "2006-01-02"
timeFormat = "2006-01-02 15:04:05"
dateTime64Format = "2006-01-02 15:04:05.999999999"
)
func escape(s string) string {
return escaper.Replace(s)
}
func quote(s string) string {
return "'" + s + "'"
}
func formatTime(value time.Time) string {
return quote(value.Format(timeFormat))
}
func formatDate(value time.Time) string {
return quote(value.Format(dateFormat))
}
func readResponse(response *http.Response) (result []byte, err error) {
if response.ContentLength > 0 {
result = make([]byte, 0, response.ContentLength)
}
buf := bytes.NewBuffer(result)
defer response.Body.Close()
_, err = buf.ReadFrom(response.Body)
result = buf.Bytes()
return
}