mysql - How to tell SQLAlchemy once that I want InnoDB for the entire database? -


i managing mysql database (flask-)sqlalchemy , want explicitly use mysql_engine = innodb tables. there way tell database connection once want this, don't have repeat every individual table? in advance.

do use declarative extension? if so, can set default __table_args__ simple metaclass (stolen here):

def tableargsmeta(table_args):      class _tableargsmeta(declarative.declarativemeta):          def __init__(cls, name, bases, dict_):             if (    # not extend base class                     '_decl_class_registry' not in cls.__dict__ ,                      # missing __tablename_ or equal none means single table                     # inheritance — no table (columns go table of                     # base class)                     cls.__dict__.get('__tablename__') ,                     # abstract class — no table (columns go table[s]                     # of subclass[es]                     not cls.__dict__.get('__abstract__', false)):                 ta = getattr(cls, '__table_args__', {})                 if isinstance(ta, dict):                     ta = dict(table_args, **ta)                     cls.__table_args__ = ta                 else:                     assert isinstance(ta, tuple)                     if ta , isinstance(ta[-1], dict):                         tad = dict(table_args, **ta[-1])                         ta = ta[:-1]                     else:                         tad = dict(table_args)                     cls.__table_args__ = ta + (tad,)             super(_tableargsmeta, cls).__init__(name, bases, dict_)      return _tableargsmeta 

the usage:

base = declarative_base(             name='base',             metaclass=tableargsmeta({'mysql_engine': 'innodb'})) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -