Add MySQL (GIS) support

Add mysqlgis url scheme which uses django.contrib.gis.db.backends.mysql,
add a test, and update the README.
This commit is contained in:
Michael Warkentin 2013-09-26 10:39:16 -04:00
parent 958717e05d
commit 5abe35049f
3 changed files with 17 additions and 4 deletions

View file

@ -12,10 +12,10 @@ This simple Django utility allows you to utilize the
Usage
-----
Configure your database in ``settings.py`` from ``DATABASE_URL``
Configure your database in ``settings.py`` from ``DATABASE_URL``
(``default`` is optional)::
DATABASES = {'default': dj_database_url.config(default='postgres://...')}
DATABASES = {'default': dj_database_url.config(default='postgres://...')}
Parse an arbitrary Database URL::
@ -24,7 +24,7 @@ Parse an arbitrary Database URL::
Supported databases
-------------------
Support currently exists for PostgreSQL, PostGIS, MySQL and SQLite.
Support currently exists for PostgreSQL, PostGIS, MySQL, MySQL (GIS) and SQLite.
SQLite connects to file based databases. The same URL format is used, omitting
the hostname, and using the "file" portion as the filename of the database.

View file

@ -16,6 +16,7 @@ urlparse.uses_netloc.append('pgsql')
urlparse.uses_netloc.append('postgis')
urlparse.uses_netloc.append('mysql')
urlparse.uses_netloc.append('mysql2')
urlparse.uses_netloc.append('mysqlgis')
urlparse.uses_netloc.append('spatialite')
urlparse.uses_netloc.append('sqlite')
@ -28,8 +29,9 @@ SCHEMES = {
'postgis': 'django.contrib.gis.db.backends.postgis',
'mysql': 'django.db.backends.mysql',
'mysql2': 'django.db.backends.mysql',
'mysqlgis': 'django.contrib.gis.db.backends.mysql',
'spatialite': 'django.contrib.gis.db.backends.spatialite',
'sqlite': 'django.db.backends.sqlite3'
'sqlite': 'django.db.backends.sqlite3',
}

View file

@ -34,6 +34,17 @@ class DatabaseTestSuite(unittest.TestCase):
assert url['PASSWORD'] == 'wegauwhgeuioweg'
assert url['PORT'] == 5431
def test_mysql_gis_parsing(self):
url = 'mysqlgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
url = dj_database_url.parse(url)
assert url['ENGINE'] == 'django.contrib.gis.db.backends.mysql'
assert url['NAME'] == 'd8r82722r2kuvn'
assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com'
assert url['USER'] == 'uf07k1i6d8ia0v'
assert url['PASSWORD'] == 'wegauwhgeuioweg'
assert url['PORT'] == 5431
def test_cleardb_parsing(self):
url = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true'
url = dj_database_url.parse(url)