On 6/4/15 12:10 PM, eli rashlin wrote:
Thank you.
I tried the method described here
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/EntityName
<https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/EntityName>, my
tables are defined as modules but I'm unable to understand how he does it
you wouldn't want to use the entity name approach unless you need to
refer to multiple schemas in one session at the same time. It requires
that you have a copy of every class for every schema. If you have only
a limited number of schemas, then that might be what you want. But OTOH
if you are doing somethign like multi-tenancy, where each user has their
own schema and they only use their schema at once, then you'd want to do
this on a per-session basis without using entity name.
Need to know that part before recommending an approach.
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...
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.