1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Проверка 09.02.2025

This commit is contained in:
MoonTestUse1
2025-02-09 01:11:49 +06:00
parent ce52f8a23a
commit 0aa3ef8fc2
5827 changed files with 14316 additions and 1906434 deletions

View File

@@ -1,5 +1,5 @@
# ext/asyncio/engine.py
# Copyright (C) 2020-2024 the SQLAlchemy authors and contributors
# Copyright (C) 2020-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -41,6 +41,8 @@ from ...engine.base import NestedTransaction
from ...engine.base import Transaction
from ...exc import ArgumentError
from ...util.concurrency import greenlet_spawn
from ...util.typing import Concatenate
from ...util.typing import ParamSpec
if TYPE_CHECKING:
from ...engine.cursor import CursorResult
@@ -61,6 +63,7 @@ if TYPE_CHECKING:
from ...sql.base import Executable
from ...sql.selectable import TypedReturnsRows
_P = ParamSpec("_P")
_T = TypeVar("_T", bound=Any)
@@ -195,6 +198,7 @@ class AsyncConnection(
method of :class:`_asyncio.AsyncEngine`::
from sqlalchemy.ext.asyncio import create_async_engine
engine = create_async_engine("postgresql+asyncpg://user:pass@host/dbname")
async with engine.connect() as conn:
@@ -414,6 +418,7 @@ class AsyncConnection(
yield_per: int = ...,
insertmanyvalues_page_size: int = ...,
schema_translate_map: Optional[SchemaTranslateMapType] = ...,
preserve_rowcount: bool = False,
**opt: Any,
) -> AsyncConnection: ...
@@ -540,7 +545,7 @@ class AsyncConnection(
E.g.::
result = await conn.stream(stmt):
result = await conn.stream(stmt)
async for row in result:
print(f"{row}")
@@ -812,9 +817,12 @@ class AsyncConnection(
yield result.scalars()
async def run_sync(
self, fn: Callable[..., _T], *arg: Any, **kw: Any
self,
fn: Callable[Concatenate[Connection, _P], _T],
*arg: _P.args,
**kw: _P.kwargs,
) -> _T:
"""Invoke the given synchronous (i.e. not async) callable,
'''Invoke the given synchronous (i.e. not async) callable,
passing a synchronous-style :class:`_engine.Connection` as the first
argument.
@@ -824,26 +832,26 @@ class AsyncConnection(
E.g.::
def do_something_with_core(conn: Connection, arg1: int, arg2: str) -> str:
'''A synchronous function that does not require awaiting
"""A synchronous function that does not require awaiting
:param conn: a Core SQLAlchemy Connection, used synchronously
:return: an optional return value is supported
'''
conn.execute(
some_table.insert().values(int_col=arg1, str_col=arg2)
)
"""
conn.execute(some_table.insert().values(int_col=arg1, str_col=arg2))
return "success"
async def do_something_async(async_engine: AsyncEngine) -> None:
'''an async function that uses awaiting'''
"""an async function that uses awaiting"""
async with async_engine.begin() as async_conn:
# run do_something_with_core() with a sync-style
# Connection, proxied into an awaitable
return_code = await async_conn.run_sync(do_something_with_core, 5, "strval")
return_code = await async_conn.run_sync(
do_something_with_core, 5, "strval"
)
print(return_code)
This method maintains the asyncio event loop all the way through
@@ -874,9 +882,11 @@ class AsyncConnection(
:ref:`session_run_sync`
""" # noqa: E501
''' # noqa: E501
return await greenlet_spawn(fn, self._proxied, *arg, **kw)
return await greenlet_spawn(
fn, self._proxied, *arg, _require_await=False, **kw
)
def __await__(self) -> Generator[Any, None, AsyncConnection]:
return self.start().__await__()
@@ -921,7 +931,7 @@ class AsyncConnection(
return self._proxied.invalidated
@property
def dialect(self) -> Any:
def dialect(self) -> Dialect:
r"""Proxy for the :attr:`_engine.Connection.dialect` attribute
on behalf of the :class:`_asyncio.AsyncConnection` class.
@@ -930,7 +940,7 @@ class AsyncConnection(
return self._proxied.dialect
@dialect.setter
def dialect(self, attr: Any) -> None:
def dialect(self, attr: Dialect) -> None:
self._proxied.dialect = attr
@property
@@ -991,6 +1001,7 @@ class AsyncEngine(ProxyComparable[Engine], AsyncConnectable):
:func:`_asyncio.create_async_engine` function::
from sqlalchemy.ext.asyncio import create_async_engine
engine = create_async_engine("postgresql+asyncpg://user:pass@host/dbname")
.. versionadded:: 1.4
@@ -1047,7 +1058,6 @@ class AsyncEngine(ProxyComparable[Engine], AsyncConnectable):
)
await conn.execute(text("my_special_procedure(5)"))
"""
conn = self.connect()