aboutsummaryrefslogtreecommitdiff
path: root/dodai/config/db/sa.py
diff options
context:
space:
mode:
Diffstat (limited to 'dodai/config/db/sa.py')
-rw-r--r--dodai/config/db/sa.py67
1 files changed, 0 insertions, 67 deletions
diff --git a/dodai/config/db/sa.py b/dodai/config/db/sa.py
deleted file mode 100644
index 7654b44..0000000
--- a/dodai/config/db/sa.py
+++ /dev/null
@@ -1,67 +0,0 @@
1# Copyright (C) 2010 Leonard Thomas
2#
3# This file is part of Dodai.
4#
5# Dodai is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# Dodai is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
17
18from dodai.config.db import BaseConfigDb
19from dodai.db import Db
20
21class Sa(BaseConfigDb):
22
23
24 def load(self, obj):
25 from sqlalchemy.orm import sessionmaker
26 self._clean(obj)
27 db = Db()
28 db.engine = self._build_engine(obj)
29 Session = sessionmaker(bind=db.engine)
30 db.session = Session()
31 db.name = obj.name
32 db.protocol = obj.protocol
33 if hasattr(obj, 'schema'):
34 if obj.schema:
35 db.schema = obj.schema
36 if hasattr(obj, 'filename') and obj.filename:
37 db.filename = obj.filename
38 else:
39 db.hostname = obj.hostname
40 if hasattr(obj, 'port') and obj.port:
41 db.port = obj.port
42 db.database = obj.database
43 return db
44
45 def _build_connection_string(self, obj):
46 out = []
47 out.append('{db.protocol}')
48 if hasattr(obj, 'protocol_extra') and obj.protocol_extra:
49 out.append('+{db.protocol_extra}')
50 out.append('://')
51 if hasattr(obj, 'filename') and obj.filename:
52 out.append('{db.filename}')
53 else:
54 out.append('{db.username}:{db.password}@')
55 out.append('{db.hostname}')
56 if hasattr(obj, 'port') and obj.port:
57 out.append(':{db.port}')
58 out.append('/{db.database}')
59 out = ''.join(out)
60 out = out.format(db=obj)
61 return out
62
63 def _build_engine(self, obj):
64 from sqlalchemy import create_engine
65 connection_string = self._build_connection_string(obj)
66 db_obj = create_engine(connection_string)
67 return db_obj