Skip to content

Commit

Permalink
Merge 1697cf3 into f16ee58
Browse files Browse the repository at this point in the history
  • Loading branch information
gabolaev committed Oct 16, 2018
2 parents f16ee58 + 1697cf3 commit 74cf6ba
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
_vendor/
vendor/
coverage.out
19 changes: 8 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@ notifications:
email: false
language: go
go:
- 1.8
- 1.9
- "1.8"
- "1.9"
- "1.10"
- "1.11"

services:
- docker

before_install:
- travis_retry docker pull yandex/clickhouse-server
- docker run -d -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server yandex/clickhouse-server
- make up_docker_server
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

install:
- travis_retry go get -u github.com/golang/lint/golint
- travis_retry go get github.com/mattn/goveralls
- travis_retry go get golang.org/x/tools/cmd/cover
- travis_retry go get github.com/stretchr/testify
- make init
- travis_retry go get -v github.com/mattn/goveralls/...

before_script:
- export TEST_CLICKHOUSE_DSN="http://localhost:8123/default"

script:
- test -z "$(golint ./... | tee /dev/stderr)"
- go vet ./...
- test -z "$(gofmt -d -s . | tee /dev/stderr)"
- go test -v -covermode=count -coverprofile=coverage.out .
- make test
- goveralls -coverprofile=coverage.out -service=travis-ci
64 changes: 64 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true

# for tests
required = ["github.com/golang/lint/golint"]

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.2"

[prune]
go-tests = true
unused-packages = true
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SHELL := /bin/bash

init:
dep ensure -v
go install ./vendor/...

up_docker_server:
test -n "$$(docker ps -a --format {{.Names}} | grep -o dbr-clickhouse-server)" && docker rm -f dbr-clickhouse-server; \
docker run -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server -d yandex/clickhouse-server;

test: up_docker_server
test -z "$$(golint ./... | grep -v vendor | tee /dev/stderr)"
go vet ./...
test -z "$$(gofmt -d -s $$(find . -name \*.go -print | grep -v vendor) | tee /dev/stderr)"
go test -v -covermode=count -coverprofile=coverage.out .
54 changes: 48 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import (
"database/sql"
"log"
"time"

"github.com/mailru/go-clickhouse"
)

Expand Down Expand Up @@ -86,7 +86,18 @@ func main() {
if err != nil {
log.Fatal(err)
}
stmt, err := tx.Prepare("INSERT INTO example (country_code, os_id, browser_id, categories, action_day, action_time) VALUES (?, ?, ?, ?, ?, ?)")
stmt, err := tx.Prepare(`
INSERT INTO example (
country_code,
os_id,
browser_id,
categories,
action_day,
action_time
) VALUES (
?, ?, ?, ?, ?, ?
)`)

if err != nil {
log.Fatal(err)
}
Expand All @@ -108,7 +119,17 @@ func main() {
log.Fatal(err)
}

rows, err := connect.Query("SELECT country_code, os_id, browser_id, categories, action_day, action_time FROM example")
rows, err := connect.Query(`
SELECT
country_code,
os_id,
browser_id,
categories,
action_day,
action_time
FROM
example`)

if err != nil {
log.Fatal(err)
}
Expand All @@ -120,10 +141,19 @@ func main() {
categories []int16
actionDay, actionTime time.Time
)
if err := rows.Scan(&country, &os, &browser, &categories, &actionDay, &actionTime); err != nil {
if err := rows.Scan(
&country,
&os,
&browser,
&categories,
&actionDay,
&actionTime,
); err != nil {
log.Fatal(err)
}
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_day: %s, action_time: %s", country, os, browser, categories, actionDay, actionTime)
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_day: %s, action_time: %s",
country, os, browser, categories, actionDay, actionTime,
)
}
}
```
Expand Down Expand Up @@ -161,7 +191,19 @@ func main() {
}

for _, item := range items {
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_time: %s", item.CountryCode, item.OsID, item.BrowserID, item.Categories, item.ActionTime)
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_time: %s",
item.CountryCode, item.OsID, item.BrowserID, item.Categories, item.ActionTime,
)
}
}
```

## Development:
You can check the effect of changes on Travis CI or run tests locally:

``` bash
make init # dep ensure and install
make test
```

_Remember that `init` will add a few binaries used for testing (like `golint`) into your GOPATH_
3 changes: 1 addition & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func ParseDSN(dsn string) (*Config, error) {
}
cfg := NewConfig()

cfg.Scheme = u.Scheme
cfg.Host = u.Host
cfg.Scheme, cfg.Host = u.Scheme, u.Host
if len(u.Path) > 1 {
// skip '/'
cfg.Database = u.Path[1:]
Expand Down
5 changes: 2 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func readResponse(response *http.Response) (result []byte, err error) {
}

func numOfColumns(data []byte) int {
cnt := 0
var cnt int
for _, ch := range data {
switch ch {
case '\t':
Expand All @@ -66,8 +66,7 @@ func numOfColumns(data []byte) int {

// splitTSV splits one row of tab separated values, returns begin of next row
func splitTSV(data []byte, out []string) int {
i := 0
k := 0
var i, k int
for j, ch := range data {
switch ch {
case '\t':
Expand Down

0 comments on commit 74cf6ba

Please sign in to comment.