Skip to content

Commit 9bed0fb

Browse files
pydannyjph00
andcommitted
Conciseness improvements
Co-Authored-By: Jeremy Howard <[email protected]>
1 parent 8d80d59 commit 9bed0fb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

apswutils/db.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def query(
415415
"""
416416
cursor = self.execute(sql, tuple(params or tuple()))
417417
cursor.row_trace = cursor_row2dict
418-
for row in cursor: yield row
418+
yield from cursor
419419

420420
def execute(
421421
self, sql: str, parameters: Optional[Union[Iterable, dict]] = None
@@ -1294,7 +1294,7 @@ def rows_where(
12941294
sql += f" offset {offset}"
12951295
cursor = self.db.execute(sql, where_args or [])
12961296
cursor.row_trace = cursor_row2dict
1297-
for row in cursor: yield row
1297+
yield from cursor
12981298

12991299
def pks_and_rows_where(
13001300
self,
@@ -2666,7 +2666,7 @@ def search(
26662666
args,
26672667
)
26682668
cursor.row_trace = cursor_row2dict
2669-
for row in cursor: yield row
2669+
yield from cursor
26702670

26712671
def value_or_default(self, key, value):
26722672
return self._defaults[key] if value is DEFAULT else value
@@ -2758,7 +2758,7 @@ def update(
27582758
try:
27592759
cursor = self.db.execute(sql, args)
27602760
cursor.row_trace = cursor_row2dict
2761-
self.result = [x for x in cursor]
2761+
self.result = list(cursor)
27622762
except apsw.SQLError as e:
27632763
if alter and (" column" in e.args[0]):
27642764
# Attempt to add any missing columns, then try again
@@ -2921,14 +2921,14 @@ def insert_chunk(
29212921
try:
29222922
cursor = self.db.execute(query, tuple(params))
29232923
cursor.row_trace = cursor_row2dict
2924-
for row in cursor: records.append(row)
2924+
records += list(cursor)
29252925
except apsw.SQLError as e:
29262926
if alter and (" column" in e.args[0]):
29272927
# Attempt to add any missing columns, then try again
29282928
self.add_missing_columns(chunk)
29292929
cursor = self.db.execute(query, params)
29302930
cursor.row_trace = cursor_row2dict
2931-
for row in cursor: records.append(row)
2931+
records += list(cursor)
29322932
elif e.args[0] == "too many SQL variables":
29332933
first_half = chunk[: len(chunk) // 2]
29342934
second_half = chunk[len(chunk) // 2 :]

0 commit comments

Comments
 (0)