Skip to content

Instantly share code, notes, and snippets.

@beccam
Last active February 4, 2016 18:34
Show Gist options
  • Save beccam/17a704584596590b6311 to your computer and use it in GitHub Desktop.
Save beccam/17a704584596590b6311 to your computer and use it in GitHub Desktop.
Getting Started with Apache Cassandra Part III (cqlengine)
from cqlengine import columns
from cqlengine.models import Model
class Users(Model):
firstname = columns.Text()
age = columns.Integer()
city = columns.Text()
email = columns.Text()
lastname = columns.Text(primary_key=True)
def __repr__(self):
return 'user(firstname=%s, age=%d)' % (self.firstname, self.age)
from cqlengine import connection
connection.setup(['127.0.0.1'], "demo")
from cqlengine.management import sync_table
sync_table(Users)
Users.create(firstname='Bob', age=35, city='Austin', email='[email protected]', lastname='Jones')
q=Users.get(lastname='Jones')
print q
q.update(age=36)
print q
q.delete()
q=Users.objects()
for i in q: print i
@rustyrazorblade
Copy link

q=Users.objects.all() can just be User.objects()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment