1
1
from collections import namedtuple
2
+ import urllib
2
3
3
- from sqlalchemy .sql import Select
4
-
5
- from grice .errors import ConfigurationError , NotFoundError , JoinError
6
4
from sqlalchemy import create_engine , MetaData , Column , Table , select , not_ , or_ , asc , desc , and_
7
5
from sqlalchemy import engine
6
+ from sqlalchemy .sql import Select
8
7
from sqlalchemy .engine import reflection
9
8
9
+ from grice .errors import ConfigurationError , NotFoundError , JoinError
10
+
11
+
10
12
DEFAULT_PAGE = 0
11
13
DEFAULT_PER_PAGE = 50
12
14
LIST_FILTERS = ['in' , 'not_in' , 'bt' , 'nbt' ]
@@ -24,6 +26,7 @@ def init_database(db_config):
24
26
:param db_config:
25
27
:return: SqlAlchemy engine object.
26
28
"""
29
+ driver = db_config .get ('driver' , 'postgresql' )
27
30
try :
28
31
db_args = {
29
32
'username' : db_config ['username' ],
@@ -32,11 +35,13 @@ def init_database(db_config):
32
35
'port' : db_config ['port' ],
33
36
'database' : db_config ['database' ]
34
37
}
38
+ if 'query' in db_config :
39
+ db_args ['query' ] = dict (urllib .parse .parse_qsl (db_config ['query' ], keep_blank_values = True ))
35
40
except KeyError :
36
41
msg = '"username", "password", "host", "port", and "database" are required fields of database config'
37
42
raise ConfigurationError (msg )
38
43
39
- eng_url = engine .url .URL (db_config . get ( 'engine' , 'postgresql' ) , ** db_args )
44
+ eng_url = engine .url .URL (driver , ** db_args )
40
45
41
46
return create_engine (eng_url )
42
47
0 commit comments