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: