""" # noqa
+from collections import deque
+
from .pymysql import MySQLDialect_pymysql
from ... import pool
from ... import util
# see https://github.com/aio-libs/aiomysql/issues/543
self._cursor = self.await_(cursor.__aenter__())
- self._rows = []
+ self._rows = deque()
@property
def description(self):
# exhausting rows, which we already have done for sync cursor.
# another option would be to emulate aiosqlite dialect and assign
# cursor only if we are doing server side cursor operation.
- self._rows[:] = []
+ self._rows.clear()
def execute(self, operation, parameters=None):
return self.await_(self._execute_async(operation, parameters))
# of that here since our default result is not async.
# we could just as easily grab "_rows" here and be done with it
# but this is safer.
- self._rows = list(await self._cursor.fetchall())
+ self._rows = deque(await self._cursor.fetchall())
return result
async def _executemany_async(self, operation, seq_of_parameters):
def __iter__(self):
while self._rows:
- yield self._rows.pop(0)
+ yield self._rows.popleft()
def fetchone(self):
if self._rows:
- return self._rows.pop(0)
+ return self._rows.popleft()
else:
return None
if size is None:
size = self.arraysize
- retval = self._rows[0:size]
- self._rows[:] = self._rows[size:]
- return retval
+ rr = self._rows
+ return [rr.popleft() for _ in range(min(size, len(rr)))]
def fetchall(self):
- retval = self._rows[:]
- self._rows[:] = []
+ retval = list(self._rows)
+ self._rows.clear()
return retval
""" # noqa
+from collections import deque
from contextlib import asynccontextmanager
from .pymysql import MySQLDialect_pymysql
cursor = self._connection.cursor()
self._cursor = self.await_(cursor.__aenter__())
- self._rows = []
+ self._rows = deque()
@property
def description(self):
# exhausting rows, which we already have done for sync cursor.
# another option would be to emulate aiosqlite dialect and assign
# cursor only if we are doing server side cursor operation.
- self._rows[:] = []
+ self._rows.clear()
def execute(self, operation, parameters=None):
return self.await_(self._execute_async(operation, parameters))
# of that here since our default result is not async.
# we could just as easily grab "_rows" here and be done with it
# but this is safer.
- self._rows = list(await self._cursor.fetchall())
+ self._rows = deque(await self._cursor.fetchall())
return result
async def _executemany_async(self, operation, seq_of_parameters):
def __iter__(self):
while self._rows:
- yield self._rows.pop(0)
+ yield self._rows.popleft()
def fetchone(self):
if self._rows:
- return self._rows.pop(0)
+ return self._rows.popleft()
else:
return None
if size is None:
size = self.arraysize
- retval = self._rows[0:size]
- self._rows[:] = self._rows[size:]
- return retval
+ rr = self._rows
+ return [rr.popleft() for _ in range(min(size, len(rr)))]
def fetchall(self):
- retval = self._rows[:]
- self._rows[:] = []
+ retval = list(self._rows)
+ self._rows.clear()
return retval
def __init__(self, adapt_connection):
self._adapt_connection = adapt_connection
self._connection = adapt_connection._connection
- self._rows = []
+ self._rows = deque()
self._cursor = None
self.description = None
self.arraysize = 1
self._invalidate_schema_cache_asof = 0
def close(self):
- self._rows[:] = []
+ self._rows.clear()
def _handle_exception(self, error):
self._adapt_connection._handle_exception(error)
self._cursor = await prepared_stmt.cursor(*parameters)
self.rowcount = -1
else:
- self._rows = await prepared_stmt.fetch(*parameters)
+ self._rows = deque(await prepared_stmt.fetch(*parameters))
status = prepared_stmt.get_statusmsg()
reg = re.match(
def __iter__(self):
while self._rows:
- yield self._rows.pop(0)
+ yield self._rows.popleft()
def fetchone(self):
if self._rows:
- return self._rows.pop(0)
+ return self._rows.popleft()
else:
return None
if size is None:
size = self.arraysize
- retval = self._rows[0:size]
- self._rows[:] = self._rows[size:]
- return retval
+ rr = self._rows
+ return [rr.popleft() for _ in range(min(size, len(rr)))]
def fetchall(self):
- retval = self._rows[:]
- self._rows[:] = []
+ retval = list(self._rows)
+ self._rows.clear()
return retval
""" # noqa
from __future__ import annotations
+from collections import deque
import logging
import re
from typing import cast
def __init__(self, cursor, await_) -> None:
self._cursor = cursor
self.await_ = await_
- self._rows = []
+ self._rows = deque()
def __getattr__(self, name):
return getattr(self._cursor, name)
# eq/ne
if res and res.status == self._psycopg_ExecStatus.TUPLES_OK:
rows = self.await_(self._cursor.fetchall())
- if not isinstance(rows, list):
- self._rows = list(rows)
- else:
- self._rows = rows
+ self._rows = deque(rows)
return result
def executemany(self, query, params_seq):
return self.await_(self._cursor.executemany(query, params_seq))
def __iter__(self):
- # TODO: try to avoid pop(0) on a list
while self._rows:
- yield self._rows.pop(0)
+ yield self._rows.popleft()
def fetchone(self):
if self._rows:
- # TODO: try to avoid pop(0) on a list
- return self._rows.pop(0)
+ return self._rows.popleft()
else:
return None
if size is None:
size = self._cursor.arraysize
- retval = self._rows[0:size]
- self._rows = self._rows[size:]
- return retval
+ rr = self._rows
+ return [rr.popleft() for _ in range(min(size, len(rr)))]
def fetchall(self):
- retval = self._rows
- self._rows = []
+ retval = list(self._rows)
+ self._rows.clear()
return retval
""" # noqa
import asyncio
+from collections import deque
from functools import partial
from .base import SQLiteExecutionContext
self.arraysize = 1
self.rowcount = -1
self.description = None
- self._rows = []
+ self._rows = deque()
def close(self):
- self._rows[:] = []
+ self._rows.clear()
def execute(self, operation, parameters=None):
try:
self.lastrowid = self.rowcount = -1
if not self.server_side:
- self._rows = self.await_(_cursor.fetchall())
+ self._rows = deque(self.await_(_cursor.fetchall()))
else:
self.description = None
self.lastrowid = _cursor.lastrowid
def __iter__(self):
while self._rows:
- yield self._rows.pop(0)
+ yield self._rows.popleft()
def fetchone(self):
if self._rows:
- return self._rows.pop(0)
+ return self._rows.popleft()
else:
return None
if size is None:
size = self.arraysize
- retval = self._rows[0:size]
- self._rows[:] = self._rows[size:]
- return retval
+ rr = self._rows
+ return [rr.popleft() for _ in range(min(size, len(rr)))]
def fetchall(self):
- retval = self._rows[:]
- self._rows[:] = []
+ retval = list(self._rows)
+ self._rows.clear()
return retval