mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-10-30 18:22:45 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			22 lines
		
	
	
		
			627 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			627 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import json
 | |
| from app import db
 | |
| 
 | |
| 
 | |
| class ContainerColumn(db.TypeDecorator):
 | |
|     impl = db.String
 | |
| 
 | |
|     def __init__(self, container_type, *args, **kwargs):
 | |
|         super().__init__(*args, **kwargs)
 | |
|         self.container_type = container_type
 | |
| 
 | |
|     def process_bind_param(self, value, dialect):
 | |
|         if isinstance(value, self.container_type):
 | |
|             return json.dumps(value)
 | |
|         elif isinstance(value, str) and isinstance(json.loads(value), self.container_type):
 | |
|             return value
 | |
|         else:
 | |
|             return TypeError()
 | |
| 
 | |
|     def process_result_value(self, value, dialect):
 | |
|         return json.loads(value)
 |