当前位置: 首页>>代码示例>>Python>>正文


Python g._database方法代码示例

本文整理汇总了Python中flask.g._database方法的典型用法代码示例。如果您正苦于以下问题:Python g._database方法的具体用法?Python g._database怎么用?Python g._database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.g的用法示例。


在下文中一共展示了g._database方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_db

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_db():
    db = getattr(g, "_database", None)
    if db is None:
        db = g._database = sqlite3.connect(DATABASE)
        cur = db.cursor()
        cur.execute(
            """create table if not exists {} (
            Telephone char(11) PRIMARY KEY NOT NULL,
            Password  char(20) NOT NULL,
            Username  char(20),
            Sex       char(1),
            Location  char(50))""".format(TABLE)
        )
        db.isolation_level = None
    return db 
开发者ID:Randool,项目名称:pyRecommender,代码行数:17,代码来源:server.py

示例2: close_db_connection

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def close_db_connection(exception):
    db = getattr(g, "_database", None)
    if db is not None:
        db.close()


############################
######## Flask apps ########
############################ 
开发者ID:Randool,项目名称:pyRecommender,代码行数:11,代码来源:server.py

示例3: get_db

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        print("Creating new db connection {}".format(DATABASE))
        db = g._database = sqlite3.connect(DATABASE)
        db.row_factory = make_dicts
    return db 
开发者ID:stopipv,项目名称:isdi,代码行数:9,代码来源:db.py

示例4: get_context_conn

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_context_conn():
    """
    Flask needs a database connection per request context, and that
    is registered to close in route.py
    """
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = sqlite3.connect(db_name)
    return db 
开发者ID:jedimatt42,项目名称:tipi,代码行数:11,代码来源:tipi_cache.py

示例5: get_db_con

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_db_con():
    global pool
    max_attempts = 10
    con = getattr(g, '_database', None)
    if con is None:
        #Need to get a connection, use a try loop to handle pool depletions a bit better 
        #Otherwise psycopg2.pool throws exception and server returns 500 error to client
        for attempt in range(1, max_attempts):
            try:
                 con = g._database = pool.getconn()
                 if (attempt > 1):
                     log.debug("connection newly acquired from pool, attempt=%s" % attempt)
                 return con
            except:
                 #On any errors, add exponentially increasing time delays.
                 #This seems to handle at least 30X the pool size in requests without hard errors.
                 e = sys.exc_info()[0]
                 log.error("exception during connection attempt=%s: %s" % (attempt, e))
                 if (attempt == max_attempts):
                     #give up!
                     raise
                 time.sleep(attempt**2)
    else:
      log.debug("connection reused from session variable.")
    con.autocommit = True
    return con


#Automatically return db connections 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:31,代码来源:htc_api.py

示例6: return_db_con

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def return_db_con(exception):
    global pool
    con = getattr(g, '_database', None)
    if con is not None:
        pool.putconn(con)
        #log.debug("connection returned to pool.")


#format simple data for return as JSON 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:11,代码来源:htc_api.py

示例7: get_db

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = sqlite3.connect(DATABASE)
    return db 
开发者ID:mlperf,项目名称:training,代码行数:7,代码来源:joseki_query.py

示例8: close_connection

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.close() 
开发者ID:mlperf,项目名称:training,代码行数:6,代码来源:joseki_query.py

示例9: get_db

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_db():
    db = getattr(g, "_database", None)
    if db is None:
        db = g._database = sqlite3.connect(DATABASE)

        with db:
            try:
                db.execute(
                    "CREATE TABLE numbers_table (name TEXT NOT NULL, number INTEGER NOT NULL)"
                )
            except Exception:
                pass

    return db 
开发者ID:taverntesting,项目名称:tavern,代码行数:16,代码来源:server.py

示例10: close_connection

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def close_connection(exception):
    db = getattr(g, "_database", None)
    if db is not None:
        db.close() 
开发者ID:taverntesting,项目名称:tavern,代码行数:6,代码来源:server.py

示例11: get_db

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_db():
    db = getattr(g, "_database", None)
    if db is None:
        db = g._database = sqlite3.connect(DATABASE)

        with db:
            try:
                db.execute(
                    "CREATE TABLE numbers_table (name TEXT NOT NULL, number INTEGER NOT NULL)"
                )
            except:
                pass

    return db 
开发者ID:taverntesting,项目名称:tavern,代码行数:16,代码来源:server.py

示例12: get_cached_db

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import _database [as 别名]
def get_cached_db():
    db = getattr(g, "_database", None)
    if db is None:
        db = g._database = get_db()

    return db 
开发者ID:taverntesting,项目名称:tavern,代码行数:8,代码来源:server.py


注:本文中的flask.g._database方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。