Browse Source

Fixed connection strings for mysql

Roland Haroutiounian 9 years ago
parent
commit
9f47b7848f
2 changed files with 10 additions and 10 deletions
  1. 9
    8
      leobject/datasources/ledatasourcesql.py
  2. 1
    2
      leobject/test/test_ledatasourcesql.py

+ 9
- 8
leobject/datasources/ledatasourcesql.py View File

@@ -1,10 +1,13 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-import sqlite3
3
+
4
+import pymysql
4 5
 from leobject.datasources.dummy import DummyDatasource
5 6
 from mosql.db import Database, all_to_dicts
6 7
 from mosql.query import select, insert, update, delete, join
7 8
 from leobject.leobject import REL_SUB, REL_SUP
9
+import mosql.mysql
10
+
8 11
 
9 12
 ## SQL DataSource for LeObject
10 13
 class LeDataSourceSQL(DummyDatasource):
@@ -13,12 +16,10 @@ class LeDataSourceSQL(DummyDatasource):
13 16
     RELATIONS_POSITIONS_FIELDS = {REL_SUP: 'superior_id', REL_SUB: 'subordinate_id'}
14 17
     RELATIONS_NATURE_FIELD = 'nature'
15 18
 
16
-    MODULE = sqlite3
17
-
18
-    def __init__(self, module=None, *conn_args, **conn_kargs):
19
+    def __init__(self, module=pymysql, conn_args={'host': '127.0.0.1', 'user':'lodel', 'passwd':'bruno', 'db': 'lodel2'}):
19 20
         super(LeDataSourceSQL, self).__init__()
20
-        self.module = self.MODULE if module is None else module
21
-        self.connection = Database(self.module, *conn_args, **conn_kargs)
21
+        self.module = module
22
+        self.connection = Database(pymysql, host=conn_args['host'], user=conn_args['user'], passwd=conn_args['passwd'], db=conn_args['db'])
22 23
 
23 24
     ## @brief update an existing object's data
24 25
     # @param letype LeType
@@ -78,7 +79,7 @@ class LeDataSourceSQL(DummyDatasource):
78 79
     # @return list
79 80
     def get(self, leclass, letype, field_list, filters, relational_filters=None):
80 81
 
81
-        query_table_name = 'LodelTestInstance_document' if isinstance(leclass, str) else leclass.name
82
+        query_table_name = leclass.name
82 83
         where_filters = self._prepare_filters(filters)
83 84
         join_fields = {}
84 85
 
@@ -107,7 +108,7 @@ class LeDataSourceSQL(DummyDatasource):
107 108
             query = select(query_table_name, where=where_filters, select=field_list)
108 109
 
109 110
         # Executing the query
110
-        with self.db as cur:
111
+        with self.connection as cur:
111 112
             results = all_to_dicts(cur.execute(query))
112 113
 
113 114
         # Returning it as a list of dict

+ 1
- 2
leobject/test/test_ledatasourcesql.py View File

@@ -11,7 +11,7 @@ from mosql.db import Database
11 11
 class _LeDataSourceTestCase(TestCase):
12 12
 
13 13
     def setUp(self):
14
-        self.mydatasource = LeDataSourceSQL(pymysql, *{'host':'localhost','user':'lodel','passwd':'bruno'})
14
+        self.mydatasource = LeDataSourceSQL()
15 15
 
16 16
     def tearDown(self):
17 17
         del self.mydatasource
@@ -26,7 +26,6 @@ class _LeDataSourceTestCase(TestCase):
26 26
         pass
27 27
 
28 28
     def test_get(self):
29
-
30 29
         pass
31 30
 
32 31
     def test_update(self):

Loading…
Cancel
Save