384 self.doexec(session, sql, attrs) |
384 self.doexec(session, sql, attrs) |
385 |
385 |
386 def update_entity(self, session, entity): |
386 def update_entity(self, session, entity): |
387 """replace an entity in the source""" |
387 """replace an entity in the source""" |
388 attrs = self.preprocess_entity(entity) |
388 attrs = self.preprocess_entity(entity) |
389 sql = self.sqlgen.update(SQL_PREFIX + str(entity.e_schema), attrs, [SQL_PREFIX + 'eid']) |
389 sql = self.sqlgen.update(SQL_PREFIX + str(entity.e_schema), attrs, |
|
390 [SQL_PREFIX + 'eid']) |
390 self.doexec(session, sql, attrs) |
391 self.doexec(session, sql, attrs) |
391 |
392 |
392 def delete_entity(self, session, etype, eid): |
393 def delete_entity(self, session, etype, eid): |
393 """delete an entity from the source""" |
394 """delete an entity from the source""" |
394 attrs = {SQL_PREFIX + 'eid': eid} |
395 attrs = {SQL_PREFIX + 'eid': eid} |
395 sql = self.sqlgen.delete(SQL_PREFIX + etype, attrs) |
396 sql = self.sqlgen.delete(SQL_PREFIX + etype, attrs) |
396 self.doexec(session, sql, attrs) |
397 self.doexec(session, sql, attrs) |
397 |
398 |
398 def add_relation(self, session, subject, rtype, object): |
399 def add_relation(self, session, subject, rtype, object, inlined=False): |
399 """add a relation to the source""" |
400 """add a relation to the source""" |
400 attrs = {'eid_from': subject, 'eid_to': object} |
401 if inlined is False: |
401 sql = self.sqlgen.insert('%s_relation' % rtype, attrs) |
402 attrs = {'eid_from': subject, 'eid_to': object} |
|
403 sql = self.sqlgen.insert('%s_relation' % rtype, attrs) |
|
404 else: # used by data import |
|
405 etype = session.describe(subject)[0] |
|
406 attrs = {SQL_PREFIX + 'eid': subject, SQL_PREFIX + rtype: object} |
|
407 sql = self.sqlgen.update(SQL_PREFIX + etype, attrs, |
|
408 [SQL_PREFIX + 'eid']) |
402 self.doexec(session, sql, attrs) |
409 self.doexec(session, sql, attrs) |
403 |
410 |
404 def delete_relation(self, session, subject, rtype, object): |
411 def delete_relation(self, session, subject, rtype, object): |
405 """delete a relation from the source""" |
412 """delete a relation from the source""" |
406 rschema = self.schema.rschema(rtype) |
413 rschema = self.schema.rschema(rtype) |