示例#1
0
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))
示例#2
0
def _fetch_all(cursor: sqlite3.Cursor) -> t.Iterable[t.Tuple]:
    while True:
        rows = cursor.fetchmany()
        if not rows:
            break
        yield from rows
示例#3
0
文件: database.py 项目: cryzed/Bitrat
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)