.. change::
:tags: usecase, orm, asyncio
- :tickets: 5796, 5797
+ :tickets: 5796, 5797, 5802
- Added :meth:`_asyncio.AsyncSession.scalar` as well as support for
+ Added :meth:`_asyncio.AsyncSession.scalar`,
+ :meth:`_asyncio.AsyncSession.get` as well as support for
:meth:`_orm.sessionmaker.begin` to work as an async context manager with
:class:`_asyncio.AsyncSession`. Also added
:meth:`_asyncio.AsyncSession.in_transaction` accessor.
\ No newline at end of file
)
return result.scalar()
+ async def get(
+ self,
+ entity,
+ ident,
+ options=None,
+ populate_existing=False,
+ with_for_update=None,
+ identity_token=None,
+ ):
+ """Return an instance based on the given primary key identifier,
+ or ``None`` if not found.
+
+
+ """
+ return await greenlet_spawn(
+ self.sync_session.get,
+ entity,
+ ident,
+ options=options,
+ populate_existing=populate_existing,
+ with_for_update=with_for_update,
+ identity_token=identity_token,
+ )
+
async def stream(
self,
statement,
result = await async_session.scalar(stmt)
eq_(result, 7)
+ @async_test
+ async def test_get(self, async_session):
+ User = self.classes.User
+
+ u1 = await async_session.get(User, 7)
+
+ eq_(u1.name, "jack")
+
+ u2 = await async_session.get(User, 7)
+
+ is_(u1, u2)
+
+ u3 = await async_session.get(User, 12)
+ is_(u3, None)
+
@async_test
@testing.requires.independent_cursors
async def test_stream_partitions(self, async_session):