From a5bafe297a405c94cb7dbdd30d05c2a0c5548e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Mon, 30 Dec 2024 23:36:38 +0200 Subject: [PATCH] Updated the examples for Asphalt 5 --- examples/csvimport.py | 16 +++++++--------- examples/csvimport_orm.py | 16 +++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/examples/csvimport.py b/examples/csvimport.py index e3c15f6..0efe01c 100644 --- a/examples/csvimport.py +++ b/examples/csvimport.py @@ -37,19 +37,17 @@ class CSVImporterComponent(CLIApplicationComponent): def __init__(self) -> None: super().__init__() self.csv_path = Path(__file__).with_name("people.csv") - - async def start(self) -> None: - # Remove the db file if it exists - db_path = self.csv_path.with_name("people.db") - if db_path.exists(): - db_path.unlink() - + self.db_path = self.csv_path.with_name("people.db") self.add_component( "sqlalchemy", - url=f"sqlite:///{db_path}", + url=f"sqlite:///{self.db_path}", ready_callback=lambda bind, factory: metadata.create_all(bind), ) - await super().start() + + async def start(self) -> None: + # Remove the db file if it exists + if self.db_path.exists(): + self.db_path.unlink() @inject async def run(self, *, dbsession: Session = resource()) -> None: diff --git a/examples/csvimport_orm.py b/examples/csvimport_orm.py index 79e753e..1bab954 100644 --- a/examples/csvimport_orm.py +++ b/examples/csvimport_orm.py @@ -39,21 +39,19 @@ class CSVImporterComponent(CLIApplicationComponent): def __init__(self) -> None: super().__init__() self.csv_path = Path(__file__).with_name("people.csv") - - async def start(self) -> None: - # Remove the db file if it exists - db_path = self.csv_path.with_name("people.db") - if db_path.exists(): - db_path.unlink() - + self.db_path = self.csv_path.with_name("people.db") self.add_component( "sqlalchemy", - url=f"sqlite:///{db_path}", + url=f"sqlite:///{self.db_path}", ready_callback=lambda bind, factory: DeclarativeBase.metadata.create_all( bind ), ) - await super().start() + + async def start(self) -> None: + # Remove the db file if it exists + if self.db_path.exists(): + self.db_path.unlink() @inject async def run(self, *, dbsession: Session = resource()) -> None: