mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-09 17:20:17 +00:00
Rearrange project layout and the database started working in there somewhere
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
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()
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
from src.Database.Database import Database
|
||||
from Pilgrim.Database import Database
|
||||
|
||||
|
||||
class Application:
|
||||
database = Database()
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
self.database = Database()
|
||||
|
||||
def run(self):
|
||||
self.database.create()
|
||||
@@ -0,0 +1,21 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
def create(self):
|
||||
Base.metadata.create_all(self.engine)
|
||||
|
||||
def get_db(self):
|
||||
return self.Session()
|
||||
@@ -1,8 +1,9 @@
|
||||
from sqlalchemy import Column, String, Integer
|
||||
|
||||
from src.Application.Application import Application
|
||||
from Pilgrim import Application, Base
|
||||
|
||||
class TravelDiary(Application.database.Base):
|
||||
|
||||
class TravelDiary(Base):
|
||||
__tablename__ = "TravelDiary"
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String)
|
||||
@@ -0,0 +1,6 @@
|
||||
from Pilgrim.Application import Application
|
||||
from Pilgrim.command import main
|
||||
from Pilgrim.Database import Database, Base
|
||||
from Pilgrim.TravelDiary import TravelDiary
|
||||
|
||||
__all__ = ["Application", "Database", "TravelDiary", "main", "Base"]
|
||||
@@ -0,0 +1,6 @@
|
||||
from Pilgrim import Application
|
||||
|
||||
|
||||
def main():
|
||||
app = Application()
|
||||
app.run()
|
||||
@@ -1,6 +0,0 @@
|
||||
from src.Application.Application import Application
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
App = Application()
|
||||
App.run()
|
||||
Reference in New Issue
Block a user