masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
227 stars 67 forks source link

Getting metadata not as expected #213

Closed vgjenks closed 4 years ago

vgjenks commented 4 years ago

I'm trying to make some dynamic decisions about data based on metadata. It sounds like I should be able to get at the underlying Datastax driver to do this:

https://docs.datastax.com/en/developer/nodejs-driver/4.3/features/metadata/

...but I just don't see how. Maybe there's not enough documentation available? All I could find is this:

https://express-cassandra.readthedocs.io/en/stable/notes/#get-the-client-driver-instance

But, when I get the underlying driver.Metadata, it's a function, not an object. It takes params and I'm unclear how to use it:

`let { Metadata } = models.driver.metadata;`

How do I use it like the first link demonstrates?

masumsoft commented 4 years ago

You can use the models.driver instance similar to the cassandra-driver docs. Actually the metadata is an instance of a function in the cassandra-driver itself. You'll get the same thing if you require('cassandra-driver') instance. It feels like an object but it's actually a function that contains getter/setter methods.

So you should be able to use it similar to the way presented in the cassandra-driver docs. For example: models.driver.metadata.keyspaces will output the keyspaces.

vgjenks commented 4 years ago

You can use the models.driver instance similar to the cassandra-driver docs. Actually the metadata is an instance of a function in the cassandra-driver itself. You'll get the same thing if you require('cassandra-driver') instance. It feels like an object but it's actually a function that contains getter/setter methods.

So you should be able to use it similar to the way presented in the cassandra-driver docs. For example: models.driver.metadata.keyspaces will output the keyspaces.

Thanks for the info. I got a little further with it but it's still not working for me. It doesn't seem to work quite like the cassandra-driver. With that one, it's simple:

let client = new cassandra.Client({ contactPoints: ["127.0.0.1"], localDataCenter: "127.0.0.1" }); await client.connect(); console.log("Connected!"); console.log(Object.keys(client.metadata.keyspaces)); client.shutdown();

I'm attempting something similar with express-cassandra like so:

try { let md = new models.driver.metadata.Metadata({ contactPoints: ["127.0.0.1"], localDataCenter: "127.0.0.1" }); let tables = await md.getTable(); } catch (e) { console.error("Shrugs:", e); } finally { models.close(); }

...but getting this error:

Error: Metadata has not been initialized. This could only happen if you have not connected yet.

Seems strange, since models is fully loaded and I'm able to work w/ data just fine. It seems to be connected, until I create this Metadata instance and try to work with it.

Is there some extra documentation out there for how to do this correctly? Would be better than digging through source code and/or trying to guess how it works. I've got some tools I need to build and would rather continue to use express-cassandra since it's the basis of all of our API work. Would prefer not to use the underlying driver directly if I don't have to.

Thanks!