airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [airflow] feluelle commented on a change in pull request #6432: [AIRFLOW-5758] Support the custom cursor classes for the PostgreSQL hook
Date Sat, 26 Oct 2019 16:42:19 GMT
feluelle commented on a change in pull request #6432: [AIRFLOW-5758] Support the custom cursor
classes for the PostgreSQL hook
URL: https://github.com/apache/airflow/pull/6432#discussion_r339306887
 
 

 ##########
 File path: airflow/hooks/postgres_hook.py
 ##########
 @@ -67,6 +68,13 @@ def get_conn(self):
             password=conn.password,
             dbname=self.schema or conn.schema,
             port=conn.port)
+        if conn.extra_dejson.get('cursor', False):
+            if (conn.extra_dejson['cursor']).lower() == 'dictcursor':
+                conn_args['cursor_factory'] = psycopg2.extras.DictCursor
+            elif (conn.extra_dejson['cursor']).lower() == 'realdictcursor':
+                conn_args['cursor_factory'] = psycopg2.extras.RealDictCursor
+            elif (conn.extra_dejson['cursor']).lower() == 'namedtuplecursor':
+                conn_args['cursor_factory'] = psycopg2.extras.NamedTupleCursor
 
 Review comment:
   ```python
   def _get_cursor(self, raw_cursor):
       _cursor = raw_cursor.lower()
       if _cursor == 'dictcursor':
           return psycopg2.extras.DictCursor
       if _cursor == 'realdictcursor':
           return psycopg2.extras.RealDictCursor
       if _cursor == 'namedtuplecursor':
           return psycopg2.extras.NamedTupleCursor
       raise ValueError('Invalid cursor passed {}'.format(_cursor))
   ```
   
   ```python
   raw_cursor = conn.extra_dejson.get('cursor', False)
   if raw_cursor:
       conn_args['cursor_factory'] = self._get_cursor(raw_cursor)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message