[openstack-dev] IPAddress SQLAlchemy type and other db-specific datatypes

Ionuț Arțăriși iartarisi at suse.cz
Mon Nov 12 12:55:03 UTC 2012


Hi,

I submitted a patch for review last week[1] which started a discussion
about implementing sqlalchemy dialect specific datatypes
(e.g. postgresql, mysql etc.).

I think it would be great to abstract some common datatypes (such as for
ip addresses) so we can then add custom validations or use different
backend datatypes where that makes sense.

The way the IPAddress is implemented should be pretty straightforward and
very backwards compatible (the INET datatype acts as a string for basic
operations). Just defining a new datatype:

IPAddress = lambda: String(255).with_variant(postgresql.INET(),
'postgresql')

which can then be used instead of the string like so:

access_ip_v4 = Column(IPAddress())

I guess now there's the question of where we want to store these
custom dataypes' implementations. Would it be enough to have a datatypes.py
module in there and have all our custom types inside?


[1] https://review.openstack.org/#/c/15566/

-Ionuț



More information about the OpenStack-dev mailing list