Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change configured database after initial client creation #159

Open
viveknair opened this issue May 16, 2023 · 1 comment
Open

Change configured database after initial client creation #159

viveknair opened this issue May 16, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@viveknair
Copy link

viveknair commented May 16, 2023

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

  1. Create a Clickhouse client instance

const client = createClient(options)

  1. 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 viveknair added the bug Something isn't working label May 16, 2023
@slvrtrn slvrtrn added enhancement New feature or request and removed bug Something isn't working labels May 16, 2023
@slvrtrn
Copy link
Contributor

slvrtrn commented May 16, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants