mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-02-21 18:50:34 +03:00
Added Database.does_table_exist
method
This commit is contained in:
parent
378cae88bc
commit
44d3dcee34
|
@ -5,6 +5,7 @@ Unreleased
|
||||||
----------
|
----------
|
||||||
- Include alias and materialized fields in queryset results
|
- Include alias and materialized fields in queryset results
|
||||||
- Check for database existence, to allow delayed creation
|
- Check for database existence, to allow delayed creation
|
||||||
|
- Added `Database.does_table_exist` method
|
||||||
|
|
||||||
v1.0.1
|
v1.0.1
|
||||||
------
|
------
|
||||||
|
|
|
@ -134,6 +134,15 @@ class Database(object):
|
||||||
raise DatabaseException("You can't drop system table")
|
raise DatabaseException("You can't drop system table")
|
||||||
self._send(model_class.drop_table_sql(self))
|
self._send(model_class.drop_table_sql(self))
|
||||||
|
|
||||||
|
def does_table_exist(self, model_class):
|
||||||
|
'''
|
||||||
|
Checks whether a table for the given model class already exists.
|
||||||
|
Note that this only checks for existence of a table with the expected name.
|
||||||
|
'''
|
||||||
|
sql = "SELECT count() FROM system.tables WHERE database = '%s' AND name = '%s'"
|
||||||
|
r = self._send(sql % (self.db_name, model_class.table_name()))
|
||||||
|
return r.text.strip() == '1'
|
||||||
|
|
||||||
def insert(self, model_instances, batch_size=1000):
|
def insert(self, model_instances, batch_size=1000):
|
||||||
'''
|
'''
|
||||||
Insert records into the database.
|
Insert records into the database.
|
||||||
|
|
|
@ -179,3 +179,8 @@ class DatabaseTestCase(TestCaseWithData):
|
||||||
instance = Model1.objects_in(self.database)[0]
|
instance = Model1.objects_in(self.database)[0]
|
||||||
self.assertEquals(instance.to_dict(), dict(system='s', readonly='r'))
|
self.assertEquals(instance.to_dict(), dict(system='s', readonly='r'))
|
||||||
|
|
||||||
|
def test_does_table_exist(self):
|
||||||
|
class Person2(Person):
|
||||||
|
pass
|
||||||
|
self.assertTrue(self.database.does_table_exist(Person))
|
||||||
|
self.assertFalse(self.database.does_table_exist(Person2))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user