wip
This commit is contained in:
		
							parent
							
								
									7b9e91acd0
								
							
						
					
					
						commit
						eefd4272ff
					
				
					 1 changed files with 2 additions and 9 deletions
				
			
		|  | @ -4,8 +4,6 @@ import pg8000 | ||||||
| 
 | 
 | ||||||
| from flask import g | from flask import g | ||||||
| 
 | 
 | ||||||
| DBResult = namedtuple('Result', 'rows rowcount') |  | ||||||
| 
 |  | ||||||
| def db(): | def db(): | ||||||
|     if not hasattr(g, 'db_connection'): |     if not hasattr(g, 'db_connection'): | ||||||
|         g.db_connection = pg8000.connect( |         g.db_connection = pg8000.connect( | ||||||
|  | @ -23,13 +21,8 @@ def query(query, **params): | ||||||
|         cursor.execute(query, params) |         cursor.execute(query, params) | ||||||
|         db().commit() |         db().commit() | ||||||
| 
 | 
 | ||||||
|         if cursor._cached_rows: |  | ||||||
|         columns = [x[0] for x in cursor.description] |         columns = [x[0] for x in cursor.description] | ||||||
|         rows = [dict(zip(columns, row)) for row in cursor.fetchall()] |         rows = [dict(zip(columns, row)) for row in cursor.fetchall()] | ||||||
|             # rdef = namedtuple('row', ' '.join([x[0] for x in cursor.description])) |  | ||||||
|             # rows = list(map(rdef._make, cursor.fetchall())) |  | ||||||
|         else: |  | ||||||
|             rows = [] |  | ||||||
| 
 | 
 | ||||||
|         return DBResult( |         return DBResult( | ||||||
|             rows=rows, |             rows=rows, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 mwiegand
						mwiegand