constants.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """
  2. Constants specific to the SQL storage portion of the ORM.
  3. """
  4. from collections import namedtuple
  5. import re
  6. # Valid query types (a set is used for speedy lookups). These are (currently)
  7. # considered SQL-specific; other storage systems may choose to use different
  8. # lookup types.
  9. QUERY_TERMS = set([
  10. 'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
  11. 'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year',
  12. 'month', 'day', 'week_day', 'hour', 'minute', 'second', 'isnull', 'search',
  13. 'regex', 'iregex',
  14. ])
  15. # Size of each "chunk" for get_iterator calls.
  16. # Larger values are slightly faster at the expense of more storage space.
  17. GET_ITERATOR_CHUNK_SIZE = 100
  18. # Namedtuples for sql.* internal use.
  19. # Join lists (indexes into the tuples that are values in the alias_map
  20. # dictionary in the Query class).
  21. JoinInfo = namedtuple('JoinInfo',
  22. 'table_name rhs_alias join_type lhs_alias '
  23. 'join_cols nullable join_field')
  24. # Pairs of column clauses to select, and (possibly None) field for the clause.
  25. SelectInfo = namedtuple('SelectInfo', 'col field')
  26. # How many results to expect from a cursor.execute call
  27. MULTI = 'multi'
  28. SINGLE = 'single'
  29. CURSOR = 'cursor'
  30. NO_RESULTS = 'no results'
  31. ORDER_PATTERN = re.compile(r'\?|[-+]?[.\w]+$')
  32. ORDER_DIR = {
  33. 'ASC': ('ASC', 'DESC'),
  34. 'DESC': ('DESC', 'ASC'),
  35. }