Main program function.
()
| 64 | |
| 65 | |
| 66 | async def async_main(): |
| 67 | """Main program function.""" |
| 68 | |
| 69 | engine = create_async_engine( |
| 70 | "postgresql+asyncpg://scott:tiger@localhost/test", |
| 71 | echo=True, |
| 72 | ) |
| 73 | async with engine.begin() as conn: |
| 74 | await conn.run_sync(Base.metadata.drop_all) |
| 75 | await conn.run_sync(Base.metadata.create_all) |
| 76 | |
| 77 | async with AsyncSession(engine) as session: |
| 78 | async with session.begin(): |
| 79 | session.add_all( |
| 80 | [ |
| 81 | A(bs=[B(), B()], data="a1"), |
| 82 | A(bs=[B()], data="a2"), |
| 83 | A(bs=[B(), B()], data="a3"), |
| 84 | ] |
| 85 | ) |
| 86 | |
| 87 | # we have the option to run a function written in sync style |
| 88 | # within the AsyncSession.run_sync() method. The function will |
| 89 | # be passed a synchronous-style Session object and the function |
| 90 | # can use traditional ORM patterns. |
| 91 | await session.run_sync(run_queries) |
| 92 | |
| 93 | await session.commit() |
| 94 | |
| 95 | |
| 96 | asyncio.run(async_main()) |
no test coverage detected