niwibe/djorm-ext-core — pull request #6 by scibi (2013-12-12 03:06:10+00:00)
Title: Add ability enable/disable server side cursor or run it only once

This change adds ability to enable disable server side cursor at any
time like this:

from djorm_core.postgresql import server_side_cursors

with server_side_cursors() as c:
for item in Model1.objects.iterator():
print item.value

c.enabled = False

for item in Model2.objects.iterator():
print item.value

c.enabled = True

for item in Model3.objects.iterator():
print item.value

It also adds ability to use it only once which is useful if you run some
queries inside a loop:

from djorm_core.postgresql import server_side_cursors

with server_side_cursors(once=True):
for item in Model1.objects.iterator():
print item.value
if item.value == 'good':
m = Model2(x=item.value)
m.save()

It also adds ability to set withhold attribute of the psycopg2 cursor
which allows you to use single cursor across transactions.