Commit Graph

13 Commits

Author SHA1 Message Date
Federico Caselli 9b153ff18f Update black to 24.1.1
Change-Id: Iadaea7b798d8e99302e1acb430dc7b758ca61137
2024-01-31 21:54:59 +01:00
Gord Thompson aed8ac5985 Fix async ORM example
Reverting change from b3216486 that causes error

sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when exactly one was required

Change-Id: I9b249ff6e8e336f9c224e670359b4df99bc06092
2023-09-06 09:33:27 -06:00
Federico Caselli a48ebfe725 change gather orm example
changed gather orm example to avoid passing the same session to the
function called in the gather. While this is not an issue since no
sql is executed on it, it's still confusing for some users

References: #9312
Change-Id: I7f86e9c1640649ac13fd459b761d67718d4c3dc0
2023-06-30 12:38:43 -04:00
Federico Caselli 058c230cea Update black to v23.3.0 and flake8 to v6
This change could be added to .git-blame-ignore-revs

Change-Id: I7ba10052b26bc3c178d23fb50a1123d0aae965ca
2023-05-30 21:44:26 +02:00
Mike Bayer b3216486c4 add AsyncAttrs
Added a new helper mixin :class:`_asyncio.AsyncAttrs` that seeks to improve
the use of lazy-loader and other expired or deferred ORM attributes with
asyncio, providing a simple attribute accessor that provides an ``await``
interface to any ORM attribute, whether or not it needs to emit SQL.

Change-Id: I1427b288dc28319c854372643066c491b9ee8dc0
References: #9731
2023-05-08 11:50:03 -04:00
Mike Bayer af24660a96 update asyncio examples and add notes about writeonly
Change-Id: I1233eb1a860b915fb265ec8bf177f1a0471cdbd1
2023-02-05 16:42:27 -05:00
Mike Bayer d24cd5e96d establish sessionmaker and async_sessionmaker as generic
This is so that custom Session and AsyncSession classes
can be typed for these factories.  Added appropriate
typevars to  `__call__()`, `__enter__()` and other methods
so that a custom Session or AsyncSession subclass is carried
through.

Fixes: #7656
Change-Id: Ia2b8c1f22b4410db26005c3285f6ba3d13d7f0e0
2022-05-31 15:17:48 -04:00
Mike Bayer a45e2284da pep-484: asyncio
in this patch the asyncio/events.py module, which
existed only to raise errors when trying to attach event
listeners, is removed, as we were already coding an asyncio-specific
workaround in upstream Pool / Session to raise this error,
just moved the error out to the target and did the same thing
for Engine.

We also add an async_sessionmaker class.  The initial rationale
here is because sessionmaker() is hardcoded to Session subclasses,
and there's not a way to get the use case of
sessionmaker(class_=AsyncSession) to type correctly without changing
the sessionmaker() symbol itself to be a function and not a class,
which gets too complicated for what this is. Additionally,
_SessionClassMethods has only three methods on it, one of which
is not usable with asyncio (close_all()), the others
not generally used from the session class.

Change-Id: I064a5fa5d91cc8d5bbe9597437536e37b4e801fe
2022-04-11 22:11:07 -04:00
Gord Thompson 7f8bf038b7 Apply minor update to async_orm example
- Fixed import to avoid MovedIn20Warning.

- Separated drop_all() and create_all() into separate
context managers to avoid dropping and creating the
same table within the same transaction. Apparently
some databases (e.g., CockroachDB) don't allow that.

Change-Id: Id26d7d719871a75ffb78c6af589658666802fb2f
2021-10-20 15:15:37 -06:00
Mike Bayer d640192877 add asyncio.gather() example; add connection opts
while I dont like this approach very much, people will likely
be asking for it a lot, so represent the most correct and
efficient form we can handle right now.

Added missing ``**kw`` arguments to the
:meth:`_asyncio.AsyncSession.connection` method.

Change-Id: Idadae2a02a4d96ecb96a5723ce64d017ab4c6217
References: https://github.com/sqlalchemy/sqlalchemy/discussions/6965
2021-09-02 14:19:20 +00:00
Mike Bayer 10f05288dc Document implicit IO points in ORM
I purposely didn't spend much documentation writing
about implicit IO when I first pushed out the asyncio
extension because I wanted to get a sense on what kinds
of issues people had.   Now we know and the answer is
predictably "all of them".  List out all the known
implicit IO points and how to avoid them.  Also rename
the "adapting lazy loads" section, so that the title is less
suggestive that this is a necessary technique.

References: #5926

Change-Id: I3933b74bd37a5b06989531adbeade34347db679b
2021-02-07 09:51:48 -05:00
Mike Bayer c3f102c9fe upgrade to black 20.8b1
It's better, the majority of these changes look more readable to me.
also found some docstrings that had formatting / quoting issues.

Change-Id: I582a45fde3a5648b2f36bab96bad56881321899b
2020-09-28 15:17:26 -04:00
Mike Bayer 5fb0138a32 Implement rudimentary asyncio support w/ asyncpg
Using the approach introduced at
https://gist.github.com/zzzeek/6287e28054d3baddc07fa21a7227904e

We can now create asyncio endpoints that are then handled
in "implicit IO" form within the majority of the Core internals.
Then coroutines are re-exposed at the point at which we call
into asyncpg methods.

Patch includes:

* asyncpg dialect

* asyncio package

* engine, result, ORM session classes

* new test fixtures, tests

* some work with pep-484 and a short plugin for the
  pyannotate package, which seems to have so-so results

Change-Id: Idbcc0eff72c4cad572914acdd6f40ddb1aef1a7d
Fixes: #3414
2020-08-13 18:41:53 -04:00