db.py 404 B

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