from .proto import Query, Params, DumpersMap, LoadersMap, PQGen
from .utils.queries import PostgresQuery
from .copy import Copy, AsyncCopy
-from .sql import Composable
if TYPE_CHECKING:
from .connection import BaseConnection, Connection, AsyncConnection
"""
Implement part of execute() before waiting common to sync and async
"""
- if isinstance(query, Composable):
- query = query.as_string(self)
-
pgq = PostgresQuery(self._transformer)
pgq.convert(query, vars)
"""
Implement part of execute() before waiting common to sync and async
"""
- if isinstance(query, Composable):
- query = query.as_string(self)
-
pgq = PostgresQuery(self._transformer)
pgq.convert(query, vars)
from .cursor import BaseCursor
from .adapt import Dumper, Loader
from .waiting import Wait, Ready
+ from .sql import Composable
EncodeFunc = Callable[[str], Tuple[bytes, int]]
DecodeFunc = Callable[[bytes], Tuple[str, int]]
LoadersMap = Dict[Tuple[int, Format], LoaderType]
-class Composable(Protocol):
- def as_string(self, context: AdaptContext) -> str:
- ...
-
-
class Transformer(Protocol):
def __init__(self, context: AdaptContext = None):
...
from .. import errors as e
from ..pq import Format
from ..proto import Query, Params
+from ..sql import Composable
if TYPE_CHECKING:
from ..proto import Transformer
The results of this function can be obtained accessing the object
attributes (`query`, `params`, `types`, `formats`).
"""
+ if isinstance(query, Composable):
+ query = query.as_string(self._tx)
+
codec = self._tx.codec
if vars is not None:
self.query, self.formats, self._order, self._parts = _query2pg(
@lru_cache()
def _query2pg(
- query: Query, encoding: str
+ query: Union[bytes, str], encoding: str
) -> Tuple[bytes, List[Format], Optional[List[str]], List[QueryPart]]:
"""
Convert Python query and params into something Postgres understands.