mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-04-29 03:04:43 +00:00
commit
19e8bd30b9
2 changed files with 31 additions and 1 deletions
|
|
@ -45,6 +45,17 @@ def config(env=DEFAULT_ENV, default=None):
|
|||
def parse(url):
|
||||
"""Parses a database URL."""
|
||||
|
||||
if url == 'sqlite://:memory:':
|
||||
# this is a special case, because if we pass this URL into
|
||||
# urlparse, urlparse will choke trying to interpret "memory"
|
||||
# as a port number
|
||||
return {
|
||||
'ENGINE': SCHEMES['sqlite'],
|
||||
'NAME': ':memory:'
|
||||
}
|
||||
# note: no other settings are required for sqlite
|
||||
|
||||
# otherwise parse the url as normal
|
||||
config = {}
|
||||
|
||||
url = urlparse.urlparse(url)
|
||||
|
|
@ -53,6 +64,11 @@ def parse(url):
|
|||
path = url.path[1:]
|
||||
path = path.split('?', 2)[0]
|
||||
|
||||
# if we are using sqlite and we have no path, then assume we
|
||||
# want an in-memory database (this is the behaviour of sqlalchemy)
|
||||
if url.scheme == 'sqlite' and path == '':
|
||||
path = ':memory:'
|
||||
|
||||
# Update with environment configuration.
|
||||
config.update({
|
||||
'NAME': path,
|
||||
|
|
|
|||
|
|
@ -63,8 +63,22 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
assert url['PASSWORD'] == 'wegauwhgeuioweg'
|
||||
assert url['PORT'] == 5431
|
||||
|
||||
def test_empty_sqlite_url(self):
|
||||
url = 'sqlite://'
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url['ENGINE'] == 'django.db.backends.sqlite3'
|
||||
assert url['NAME'] == ':memory:'
|
||||
|
||||
def test_memory_sqlite_url(self):
|
||||
url = 'sqlite://:memory:'
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url['ENGINE'] == 'django.db.backends.sqlite3'
|
||||
assert url['NAME'] == ':memory:'
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue