2015-02-24 43 views
0

我在卡桑德拉集羣如何在cqlengine蟒蛇模型

CREATE TABLE users (
username text PRIMARY KEY, 
creationdate bigint, 
email text, 
firstlogin boolean, 
firstname text, 
lastloggedin bigint, 
lastname text, 
lastprofileupdate bigint, 
name text, 
olduserid int, 
profile frozen<profile_type>, 
user_id uuid 

和用戶定義類型,profile_type定義爲如下以下表模式代表卡桑德拉用戶定義類型...

CREATE TYPE profile_type (
birthdate timestamp, 
gender text, 
title text, 
relationshipstatus text, 
homecountry text, 
currentcountry text, 
timezone text, 
profilepicture blob, 
alternate_email text, 
religion text, 
interests list<text>, 
cellphone text, 
biography text 
); 

如何將此結構表示爲cqlengine模型?我對用戶定義的類型表示特別感興趣,因爲我沒有看到任何列定義來表示這種情況?那麼我需要手動映射嗎?到目前爲止,我有這個python ....

class User(Model): 
    username = columns.Text(primary_key=True) 
    firstname = columns.Text(required=True) 
    lastname = columns.Text(required=True) 
    email = columns.Text(required=True) 
    name = columns.Text(required=False) 
    olduserid = columns.Integer() 
    user_id = columns.UUID(default=uuid.uuid4) 
    creationdate = columns.BigInt() 

回答

0

顯然,cqlengine目前尚不支持此功能,並有近期提供此功能的發展。所以目前來說,它重新使用datastax提供的cassandra python驅動程序來使代碼中的工作成爲可能。當cqlengine實現可用並在此處反饋時,我會尋找。

0

的UDT支持纔可用cqlengine,請參閱this

from cassandra.cqlengine.columns import * 
from cassandra.cqlengine.models import Model 
from cassandra.cqlengine.usertype import UserType 

class address(UserType): 
    street = Text() 
    zipcode = Integer() 

class users(Model): 
    __keyspace__ = 'account' 
    name = Text(primary_key=True) 
    addr = UserDefinedType(address) 

sync_table(users) 

users.create(name="Joe", addr=address(street="Easy St.", zip=99999)) 
user = users.objects(name="Joe")[0] 
print user.name, user.addr 
# Joe {'street': Easy St., 'zipcode': None}