Skip to content

Commit

Permalink
raise error only when specified
Browse files Browse the repository at this point in the history
  • Loading branch information
SoumayaMauthoorMOJ committed Mar 29, 2023
1 parent 3ef3287 commit 184a37a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions dataengineeringutils3/db.py
Expand Up @@ -62,20 +62,25 @@ def __iter__(self):
for r in self.cursor:
yield r

def iter_chunks(self):
def iter_chunks(self, raise_error=False):
results = self.cursor.fetchmany(self.fetch_size)
while results:
yield results
try:
results = self.cursor.fetchmany(self.fetch_size)
except Exception as e:
raise e
if raise_error:
raise e
else:
results = None
break


@property
def headers(self):
"""Return column names"""
return [c[0] for c in self.cursor.description]

def write_to_file(self, file_writer, line_transform=lambda x: x):
for results in self.iter_chunks():
def write_to_file(self, file_writer, line_transform=lambda x: x, raise_error=False):
for results in self.iter_chunks(raise_error=raise_error):
file_writer.write_lines(results, line_transform)

0 comments on commit 184a37a

Please sign in to comment.