from .conninfo import make_conninfo
from .generators import notifies
from .transaction import Transaction, AsyncTransaction
-from .named_cursor import NamedCursor, AsyncNamedCursor
+from .server_cursor import ServerCursor, AsyncServerCursor
from ._preparing import PrepareManager
logger = logging.getLogger(__name__)
...
@overload
- def cursor(self, name: str, *, binary: bool = False) -> NamedCursor:
+ def cursor(self, name: str, *, binary: bool = False) -> ServerCursor:
...
def cursor(
self, name: str = "", *, binary: bool = False
- ) -> Union[Cursor, NamedCursor]:
+ ) -> Union[Cursor, ServerCursor]:
"""
Return a new `Cursor` to send commands and queries to the connection.
"""
format = Format.BINARY if binary else Format.TEXT
if name:
- return NamedCursor(self, name=name, format=format)
+ return ServerCursor(self, name=name, format=format)
else:
return Cursor(self, format=format)
...
@overload
- def cursor(self, name: str, *, binary: bool = False) -> AsyncNamedCursor:
+ def cursor(self, name: str, *, binary: bool = False) -> AsyncServerCursor:
...
def cursor(
self, name: str = "", *, binary: bool = False
- ) -> Union[AsyncCursor, AsyncNamedCursor]:
+ ) -> Union[AsyncCursor, AsyncServerCursor]:
"""
Return a new `AsyncCursor` to send commands and queries to the connection.
"""
format = Format.BINARY if binary else Format.TEXT
if name:
- return AsyncNamedCursor(self, name=name, format=format)
+ return AsyncServerCursor(self, name=name, format=format)
else:
return AsyncCursor(self, format=format)
"""
-psycopg3 named cursor objects (server-side cursors)
+psycopg3 server-side cursor objects.
"""
# Copyright (C) 2020-2021 The Psycopg Team
DEFAULT_ITERSIZE = 100
-class NamedCursorHelper(Generic[ConnectionType]):
+class ServerCursorHelper(Generic[ConnectionType]):
__slots__ = ("name", "described")
- """Helper object for common NamedCursor code.
+ """Helper object for common ServerCursor code.
TODO: this should be a mixin, but couldn't find a way to work it
correctly with the generic.
query: Query,
params: Optional[Params] = None,
) -> PQGen[None]:
- """Generator implementing `NamedCursor.execute()`."""
+ """Generator implementing `ServerCursor.execute()`."""
conn = cur._conn
yield from cur._start_query(query)
pgq = cur._convert_query(query, params)
)
-class NamedCursor(BaseCursor["Connection"]):
+class ServerCursor(BaseCursor["Connection"]):
__module__ = "psycopg3"
__slots__ = ("_helper", "itersize")
format: Format = Format.TEXT,
):
super().__init__(connection, format=format)
- self._helper: NamedCursorHelper["Connection"] = NamedCursorHelper(name)
+ self._helper: ServerCursorHelper["Connection"] = ServerCursorHelper(
+ name
+ )
self.itersize = DEFAULT_ITERSIZE
def __del__(self) -> None:
if not self._closed:
warnings.warn(
- f"named cursor {self} was deleted while still open."
+ f"the server-side cursor {self} was deleted while still open."
f" Please use 'with' or '.close()' to close the cursor properly",
ResourceWarning,
)
- def __enter__(self) -> "NamedCursor":
+ def __enter__(self) -> "ServerCursor":
return self
def __exit__(
*,
scrollable: bool = True,
hold: bool = False,
- ) -> "NamedCursor":
+ ) -> "ServerCursor":
"""
Execute a query or command to the database.
"""
return self
def executemany(self, query: Query, params_seq: Sequence[Params]) -> None:
- raise e.NotSupportedError("executemany not supported on named cursors")
+ raise e.NotSupportedError(
+ "executemany not supported on server-side cursors"
+ )
def fetchone(self) -> Optional[Sequence[Any]]:
with self._conn.lock:
self._pos = value
-class AsyncNamedCursor(BaseCursor["AsyncConnection"]):
+class AsyncServerCursor(BaseCursor["AsyncConnection"]):
__module__ = "psycopg3"
__slots__ = ("_helper", "itersize")
format: Format = Format.TEXT,
):
super().__init__(connection, format=format)
- self._helper: NamedCursorHelper["AsyncConnection"]
- self._helper = NamedCursorHelper(name)
+ self._helper: ServerCursorHelper["AsyncConnection"]
+ self._helper = ServerCursorHelper(name)
self.itersize = DEFAULT_ITERSIZE
def __del__(self) -> None:
if not self._closed:
warnings.warn(
- f"named cursor {self} was deleted while still open."
+ f"the server-side cursor {self} was deleted while still open."
f" Please use 'with' or '.close()' to close the cursor properly",
ResourceWarning,
)
- async def __aenter__(self) -> "AsyncNamedCursor":
+ async def __aenter__(self) -> "AsyncServerCursor":
return self
async def __aexit__(
*,
scrollable: bool = True,
hold: bool = False,
- ) -> "AsyncNamedCursor":
+ ) -> "AsyncServerCursor":
"""
Execute a query or command to the database.
"""
async def executemany(
self, query: Query, params_seq: Sequence[Params]
) -> None:
- raise e.NotSupportedError("executemany not supported on named cursors")
+ raise e.NotSupportedError(
+ "executemany not supported on server-side cursors"
+ )
async def fetchone(self) -> Optional[Sequence[Any]]:
async with self._conn.lock: