mirror of
https://github.com/simon987/hexlib.git
synced 2025-12-17 16:49:04 +00:00
add pgsql cursor util & silent stdout
This commit is contained in:
17
hexlib/db.py
17
hexlib/db.py
@@ -129,3 +129,20 @@ def _deserialize(value, col_type):
|
||||
if col_type == "blob":
|
||||
return base64.b64decode(value)
|
||||
return value
|
||||
|
||||
|
||||
def pg_fetch_cursor_all(cur, name, batch_size=1000):
|
||||
|
||||
while True:
|
||||
cur.execute("FETCH FORWARD %s FROM %s", (batch_size, name))
|
||||
cnt = 0
|
||||
|
||||
for row in cur:
|
||||
cnt += 1
|
||||
yield row
|
||||
|
||||
if cnt != batch_size:
|
||||
cur.execute("FETCH ALL FROM %s", (batch_size, name))
|
||||
for row in cur:
|
||||
yield row
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user