dse.cqlengine.columns - Column types for object mapping models

Columns

Columns in your models map to columns in your CQL table. You define CQL columns by defining column attributes on your model classes. For a model to be valid it needs at least one primary key column and one non-primary key column.

Just as in CQL, the order you define your columns in is important, and is the same order they are defined in on a model’s corresponding table.

Each column on your model definitions needs to be an instance of a Column class.

class Column

Attributes

primary_key
= False

bool flag, indicates this column is a primary key. The first primary key defined on a model is the partition key (unless partition keys are set), all others are cluster keys

partition_key
= False

indicates that this column should be the partition key, defining more than one partition key column creates a compound partition key

index
= False

bool flag, indicates an index should be created for this column

custom_index
= False

bool flag, indicates an index is managed outside of cqlengine. This is useful if you want to do filter queries on fields that have custom indexes.

db_field
= None

the fieldname this field will map to in the database

default
= None

the default value, can be a value or a callable (no args)

required
= False

boolean, is the field required? Model validation will raise and exception if required is set to True and there is a None value assigned

clustering_order
= None

only applicable on clustering keys (primary keys that are not partition keys) determines the order that the clustering keys are sorted on disk

discriminator_column
= False

boolean, if set to True, this column will be used for discriminating records of inherited models.

Should only be set on a column of an abstract model being used for inheritance.

There may only be one discriminator column per model. See __discriminator_value__ for how to specify the value of this column on specialized models.

static
= False

boolean, if set to True, this is a static column, with a single value per partition

Column Types

Columns of all types are initialized by passing Column attributes to the constructor by keyword.

class Ascii

Stores a US-ASCII character string

Parameters
  • min_length (int) – Sets the minimum length of this string, for validation purposes. Defaults to 1 if this is a required column. Otherwise, None.

  • max_length (int) – Sets the maximum length of this string, for validation purposes.

class BigInt

Stores a 64-bit signed integer value

class Blob

Stores a raw binary value

Attributes

dse.cqlengine.columns.

Bytes

class Boolean

Stores a boolean True or False value

class Counter

Stores a counter that can be incremented and decremented

class Date

Stores a simple date, with no time-of-day

Changed in version 2.6.0: removed overload of Date and DateTime. DateTime is a drop-in replacement for legacy models

requires C* 2.2+ and protocol v4+

class DateTime

Stores a datetime value

Attributes

truncate_microseconds
= False

Set this True to have model instances truncate the date, quantizing it in the same way it will be in the database. This allows equality comparison between assigned values and values read back from the database:

DateTime.truncate_microseconds = True
assert Model.create(id=0, d=datetime.utcnow()) == Model.objects(id=0).first()

Defaults to False to preserve legacy behavior. May change in the future.

class Decimal

Stores a variable precision decimal value

class Double

Stores a double-precision floating-point value

class Float

Stores a single-precision floating-point value

class Integer

Stores a 32-bit signed integer value

class List

Stores a list of ordered values

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_list_t.html

Parameters

value_type – a column class indicating the types of the value

class Map

Stores a key -> value map (dictionary)

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_map_t.html

Parameters
  • key_type – a column class indicating the types of the key

  • value_type – a column class indicating the types of the value

class Set

Stores a set of unordered, unique values

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_set_t.html

Parameters
  • value_type – a column class indicating the types of the value

  • strict – sets whether non set values will be coerced to set type on validation, or raise a validation error, defaults to True

class SmallInt

Stores a 16-bit signed integer value

New in version 2.6.0.

requires C* 2.2+ and protocol v4+

class Text

Stores a UTF-8 encoded string

Parameters
  • min_length (int) – Sets the minimum length of this string, for validation purposes. Defaults to 1 if this is a required column. Otherwise, None.

  • max_length (int) – Sets the maximum length of this string, for validation purposes.

class Time

Stores a timezone-naive time-of-day, with nanosecond precision

New in version 2.6.0.

requires C* 2.2+ and protocol v4+

class TimeUUID

UUID containing timestamp

class TinyInt

Stores an 8-bit signed integer value

New in version 2.6.0.

requires C* 2.2+ and protocol v4+

class UserDefinedType

User Defined Type column

http://www.datastax.com/documentation/cql/3.1/cql/cql_using/cqlUseUDT.html

These columns are represented by a specialization of dse.cqlengine.usertype.UserType.

Please see User Defined Types for examples and discussion.

Parameters

user_type (type) – specifies the UserType model of the column

class UUID

Stores a type 1 or 4 UUID

class VarInt

Stores an arbitrary-precision integer