From 925164e21db86e9a8b7732e1ae2ba82ff0acfeec Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Fri, 11 Mar 2022 18:09:49 +0100 Subject: [PATCH] Add database structure --- db/connector.py | 17 +++++++++++++++++ db/model/image_table.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 db/connector.py create mode 100644 db/model/image_table.py diff --git a/db/connector.py b/db/connector.py new file mode 100644 index 0000000..e262970 --- /dev/null +++ b/db/connector.py @@ -0,0 +1,17 @@ +import os + +from sqlalchemy import create_engine + +user = os.environ['DB_USER'] +password = os.environ['DB_PASSWORD'] +host = os.environ['DB_HOST'] +port = os.environ['DB_PORT'] +database = os.environ['DB_DATABASE'] + + +def get_connection(): + return create_engine( + url="mysql+pymysql://{0}:{1}@{2}:{3}/{4}".format( + user, password, host, port, database + ) + ) diff --git a/db/model/image_table.py b/db/model/image_table.py new file mode 100644 index 0000000..a6af713 --- /dev/null +++ b/db/model/image_table.py @@ -0,0 +1,18 @@ +import sqlalchemy as db + +from db import connector + +engine = connector.create_engine + +metadata_obj = db.MetaData() + +profile = db.Table( + 'images', + metadata_obj, + db.Column('id', db.Integer, primary_key=True), + db.Column('location', db.String), + db.Column('copyright', db.String), + db.Column('date_added', db.TIMESTAMP), +) + +metadata_obj.create_all(engine)