From d0278f8650a6a740dd7d51cab09ad66224ea14ba Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Tue, 3 Jun 2025 18:55:58 -0300 Subject: [PATCH] Added Few Classes to the application to be used on the Database --- .idea/Pilgrim.iml | 10 ++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 117 ++++++++++++++++++ src/Application/Application.py | 11 ++ src/Application/__init__.py | 0 src/Database/Database.py | 19 +++ src/Database/__init__.py | 0 src/Models/TravelDiary/TravelDiary.py | 8 ++ src/Models/TravelDiary/__init__.py | 0 src/Models/__init__.py | 0 src/main.py | 6 + 13 files changed, 191 insertions(+) create mode 100644 .idea/Pilgrim.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 src/Application/Application.py create mode 100644 src/Application/__init__.py create mode 100644 src/Database/Database.py create mode 100644 src/Database/__init__.py create mode 100644 src/Models/TravelDiary/TravelDiary.py create mode 100644 src/Models/TravelDiary/__init__.py create mode 100644 src/Models/__init__.py create mode 100644 src/main.py diff --git a/.idea/Pilgrim.iml b/.idea/Pilgrim.iml new file mode 100644 index 0000000..3defecc --- /dev/null +++ b/.idea/Pilgrim.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..daedced --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..3586794 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1748985568579 + + + + + + + + + + \ No newline at end of file diff --git a/src/Application/Application.py b/src/Application/Application.py new file mode 100644 index 0000000..cbdad0b --- /dev/null +++ b/src/Application/Application.py @@ -0,0 +1,11 @@ +from src.Database.Database import Database + + +class Application: + database = Database() + + def __init__(self): + pass + + def run(self): + self.database.create() diff --git a/src/Application/__init__.py b/src/Application/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/Database/Database.py b/src/Database/Database.py new file mode 100644 index 0000000..a9b08c4 --- /dev/null +++ b/src/Database/Database.py @@ -0,0 +1,19 @@ +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker + +class Database: + def __init__(self): + self.engine = create_engine('sqlite:///database.db', echo=False,connect_args={"check_same_thread": False}) + self.Session = sessionmaker(bind=self.engine,autoflush=False,autocommit=False) + self.Base = declarative_base() + def create(self): + self.Base.metadata.create_all(self.engine) + def get_db(self): + db = self.Session() + try: + yield db + finally: + db.close() + + diff --git a/src/Database/__init__.py b/src/Database/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/Models/TravelDiary/TravelDiary.py b/src/Models/TravelDiary/TravelDiary.py new file mode 100644 index 0000000..3917bf1 --- /dev/null +++ b/src/Models/TravelDiary/TravelDiary.py @@ -0,0 +1,8 @@ +from sqlalchemy import Column, String, Integer + +from src.Application.Application import Application + +class TravelDiary(Application.database.Base): + __tablename__ = "TravelDiary" + id = Column(Integer, primary_key=True) + name = Column(String) diff --git a/src/Models/TravelDiary/__init__.py b/src/Models/TravelDiary/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/Models/__init__.py b/src/Models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..43d5d75 --- /dev/null +++ b/src/main.py @@ -0,0 +1,6 @@ +from src.Application.Application import Application + + +if __name__ == '__main__': + App = Application() + App.run()