mirror of https://github.com/gmbrax/Pilgrim.git
Rearrange project layout and the database started working in there somewhere
This commit is contained in:
parent
d0278f8650
commit
ada761bf9a
|
|
@ -0,0 +1,2 @@
|
|||
database.db
|
||||
__pycache__
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
|
||||
[project]
|
||||
name = "Pilgrim"
|
||||
version = "0.0.1"
|
||||
authors = [
|
||||
{ name="Gustavo Henrique Santos Souza de Miranda", email="gustavohssmiranda@gmail.com" }
|
||||
]
|
||||
description = "Pilgrim's Travel Log"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
]
|
||||
dependencies = [
|
||||
"sqlalchemy"
|
||||
]
|
||||
[template.plugins.default]
|
||||
src-layout = true
|
||||
[project.urls]
|
||||
Homepage = "https://git.gustavomiranda.xyz/GHMiranda/Pilgrim"
|
||||
Issues = "https://git.gustavomiranda.xyz/GHMiranda/Pilgrim"
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["src/Pilgrim"]
|
||||
[project.scripts]
|
||||
pilgrim = "Pilgrim:main"
|
||||
|
|
@ -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()
|
||||
Loading…
Reference in New Issue