beer_data/src/flask/mongo/query_db.py
Andrew Ridgway 1470f0979a
Some checks failed
Build and Push Image / Build and push image (push) Has been cancelled
initial
2024-09-07 23:24:32 +10:00

56 lines
1.7 KiB
Python

import string
import secrets
from mongo.get_conn import db_conn
class pool_query:
"""
This class will allow us to
interact with our data to interact
just create a realestate_data var
"""
def __init__(self):
#db_conn has all the the things
#already created from here
#we can get self.db.real_db etc
self.db = db_conn()
def record_exists(self, beer_run_id, date):
"""
This function will accept an address
if it find that address in the database it will return True
and set set the existing_record variable of the class to the
queried record
"""
query = {"beer_run_id": f"{beer_run_id}", "date": f"{date}"}
record = self.db.beer_db.find_one(query)
if record:
self.existing_record = record
return True
else:
return False
def get_top(self, num_limit, value_field):
"""
This function will return the
last n records of the chosen value field
It will take the number of records you want to
return as a parameter
"""
records = self.db.beer_db.find({}, {"beer_run_id": 1, "_id": 0, "date": 1, f"{value_field}": 1}).sort("date", -1).limit(num_limit)
return records
def user_check(self, username, password):
"""
function to check username and password
back in db
"""
#TODO: this ueses my own quick hack it likley needs to be rewrittent to follow best practice
query = { "username" : f"{username}", "password" : f"{password}" }
record = self.db.users.find_one(query)
if record:
return True
else:
return False