|
@@ -32,40 +32,20 @@ sqlcfg = settings.LODEL2SQLWRAPPER
|
32
|
32
|
# @param sqlaloggin None|bool: If None leave default value, if true activate sqlalchemy logging
|
33
|
33
|
# @return SqlAlchemy engine
|
34
|
34
|
def get_engine(ename='default',sqlalogging=None):
|
35
|
|
- return getEngine(ename=ename, sqlalogging=sqlalogging)
|
36
|
|
-
|
37
|
|
-
|
38
|
|
-
|
39
|
|
-def db_engine(cls):
|
40
|
|
- return sqlutils.getEngine(cls.dbconf)
|
41
|
|
-## Return an engine given a dbconf name
|
42
|
|
-# @param ename str: Its a name of an item in django.conf.settings.LODEL2SQLWRAPPER['db']
|
43
|
|
-# @param sqlalogging None|bool : If None leave default value, if true activate sqlalchemy logging
|
44
|
|
-# @return An sqlalchemy engine
|
45
|
|
-def getEngine(ename = 'default', sqlalogging = None):
|
46
|
|
- """ Return a sqlalchemy engine
|
47
|
|
- @param read bool: If True return the read engine, else
|
48
|
|
- return the write one
|
49
|
|
- @return a sqlachemy engine instance
|
50
|
|
-
|
51
|
|
- @todo Put the check on db config in SqlWrapper.checkConf()
|
52
|
|
- """
|
53
|
|
- #Loading confs
|
|
35
|
+ # Loading confs
|
54
|
36
|
cfg = sqlcfg['db'][ename]
|
55
|
37
|
|
56
|
|
- edata = ENGINES[cfg['ENGINE']] #engine infos
|
|
38
|
+ edata = ENGINES[cfg['ENGINE']] # engine infos
|
57
|
39
|
conn_str = ""
|
58
|
40
|
|
59
|
|
- if cfg['ENGINE'] == 'sqlite':
|
60
|
|
- #Sqlite connection string
|
61
|
|
- conn_str = '%s+%s:///%s'%( cfg['ENGINE'],
|
62
|
|
- edata['driver'],
|
63
|
|
- cfg['NAME'])
|
|
41
|
+ if cfg['ENGINE'] =='sqlite':
|
|
42
|
+ #SQLite connection string
|
|
43
|
+ conn_str = '%s+%s:///%s' % (cfg['ENGINE'], edata['driver'], cfg['NAME'])
|
64
|
44
|
else:
|
65
|
|
- #Mysql and Postgres connection string
|
|
45
|
+ #MySQL and PostgreSQL connection string
|
66
|
46
|
user = cfg['USER']
|
67
|
47
|
user += (':'+cfg['PASSWORD'] if 'PASSWORD' in cfg else '')
|
68
|
|
-
|
|
48
|
+
|
69
|
49
|
if 'HOST' not in cfg:
|
70
|
50
|
logger.info('Not HOST in configuration, using localhost')
|
71
|
51
|
host = 'localhost'
|
|
@@ -73,17 +53,18 @@ def getEngine(ename = 'default', sqlalogging = None):
|
73
|
53
|
host = cfg['HOST']
|
74
|
54
|
|
75
|
55
|
host += (':'+cfg['PORT'] if 'PORT' in cfg else '')
|
76
|
|
-
|
77
|
|
- conn_str = '%s+%s://'%(cfg['ENGINE'], edata['driver'])
|
78
|
|
- conn_str += '%s@%s/%s'%(user,host,cfg['NAME'])
|
79
|
|
-
|
|
56
|
+ conn_str = '%s+%s://' % (cfg['ENGINE'], edata['driver'])
|
|
57
|
+ conn_str += '%s@%s/%s' % (user, host, cfg['NAME'])
|
80
|
58
|
|
81
|
59
|
ret = sqla.create_engine(conn_str, encoding=edata['encoding'], echo=sqlalogging)
|
82
|
|
-
|
83
|
60
|
logger.debug("Getting engine :"+str(ret))
|
84
|
61
|
|
85
|
62
|
return ret
|
86
|
63
|
|
|
64
|
+
|
|
65
|
+def getEngine(ename='default', sqlalogging=None):
|
|
66
|
+ return get_engine(ename=ename, sqlalogging=sqlalogging)
|
|
67
|
+
|
87
|
68
|
## Return a sqlalchemy.MetaData object
|
88
|
69
|
# @param engine sqlalchemy.engine : A sqlalchemy engine
|
89
|
70
|
# @return an sql alechemy MetaData instance bind to engine
|