added static column support
This commit is contained in:
@@ -99,7 +99,8 @@ class Column(object):
|
||||
default=None,
|
||||
required=False,
|
||||
clustering_order=None,
|
||||
polymorphic_key=False):
|
||||
polymorphic_key=False,
|
||||
static=False):
|
||||
"""
|
||||
:param primary_key: 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
|
||||
@@ -125,6 +126,7 @@ class Column(object):
|
||||
self.polymorphic_key = polymorphic_key
|
||||
#the column name in the model definition
|
||||
self.column_name = None
|
||||
self.static = static
|
||||
|
||||
self.value = None
|
||||
|
||||
@@ -182,7 +184,8 @@ class Column(object):
|
||||
"""
|
||||
Returns a column definition for CQL table definition
|
||||
"""
|
||||
return '{} {}'.format(self.cql, self.db_type)
|
||||
static = "static" if self.static else ""
|
||||
return '{} {} {}'.format(self.cql, self.db_type, static)
|
||||
|
||||
def set_column_name(self, name):
|
||||
"""
|
||||
|
@@ -637,7 +637,6 @@ class ModelMetaClass(type):
|
||||
is_polymorphic_base = any([c[1].polymorphic_key for c in column_definitions])
|
||||
|
||||
column_definitions = [x for x in inherited_columns.items()] + column_definitions
|
||||
|
||||
polymorphic_columns = [c for c in column_definitions if c[1].polymorphic_key]
|
||||
is_polymorphic = len(polymorphic_columns) > 0
|
||||
if len(polymorphic_columns) > 1:
|
||||
|
@@ -1,5 +1,6 @@
|
||||
|
||||
import mock
|
||||
from cqlengine import ALL, CACHING_ALL, CACHING_NONE
|
||||
from cqlengine.connection import get_session
|
||||
from cqlengine.exceptions import CQLEngineException
|
||||
from cqlengine.management import get_fields, sync_table, drop_table
|
||||
from cqlengine.tests.base import BaseCassEngTestCase, CASSANDRA_VERSION
|
||||
@@ -244,3 +245,30 @@ class NonModelFailureTest(BaseCassEngTestCase):
|
||||
def test_failure(self):
|
||||
with self.assertRaises(CQLEngineException):
|
||||
sync_table(self.FakeModel)
|
||||
|
||||
|
||||
def test_static_columns():
|
||||
class StaticModel(Model):
|
||||
id = columns.Integer(primary_key=True)
|
||||
c = columns.Integer(primary_key=True)
|
||||
name = columns.Text(static=True)
|
||||
|
||||
drop_table(StaticModel)
|
||||
|
||||
from mock import patch
|
||||
|
||||
from cqlengine.connection import get_session
|
||||
session = get_session()
|
||||
|
||||
with patch.object(session, "execute", side_effect=Exception) as m:
|
||||
try:
|
||||
sync_table(StaticModel)
|
||||
except:
|
||||
pass
|
||||
|
||||
assert m.call_count > 0
|
||||
statement = m.call_args[0][0].query_string
|
||||
assert '"name" text static' in statement, statement
|
||||
|
||||
|
||||
|
||||
|
@@ -53,4 +53,6 @@ class BuiltInAttributeConflictTest(TestCase):
|
||||
class IllegalFilterColumnModel(Model):
|
||||
__keyspace__ = 'test'
|
||||
my_primary_key = columns.Integer(primary_key=True)
|
||||
filter = columns.Text()
|
||||
filter = columns.Text()
|
||||
|
||||
|
||||
|
@@ -464,7 +464,7 @@ QuerySet method reference
|
||||
Sets the field to order on.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
from uuid import uuid1,uuid4
|
||||
|
||||
class Comment(Model):
|
||||
|
Reference in New Issue
Block a user