Reputation: 1292
I need to save a keyspace schema.
The command that I would use, using the cqlsh interface would be:
"describe keyspace demo"
How can I do the same thing using the Java driver?
Upvotes: 1
Views: 302
Reputation: 4536
The Java driver does have an equivalent of cqlsh DESCRIBE KEYSPACE
comamnd, it's KeyspaceMetadata.exportAsString()
.
Upvotes: 2
Reputation: 12840
DESCRIBE
is a cqlsh command, Java Driver don't have it.
But you can get the schema from Java Driver from KeyspaceMetadata
Sample Code to get the full Schema of ashraful_test
keyspace:
try (Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withCredentials("cassandra", "cassandra").build();) {
System.out.println(cluster.getMetadata().getKeyspace("ashraful_test").exportAsString());
}
Or
If you want to save the schema to file in linux command:
cqlsh -u cassandra -p cassandra -e "DESC ashraful_test" > ashraful_test.cql
Here
-u username
-p password
-e command to execute
> ashraful_test.cql will save the command output to ashraful_test.cql file
Upvotes: 2