def dict_gen(curs: sqlite3.Cursor): """ Generates a dictionary of a sqlite3.Cursor object by fetching the query's results. Taken from Python Essential Reference by David Beazley. """ field_names = [d[0] for d in curs.description] while True: rows = curs.fetchmany() if not rows: return for row in rows: yield dict(zip(field_names, row))
def _fetch_all(cursor: sqlite3.Cursor) -> t.Iterable[t.Tuple]: while True: rows = cursor.fetchmany() if not rows: break yield from rows
def yield_records(cursor: sqlite3.Cursor) -> T.Generator[Record, None, None]: cursor.execute("SELECT path, hash, modified FROM records") while chunk := cursor.fetchmany(): for record in chunk: yield Record(*record)