UNKNOWN
Project description
Copyright (c) 2014, Friedrich Paetzke (f.paetzke@gmail.com) All rights reserved.
Django-db-call creates a database configuration for a django project from command line input.
It comes with two functions:
from_call()
from_calls()
You can install django-db-call via pip.
$ pip install django-db-call
An usage example:
from django_db_call import from_call
DATABASES = from_call('mysql -h localhost -u root -p my_sweet_secret -D my_db')
That will become:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'PORT': '',
'PASSWORD': 'my_sweet_secret',
'HOST': 'localhost',
'NAME': 'my_db',
'USER': 'root'
}
}
You can change the connection name by passing a name for it:
DATABASES = from_call('mysql', connection='not_default')
And that is equivalent to:
DATABASES = {
'not_default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '',
'NAME': '',
'PASSWORD': '',
'PORT': '',
'USER': ''
}
}
You can also pass additional arguments to be used in OPTIONS.
DATABASES = from_call('mysql', autocommit=True)
And that will give you:
{
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
'OPTIONS': {
'autocommit': True,
},
}
}
For creating multiple databases connections you can use from_calls().
from django_db_call import from_calls
DATABASES = from_calls(
[
['mysql -h localhost -u root -p my_sweet_secret -D my_db'],
['mysql -h localhost -u root -p my_sweet_secret -D archive',
{'connection': 'archive'}],
])
And that will result in:
DATABASES = {
'default': {
'PASSWORD': 'my_sweet_secret',
'ENGINE': 'django.db.backends.mysql',
'PORT': '',
'USER': 'root',
'HOST': 'localhost',
'NAME': 'my_db'
},
'archive': {
'PASSWORD': 'my_sweet_secret',
'ENGINE': 'django.db.backends.mysql',
'PORT': '',
'USER': 'root',
'HOST': 'localhost',
'NAME': 'archive'
}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-db-call-0.0.1.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for django_db_call-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 330e357d6450b3dd555ecea1071e236a060c397a453b4bc961f0ae9b7d8da1eb |
|
MD5 | 1aab6eb72a7d3d7c1b9a953bf20d0a03 |
|
BLAKE2b-256 | 40c24fe004a333d4ae05de3dcea5598c6b5d0d3dc11ff55dbc838a499779616b |