From 5b67534e97d568e4a92e9b7a6a45e5c31330a627 Mon Sep 17 00:00:00 2001 From: y2-youssef <youssef2.youssef@live.uwe.ac.uk> Date: Sat, 15 Jul 2023 00:53:26 +0000 Subject: [PATCH] Upload New File --- backup/models/location.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 backup/models/location.py diff --git a/backup/models/location.py b/backup/models/location.py new file mode 100644 index 0000000..e2866a4 --- /dev/null +++ b/backup/models/location.py @@ -0,0 +1,31 @@ +from database.connect import connection, base +import sqlalchemy as db +from sqlalchemy.orm import relationship +from datetime import date + +class LocationModel(base): + __tablename__ = "location" + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(20), nullable=False) + + def __init__(self, name: str): + self.name = name + + def __repr__(self): + return "<Location %r>" % self.id + +class Location: + def __init__(self): + # Get connection to database as session + engine, base, session, meta = connection() + self.session = session + + def get_locations(self) -> list: + """ + Get locations from database + + Returns: + list: List of all locations + """ + locations = self.session.query(LocationModel).all() + return locations \ No newline at end of file -- GitLab