Skip to content

Commit

Permalink
Remove closing of connection
Browse files Browse the repository at this point in the history
  • Loading branch information
maver1ck authored Sep 25, 2024
1 parent e5703a7 commit 45bd9f5
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions aiosql/adapters/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,36 @@ def insert_returning(self, conn, query_name, sql, parameters): # pragma: no cov
def select(self, conn, query_name: str, sql: str, parameters, record_class=None):
column_names: List[str] = []
cur = self._cursor(conn)
try:
cur.execute(sql, parameters)
if record_class is None:
first = True
for row in cur.fetchall():
if first: # get column names on the fly
column_names = [c[0] for c in cur.description or []]
first = False
if self._convert_row_to_dict: # pragma: no cover
# strict=False: requires 3.10
yield dict(zip(column_names, row))
else:
yield row
else: # pragma: no cover
first = True
for row in cur.fetchall():
if first: # only get description on the fly, for apsw
column_names = [c[0] for c in cur.description or []]
first = False
cur.execute(sql, parameters)
if record_class is None:
first = True
for row in cur.fetchall():
if first: # get column names on the fly
column_names = [c[0] for c in cur.description or []]
first = False
if self._convert_row_to_dict: # pragma: no cover
# strict=False: requires 3.10
yield record_class(**dict(zip(column_names, row)))
finally:
cur.close()
yield dict(zip(column_names, row))
else:
yield row
else: # pragma: no cover
first = True
for row in cur.fetchall():
if first: # only get description on the fly, for apsw
column_names = [c[0] for c in cur.description or []]
first = False
# strict=False: requires 3.10
yield record_class(**dict(zip(column_names, row)))

def select_one(self, conn, query_name, sql, parameters, record_class=None):
cur = self._cursor(conn)
try:
cur.execute(sql, parameters)
result = cur.fetchone()
if result is not None and record_class is not None: # pragma: no cover
column_names = [c[0] for c in cur.description or []]
# strict=False: requires 3.10
result = record_class(**dict(zip(column_names, result)))
elif result is not None and self._convert_row_to_dict: # pragma: no cover
column_names = [c[0] for c in cur.description or []]
result = dict(zip(column_names, result))
finally:
cur.close()
cur.execute(sql, parameters)
result = cur.fetchone()
if result is not None and record_class is not None: # pragma: no cover
column_names = [c[0] for c in cur.description or []]
# strict=False: requires 3.10
result = record_class(**dict(zip(column_names, result)))
elif result is not None and self._convert_row_to_dict: # pragma: no cover
column_names = [c[0] for c in cur.description or []]
result = dict(zip(column_names, result))
return result

0 comments on commit 45bd9f5

Please sign in to comment.