You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

general.py 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django.db.models.aggregates import Aggregate
  2. __all__ = [
  3. 'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'StringAgg',
  4. ]
  5. class ArrayAgg(Aggregate):
  6. function = 'ARRAY_AGG'
  7. def convert_value(self, value, expression, connection, context):
  8. if not value:
  9. return []
  10. return value
  11. class BitAnd(Aggregate):
  12. function = 'BIT_AND'
  13. class BitOr(Aggregate):
  14. function = 'BIT_OR'
  15. class BoolAnd(Aggregate):
  16. function = 'BOOL_AND'
  17. class BoolOr(Aggregate):
  18. function = 'BOOL_OR'
  19. class StringAgg(Aggregate):
  20. function = 'STRING_AGG'
  21. template = "%(function)s(%(expressions)s, '%(delimiter)s')"
  22. def __init__(self, expression, delimiter, **extra):
  23. super(StringAgg, self).__init__(expression, delimiter=delimiter, **extra)
  24. def convert_value(self, value, expression, connection, context):
  25. if not value:
  26. return ''
  27. return value