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?
const default_options = { contactPoints: [process.env.CONTACT_POINTS], localDataCenter: process.env.LOCAL_DATA_CENTER, keyspace: process.env.KEYSPACE, };
When I should specify the keyspace while creating a client. – Surber