Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b5dc8e71a | |||
| 562c75880b |
@@ -8,7 +8,7 @@ PYTHON3 = True
|
|||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
PYTHON3 = False
|
PYTHON3 = False
|
||||||
|
|
||||||
VERSION = "0.0.14"
|
VERSION = "0.0.15"
|
||||||
|
|
||||||
|
|
||||||
def is_map(obj):
|
def is_map(obj):
|
||||||
@@ -241,6 +241,7 @@ class SQLQuery(object):
|
|||||||
self._limits = None
|
self._limits = None
|
||||||
self._sql = sql
|
self._sql = sql
|
||||||
self._nolock = False
|
self._nolock = False
|
||||||
|
self._distinct = False
|
||||||
|
|
||||||
def has_filters(self,):
|
def has_filters(self,):
|
||||||
return self._order_by or self._group_by or self._joins\
|
return self._order_by or self._group_by or self._joins\
|
||||||
@@ -272,6 +273,11 @@ class SQLQuery(object):
|
|||||||
clone._nolock = enabled
|
clone._nolock = enabled
|
||||||
return clone
|
return clone
|
||||||
|
|
||||||
|
def distinct(self, enabled=True):
|
||||||
|
clone = self._clone()
|
||||||
|
clone._distinct = enabled
|
||||||
|
return clone
|
||||||
|
|
||||||
def filter(self, *args, **kwargs):
|
def filter(self, *args, **kwargs):
|
||||||
clone = self._clone()
|
clone = self._clone()
|
||||||
clone._filters &= self._q(*args, **kwargs)
|
clone._filters &= self._q(*args, **kwargs)
|
||||||
@@ -308,6 +314,9 @@ class SQLQuery(object):
|
|||||||
return clone
|
return clone
|
||||||
|
|
||||||
def __getitem__(self, slice):
|
def __getitem__(self, slice):
|
||||||
|
if isinstance(slice, str):
|
||||||
|
raise IndexError
|
||||||
|
|
||||||
clone = self._clone()
|
clone = self._clone()
|
||||||
clone._limits = slice
|
clone._limits = slice
|
||||||
return clone
|
return clone
|
||||||
@@ -371,6 +380,11 @@ class SQLCompiler(object):
|
|||||||
return " WITH (NOLOCK)"
|
return " WITH (NOLOCK)"
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def get_distinct(self,):
|
||||||
|
if self._distinct:
|
||||||
|
return " DISTINCT "
|
||||||
|
return ""
|
||||||
|
|
||||||
def get_limits(self,):
|
def get_limits(self,):
|
||||||
if self._limits and self.sql_mode != "SQL_SERVER":
|
if self._limits and self.sql_mode != "SQL_SERVER":
|
||||||
offset = self._limits.start
|
offset = self._limits.start
|
||||||
@@ -394,7 +408,10 @@ class SQLCompiler(object):
|
|||||||
else:
|
else:
|
||||||
table = self.get_table()
|
table = self.get_table()
|
||||||
|
|
||||||
sql = ["SELECT", self.get_top(), self.get_columns(),
|
sql = ["SELECT",
|
||||||
|
self.get_distinct(),
|
||||||
|
self.get_top(),
|
||||||
|
self.get_columns(),
|
||||||
"FROM", table,
|
"FROM", table,
|
||||||
self.get_nolock(),
|
self.get_nolock(),
|
||||||
self.get_joins(), self.get_where(),
|
self.get_joins(), self.get_where(),
|
||||||
|
|||||||
Reference in New Issue
Block a user