Allow setting custom length to EmailType, refs #229

This commit is contained in:
Pekka Pöyry
2016-07-05 11:06:42 +03:00
parent 8b20340bc8
commit a9e6444cc8
2 changed files with 8 additions and 1 deletions

View File

@@ -4,9 +4,12 @@ from ..operators import CaseInsensitiveComparator
class EmailType(sa.types.TypeDecorator):
impl = sa.Unicode(255)
impl = sa.Unicode
comparator_factory = CaseInsensitiveComparator
def __init__(self, length=255, *args, **kwargs):
super(EmailType, self).__init__(length=length, *args, **kwargs)
def process_bind_param(self, value, dialect):
if value is not None:
return value.lower()

View File

@@ -10,6 +10,7 @@ def User(Base):
__tablename__ = 'user'
id = sa.Column(sa.Integer, primary_key=True)
email = sa.Column(EmailType)
short_email = sa.Column(EmailType(length=70))
def __repr__(self):
return 'User(%r)' % self.id
@@ -30,3 +31,6 @@ class TestEmailType(object):
clause = User.email == 'Someone@example.com'
compiled = str(clause.compile(compile_kwargs={'literal_binds': True}))
assert compiled == '"user".email = lower(\'Someone@example.com\')'
def test_custom_length(self, session, User):
assert User.short_email.type.impl.length == 70