You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dorm/vendor/github.com/mailru/go-clickhouse/v2/helpers.go

43 lines
846 B

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
}