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 2 commits into from Jun 2, 2019
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


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)
@@ -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

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

class KeyTransformIExact(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IExact):
class KeyTransformIExact(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IExact):

class KeyTransformIContains(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IContains):
class KeyTransformIContains(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IContains):

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

class KeyTransformIStartsWith(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IStartsWith):
class KeyTransformIStartsWith(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IStartsWith):

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

class KeyTransformIEndsWith(MySQLCaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IEndsWith):
class KeyTransformIEndsWith(CaseInsensitiveMixin, StringKeyTransformTextLookupMixin, builtin_lookups.IEndsWith):

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