Skip to content

Commit

Permalink
Add no cursor test
Browse files Browse the repository at this point in the history
  • Loading branch information
maver1ck committed Sep 30, 2024
1 parent 89b4f4c commit 251b960
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aiosql/adapters/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def insert_returning(self, conn, query_name, sql, parameters): # pragma: no cov
# https://github.com/duckdb/duckdb/issues/6008
res = cur.fetchall()
finally:
if not self._use_cursor:
if self._use_cursor:
cur.close()
if isinstance(res, list):
res = res[0]
Expand Down Expand Up @@ -73,7 +73,7 @@ def select(self, conn, query_name: str, sql: str, parameters, record_class=None)
# strict=False: requires 3.10
yield record_class(**dict(zip(column_names, row)))
finally:
if not self._use_cursor:
if self._use_cursor:
cur.close()

def select_one(self, conn, query_name, sql, parameters, record_class=None):
Expand All @@ -89,6 +89,6 @@ def select_one(self, conn, query_name, sql, parameters, record_class=None):
column_names = [c[0] for c in cur.description or []]
result = dict(zip(column_names, result))
finally:
if not self._use_cursor:
if self._use_cursor:
cur.close()
return result
5 changes: 5 additions & 0 deletions tests/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ def conn(duckdb_conn):
run_execute_script as test_execute_script,
run_modulo as test_modulo,
)

def test_no_cursor(conn):
adapter = aiosql.adapters.duckdb.DuckDBAdapter(use_cursor=False)
cursor = adapter._cursor(conn)
assert cursor == conn

0 comments on commit 251b960

Please sign in to comment.