Exemplo n.º 1
0
def _str_to_column(type_str, key_type=None, value_type=None, column_def={}):
    '''
    Converts name of Cassandra types to driver class wrapper for
    that type.
    '''
    type_str = type_str.lower()

    if type_str == 'integer':
        return Integer(**column_def)
    elif type_str == 'text':
        return Text(**column_def)
    elif type_str == 'ascii':
        return Ascii(**column_def)
    elif type_str == 'bigint':
        return BigInt(**column_def)
    elif type_str == 'blob':
        return Blob(**column_def)
    elif type_str == 'bytes':
        return Bytes(**column_def)
    elif type_str == 'boolean':
        return Boolean(**column_def)
    elif type_str == 'counter':
        return Counter(**column_def)
    elif type_str == 'date':
        return Date(**column_def)
    elif type_str == 'datetime':
        return DateTime(**column_def)
    elif type_str == 'decimal':
        return Decimal(**column_def)
    elif type_str == 'double':
        return Double(**column_def)
    elif type_str == 'float':
        return Float(**column_def)
    elif type_str == 'list':
        _assert_type_exception(value_type, "list type requires value_type")
        return List(value_type=value_type, **column_def)
    elif type_str == 'map':
        _assert_type_exception(key_type, "list type requires key_type")
        _assert_type_exception(value_type, "list type requires value_type")
        return Map(key_type=key_type, value_type=value_type, **column_def)
    elif type_str == 'set':
        _assert_type_exception(value_type, "set type requires value_type")
        return Set(value_type=value_type, **column_def)
    elif type_str == 'smallint':
        return SmallInt(**column_def)
    elif type_str == 'time':
        return Time(**column_def)
    elif type_str == 'timeuuid':
        return TimeUUID(**column_def)
    elif type_str == 'timestamp':
        return TimeUUID(**column_def)
    elif type_str == 'tinyint':
        return TinyInt(**column_def)
    elif type_str == 'uuid':
        return UUID(**column_def)
    elif type_str == 'varint':
        return VarInt(**column_def)
    else:
        raise Exception('Type {} is not defined.'.format(type_str))
Exemplo n.º 2
0
class User(UserType):
    # We use Date and Time to ensure to_python
    # is called for these columns
    age = Integer()
    date_param = Date()
    map_param = Map(Integer, Time)
    list_param = List(Date)
    set_param = Set(Date)
    tuple_param = Tuple(Date, Decimal, Boolean, VarInt, Double, UUID)
Exemplo n.º 3
0
class UserRoundtimeSpots(AioModel):
    __table_name__ = "user_roundtime_spots"
    __keyspace__ = "presidents"
    user_id = UUID(primary_key=True, partition_key=True, required=True)
    round_id = UUID(primary_key=True, partition_key=True, required=True)
    # round time is either simply start of round if player did not join
    # mid round, or the time the round is joined; it is like this
    # because a player can join and leave the same round multiple times
    roundtime_to_spot = Map(key_type=DateTime,
                            value_type=TinyInt,
                            required=True)
    spot = TinyInt(required=True)
Exemplo n.º 4
0
class User(AioModel):
    __table_name__ = "user"
    __keyspace__ = "presidents"
    user_id = UUID(primary_key=True, partition_key=True, required=True)
    username = Text(
        required=True, index=True
    )  # TODO: maintain separate Username table for this when affordable
    previous_usernames = List(value_type=Text)
    password = Text(required=True)  # hashed
    created = DateTime(required=True)
    # stores all user preferences like unselecting cards on store hand,
    # etc.
    settings = Map(key_type=Text, value_type=Text)