U a!<@sddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd l mZeje d d d dgddddddddddddg dddddd d!d"gd#Gd$d%d%eZGd&d'd'ZGd(d)d)eeZd*d+Zd,d-Zee _d.S)/)engine)result)ReversibleProxy)StartableContext)util)object_session)Session)state)greenlet_spawnz:class:`_orm.Session`z:class:`_asyncio.AsyncSession`rZ identity_key __contains____iter__addZadd_allZexpireZ expire_allZexpungeZ expunge_allZget_bindZ is_modifiedZin_transactionZin_nested_transactionZdirtyZdeletednewZ identity_map is_activeZ autoflushZ no_autoflushinfo)Z classmethodsmethods attributesc@seZdZdZdZdZd2ddZd3ddZdd Zde j dfd d Z de j dfd d Z d4ddZ de j dfddZddZd5ddZd6ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zed*d+Zd,d-Zd.d/Zd0d1ZdS)7 AsyncSessionzKAsyncio version of :class:`_orm.Session`. .. versionadded:: 1.4 )bindsbind sync_session_proxiedZ_slots_dispatchNcKs^d|d<|r||_t|}|r8||_dd|D}|tf||d||_|_dS)NTfuturecSsi|]\}}|t|qS)r_get_sync_engine_or_connection).0keybrr_C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\ext\asyncio\session.py Jsz)AsyncSession.__init__..)rr) rrrritems_assign_proxiedr rr)selfrrkwrrr__init__Bs zAsyncSession.__init__cst|jj|||dIdHS)aTExpire and refresh the attributes on the given instance. A query will be issued to the database and all attributes will be refreshed with their current database value. This is the async version of the :meth:`_orm.Session.refresh` method. See that method for a complete description of all options. )attribute_nameswith_for_updateN)r rrefresh)r#instancer&r'rrrr(Ss zAsyncSession.refreshcst||jf||IdHS)aInvoke the given sync callable passing sync self as the first argument. This method maintains the asyncio event loop all the way through to the database connection by running the given callable in a specially instrumented greenlet. E.g.:: with AsyncSession(async_engine) as session: await session.run_sync(some_business_method) .. note:: The provided callable is invoked inline within the asyncio event loop, and will block on traditional IO calls. IO within this callable should only call into SQLAlchemy's asyncio database APIs which will be properly adapted to the greenlet context. .. seealso:: :ref:`session_run_sync` N)r r)r#fnargr$rrrrun_syncgszAsyncSession.run_synccs2|ddi}t|jj|f|||d|IdHS)zQExecute a statement and return a buffered :class:`_engine.Result` object.Zprebuffer_rowsTparamsexecution_optionsbind_argumentsN)unionr rexecute)r# statementr.r/r0r$rrrr2s zAsyncSession.executecs(|j|f|||d|IdH}|S)z/Execute a statement and return a scalar result.r-N)r2scalarr#r3r.r/r0r$rrrrr4s  zAsyncSession.scalarFc s t|jj||||||dIdHS)zjReturn an instance based on the given primary key identifier, or ``None`` if not found. )optionspopulate_existingr'identity_tokenN)r rget)r#entityidentr6r7r'r8rrrr9szAsyncSession.getcs<|ddi}t|jj|f|||d|IdH}t|S)zXExecute a statement and return a streaming :class:`_asyncio.AsyncResult` object.Zstream_resultsTr-N)r1r rr2_resultZ AsyncResultr5rrrstreams  zAsyncSession.streamcst|jj|IdHS)zMark an instance as deleted. The database delete operation occurs upon ``flush()``. As this operation may need to cascade along unloaded relationships, it is awaitable to allow for those queries to take place. N)r rdelete)r#r)rrrr>s zAsyncSession.deleteTcst|jj||dIdHS)z~Copy the state of a given instance into a corresponding instance within this :class:`_asyncio.AsyncSession`. )loadN)r rmerge)r#r)r?rrrr@s zAsyncSession.mergecst|jj|dIdHdS)zuFlush all the object changes to the database. .. seealso:: :meth:`_orm.Session.flush` )objectsN)r rflush)r#rArrrrBszAsyncSession.flushcCs$|j}|dk rt|SdSdS)zReturn the current root transaction in progress, if any. :return: an :class:`_asyncio.AsyncSessionTransaction` object, or ``None``. .. versionadded:: 1.4.18 N)rget_transactionAsyncSessionTransaction_retrieve_proxy_for_targetr#transrrrrCs  zAsyncSession.get_transactioncCs$|j}|dk rt|SdSdS)zReturn the current nested transaction in progress, if any. :return: an :class:`_asyncio.AsyncSessionTransaction` object, or ``None``. .. versionadded:: 1.4.18 N)rget_nested_transactionrDrErFrrrrHs  z#AsyncSession.get_nested_transactioncst|jjIdH}tj|S)zReturn a :class:`_asyncio.AsyncConnection` object corresponding to this :class:`.Session` object's transactional state. N)r r connectionrZAsyncConnectionrE)r#Zsync_connectionrrrrIszAsyncSession.connectioncKst|S)aReturn an :class:`_asyncio.AsyncSessionTransaction` object. The underlying :class:`_orm.Session` will perform the "begin" action when the :class:`_asyncio.AsyncSessionTransaction` object is entered:: async with async_session.begin(): # .. ORM transaction is begun Note that database IO will not normally occur when the session-level transaction is begun, as database transactions begin on an on-demand basis. However, the begin block is async to accommodate for a :meth:`_orm.SessionEvents.after_transaction_create` event hook that may perform IO. For a general description of ORM begin, see :meth:`_orm.Session.begin`. rDr#r$rrrbegin#szAsyncSession.begincKs t|ddS)a:Return an :class:`_asyncio.AsyncSessionTransaction` object which will begin a "nested" transaction, e.g. SAVEPOINT. Behavior is the same as that of :meth:`_asyncio.AsyncSession.begin`. For a general description of ORM begin nested, see :meth:`_orm.Session.begin_nested`. T)nestedrJrKrrr begin_nested:s zAsyncSession.begin_nestedcst|jjIdHS)z-Rollback the current transaction in progress.N)r rrollbackr#rrrrOGszAsyncSession.rollbackcst|jjIdHS)z+Commit the current transaction in progress.N)r rcommitrPrrrrQKszAsyncSession.commitcst|jjIdHS)aPClose out the transactional resources and ORM objects used by this :class:`_asyncio.AsyncSession`. This expunges all ORM objects associated with this :class:`_asyncio.AsyncSession`, ends any transaction in progress and :term:`releases` any :class:`_asyncio.AsyncConnection` objects which this :class:`_asyncio.AsyncSession` itself has checked out from associated :class:`_asyncio.AsyncEngine` objects. The operation then leaves the :class:`_asyncio.AsyncSession` in a state which it may be used again. .. tip:: The :meth:`_asyncio.AsyncSession.close` method **does not prevent the Session from being used again**. The :class:`_asyncio.AsyncSession` itself does not actually have a distinct "closed" state; it merely means the :class:`_asyncio.AsyncSession` will release all database connections and ORM objects. .. seealso:: :ref:`session_closing` - detail on the semantics of :meth:`_asyncio.AsyncSession.close` N)r rcloserPrrrrROszAsyncSession.closecst|jjIdHS)z2Close all :class:`_asyncio.AsyncSession` sessions.N)r r close_allrPrrrrSmszAsyncSession.close_allcs|SNrrPrrr __aenter__rszAsyncSession.__aenter__cs|IdHdSrT)rRr#type_value tracebackrrr __aexit__uszAsyncSession.__aexit__cCst|SrT)_AsyncSessionContextManagerrPrrr_maker_context_managerxsz#AsyncSession._maker_context_manager)NN)NN)NFNN)T)N)__name__ __module__ __qualname____doc__ __slots__dispatchr%r(r,r EMPTY_DICTr2r4r9r=r>r@rBrCrHrIrLrNrOrQrR classmethodrSrUrZr\rrrrrsR          rc@s$eZdZddZddZddZdS)r[cCs ||_dSrT) async_session)r#rerrrr%~sz$_AsyncSessionContextManager.__init__cs"|j|_|jIdH|jSrT)rerLrGrUrPrrrrUs z&_AsyncSessionContextManager.__aenter__cs0|j|||IdH|j|||IdHdSrT)rGrZrerVrrrrZsz%_AsyncSessionContextManager.__aexit__N)r]r^r_r%rUrZrrrrr[}sr[c@sTeZdZdZdZdddZeddZdd Zd d Z d d Z dddZ ddZ dS)rDaA wrapper for the ORM :class:`_orm.SessionTransaction` object. This object is provided so that a transaction-holding object for the :meth:`_asyncio.AsyncSession.begin` may be returned. The object supports both explicit calls to :meth:`_asyncio.AsyncSessionTransaction.commit` and :meth:`_asyncio.AsyncSessionTransaction.rollback`, as well as use as an async context manager. .. versionadded:: 1.4 )sessionsync_transactionrMFcCs||_||_d|_dSrT)rfrMrg)r#rfrMrrrr%sz AsyncSessionTransaction.__init__cCs|dk o|jSrT)_sync_transactionrrPrrrrs z!AsyncSessionTransaction.is_activecCs|js||jSrT)rgZ_raise_for_not_startedrPrrrrhsz)AsyncSessionTransaction._sync_transactioncst|jIdHdS)z2Roll back this :class:`_asyncio.AsyncTransaction`.N)r rhrOrPrrrrOsz AsyncSessionTransaction.rollbackcst|jIdHdS)z/Commit this :class:`_asyncio.AsyncTransaction`.N)r rhrQrPrrrrQszAsyncSessionTransaction.commitcs>|t|jr|jjjn|jjjIdH|_|r:|j|SrT) r"r rMrfrrNrLrg __enter__)r#Z is_ctxmanagerrrrstarts  zAsyncSessionTransaction.startcst|j|||IdHdSrT)r rh__exit__rVrrrrZs z!AsyncSessionTransaction.__aexit__N)F)F) r]r^r_r`rar%propertyrrhrOrQrjrZrrrrrDs   rDcCs t|}|dk rt|SdSdS)aReturn the :class:`_asyncio.AsyncSession` to which the given instance belongs. This function makes use of the sync-API function :class:`_orm.object_session` to retrieve the :class:`_orm.Session` which refers to the given instance, and from there links it to the original :class:`_asyncio.AsyncSession`. If the :class:`_asyncio.AsyncSession` has been garbage collected, the return value is ``None``. This functionality is also available from the :attr:`_orm.InstanceState.async_session` accessor. :param instance: an ORM mapped instance :return: an :class:`_asyncio.AsyncSession` object, or ``None``. .. versionadded:: 1.4.18 N)rre)r)rfrrrasync_object_sessionsrmcCstj|ddS)aReturn the :class:`_asyncio.AsyncSession` which is proxying the given :class:`_orm.Session` object, if any. :param session: a :class:`_orm.Session` instance. :return: a :class:`_asyncio.AsyncSession` instance, or ``None``. .. versionadded:: 1.4.18 F)Z regenerate)rrE)rfrrrres reN)rrr<baserrrZormrr r Z_instance_stateZutil.concurrencyr Zcreate_proxy_methodsrr[rDrmreZ_async_providerrrrrsX         O>