diff --git a/README.md b/README.md index 2aa9431..165dbda 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,16 @@ A pre-compiled binary can be downloaded from the [releases](https://github.com/z ### 2) Configure Copy the `config.toml.sample` file as `config.toml` somewhere and edit the configuration values. +Source (`[db.*]`) and result (`[results.*]`) databases are configured with a driver `type` and a `dsn`: + +| type | dsn | +|------|-----| +| `postgres` | `postgres://user:password@host:5432/dbname?sslmode=disable` | +| `mysql` | `user:password@tcp(host:3306)/dbname` | +| `clickhouse` | `tcp://host:9000?username=user&password=password&database=dbname` | + +ClickHouse v1 reads credentials and the database from query parameters. The `user@pass` format is not supported. + ### 3) Setup tasks Write your SQL query tasks in `.sql` files in the `goyesql` format (as shown in the examples earlier) and put them in a directory somewhere. diff --git a/cmd/config.sample.toml b/cmd/config.sample.toml index c031d9c..5aa4ea4 100644 --- a/cmd/config.sample.toml +++ b/cmd/config.sample.toml @@ -61,6 +61,8 @@ results_table = "results_%s" # type = "postgres" dsn = "postgres://user:password@host:5432/dbname?sslmode=disable" # type = "mysql" dsn = "user:password@tcp(host:3306)/dbname" +# type = "clickhouse" dsn = "tcp://host:9000?username=user&password=url-encoded-password&database=dbname" +# IMPORTANT: clickhouse DSN requires passwords to be urlencoded if they have special characters. [db.my_db] type = "mysql" diff --git a/config.toml.sample b/config.toml.sample index 1d958a0..9d4b3d3 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -41,18 +41,10 @@ max_idle = 10 max_active = 100 connect_timeout = "10s" +# URL-encode ClickHouse query values (e.g. % as %25, + as %2B). [db.ch_db] type = "clickhouse" -dsn = "clickhouse://default:@127.0.0.1:9000/default?sslmode=disable" +dsn = "tcp://127.0.0.1:9000?username=default&password=&database=default" max_idle = 10 max_active = 100 connect_timeout = "10s" -# host = "localhost" -# port = 9000 -# db = "default" -# user = "default" -# password = "" -# autocommit = false -# max_active = 100 -# max_idle = 100 -# connect_timeout = 60 \ No newline at end of file diff --git a/internal/dbpool/dbpool.go b/internal/dbpool/dbpool.go index e690dd6..e486a66 100644 --- a/internal/dbpool/dbpool.go +++ b/internal/dbpool/dbpool.go @@ -30,7 +30,7 @@ func New(mp map[string]Config) (map[string]*sql.DB, error) { for name, cfg := range mp { db, err := NewConn(cfg) if err != nil { - return nil, err + return nil, fmt.Errorf("db %q: %w", name, err) } out[name] = db