BritishGeologicalSurvey / etlhelper

ETL Helper is a Python ETL library to simplify data transfer into and out of databases.
https://britishgeologicalsurvey.github.io/etlhelper/
GNU Lesser General Public License v3.0
105 stars 25 forks source link

Add fetch methods #29

Closed volcan01010 closed 4 years ago

volcan01010 commented 4 years ago

Summary

Adding fetchone provides a convenient way to get a single row tuple. Adding fetchmany and fetchall methods make the methods consistent with the DB API 2.0 cursor specifications.

Description

There is currently no easy way to return a single row, equivalent to cursor.fetchone using the etl methods. Instead, values need to be unpacked from a list, or calling next on iter_rows results. Adding a fetchone function would make this nicer. It would just use iter_rows and return the first value.

fetchmany could be modelled on the the cursor.fetchmany call signature and use itertools.slice to return the correct number of rows. Whether or not to use named arguments and default values should be investigated.

fetchall would be synonymous with get_rows.

These new functions would be defined in the etl module.

Acceptance criteria

metazool commented 4 years ago

I like this suggestion, been doing a lot of catching StopIteration when i really intended to fetchone()