RE: [Twisted-Python] problem with combining deferreds together
i've stuck on one problem (probably i'm not the first, but couldn't google out the soultion).
i have an object, which data is spread between two tables - the MainTable with some data and reference to some row in SubTable with additional things.
Why don't you fetch both in one query (using LEFT JOIN or just WHERE clauses), that would be faster anyway.
class ObjectRepository:
def getById(self, id): dMain = self.dbpool.runInteraction( fetchOneAndMapToDictionary, "SELECT * FROM MainTable WHERE id = '%d'" % (id,) ) dMain.addCallback(self._gotMainData) return dMain
def _gotMainData(self, mappedRow): dSub = self.dbpool.runInteraction( fetchOneAndMapToDictionary, "SELECT * FROM SubTable WHERE id = '%d'" % (mappedRow['SubID'],) ) dSub.addCallback(self._gotSubData) return [what to return ????]
how can i return the result that consist of data from both queries?
dSub.addCallback(self._gotSubData, mappedRow) return dSub # what else? Just make sure you handle mappedRow in _gotSubData. Or did I miss your point? Best regards, Henning Hraban Ramm Südkurier Medienhaus / MediaPro Support/Admin/Development Dept.
participants (1)
-
Henning.Ramm@mediapro-gmbh.de