db.py 394 B

12345678910111213
  1. from django.db import connections
  2. def fetch_assoc(query, *args):
  3. """return all rows from a cursor as a dict"""
  4. with connections['misago05'].cursor() as cursor:
  5. cursor.execute(query, *args)
  6. columns = [col[0] for col in cursor.description]
  7. row = cursor.fetchone()
  8. while row:
  9. yield dict(zip(columns, row))
  10. row = cursor.fetchone()