Added tools to store lists as json
This commit is contained in:
		
							
								
								
									
										16
									
								
								server/app/tools/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								server/app/tools/models.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
from sqlalchemy import JSON, TypeDecorator
 | 
			
		||||
from sqlalchemy.dialects.sqlite import JSON
 | 
			
		||||
 | 
			
		||||
from json import dumps, loads
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class JsonString(TypeDecorator):
 | 
			
		||||
    """Enables JSON storage by encoding and decoding on the fly."""
 | 
			
		||||
 | 
			
		||||
    impl = JSON
 | 
			
		||||
 | 
			
		||||
    def process_bind_param(self, value, dialect):
 | 
			
		||||
        return dumps(value)
 | 
			
		||||
 | 
			
		||||
    def process_result_value(self, value, dialect):
 | 
			
		||||
        return loads(value)
 | 
			
		||||
		Reference in New Issue
	
	Block a user