s_om
s_om

Reputation: 681

Flask-CQLAlchemy DB objects dont have 'query' attribute

I am trying to write a flask application with Cassandra. I am using the Flask-CQLAlchemy library to do this and the basic querying supported by the ORM doesn't seem to work.

My code looks something like this :

class Person(db.Model):
    id = db.columns.UUID(primary_key=True)
    first_name  = db.columns.Text()
    last_name = db.columns.Text()

When I open up the terminal and go to Python, I create a new person with

person1 = Person(first_name='ABC', last_name='WYZ')

It goes through but when I query the Person database with :

Person.query.limit(1).all()

I get an error saying :

AttributeError: type object 'Person' has no attribute 'query'

Is there something else that needs to be added in the CQLAlchemy program?

Upvotes: 0

Views: 452

Answers (1)

Danila Ganchar
Danila Ganchar

Reputation: 11302

As I understood you try to use Flask-CQLAlchemy as Flask-SQLAlchemy. But this is different libraries.

To find objects with limit:

for p in Person.objects().limit(100):
    print(p)

To find by field:

print(Person.get(uid='uid_here'))

You can find other useful methods here

Hope this helps.

Upvotes: 2

Related Questions