async def test_null(NullDatastore): s = NullDatastore() for c in range(1, 20): if NullDatastore is BinaryNullDatastore: v = str(c).encode() else: v = [c] k = Key(str(c)) assert not await s.contains(k) with pytest.raises(KeyError): await s.get(k) await s.put(k, v) assert not await s.contains(k) with pytest.raises(KeyError): await s.get(k) for item in await s.query(Query(Key('/'))): raise Exception('Should not have found anything.')
def get_organizations(): # Gather filter and order information from query filters = {} for key in ('id', 'name', 'city', 'state', 'postal', 'category'): value = request.args.get(key) if value: filters[key] = value isAscending = not (request.args.get('direction') == 'DSC') cursor = Query(filters=filters, orderBy=request.args.get('orderBy'), isAscending=isAscending).cursor() results = [] schema = cursor.description for row in cursor: entry = {} for (idx, desc) in enumerate(schema): entry[desc[0]] = row[idx] results.append(entry) return jsonify({'organizations': results})
def query(self, query=None): '''Execute a query on the underlying datastore''' mgr_query = query.copy() if query else Query() mgr_query.key = self.key.child(mgr_query.key) return self.datastore.query(mgr_query)
async def query(self, query: datastore.Query) -> datastore.Cursor: """Returns a sequence of objects matching criteria expressed in `query`""" query = query.copy() query.key = self.key_transform_fn(query.key) return await super().query(query) # type: ignore[misc] # noqa: F821
def init_query(self): '''Initiates a Query object for the model''' if not self.model: raise Exception( 'Can not query when no model is set on the manager') return Query(Key('/' + self.model.key_type))