Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqlalchemy_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
ScalarListException,
ScalarListType,
StringEncryptedType,
TextEncryptedType,
TimezoneType,
TSVectorType,
URLType,
Expand Down
3 changes: 2 additions & 1 deletion sqlalchemy_utils/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from .email import EmailType # noqa
from .encrypted.encrypted_type import ( # noqa
EncryptedType,
StringEncryptedType
StringEncryptedType,
TextEncryptedType
)
from .enriched_datetime.enriched_date_type import EnrichedDateType # noqa
from .ip_address import IPAddressType # noqa
Expand Down
24 changes: 23 additions & 1 deletion sqlalchemy_utils/types/encrypted/encrypted_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import warnings

from sqlalchemy.types import LargeBinary, String, TypeDecorator
from sqlalchemy.types import LargeBinary, String, Text, TypeDecorator

from sqlalchemy_utils.exceptions import ImproperlyConfigured
from sqlalchemy_utils.types.encrypted.padding import PADDING_MECHANISM
Expand Down Expand Up @@ -456,6 +456,28 @@ def _coerce(self, value):
return value


class TextEncryptedType(StringEncryptedType):
"""
The 'TextEncryptedType' creates a Text column instead of a String column
"""
impl = Text

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def process_bind_param(self, value, dialect):
value = super().process_bind_param(value=value, dialect=dialect)
if isinstance(value, str):
value = value.encode()
return value

def process_result_value(self, value, dialect):
if isinstance(value, bytes):
value = value.decode()
value = super().process_result_value(value=value, dialect=dialect)
return value


class EncryptedType(StringEncryptedType):
"""
The 'EncryptedType' class will change implementation from
Expand Down