Thank you.
I tried the method described here
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/EntityName, my tables are defined as modules but I'm unable to understand how he does it
those are my classes
GlobBase.py:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.schema import CreateTable
Base = declarative_base()
Messages.py
from datetime import datetime
from sqlalchemy import *
from GlobBase import Base
from sqlalchemy.orm import relationship
class Messages(Base):
__table_args__ = {
'mysql_engine': 'InnoDB',
'mysql_charset': 'utf8'
}
__tablename__ = 'Messages'
id = Column(Integer, autoincrement=True, primary_key=True)
message_name = Column(String(50))
protocol_name = Column(String(50))
def get_table_orm_def(self):
return self.__table__
def __init__(self, message_name=None, protocol_name=None):
self.message_name = message_name
self.protocol_name = protocol_name
def __repr__(self):
return "<Messages ('%s %s')>" % (self.message_name, self.protocol_name)
tst.py
def map_class_to_some_table(cls, table, entity_name, **kw):
newcls = type(entity_name, (cls, ), {})
mapper(newcls, table, **kw)
return newcls
class Foo(object):
pass
connection = create_engine(connection_line, pool_recycle = pool_time, echo = False)
engine = sessionmaker(bind = connection, expire_on_commit=False)()
row = engine.query(Messages).first()
but i don't understand how to make it work...