diff --git a/contrib/clickhouse/podman-config b/contrib/clickhouse/podman-config index 9b69f59ac9c..81464a9788c 100644 --- a/contrib/clickhouse/podman-config +++ b/contrib/clickhouse/podman-config @@ -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" diff --git a/contrib/clickhouse/usql-config b/contrib/clickhouse/usql-config index 4d90f6b5b98..4c6606e5fd1 100644 --- a/contrib/clickhouse/usql-config +++ b/contrib/clickhouse/usql-config @@ -1,2 +1,2 @@ -DB="clickhouse://localhost" +DB="clickhouse://clickhouse:P4ssw0rd@localhost" VSQL="select version() as version;" diff --git a/contrib/usqlpass b/contrib/usqlpass index 382d8bef284..1a364d137d9 100644 --- a/contrib/usqlpass +++ b/contrib/usqlpass @@ -5,6 +5,7 @@ postgres:*:*:*:postgres:P4ssw0rd cql:*:*:*:cassandra:cassandra +clickhouse:*:*:*:clickhouse:P4ssw0rd godror:*:*:*:system:P4ssw0rd ignite:*:*:*:ignite:ignite mymysql:*:*:*:root:P4ssw0rd diff --git a/drivers/clickhouse/clickhouse.go b/drivers/clickhouse/clickhouse.go index 5e101d1d5a0..759146c7346 100644 --- a/drivers/clickhouse/clickhouse.go +++ b/drivers/clickhouse/clickhouse.go @@ -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" ) @@ -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, })