datastax / cdc-apache-cassandra

Datastax CDC for Apache Cassandra
Apache License 2.0
35 stars 21 forks source link

How can I connect to multiple keyspaces using one Cassandra Client object? #107

Closed bestofman closed 1 year ago

bestofman commented 1 year ago

I was using such a following code to connect to only 1 keyspace:

This is `/config/db.ts:

import cassandra from "cassandra-driver";

class Cpool {
static _pool : cassandra.Client;

static connect(options : any){
  this._pool = new cassandra.Client(options);
}

  static execute(query: string, params?: cassandra.ArrayOrObject | undefined, options?: cassandra.QueryOptions | undefined)
  {
    return this._pool.execute(query, params, options);
  }
}

export { Cpool };

And the below code is the index.ts:

  const default_options = {
    contactPoints: [process.env.CONTACT_POINTS],
    localDataCenter: process.env.LOCAL_DATA_CENTER,
    keyspace: process.env.KEYSPACE,
  };

  try {
    await Cpool.connect(default_options);
    console.log("Connected to Cassandra");
  } catch (err) {
    console.log(err);
  }

Now I want to have 2 or more keyspaces but don't know should I create a new client in order to each of them or I can use only 1 client to connect to multiple keyspaces? How?

aymkhalil commented 1 year ago

@bestofman thanks for reaching out. It seems your inquiry is not related to CDC - for C OSS support, please check the C community home page - it has useful resources for how/where to get support from the community.

Hope that helps.