Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some conditionals with as_mysql method #3

Merged
merged 2 commits into from Jun 2, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -65,7 +65,7 @@ def get_db_prep_value(self, value, connection, prepared=False):
def from_db_value(self, value, expression, connection):
if connection.vendor == 'postgresql':
return value
elif connection.vendor == 'postgresql':
elif connection.vendor == 'mysql':
if isinstance(value, str):
return self.decoder.decode(value)
else:
@@ -338,18 +338,15 @@ def process_rhs(self, compiler, connection):
return rhs


class MySQLCaseInsensitiveMixin:
def process_lhs(self, compiler, connection, lhs=None):
lhs = super().process_lhs(compiler, connection, lhs=None)
if connection.vendor == 'mysql':
lhs = 'LOWER(%s)' % lhs[0], lhs[1]
return lhs

def process_rhs(self, compiler, connection):
rhs = super().process_rhs(compiler, connection)
if connection.vendor == 'mysql':
rhs = 'LOWER(%s)' % rhs[0], rhs[1]
return rhs
class CaseInsensitiveMixin:
def as_mysql(self, compiler, connection):
lhs, lhs_params = super().process_lhs(compiler, connection, lhs=None)
lhs = 'LOWER(%s)' % lhs
rhs, rhs_params, = super().process_rhs(compiler, connection)
rhs = 'LOWER(%s)' % rhs
params = lhs_params + rhs_params
rhs = self.get_rhs_op(connection, rhs)
return '%s %s' % (lhs, rhs), params


@FallbackKeyTransform.register_lookup
@@ -378,12 +375,12 @@ def process_rhs(self, compiler, connection):


@FallbackKeyTransform.register_lookup
class KeyTransformIExact(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IExact):
class KeyTransformIExact(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IExact):
pass


@FallbackKeyTransform.register_lookup
class KeyTransformIContains(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IContains):
class KeyTransformIContains(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IContains):
pass


@@ -398,7 +395,7 @@ class KeyTransformStartsWith(StringKeyTransformTextLookupMixin, builtin_lookups.


@FallbackKeyTransform.register_lookup
class KeyTransformIStartsWith(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IStartsWith):
class KeyTransformIStartsWith(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IStartsWith):
pass


@@ -408,7 +405,7 @@ class KeyTransformEndsWith(StringKeyTransformTextLookupMixin, builtin_lookups.En


@FallbackKeyTransform.register_lookup
class KeyTransformIEndsWith(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IEndsWith):
class KeyTransformIEndsWith(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IEndsWith):
pass


ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.