Hi all,
I have a question here.
Here is my db init code snippet:
engine = create_engine(db_url,
pool_size=100,max_overflow=150,echo=engine_echo,pool_recycle=3600)
session = scoped_session(sessionmaker(bind=engine))
metadata = MetaData(bind=engine)
Then, I use engine to do update/insert
To make more connections, call connect(), and/or use more session objects.
Each session uses one connection.
If you see three connections, that means your script has only worked with three
connections at once, such as, you opened three Session objects concurrently.
Sqlalchemy does not
For me, I just use engine.execute most of the time, any problem with this?
Or if I use session or connect, do I need to close the session or
connection everytime? otherwise, it will trigger the pool size limit error
as the connection is increasing, right?
在 2014年4月8日星期二UTC+8下午8时49分16秒,Michael
The above procedure can be performed in a shorthand way by using the
execute()http://docs.sqlalchemy.org/en/rel_0_9/core/connections.html#sqlalchemy.engine.Engine.execute
method
of
Enginehttp://docs.sqlalchemy.org/en/rel_0_9/core/connections.html#sqlalchemy.engine.Engine
itself:
result =
There is no need to use a scoped_session() in a function that is just running a
single query. There’s no need to use a Session in a function that is not
running an ORM query - session.execute() and engine.execute() are equivalent.
Most of this code is unnecessary.
There is however a need to
在 2014年4月8日星期二UTC+8下午11时15分27秒,Michael Bayer写道:
There is no need to use a scoped_session() in a function that is just
running a single query. There’s no need to use a Session in a function
that is not running an ORM query - session.execute() and engine.execute()
are equivalent. Most of