Made Arrow and IPAddress types use ScalarCoercible
This commit is contained in:
@@ -10,9 +10,10 @@ except:
|
|||||||
pass
|
pass
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
from sqlalchemy_utils import ImproperlyConfigured
|
from sqlalchemy_utils import ImproperlyConfigured
|
||||||
|
from .scalar_coercible import ScalarCoercible
|
||||||
|
|
||||||
|
|
||||||
class ArrowType(types.TypeDecorator):
|
class ArrowType(types.TypeDecorator, ScalarCoercible):
|
||||||
impl = types.DateTime
|
impl = types.DateTime
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -33,7 +34,7 @@ class ArrowType(types.TypeDecorator):
|
|||||||
return arrow.get(value)
|
return arrow.get(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def coercion_listener(self, target, value, oldvalue, initiator):
|
def _coerce(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
elif isinstance(value, six.string_types):
|
elif isinstance(value, six.string_types):
|
||||||
|
@@ -12,9 +12,10 @@ except ImportError:
|
|||||||
|
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
from sqlalchemy_utils import ImproperlyConfigured
|
from sqlalchemy_utils import ImproperlyConfigured
|
||||||
|
from .scalar_coercible import ScalarCoercible
|
||||||
|
|
||||||
|
|
||||||
class IPAddressType(types.TypeDecorator):
|
class IPAddressType(types.TypeDecorator, ScalarCoercible):
|
||||||
"""
|
"""
|
||||||
Changes IPAddress objects to a string representation on the way in and
|
Changes IPAddress objects to a string representation on the way in and
|
||||||
changes them back to IPAddress objects on the way out.
|
changes them back to IPAddress objects on the way out.
|
||||||
@@ -38,5 +39,5 @@ class IPAddressType(types.TypeDecorator):
|
|||||||
def process_result_value(self, value, dialect):
|
def process_result_value(self, value, dialect):
|
||||||
return ip_address(value) if value else None
|
return ip_address(value) if value else None
|
||||||
|
|
||||||
def coercion_listener(self, target, value, oldvalue, initiator):
|
def _coerce(self, value):
|
||||||
return ip_address(value) if value else None
|
return ip_address(value) if value else None
|
||||||
|
Reference in New Issue
Block a user