Skip to content

Commit

Permalink
Updated the examples for Asphalt 5
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Dec 30, 2024
1 parent 4d9f1c7 commit a5bafe2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
16 changes: 7 additions & 9 deletions examples/csvimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 7 additions & 9 deletions examples/csvimport_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a5bafe2

Please sign in to comment.