Add methods sql_insert, sql_update to centralize sqlhelper work.
This commit is contained in:
		
							parent
							
								
									655d1fa235
								
							
						
					
					
						commit
						3e5031a1c5
					
				
					 1 changed files with 22 additions and 0 deletions
				
			
		|  | @ -1321,6 +1321,28 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs | ||||||
|             thing = thing_map['class'](self, db_row=thing) |             thing = thing_map['class'](self, db_row=thing) | ||||||
|             yield thing |             yield thing | ||||||
| 
 | 
 | ||||||
|  |     def sql_insert(self, table, data, *, commit=True): | ||||||
|  |         column_names = constants.SQL_COLUMNS[table] | ||||||
|  |         cur = self.sql.cursor() | ||||||
|  | 
 | ||||||
|  |         (qmarks, bindings) = sqlhelpers.insert_filler(column_names, data) | ||||||
|  |         query = 'INSERT INTO %s VALUES(%s)' % (table, qmarks) | ||||||
|  |         cur.execute(query, bindings) | ||||||
|  | 
 | ||||||
|  |         if commit: | ||||||
|  |             self.sql.commit() | ||||||
|  | 
 | ||||||
|  |     def sql_update(self, table, pairs, where_key, *, commit=True): | ||||||
|  |         column_names = constants.SQL_COLUMNS[table] | ||||||
|  |         cur = self.sql.cursor() | ||||||
|  | 
 | ||||||
|  |         (query, bindings) = sqlhelpers.update_filler(pairs, where_key=where_key) | ||||||
|  |         query = 'UPDATE %s %s' % (table, query) | ||||||
|  |         cur.execute(query, bindings) | ||||||
|  | 
 | ||||||
|  |         if commit: | ||||||
|  |             self.sql.commit() | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| _THING_CLASSES = { | _THING_CLASSES = { | ||||||
|     'album': |     'album': | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue