Browse Source

[#61] Added the prepare_filters method

Roland Haroutiounian 9 years ago
parent
commit
89b13c5d91
2 changed files with 25 additions and 6 deletions
  1. 4
    3
      leobject/datasources/ledatasource.py
  2. 21
    3
      leobject/datasources/ledatasourcesql.py

+ 4
- 3
leobject/datasources/ledatasource.py View File

@@ -4,9 +4,10 @@
4 4
 
5 5
 class LeDataSource(object):
6 6
 
7
-    def __init__(self, options=None):
8
-        self.options = options
9
-
7
+    def __init__(self, module=None, *conn_args, **conn_kargs):
8
+        self.module = module
9
+        self.conn_args = conn_args
10
+        self.conn_kargs = conn_kargs
10 11
 
11 12
     ## @brief update an existing LeObject
12 13
     # @param lodel_id (int) : list of lodel_id

+ 21
- 3
leobject/datasources/ledatasourcesql.py View File

@@ -2,15 +2,16 @@
2 2
 
3 3
 from ledatasource import LeDataSource
4 4
 from mosql.db import Database
5
+from mosql.query import select
6
+
5 7
 from Lodel.utils.mosql import *
6 8
 
7 9
 ## SQL DataSource for LeObject
8 10
 class LeDataSourceSQL(LeDataSource):
9 11
 
10
-    def __init__(self, options=None):
12
+    def __init__(self, module=None, *conn_args, **conn_kargs):
11 13
         super(LeDataSourceSQL, self).__init__()
12
-            
13
-        self.options = options
14
+        self.db = Database(self.module, self.conn_args, self.conn_kargs)
14 15
 
15 16
     ## @brief search for a collection of objects
16 17
     # @param emclass
@@ -18,4 +19,21 @@ class LeDataSourceSQL(LeDataSource):
18 19
     # @param filters list : list of tuples formatted as (FIELD, OPERATOR, VALUE)
19 20
     # @param relational_filters
20 21
     def get(self, emclass, emtype, field_list, filters, relational_filters):
22
+
23
+        class_name = emclass.name
24
+        type_name = emtype.name
25
+
26
+        tablename = ""
27
+        where_filters = self._prepare_filters(filters)
28
+        query = select(tablename, where=where_filters, select=field_list)
29
+        self.db.execute(query)
21 30
         pass
31
+
32
+    def _prepare_filters(self, filters):
33
+        prepared_filters = {}
34
+        for filter in filters:
35
+            prepared_filter_key = (filter[0], filter[1])
36
+            prepared_filter_value = filter[2]
37
+            prepared_filters[prepared_filter_key] = prepared_filter_value
38
+
39
+        return prepared_filters

Loading…
Cancel
Save