schema - Create and change to new keyspace with Cassandra cqlengine? -
let's connect cassandra cluster:
cqlengine.connection.setup('hostname', 'some_keyspace')
the method requires know @ least 1 existing keyspace. if don't?
what if wish check if keyspace exists , create otherwise?
we create keyspace this:
cqlengine.management.create_keyspace('keyspace_name', some_other_args)
so there 3 questions here:
- how connect without supplying keyspace?
- what correct way create new keyspace (what other arguments besides name of keyspace)?
- how switch keyspaces using cqlengine?
you need 'default' keyspace. can exists. think cassandra have default keyspaces.
the correct way create keyspace using
create_keyspace_simple
command:from cassandra.cqlengine.management import create_keyspace_simple create_keyspace_simple(keyspace_name, replication_factor)
to change keyspace:
from cassandra.cqlengine import models models.default_keyspace = keyspace_name
assuming connection imported , have defined keyspace_name
Comments
Post a Comment