Comments (6)
The way to do it is demonstrated in this function from the file app/services/backandServices.ts:
public filterItems(query) {
let filter =
[
{
fieldName: 'name',
operator: 'contains',
value: query
}
]
;
return this.http.get(this.api_url + '/1/objects/todo?filter=' + encodeURI(JSON.stringify(filter)),
{
headers: this.authHeader
})
.retry(3)
.map(res => res.json().data);
}
As you can see in the CRUD tab as we filter with a search window.
from backand-ionic2-starter.
That's great thanks, so how would this work with a location based query such as in the Backand documentation:
{
"object": "restaurants",
"q": {
"location" : { "$withinMiles" : [[37.8019859, -122.4414805], 25] }
}
}
Could you use this same filter logic against an /1/objects/restaurants
object with the fieldName: 'location'
if so what would the operator
and value
attributes look like
from backand-ionic2-starter.
The filter parameter in GET objects '/1/objects/restaurants' can work in two ways
- One way is with field, operator and value array like this
[{fieldName: 'name',operator: 'contains',value: 'something'}] - The other is with a NoSQL condition, something like this
{
"object": "restaurants",
"q": {
"name" : { "$like" : 'something' }
}
}
both ways are equivalent.
however for location you must only use the NoSQL way like in the example above and should look like this:
public filterLocation(point, miles) {
let withinMiles =
{
"q": {
"location" : { "$withinMiles" : [point, miles] }
}
}
return this.http.get(this.api_url + '/1/objects/todo?filter=' + encodeURI(JSON.stringify(withinMiles)),
{
headers: this.authHeader
})
.retry(3)
.map(res => res.json().data);
}
from backand-ionic2-starter.
Thanks @relly and @kornatzky that's sorted it
One last question; is there any way of sorting a $withinMiles
query by distance from the point ASC or DESC?
Cheers
from backand-ionic2-starter.
You can use Backand queries for that. Backand Query works for both SQL and NoSQL syntax.
You can read more at the docs.
Here is an example for the SQL that you may use:
SELECT * FROM
restaurants WHERE (ST_Distance (
restaurants.
location, ST_GeomFromText('POINT( 37.8019859 -122.4414805 )') ) <= 25 /(69)) ORDER BY ST_Distance (
restaurants.
location, ST_GeomFromText('POINT( 37.8019859 -122.4414805 )') )
It is a basic suggestion that I am sure you will improve. There is a lot of information how to work with MySQL and GEO Point, That is what we use in Backand.
I also suggest that you will send the point values as parameters to the query
You can see it in the docs for NoSQL but it is the same as for SQL
from backand-ionic2-starter.
That's brilliant thanks @relly
It brings me back to my original point however as to how one executes a custom query, with input parameters, in an ionic2 app? Unfortunately I can't find any docs around this.
Many thanks
from backand-ionic2-starter.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backand-ionic2-starter.