mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-21 16:46:33 +03:00
Refactor get_sql in enum fields
This commit is contained in:
parent
f35333a7b6
commit
633c7ee1e9
|
@ -89,7 +89,7 @@ class Field(FunctionOperatorsMixin):
|
|||
sql = self.db_type
|
||||
args = self.get_db_type_args()
|
||||
if args:
|
||||
sql += '(%s)' % ', '.join(args)
|
||||
sql += '(%s)' % comma_join(args)
|
||||
if with_default_expression:
|
||||
sql += self._extra_params(db)
|
||||
return sql
|
||||
|
@ -480,15 +480,8 @@ class BaseEnumField(Field):
|
|||
def to_db_string(self, value, quote=True):
|
||||
return escape(value.name, quote)
|
||||
|
||||
def get_sql(self, with_default_expression=True, db=None):
|
||||
values = ['%s = %d' % (escape(item.name), item.value) for item in self.enum_cls]
|
||||
sql = '%s(%s)' % (self.db_type, ' ,'.join(values))
|
||||
if with_default_expression:
|
||||
default = self.to_db_string(self.default)
|
||||
sql = '%s DEFAULT %s' % (sql, default)
|
||||
if self.codec and db and db.has_codec_support:
|
||||
sql+= ' CODEC(%s)' % self.codec
|
||||
return sql
|
||||
def get_db_type_args(self):
|
||||
return ['%s = %d' % (escape(item.name), item.value) for item in self.enum_cls]
|
||||
|
||||
@classmethod
|
||||
def create_ad_hoc_field(cls, db_type):
|
||||
|
|
Loading…
Reference in New Issue
Block a user