diff idavoll/pgsql_storage.py @ 145:f393bccec4bc

Add get_affiliations to Node class in storage facilities in preparation of support for 'Modifying Entity Affiliations' in the JEP-0060 specification.
author Ralph Meijer <ralphm@ik.nu>
date Thu, 14 Jul 2005 20:51:48 +0000
parents 812300cdbc22
children b4490bdc77e5
line wrap: on
line diff
--- a/idavoll/pgsql_storage.py	Tue Jul 12 14:53:23 2005 +0000
+++ b/idavoll/pgsql_storage.py	Thu Jul 14 20:51:48 2005 +0000
@@ -280,6 +280,23 @@
 
         return cursor.fetchone() is not None
 
+    def get_affiliations(self):
+        return self._dbpool.runInteraction(self._get_affiliations)
+
+    def _get_affiliations(self, cursor):
+        self._check_node_exists(cursor)
+
+        cursor.execute("""SELECT jid, affiliation FROM nodes
+                          JOIN affiliations ON
+                            (nodes.id = affiliations.node_id)
+                          JOIN entities ON
+                            (affiliations.entity_id = entities.id)
+                          WHERE node=%s""",
+                       self.id)
+        result = cursor.fetchall()
+        
+        return [(jid.JID(r[0]), r[1]) for r in result]
+
 class LeafNode(Node):
 
     implements(storage.ILeafNode)
@@ -378,4 +395,3 @@
         cursor.execute("""DELETE FROM items WHERE
                           node_id=(SELECT id FROM nodes WHERE node=%s)""",
                        (self.id,))
-