def contains(self, value): if isinstance(value, dict): return Expression(self, OP_HCONTAINS_DICT, Param(value)) elif isinstance(value, (list, tuple)): return Expression(self, OP_HCONTAINS_KEYS, Param(value)) return Expression(self, OP_HCONTAINS_KEY, value)
def contains_any(self, *keys): return Expression(self, HCONTAINS_ANY_KEY, Value(list(keys), unpack=False))
def contained_by(self, other): return Expression(cast_jsonb(self), JSONB_CONTAINED_BY, Json(other))
def contains(self, *items): return Expression(self, ACONTAINS, ArrayValue(self, items))
def __getitem__(self, key): return Expression(self, HKEY, Value(key))
def concat(self, rhs): return Expression(self.as_json(True), OP.CONCAT, Json(rhs))
def contains_all(self, *keys): return Expression(self.as_json(True), JSONB_CONTAINS_ALL_KEYS, Value(list(keys), unpack=False))
def match(self, query): return Expression(self, OP_TS_MATCH, fn.to_tsquery(query))
def Match(field, query): return Expression(fn.to_tsvector(field), OP_TS_MATCH, fn.to_tsquery(query))
def contains_any(self, *items): return Expression(self, OP_JSONB_CONTAINS_ANY_KEY, Passthrough(list(items)))
def contains_all(self, *items): return Expression(self, OP_JSONB_CONTAINS_ALL_KEYS, Passthrough(list(items)))
def contained_by(self, other): return Expression(self, OP_JSONB_CONTAINED_BY, Json(other))
def contains(self, other): if isinstance(other, (list, dict)): return Expression(self, OP_JSONB_CONTAINS, Json(other)) return Expression(self, OP_JSONB_EXISTS, Passthrough(other))
def contains_any(self, *keys): return Expression(self, OP_HCONTAINS_ANY_KEY, Param(list(keys)))
def match(self, query, language=None, plain=False): params = (language, query) if language is not None else (query, ) func = fn.plainto_tsquery if plain else fn.to_tsquery return Expression(self, TS_MATCH, func(*params))
def contains_all(self, *keys): return Expression(self.as_json(True), OP_JSONB_CONTAINS_ALL_KEYS, Passthrough(list(keys)))
def Match(field, query, language=None): params = (language, query) if language is not None else (query, ) field_params = (language, field) if language is not None else (field, ) return Expression(fn.to_tsvector(*field_params), TS_MATCH, fn.to_tsquery(*params))
def pg_regex_i(lhs, rhs): return Expression(lhs, OP.IRGX, rhs)
def contains(self, other): clone = self.as_json(True) if isinstance(other, (list, dict)): return Expression(clone, JSONB_CONTAINS, Json(other)) return Expression(clone, JSONB_EXISTS, other)
def _search_by_dates(object_type, object_id_list, start_date, end_date, time_basis): time_column_name = QueryBase.time_basis_mappings.get(time_basis) object_type_column_name = QueryBase.object_type_mappings.get( object_type) if time_basis == 'submitted': time_column = getattr(TransSIP, time_column_name) else: time_column = getattr(Files, time_column_name) object_type_column = getattr(TransSIP, object_type_column_name) where_clause = Expression(time_column, OP.GTE, start_date) where_clause &= Expression(time_column, OP.LTE, end_date) where_clause &= (object_type_column << object_id_list) query = Files().select(Files.id, time_column.alias('filedate'), Files.size, Files.transaction).join( TransSIP, on=(TransSIP.id == Files.transaction)) # pylint: disable=no-member query = query.where(where_clause).order_by(time_column).objects() # pylint: enable=no-member results = { 'day_graph': { 'by_date': { 'available_dates': {}, 'file_count': {}, 'file_volume': {}, 'transactions': {}, 'file_volume_array': {}, 'transaction_count_array': {} } }, 'summary_totals': { 'upload_stats': { 'project': {}, 'instrument': {}, 'user': {} }, 'total_file_count': 0, 'total_size_bytes': 0, 'total_size_string': '' }, 'transaction_info': { 'transaction': {}, 'project': {}, 'instrument': {}, 'user': {} } } transaction_cache = {} for item in query.iterator(): if item.transaction_id not in transaction_cache: t_info = item.transaction.transsip.get().to_hash() transaction_cache[item.transaction_id] = t_info else: t_info = transaction_cache[item.transaction_id] SummarizeByDate._summarize_by_date(results['day_graph']['by_date'], item) SummarizeByDate._update_transaction_info_block( results['transaction_info'], item, t_info) SummarizeByDate._summarize_upload_stats( results['summary_totals']['upload_stats'], t_info) results['summary_totals']['total_file_count'] += 1 results['summary_totals']['total_size_bytes'] += item.size return results
def has_key(self, key): return Expression(self.as_json(True), JSONB_CONTAINS_KEY, key)
def match(lhs, rhs): return Expression(lhs, OP.MATCH, rhs)
def contains_any(self, *items): return Expression(self, ACONTAINS_ANY, ArrayValue(self, items))
def inner(self, rhs): return Expression(self, op, ArrayValue(self, rhs))
def update(self, **data): return Expression(self, HUPDATE, data)
def has_key(self, key): return Expression(cast_jsonb(self), JSONB_CONTAINS_KEY, key)
def contains(self, other): if isinstance(other, (list, dict)): return Expression(self, JSONB_CONTAINS, Json(other)) return Expression(cast_jsonb(self), JSONB_EXISTS, other)
def remove(self, *items): return Expression(cast_jsonb(self), JSONB_REMOVE, Value(list(items), unpack=False))
def contains_any(self, *items): return Expression(cast_jsonb(self), JSONB_CONTAINS_ANY_KEY, Value(list(items), unpack=False))
def __getitem__(self, key): return Expression(self, OP_HKEY, Param(key))