mahmoudimus / sqlalchemy-citext

CITEXT type for SQLAlchemy
Other
29 stars 14 forks source link

Quering against literal values doesn't always work #15

Closed libre-man closed 4 years ago

libre-man commented 4 years ago

When querying a citext column against some literal values I get the error Don't know how to literal-quote value '$LITERAL_VALUE'. It seems that a literal_processor method is missing on the CIText, class. When adding the below method everything works, is there a reason why this isn't defined in the class?

# This is  copied from the `literal_processor` of sqlalchemy's own 
# `String` type.
def literal_processor(self, dialect: t.Any) -> t.Callable[[str], str]:
    def process(value: str) -> str:
        value = value.replace("'", "''")

        if dialect.identifier_preparer._double_percents:
            value = value.replace("%", "%%")

        return "'%s'" % value

    return process
mahmoudimus commented 4 years ago

Hi @libre-man - would you mind making a PR?