Skip to content

Instantly share code, notes, and snippets.

@dcramer
Created August 8, 2012 20:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcramer/3298424 to your computer and use it in GitHub Desktop.
Save dcramer/3298424 to your computer and use it in GitHub Desktop.
Server side cursors in Django
#1: Connection method
with connections['default'].sscursor():
Foo.objects.all()
^^ this sucks because we make assumptions about where Foo routes
#2: QuerySet method
Foo.objects.all().sscursor()
^^ kind of sucks as it extends QuerySet with a dumb method name
#3: Generic Wrapper (ala crappy transaction management, but better)
with SSCursor():
Foo.objects.all()
^^ Kind of painful to implement, especially with thread-safety since it has to manage
all connections
#4: Another QuerySet method
Foo.objects.all().options(server_side_cursor=True)
So far #2 is winning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment