[BangPypers] SQLAlchemy and 'non-trivial' default values for a column

Dhruv Baldawa dhruvbaldawa at gmail.com
Tue Feb 12 08:02:01 CET 2013


Then I guess you are doing it the wrong way. You should only have a single
session object (unless working with multiple databases simultaneously). The
object should be binded with whatever connection is required.


if PRODUCTION:
    engine = create_engine(...)
else:
    engine = create_engine(...)

session = sessionmaker(bind=engine)

then import session from whichever module you have added the above code. I
don't know how you are doing the model-based queries, if you have someother
way of querying models you can follow that, the concept and method still
remains the same.

Configurations can be controlled by an optional command-line argument or
environment variable or a flag, its upto you. I run 4 different
configurations for my app using command-line arguments.

--
Dhruv Baldawa
(http://www.dhruvb.com)


On Tue, Feb 12, 2013 at 12:05 PM, Sriram Karra <karra.etc at gmail.com> wrote:

> On Tue, Feb 12, 2013 at 11:38 AM, Dhruv Baldawa <dhruvbaldawa at gmail.com
> >wrote:
>
> > try session.query(Consultation).filter_by(), sorry I am actually used to
> > using the above specified syntax because I usually use Flask-SQLAlchemy.
>
>
> Oh, well. the session object is not available inside Consultation class.
> And as I mentioned I have two session objects of which one is live at any
> given time...
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list