mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-09 17:20:17 +00:00
Added Few Classes to the application to be used on the Database
This commit is contained in:
parent
da7f4da43e
commit
d0278f8650
@@ -0,0 +1,11 @@
|
||||
from src.Database.Database import Database
|
||||
|
||||
|
||||
class Application:
|
||||
database = Database()
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
self.database.create()
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -0,0 +1,6 @@
|
||||
from src.Application.Application import Application
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
App = Application()
|
||||
App.run()
|
||||
Reference in New Issue
Block a user