python类_database()的实例源码

database.py 文件源码 项目:globus-sample-data-portal 作者: globus 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, app):
        """Constructor."""
        self.app = app

        @app.teardown_appcontext
        def close_connection(exception):
            """Close database connection when finished handling request."""
            db = getattr(g, '_database', None)

            if db is not None:
                db.close()
database.py 文件源码 项目:globus-sample-data-portal 作者: globus 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_db(self):
        """Return the app global db connection or create one."""
        db = getattr(g, '_database', None)

        if db is None:
            db = g._database = self.connect_to_db()
            db.row_factory = sqlite3.Row

        return db
db.py 文件源码 项目:craftbeerpi3 作者: Manuel83 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        def dict_factory(cursor, row):
            d = {}
            for idx, col in enumerate(cursor.description):
                d[col[0]] = row[idx]
            return d
        db = g._database = sqlite3.connect('craftbeerpi.db')
        db.row_factory = dict_factory
    return db
serverside.py 文件源码 项目:SlackRU 作者: HackRU 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_db():
    """
    From the Flask Websitei, probs best practice to connect to the databse this way
    """
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = sqlite3.connect(dbpath)
    def make_dicts(cursor, row):
        return dict((cursor.description[idx][0], value)
                    for idx, value in enumerate(row))

    db.row_factory = make_dicts
    return db
index.py 文件源码 项目:CMS 作者: Vinlagrenouille 项目源码 文件源码 阅读 59 收藏 0 点赞 0 评论 0
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        g._database = Database()
    return g._database
index.py 文件源码 项目:CMS 作者: Vinlagrenouille 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.disconnect()
__init__.py 文件源码 项目:secret-weapon 作者: junorouse 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def set_db():
    dbx = getattr(g, '_database', None)
    if dbx is None:
        dbx = g._database = db
sqlite_basic_flask.py 文件源码 项目:zajecia_python_mini_edycja4 作者: daftcode 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        db = sqlite3.connect(DATABASE)
        g._database = db
    return db


# zgapione z http://flask.pocoo.org/docs/0.12/patterns/sqlite3/
sqlite_basic_flask.py 文件源码 项目:zajecia_python_mini_edycja4 作者: daftcode 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.close()


#@app.route('/<new_user>')
#def insert_new_user(new_user):
#    db = get_db()
#    c = db.cursor()
#    c.execute("INSERT INTO users VALUES ('{}', 3)".format(new_user))
#    db.commit()
#    return 'inserted {}'.format(new_user)
run.py 文件源码 项目:demo_project_bms 作者: solheng 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_db():
    db = getattr(g,'_database',None)
    if db is None:
        db = g._database = sqlite3.connect(DATABASE_URL)
        db.row_factory = make_dicts
    return db


# ??SQL?????????
run.py 文件源码 项目:demo_project_bms 作者: solheng 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def close_connection(exeption):
    db = getattr(g,'_database',None)
    if db is not None:
        db.close()
database.py 文件源码 项目:baroness 作者: ulrichknecht 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_db():
    db = getattr(g, '_database',None)
    if db is None:
        db = g._database = sqlite3.connect(DATABASE)
    return db
database.py 文件源码 项目:baroness 作者: ulrichknecht 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def close_connection(exception):
    db = getattr(g,'_database', None)
    if db is not None:
        db.close()
server.py 文件源码 项目:PSP0201 作者: prevwong 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
server.py 文件源码 项目:PSP0201 作者: prevwong 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.close()
db_model.py 文件源码 项目:hackathon 作者: vertica 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = connect_to_db()
    return db
db_model.py 文件源码 项目:hackathon 作者: vertica 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.close()
server.py 文件源码 项目:cloud-gateway 作者: BU-NU-CLOUD-SP16 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_db():
    db = getattr(g, '_database', None)
    if db is None:
        db = g._database = connect_to_database()
    return db
server.py 文件源码 项目:cloud-gateway 作者: BU-NU-CLOUD-SP16 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def close_connection(exception):
    db = getattr(g, '_database', None)
    if db is not None:
        db.close()

#############
# HOME PAGE #
#############


问题


面经


文章

微信
公众号

扫码关注公众号