doc/book/devrepo/dataimport.rst
changeset 10513 7bec01a59f92
parent 10491 c67bcee93248
child 11238 bb5fdf1eb8fb
equal deleted inserted replaced
10512:99bdd4bddd77 10513:7bec01a59f92
    72 
    72 
    73 
    73 
    74 Stores
    74 Stores
    75 ~~~~~~
    75 ~~~~~~
    76 
    76 
    77 Stores are responsible to insert properly formatted entities and relations into the database. They
    77 .. automodule:: cubicweb.dataimport.stores
    78 have the following API::
       
    79 
       
    80     >>> user_eid = store.prepare_insert_entity('CWUser', login=u'johndoe')
       
    81     >>> group_eid = store.prepare_insert_entity('CWUser', name=u'unknown')
       
    82     >>> store.relate(user_eid, 'in_group', group_eid)
       
    83     >>> store.flush()
       
    84     >>> store.commit()
       
    85     >>> store.finish()
       
    86 
       
    87 Some stores **require a flush** to copy data in the database, so if you want to have store
       
    88 independent code you should explicitly call it. (There may be multiple flushes during the
       
    89 process, or only one at the end if there is no memory issue). This is different from the
       
    90 commit which validates the database transaction. At last, the `finish()` method should be called in
       
    91 case the store requires additional work once everything is done.
       
    92 
       
    93 * ``prepare_insert_entity(<entity type>, **kwargs) -> eid``: given an entity
       
    94   type, attributes and inlined relations, return the eid of the entity to be
       
    95   inserted, *with no guarantee that anything has been inserted in database*.
       
    96 
       
    97 * ``prepare_update_entity(<entity type>, eid, **kwargs) -> None``: given an
       
    98   entity type and eid, promise for update given attributes and inlined
       
    99   relations *with no guarantee that anything has been inserted in database*.
       
   100 
       
   101 * ``prepare_insert_relation(eid_from, rtype, eid_to) -> None``: indicate that a
       
   102   relation ``rtype`` should be added between entities with eids ``eid_from``
       
   103   and ``eid_to``. Similar to ``prepare_insert_entity()``, *there is no
       
   104   guarantee that the relation has been inserted in database*.
       
   105 
       
   106 * ``flush() -> None``: flush any temporary data to database. May be called
       
   107   several times during an import.
       
   108 
       
   109 * ``commit() -> None``: commit the database transaction.
       
   110 
       
   111 * ``finish() -> None``: additional stuff to do after import is terminated.
       
   112 
       
   113 ObjectStore
       
   114 -----------
       
   115 
       
   116 This store keeps objects in memory for *faster* validation. It may be useful in development
       
   117 mode. However, as it will not enforce the constraints of the schema nor insert anything in the
       
   118 database, so it may miss some problems.
       
   119 
       
   120 
       
   121 RQLObjectStore
       
   122 --------------
       
   123 
       
   124 This store works with an actual RQL repository, and it may be used in production mode.
       
   125 
       
   126 
       
   127 NoHookRQLObjectStore
       
   128 --------------------
       
   129 
       
   130 This store works similarly to the *RQLObjectStore* but bypasses some *CubicWeb* hooks to be faster.
       
   131 
    78 
   132 
    79 
   133 SQLGenObjectStore
    80 SQLGenObjectStore
   134 -----------------
    81 -----------------
   135 
    82