Python flask.g 模块,sqlite_db() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用flask.g.sqlite_db()

项目:pubchem-ranker    作者:jacobwindsor    | 项目源码 | 文件源码
def get_db():
    """Opens a new database connection if there is none yet for the
    current application context.
    """
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = connect_db()
    return g.sqlite_db
项目:pubchem-ranker    作者:jacobwindsor    | 项目源码 | 文件源码
def close_db(error):
    """Closes the database again at the end of the request."""
    if hasattr(g, 'sqlite_db'):
        g.sqlite_db.close()
项目:sel    作者:tiagoamartins    | 项目源码 | 文件源码
def get_db():
    """
    Opens a new database connection if there is none yet for the
    current application context.
    """
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = connect_db()
    return g.sqlite_db
项目:recon-ng    作者:captainhooligan    | 项目源码 | 文件源码
def get_db():
    '''Opens a new database connection if there is none yet for the
    current application context.'''
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = connect_db()
        debug('Database connection created.')
    return g.sqlite_db
项目:recon-ng    作者:captainhooligan    | 项目源码 | 文件源码
def close_db(error):
    '''Closes the database again at the end of the request.'''
    if hasattr(g, 'sqlite_db'):
        g.sqlite_db.close()
        debug('Database connection destroyed.')
项目:flask-product-scraper    作者:livgrhm    | 项目源码 | 文件源码
def get_db():
    # g is a general purpose variable associated with the current application context
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = connect_db()
    return g.sqlite_db

# initialise the db
项目:flask-product-scraper    作者:livgrhm    | 项目源码 | 文件源码
def close_db(error):
    """Closes the database again at the end of the request."""
    if hasattr(g, 'sqlite_db'):
        g.sqlite_db.close()
项目:hackenei16    作者:mcasx    | 项目源码 | 文件源码
def db_open():
    """Opens a new database connection if there is none yet for the
    current application context.
    """
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = db_connect()
    return g.sqlite_db
项目:hackenei16    作者:mcasx    | 项目源码 | 文件源码
def close_db(error):
    """Closes the database again at the end of the request."""
    if hasattr(g, 'sqlite_db'):
        g.sqlite_db.close()

################################################################################
# Intersections
################################################################################
项目:rmcontrol    作者:ericmagnuson    | 项目源码 | 文件源码
def get_db():
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = connect_db()
    return g.sqlite_db
项目:rmcontrol    作者:ericmagnuson    | 项目源码 | 文件源码
def close_db(error):
    if hasattr(g, 'sqlite_db'):
        g.sqlite_db.close()