Skip to content

change db pattern #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions bonobo_sqlalchemy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@

logger = get_logger()

POSTGRES_DEFAULTS = {
# mysql default config
# DATABASE_CONFIG_DEFAULTS = {
# 'driver': 'mysql',
# 'host': 'localhost',
# 'port': '3306',
# 'name': 'mysql',
# 'user': 'root',
# 'pass': '',
# }

DATABASE_CONFIG_DEFAULTS = {
'driver': 'postgres',
'host': 'localhost',
'port': '5432',
Expand All @@ -19,8 +29,8 @@
DSN_TEMPLATE = '{driver}://{user}:{pass}@{host}:{port}/{name}'


def create_postgresql_engine(*, options='client_encoding=utf8', env='POSTGRES', **kwargs):
config = defaultdict(**POSTGRES_DEFAULTS)
def create_postgresql_engine(*, env='POSTGRES', **kwargs):
config = defaultdict(**DATABASE_CONFIG_DEFAULTS)
for var in ('driver', 'user', 'pass', 'host', 'port', 'name'):
if var in kwargs:
config[var] = kwargs.pop(var)
Expand All @@ -29,8 +39,8 @@ def create_postgresql_engine(*, options='client_encoding=utf8', env='POSTGRES',
if env_var in environ:
config[var] = environ[env_var]
dsn = DSN_TEMPLATE.format(**config)
if options:
dsn += '?' + options
if DATABASE_CONFIG_DEFAULTS['driver'].upper() == 'POSTGRES': # or env == 'POSTGRES'
dsn += '?client_encoding=utf8'

logger.info('Creating database engine: ' + dsn)

Expand Down