clickhouse-js
clickhouse-js copied to clipboard
Change configured database after initial client creation
Describe the feature request
I want to change the configured database after the client has been created. For our tests, we use a client to create a variety of databases for integration tests. Ideally, we would only have a single connected client for these interactions rather than creating multiple clients (given the way our code is written).
Steps to reproduce
- Create a Clickhouse client instance
const client = createClient(options)
- Since there aren't any public setters/getters to change the database, you have to modify the client's private parameters with
client.config.database = newDbName;
Desired feature
client.setDatabase(newDbName);
@viveknair
Since it's mostly for testing purposes, could the following work for you?
// somewhere in the setup
const testDatabase = ...
await client.exec({ query: `CREATE DATABASE ${testDatabase}` })
// in the test suite
await client
.query({
query: `SELECT * FROM ${testDatabase}.${table}`,
format: 'JSONEachRow'
})
i.e. explicitly write the database in the queries.