Skip to content

Commit

Permalink
Making clickhouse operate more like the other databases
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Nov 12, 2023
1 parent 7cbf194 commit cc54528
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions contrib/clickhouse/podman-config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NAME=clickhouse
IMAGE=docker.io/clickhouse/clickhouse-server
PUBLISH=9000:9000
ENV="CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 CLICKHOUSE_USER=clickhouse CLICKHOUSE_PASSWORD=P4ssw0rd"
2 changes: 1 addition & 1 deletion contrib/clickhouse/usql-config
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DB="clickhouse://localhost"
DB="clickhouse://clickhouse:P4ssw0rd@localhost"
VSQL="select version() as version;"
1 change: 1 addition & 0 deletions contrib/usqlpass
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
postgres:*:*:*:postgres:P4ssw0rd

cql:*:*:*:cassandra:cassandra
clickhouse:*:*:*:clickhouse:P4ssw0rd
godror:*:*:*:system:P4ssw0rd
ignite:*:*:*:ignite:ignite
mymysql:*:*:*:root:P4ssw0rd
Expand Down
16 changes: 15 additions & 1 deletion drivers/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package clickhouse

import (
"database/sql"
"strconv"
"strings"

_ "github.com/ClickHouse/clickhouse-go/v2" // DRIVER
"github.com/ClickHouse/clickhouse-go/v2" // DRIVER
"github.com/xo/usql/drivers"
)

Expand All @@ -17,6 +19,18 @@ func init() {
RowsAffected: func(sql.Result) (int64, error) {
return 0, nil
},
Err: func(err error) (string, string) {
if e, ok := err.(*clickhouse.Exception); ok {
return strconv.Itoa(int(e.Code)), strings.TrimPrefix(e.Message, "clickhouse: ")
}
return "", err.Error()
},
IsPasswordErr: func(err error) bool {
if e, ok := err.(*clickhouse.Exception); ok {
return e.Code == 516
}
return false
},
Copy: drivers.CopyWithInsert(func(int) string { return "?" }),
NewMetadataReader: NewMetadataReader,
})
Expand Down

0 comments on commit cc54528

Please sign in to comment.