开发者

how do I close the engine created by sqlalchemy.ext.sqlsoup

I'm using sqlsoup to perform a simple query. My question is how do I close the engine ? thanks!

import sqlalchemy.ext.sqlsoup as SqlSoup

db = SqlSoup('sqlite:///test.sqlite')
res = db.people.fi开发者_如何学编程lter_by(id = 1).all()

return res[0]


I'm not really sure why you think you need this, but here it is:

import sqlalchemy.ext.sqlsoup as SqlSoup
import sqlalchemy

engine = sqlalchemy.create_engine('sqlite:///test.sqlite')

db = SqlSoup(engine)
res = db.people.filter_by(id = 1).first()

engine.dispose()

return res

use Query.first() not Query.all()[0], create the engine separately from SqlSoup and pass it that engine. You can dispose the engine afterwards.

Do note that a new pool is created when you dispose the engine; the database is not perminantly disconnected, but any open connections are closed, and no new connections are drawn from the new pool by the dispose operation itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜