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()
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...
On Tuesday, June 2, 2015 at 12:52:22 PM UTC+3, eli rashlin wrote:
>
> Hi,
>
> I have a very strange behavior, I have a program that uses bulk insertions
> to the DB.
> for some reason the process which iterate on one table and create bulk and
> insert into another table fails with the error of 'No database selected'.
>
>
> this is how I bind the session:
>
>
> #-------------------------------------------------------------------------------------------------------------------
> # use_db:
> # this method will return a session reference
> # using this DB
> #-------------------------------------------------------------------------------------------------------------------
>
>
> def use_db(self, new_db_name):
> self.connection.execute("USE %s" % (new_db_name))
> session_ref = sessionmaker(bind = self.connection,
> expire_on_commit=False)
> self.session_cover_tst = session_ref()
> return self.session_cover_tst
>
>
>
> engine = connection_engine.use_db(db_name)
> count_sig =
> engine.query(func.count(distinct(signals_table.Signals.sig_value)).label('count_sig')).\
>
> filter(signals_table.Signals.message_id == msg_row.id).\
>
> filter(signals_table.Signals.signal_id == sig_id).\
>
> group_by(signals_table.Signals.signal_id).\
>
> one()[0]
>
>
> now the table Signals is huge (500M records), but the table is indexed and
> everything is working great for a few rounds and then I'm getting the
> error 'No database selected' and it fails...
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.