Загрузить файлы в «venv/Lib/site-packages/sqlalchemy/engine»
This commit is contained in:
3471
venv/Lib/site-packages/sqlalchemy/engine/interfaces.py
Normal file
3471
venv/Lib/site-packages/sqlalchemy/engine/interfaces.py
Normal file
File diff suppressed because it is too large
Load Diff
133
venv/Lib/site-packages/sqlalchemy/engine/mock.py
Normal file
133
venv/Lib/site-packages/sqlalchemy/engine/mock.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
# engine/mock.py
|
||||||
|
# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
|
||||||
|
# <see AUTHORS file>
|
||||||
|
#
|
||||||
|
# This module is part of SQLAlchemy and is released under
|
||||||
|
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from operator import attrgetter
|
||||||
|
import typing
|
||||||
|
from typing import Any
|
||||||
|
from typing import Callable
|
||||||
|
from typing import cast
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Type
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from . import url as _url
|
||||||
|
from .. import util
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from .base import Engine
|
||||||
|
from .interfaces import _CoreAnyExecuteParams
|
||||||
|
from .interfaces import CoreExecuteOptionsParameter
|
||||||
|
from .interfaces import Dialect
|
||||||
|
from .url import URL
|
||||||
|
from ..sql.base import Executable
|
||||||
|
from ..sql.ddl import InvokeDDLBase
|
||||||
|
from ..sql.schema import HasSchemaAttr
|
||||||
|
from ..sql.visitors import Visitable
|
||||||
|
|
||||||
|
|
||||||
|
class MockConnection:
|
||||||
|
def __init__(self, dialect: Dialect, execute: Callable[..., Any]):
|
||||||
|
self._dialect = dialect
|
||||||
|
self._execute_impl = execute
|
||||||
|
|
||||||
|
engine: Engine = cast(Any, property(lambda s: s))
|
||||||
|
dialect: Dialect = cast(Any, property(attrgetter("_dialect")))
|
||||||
|
name: str = cast(Any, property(lambda s: s._dialect.name))
|
||||||
|
|
||||||
|
def connect(self, **kwargs: Any) -> MockConnection:
|
||||||
|
return self
|
||||||
|
|
||||||
|
def schema_for_object(self, obj: HasSchemaAttr) -> Optional[str]:
|
||||||
|
return obj.schema
|
||||||
|
|
||||||
|
def execution_options(self, **kw: Any) -> MockConnection:
|
||||||
|
return self
|
||||||
|
|
||||||
|
def _run_ddl_visitor(
|
||||||
|
self,
|
||||||
|
visitorcallable: Type[InvokeDDLBase],
|
||||||
|
element: Visitable,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> None:
|
||||||
|
kwargs["checkfirst"] = False
|
||||||
|
visitorcallable(
|
||||||
|
dialect=self.dialect, connection=self, **kwargs
|
||||||
|
).traverse_single(element)
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
self,
|
||||||
|
obj: Executable,
|
||||||
|
parameters: Optional[_CoreAnyExecuteParams] = None,
|
||||||
|
execution_options: Optional[CoreExecuteOptionsParameter] = None,
|
||||||
|
) -> Any:
|
||||||
|
return self._execute_impl(obj, parameters)
|
||||||
|
|
||||||
|
|
||||||
|
def create_mock_engine(
|
||||||
|
url: Union[str, URL], executor: Any, **kw: Any
|
||||||
|
) -> MockConnection:
|
||||||
|
"""Create a "mock" engine used for echoing DDL.
|
||||||
|
|
||||||
|
This is a utility function used for debugging or storing the output of DDL
|
||||||
|
sequences as generated by :meth:`_schema.MetaData.create_all`
|
||||||
|
and related methods.
|
||||||
|
|
||||||
|
The function accepts a URL which is used only to determine the kind of
|
||||||
|
dialect to be used, as well as an "executor" callable function which
|
||||||
|
will receive a SQL expression object and parameters, which can then be
|
||||||
|
echoed or otherwise printed. The executor's return value is not handled,
|
||||||
|
nor does the engine allow regular string statements to be invoked, and
|
||||||
|
is therefore only useful for DDL that is sent to the database without
|
||||||
|
receiving any results.
|
||||||
|
|
||||||
|
E.g.::
|
||||||
|
|
||||||
|
from sqlalchemy import create_mock_engine
|
||||||
|
|
||||||
|
|
||||||
|
def dump(sql, *multiparams, **params):
|
||||||
|
print(sql.compile(dialect=engine.dialect))
|
||||||
|
|
||||||
|
|
||||||
|
engine = create_mock_engine("postgresql+psycopg2://", dump)
|
||||||
|
metadata.create_all(engine, checkfirst=False)
|
||||||
|
|
||||||
|
:param url: A string URL which typically needs to contain only the
|
||||||
|
database backend name.
|
||||||
|
|
||||||
|
:param executor: a callable which receives the arguments ``sql``,
|
||||||
|
``*multiparams`` and ``**params``. The ``sql`` parameter is typically
|
||||||
|
an instance of :class:`.ExecutableDDLElement`, which can then be compiled
|
||||||
|
into a string using :meth:`.ExecutableDDLElement.compile`.
|
||||||
|
|
||||||
|
.. versionadded:: 1.4 - the :func:`.create_mock_engine` function replaces
|
||||||
|
the previous "mock" engine strategy used with
|
||||||
|
:func:`_sa.create_engine`.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`faq_ddl_as_string`
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# create url.URL object
|
||||||
|
u = _url.make_url(url)
|
||||||
|
|
||||||
|
dialect_cls = u.get_dialect()
|
||||||
|
|
||||||
|
dialect_args = {}
|
||||||
|
# consume dialect arguments from kwargs
|
||||||
|
for k in util.get_cls_kwargs(dialect_cls):
|
||||||
|
if k in kw:
|
||||||
|
dialect_args[k] = kw.pop(k)
|
||||||
|
|
||||||
|
# create dialect
|
||||||
|
dialect = dialect_cls(**dialect_args)
|
||||||
|
|
||||||
|
return MockConnection(dialect, executor)
|
||||||
62
venv/Lib/site-packages/sqlalchemy/engine/processors.py
Normal file
62
venv/Lib/site-packages/sqlalchemy/engine/processors.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# engine/processors.py
|
||||||
|
# Copyright (C) 2010-2026 the SQLAlchemy authors and contributors
|
||||||
|
# <see AUTHORS file>
|
||||||
|
# Copyright (C) 2010 Gaetan de Menten gdementen@gmail.com
|
||||||
|
#
|
||||||
|
# This module is part of SQLAlchemy and is released under
|
||||||
|
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
||||||
|
|
||||||
|
"""defines generic type conversion functions, as used in bind and result
|
||||||
|
processors.
|
||||||
|
|
||||||
|
They all share one common characteristic: None is passed through unchanged.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from ._py_processors import str_to_datetime_processor_factory # noqa
|
||||||
|
from ..util._has_cy import HAS_CYEXTENSION
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING or not HAS_CYEXTENSION:
|
||||||
|
from ._py_processors import int_to_boolean as int_to_boolean
|
||||||
|
from ._py_processors import str_to_date as str_to_date
|
||||||
|
from ._py_processors import str_to_datetime as str_to_datetime
|
||||||
|
from ._py_processors import str_to_time as str_to_time
|
||||||
|
from ._py_processors import (
|
||||||
|
to_decimal_processor_factory as to_decimal_processor_factory,
|
||||||
|
)
|
||||||
|
from ._py_processors import to_float as to_float
|
||||||
|
from ._py_processors import to_str as to_str
|
||||||
|
else:
|
||||||
|
from sqlalchemy.cyextension.processors import (
|
||||||
|
DecimalResultProcessor,
|
||||||
|
)
|
||||||
|
from sqlalchemy.cyextension.processors import ( # noqa: F401
|
||||||
|
int_to_boolean as int_to_boolean,
|
||||||
|
)
|
||||||
|
from sqlalchemy.cyextension.processors import ( # noqa: F401,E501
|
||||||
|
str_to_date as str_to_date,
|
||||||
|
)
|
||||||
|
from sqlalchemy.cyextension.processors import ( # noqa: F401
|
||||||
|
str_to_datetime as str_to_datetime,
|
||||||
|
)
|
||||||
|
from sqlalchemy.cyextension.processors import ( # noqa: F401,E501
|
||||||
|
str_to_time as str_to_time,
|
||||||
|
)
|
||||||
|
from sqlalchemy.cyextension.processors import ( # noqa: F401,E501
|
||||||
|
to_float as to_float,
|
||||||
|
)
|
||||||
|
from sqlalchemy.cyextension.processors import ( # noqa: F401,E501
|
||||||
|
to_str as to_str,
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_decimal_processor_factory(target_class, scale):
|
||||||
|
# Note that the scale argument is not taken into account for integer
|
||||||
|
# values in the C implementation while it is in the Python one.
|
||||||
|
# For example, the Python implementation might return
|
||||||
|
# Decimal('5.00000') whereas the C implementation will
|
||||||
|
# return Decimal('5'). These are equivalent of course.
|
||||||
|
return DecimalResultProcessor(target_class, "%%.%df" % scale).process
|
||||||
2103
venv/Lib/site-packages/sqlalchemy/engine/reflection.py
Normal file
2103
venv/Lib/site-packages/sqlalchemy/engine/reflection.py
Normal file
File diff suppressed because it is too large
Load Diff
2449
venv/Lib/site-packages/sqlalchemy/engine/result.py
Normal file
2449
venv/Lib/site-packages/sqlalchemy/engine/result.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user