Skip to content

Instantly share code, notes, and snippets.

@tglines
Created August 21, 2013 18:59
Show Gist options
  • Save tglines/6298697 to your computer and use it in GitHub Desktop.
Save tglines/6298697 to your computer and use it in GitHub Desktop.
Simple test of cqlengine in python with graph-ish sort of data
import uuid
from datetime import datetime
from cqlengine import columns
from cqlengine.models import Model
from cqlengine import connection
from cqlengine.management import sync_table
class UserModel(Model):
id = columns.UUID(primary_key=True, default=uuid.uuid4)
name = columns.Text()
created_at = columns.DateTime()
class FriendshipModel(Model):
id = columns.UUID(primary_key=True, default=uuid.uuid4)
u1_id = columns.UUID()
u2_id = columns.UUID()
created_at = columns.DateTime()
connection.setup(['127.0.0.1:9160'])
sync_table(UserModel)
sync_table(FriendshipModel)
u1 = UserModel.create(name='Paul', created_at=datetime.now())
u2 = UserModel.create(name='Ben', created_at=datetime.now())
print UserModel.objects.count()
users = UserModel.objects()
print users.count()
for user in users:
print user.name
f1 = FriendshipModel.create(u1_id=u1.id, u2_id=u2.id)
friendships = FriendshipModel.objects()
for friendship in friendships:
print friendship, friendship.u1_id, friendship.u2_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment