Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlflush Management Command Support #76

Merged
merged 1 commit into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions djangocassandra/db/backends/cassandra/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,25 @@ def sql_flush(
self,
style,
tables,
sequence_list
sequence_list,
allow_cascade=False
):
raise Exception('Not Implemented')
if tables:
cql = [
'use %s;' % (
style.SQL_FIELD(self.connection.keyspace),
)
]
for table in tables:
cql.append('%s %s;' % (
style.SQL_KEYWORD('TRUNCATE'),
style.SQL_FIELD(self.quote_name(table))
))

return cql

else:
return []

def _value_for_db(
self,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='djangocassandra',
version='0.4.7',
version='0.4.8',
description='Cassandra support for the Django web framework',
long_description=(
'The Cassandra database backend for Django has been '
Expand Down
32 changes: 20 additions & 12 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,27 @@ def tearDown(self):
destroy_db(self.connection)

def test_flush(self):
try:
self.connection.ops.sql_flush(
None, [
'ColumnFamilyTestModel'
],
None
)
self.assertTrue(False)
from django.core.management.color import no_style

test_model_names = ['testmodel']
cql = self.connection.ops.sql_flush(
no_style(),
test_model_names,
()
)

except Exception, e:
self.assertEqual(
e.message,
'Not Implemented'
self.assertEquals(
2,
len(cql)
)
self.assertEquals(
'use %s;' % (self.connection.keyspace,),
cql[0].lower()
)
for i in xrange(len(test_model_names)):
self.assertEquals(
'truncate %s;' % (test_model_names[i],),
cql[i + 1].lower()
)

def test_value_to_db_auto(self):
Expand Down