Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Support for PostGIS backend optionally #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ If you're using `south <http://south.aeracode.org>`_:
'default': 'south.db.postgresql_psycopg2'
}

If you use PostGIS (django.contrib.gis.db.backends.postgis):

::

DATABASE_POOL_POSTGIS = True


Everything should work as expected.

Expand Down Expand Up @@ -70,4 +76,4 @@ Check out the official `SQLAlchemy Connection Pooling <http://docs.sqlalchemy.or
Django 1.3 Support
------------------

django-postgrespool currently supports Django 1.4 and greater. See `this ticket <https://github.com/kennethreitz/django-postgrespool/pull/9>`_ for 1.3 support.
django-postgrespool currently supports Django 1.4 and greater. See `this ticket <https://github.com/kennethreitz/django-postgrespool/pull/9>`_ for 1.3 support.
19 changes: 13 additions & 6 deletions django_postgrespool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
from psycopg2 import InterfaceError, ProgrammingError, OperationalError

from django.conf import settings
from django.db.backends.postgresql_psycopg2.base import *
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper as Psycopg2DatabaseWrapper
from django.db.backends.postgresql_psycopg2.base import CursorWrapper as DjangoCursorWrapper
from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation as Psycopg2DatabaseCreation

if getattr(settings, 'DATABASE_POOL_POSTGIS', False):
from django.contrib.gis.db.backends.postgis.base import *
from django.contrib.gis.db.backends.postgis.base import DatabaseWrapper as BaseDatabaseWrapper
from django.contrib.gis.db.backends.postgis.base import CursorWrapper as DjangoCursorWrapper
from django.contrib.gis.db.backends.postgis.creation import DatabaseCreation as BaseDatabaseCreation
else:
from django.db.backends.postgresql_psycopg2.base import *
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper as BaseDatabaseWrapper
from django.db.backends.postgresql_psycopg2.base import CursorWrapper as DjangoCursorWrapper
from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation as BaseDatabaseCreation

POOL_SETTINGS = 'DATABASE_POOL_ARGS'

Expand Down Expand Up @@ -93,14 +100,14 @@ def executemany(self, query, args):
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]


class DatabaseCreation(Psycopg2DatabaseCreation):
class DatabaseCreation(BaseDatabaseCreation):
def destroy_test_db(self, *args, **kw):
"""Ensure connection pool is disposed before trying to drop database."""
self.connection._dispose()
super(DatabaseCreation, self).destroy_test_db(*args, **kw)


class DatabaseWrapper(Psycopg2DatabaseWrapper):
class DatabaseWrapper(BaseDatabaseWrapper):
"""SQLAlchemy FTW."""

def __init__(self, *args, **kwargs):
Expand Down