コード例 #1
0
 def __init__(self, username, collection):
     """
     Initialize a profile using the username, app instance and database collection.
     """
     self.db = Database.get_instance()
     self.id = username.lower()
     self.fullname = ""
     self.hashed_pw = ""
     self.database_collection = collection
コード例 #2
0
 def get_restaurant_name_by_id(object_id):
     """
     Given a restaurant user's database id, return the restaurant's name.
     Returns "" on failure.
     """
     try:
         db = Database.get_instance()
         user = db.query("restaurant_users",
                         {"_id": ObjectId(object_id)})[0]
         return user["profile"]["name"]
     except (QueryFailureException, IndexError, KeyError, InvalidId):
         print("Something's wrong with the query.")
         return ""
コード例 #3
0
def db(client):
    """
    Return a database instance.
    """
    with app.app_context():
        return Database.get_instance()
コード例 #4
0
ファイル: engine.py プロジェクト: anirudhdahiya9/keyval-db
def init_database(name, log_path, dump_path):
    log_path = os.path.join(log_path, name) + '.log'
    dump_path = os.path.join(dump_path, name) + '.rdb'
    database = Database.get_instance(name, log_path, dump_path)
    return database