[Twisted-Python] problem with combining deferreds together

Henning.Ramm at mediapro-gmbh.de Henning.Ramm at mediapro-gmbh.de
Mon Aug 15 11:21:38 MDT 2005


>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.




More information about the Twisted-Python mailing list