Browse Source

Ajout d'un GenericDataSource avec les signatures des méthodes de base

Roland Haroutiounian 8 years ago
parent
commit
60f88dcf0c

+ 1
- 0
lodel/datasource/generic/__init__.py View File

@@ -0,0 +1 @@
1
+# -*- coding: utf-8 -*-

+ 51
- 0
lodel/datasource/generic/datasource.py View File

@@ -0,0 +1,51 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+class GenericDataSource(object):
4
+
5
+    def __init__(self, *conn_args, **conn_kwargs):
6
+        self.conn_args = conn_args
7
+        self.conn_kwargs = conn_kwargs
8
+
9
+    ## @brief returns a selection of documents from the datasource
10
+    # @param target_cls Emclass
11
+    # @param field_list list
12
+    # @param filters list : List of filters
13
+    # @param rel_filters list : List of relational filters
14
+    # @param order list : List of column to order. ex: order = [('title', 'ASC'),]
15
+    # @param group list : List of tupple representing the column to group together. ex: group = [('title', 'ASC'),]
16
+    # @param limit int : Number of records to be returned
17
+    # @param offset int: used with limit to choose the start record
18
+    # @param instanciate bool : If true, the records are returned as instances, else they are returned as dict
19
+    # @return list
20
+    def select(self, target_cls, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0,
21
+               instanciate=True):
22
+        pass
23
+
24
+    ## @brief Deletes one record defined by its uid
25
+    # @param target_cls Emclass : class of the record to delete
26
+    # @param uid dict|list : a dictionary of fields and values composing the unique identifier of the record or a list of several dictionaries
27
+    # @return int : number of deleted records
28
+    def delete(self, target_cls, uid):
29
+        pass
30
+
31
+    ## @brief updates one or a list of records
32
+    # @param target_cls Emclass : class of the object to insert
33
+    # @param uids list : list of uids to update
34
+    # @param datas dict : datas to update (new values)
35
+    # @return int : Number of updated records
36
+    def update(self, target_cls, uids, **datas):
37
+        pass
38
+
39
+    ## @brief Inserts a record in a given collection
40
+    # @param target_cls Emclass : class of the object to insert
41
+    # @param datas dict : datas to insert
42
+    # @return bool
43
+    def insert(self, target_cls, **datas):
44
+        pass
45
+
46
+    ## @brief Inserts a list of records in a given collection
47
+    # @param target_cls Emclass : class of the objects inserted
48
+    # @param datas_list
49
+    # @return list : list of the inserted records' ids
50
+    def insert_multi(self, target_cls, datas_list):
51
+        pass

+ 3
- 1
lodel/datasource/mongodb/datasource.py View File

@@ -6,12 +6,14 @@ import urllib
6 6
 
7 7
 import lodel.datasource.mongodb.utils as utils
8 8
 
9
+from lodel.datasource.generic.datasource import GenericDataSource
10
+
9 11
 
10 12
 class MongoDbDataSourceError(Exception):
11 13
     pass
12 14
 
13 15
 
14
-class MongoDbDataSource(object):
16
+class MongoDbDataSource(GenericDataSource):
15 17
 
16 18
     MANDATORY_CONNECTION_ARGS = ('host', 'port', 'login', 'password', 'dbname')
17 19
 

+ 0
- 2
lodel/datasource/mongodb/utils.py View File

@@ -16,8 +16,6 @@ LODEL_OPERATORS_MAP = {
16 16
     '>': {'name': '$gt', 'value_type': None},
17 17
     'in': {'name': '$in', 'value_type': list},
18 18
     'not in': {'name': '$nin', 'value_type': list},
19
-    #' like ': {'name': '$text', 'value_type': str},
20
-    #' not like ': {'name': '', 'value_type': str},  # TODO Add the operator
21 19
     'OR': {'name': '$or', 'value_type': list},
22 20
     'AND': {'name': '$and', 'value_type': list}
23 21
 }

Loading…
Cancel
Save