I have a SQLAlchemy table class created using the Declarative method:
mysqlengine = create_engine(dsn)
session = scoped_session(sessionmaker(bind=mysqlengine))
Base = declarative_base()
Base.metadata.bind = mysqlengine
class MyTable(Base):
__table_args__ = {'autoload' : True}
Now that this table is used in the code, I would not have to use the session.add method to add each new record to the active session, but instead:
row = MyTable(1, 2, 3)
session.add(row)
session.commit()
I would like to:
row = MyTable(1, 2, 3)
session.commit()
Now I know about this question: Can I add an object to an SQLAlchemy session without explicit session.add ()?
And I understand that you can force this behavior to do the following:
class MyTable(Base):
def __init__(self, *args, **kw):
super(MyTable, self).__init__(*args, **kw)
session.add(self)
However, I do not want to inflate my code containing 30 tables with this method. I also know that Elixir ( http://elixir.ematia.de/trac/wiki ) does this so that it should be possible in a way.
source
share