pythondjangodictionarycassandracqlengine

Cqlengine queries: how to return dictionary?


I'm using cqlengine in Django application, where Cassandra is the secondary database.

In some cases I need to join manually the results of SQL and NoSQL database requests.

For SQL I'm using:

model_name.objects.all().values() 

to return dictionary, rather than model-instance objects.

But I can't find the appropriate methods in cqlengine.

As a beginner in python, I do not know how best to implement this functionality within cqlengine library.

Maybe you have some examples of program code, providing this?


Solution

  • I like to use a generator for loop like such:

    [dict(foo) for foo in Bar.objects.all()]
    

    That will return a dictionary of all the objects and depending on your code base will allow you to do custom serialization and deserialization.