I have a cassandra database with a keyspace that looks like:
CREATE TABLE custumer_events_service.events(
acceptFirstContactDuration decimal,
currentTime timestamp,
visitorIdentifier text,
PRIMARY KEY (visitorIdentifier, currentTime)
) WITH CLUSTERING ORDER BY (currentTime DESC);
And a python dict
{u'acceptFirstContactDuration': 0,
u'currentTime': u'2016-02-18T11:51:55.468Z',
u'12eca72928845aae26268f431b8c75b2564d7919c916e',}
Is there a way to insert this dict directly with cassandra-driver
? I am looking for something like in mongodb
>>> import datetime
>>> post = {"author": "Mike",
... "text": "My first blog post!",
... "tags": ["mongodb", "python", "pymongo"],
... "date": datetime.datetime.utcnow()}
>>> posts = db.posts
>>> post_id = posts.insert_one(post).inserted_id
You could manually construct a
CQL
insert statement iterating over the keys and values in the dictionary, but acqlengine
Model
is probably more appropriate to use than adict
, and it is easy to populate aModel
with the values from thedict
.You can define the
Model
like so (extending it with all of your columns):If
d
is the name of your dictionary variable, thenis the equivalent of your MongoDB operation.