doc/book/en/development/devweb/gettingdata.rst
changeset 4430 0b6a069eb29e
child 4437 21f2e01fdd6a
equal deleted inserted replaced
4429:0cd207567f37 4430:0b6a069eb29e
       
     1 
       
     2 .. _Getting Data:
       
     3 
       
     4 Getting Data
       
     5 ------------
       
     6 
       
     7 You might have spotted this in the explanations about the views, to
       
     8 get data, when not using a toplevel method, you will execute an RQL
       
     9 query over the request. For more details about RQL, head out to the
       
    10 `RQL chapter`
       
    11 
       
    12 Basic cases
       
    13 ```````````
       
    14 In a similiar way that you might be used to in SQL, to obtain data
       
    15 from the RQL backend, you will execute an RQL command and obtain a
       
    16 resultset ::
       
    17 
       
    18    rset = self.req.execute(rql_command)
       
    19 
       
    20 Then, you can use the data from the rset.
       
    21 
       
    22 XXX complete section with examples
       
    23 
       
    24 Use of the cache for RQL execution
       
    25 ``````````````````````````````````
       
    26 Let's say you want to get T which is in configuration C, this translates to ::
       
    27 
       
    28          self.req.execute('Any T WHERE T in_conf C, C eid "%s"' % entity.eid)
       
    29 
       
    30 But it can also be written in a syntax that will benefit from the use
       
    31 of a cache on the RQL server side. ::
       
    32 
       
    33           self.req.execute('Any T WHERE T in_conf C, C eid %(x)s', {'x': entity.eid}, 'x')
       
    34 
       
    35 The syntax tree is build once for the "generic" RQL and can be re-used
       
    36 with a number of different eid. Alternativelly, some of the common
       
    37 data related to an entity can be obtained from the top-level
       
    38 `entity.related()` method. The above would then be translated to ::
       
    39 
       
    40     entity.related('in_conf', 'object')
       
    41 
       
    42 The `related()` method makes extensive use of the cache mechanisms so
       
    43 you don't have to worry about them. Additionnaly this use will get you
       
    44 commonly used attributes that you will be able to use in your view
       
    45 generation without having to ask the data backend.
       
    46