# Path: src/infi/clickhouse_orm/utils.py
# def comma_join(items, stringify=False):
#     """
#     Joins an iterable of strings with commas.
#     """
#     if stringify:
#         return ', '.join(str(item) for item in items)
#     else:
#         return ', '.join(items)
# 
# def get_subclass_names(locals, base_class):
#     from inspect import isclass
#     return [c.__name__ for c in locals.values() if isclass(c) and issubclass(c, base_class)]


import logging
from .utils import comma_join, get_subclass_names
            from infi.clickhouse_orm.database import DatabaseException
        from .models import ModelBase
        self.sharding_key = sharding_key

    @property
    def table_name(self):
        # TODO: circular import is bad

        table = self.table

        if isinstance(table, ModelBase):
            return table.table_name()

        return table

    def create_table_sql(self, db):
        name = self.__class__.__name__
        params = self._build_sql_params(db)
        return '%s(%s)' % (name, ', '.join(params))

    def _build_sql_params(self, db):
        if self.table_name is None:
            raise ValueError("Cannot create {} engine: specify an underlying table".format(
                self.__class__.__name__))

        params = ["`%s`" % p for p in [self.cluster, db.db_name, self.table_name]]
        if self.sharding_key:
            params.append(self.sharding_key)
        return params


# Expose only relevant classes in import *

# Path: src/infi/clickhouse_orm/utils.py
# def comma_join(items, stringify=False):
#     """
#     Joins an iterable of strings with commas.
#     """
#     if stringify:
#         return ', '.join(str(item) for item in items)
#     else:
#         return ', '.join(items)
# 
# def get_subclass_names(locals, base_class):
#     from inspect import isclass
#     return [c.__name__ for c in locals.values() if isclass(c) and issubclass(c, base_class)]


# Path: src/infi/clickhouse_orm/engines.py
import logging
from .utils import comma_join, get_subclass_names
            from infi.clickhouse_orm.database import DatabaseException
        from .models import ModelBase

        self.sharding_key = sharding_key

    @property
    def table_name(self):
        # TODO: circular import is bad

        table = self.table

        if isinstance(table, ModelBase):
            return table.table_name()

        return table

    def create_table_sql(self, db):
        name = self.__class__.__name__
        params = self._build_sql_params(db)
        return '%s(%s)' % (name, ', '.join(params))

    def _build_sql_params(self, db):
        if self.table_name is None:
            raise ValueError("Cannot create {} engine: specify an underlying table".format(
                self.__class__.__name__))

        params = ["`%s`" % p for p in [self.cluster, db.db_name, self.table_name]]
        if self.sharding_key:
            params.append(self.sharding_key)
        return params


# Expose only relevant classes in import *

__all__ = get_subclass_names(locals(), Engine)