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
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 ""
def db(client): """ Return a database instance. """ with app.app_context(): return Database.get_instance()
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