connect
- connect(self)
使用范围: server
编程语言: python
父类: Task 类
描述说明
使用 connect 方法从 SQLAlchemy 连接池中取出一个连接。
该方法的返回值是一个 DBAPI 连接。
当不再需要连接时,开发者必须通过调用连接的 close 方法将它放回连接池中。
示例
def delete_rec(item, item_id):
conection = item.task.connect()
try:
cursor = conection.cursor()
cursor.execute('delete from %s where id=%s' % (item.table_name, item_id))
conection.commit()
finally:
conection.close()