Creating custom sqlalchemy types

I am trying to save ipaddress in a table. Created a custom type as follows:

class MCastIP(sqlalchemy.types.TypeDecorator):
  impl = sqlalchemy.types.Integer
  def process_bind_param(self, value, dialect):
    return int(IPAddress(value))
  def process_result_value(self, value, dialect):
    return IPAddress(value)

This seems to work, but just wondering if I need to implement any other function that will be complete. For example: python_type. Do you need the following? When will it be called and how can I explicitly call and check if it works?

def python_type(self):
   return IPAddress
+4
source share
1 answer

Under normal use, no, you have an implementation. I have several implementations with custom types and only ever defined the methods that I need "(usually what you use there).

, , .

, , ( ) , - . SQLAlchemy ( ), , / .

-1

All Articles