def get_db():
# check if _database attribute exist
db = getattr(g, '_database', None)
if db is None:
# if doesnt, establish a new connection and save _database attribute
# this prevents multiple instances to the database
db = g._database = sql.connect(DATABASE)
db.row_factory = sql.Row
return db
# @function for querying/retrieving database
评论列表
文章目录