New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting #1
base: master
Are you sure you want to change the base?
Sorting #1
Conversation
This includes support for both geometry and geography columns as well as GiST indices (used when passing the `spatial: true`). Client representations use GeoJSON (existing MySQL and MS SQL drivers use WKT (well-known text)) for compatibility with geospatial libraries such as Turf, JSTS, etc.
Good call on looking into how custom I think adding My preference would be for something along the lines of this, where const posts1 = await connection.manager
.createQueryBuilder(Post, "post")
.orderBy({
"ST_Distance(post.geog, ST_GeometryFromGeoJSON(:origin))": {
origin, // a GeoJSON object; serialized to a string by typeorm (not because of any column information, but because it is an object)
order: "ASC"
}
})
.getMany(); This would allow for PostGIS-facilitated geometry operations, e.g. Unrelated: why are you using a |
@mojodna My opinion: the user shouldn't have to know PostGIS to sort things by distance. Just the same as they don't have to know other SQL to use TypeORM. Regarding geography vs. geometry, I'm not sure I know the exact difference. My use case is measuring distance between two geographical locations, so I assumed geography was best. Perhaps there needs to be simply |
I see where you're coming from. My feeling is that it leads down a long road where sorting by distance isn't specifically privileged. Users shouldn't have to know PostGIS to sort things by area, length, similarity, number of vertices... If we can provide clean ways for people to abstract these types of sorting criteria and provide documentation for e.g. distance (with the proper PostGIS function incantations), that might be best.
|
@mojodna Unfortunately I don't know quite enough about PostGIS to come up with an API for it all. The most common requests I see are for ordering by distance, and finding results within a certain area. Maybe it's justifiable to add functions/arguments for those two use cases? Anything else would be left up to queries like yours. Just a thought. But I may use your fork and above example myself for now. |
Yep, that'd make sense, I'd just want to draw a line for maintainers to be able to say "no" to an unreasonable proliferation of criteria while providing sufficient escape hatches to do weird, unexpected things. I'll see if I can sketch something out that allows parameters to be bound to |
I don't think you can do |
I didn't think so either and started down the path of adding const posts1 = await connection.manager
.createQueryBuilder(Post, "post")
.where("ST_Distance(post.geom, ST_GeomFromGeoJSON(:origin)) > 0")
.orderBy({
"ST_Distance(post.geom, ST_GeomFromGeoJSON(:origin))": {
order: "ASC",
nulls: "NULLS FIRST"
}
})
.setParameters({ origin: JSON.stringify(origin) })
.getMany(); const posts2 = await connection.manager
.createQueryBuilder(Post, "post")
.orderBy("ST_Distance(post.geom, ST_GeomFromGeoJSON(:origin))", "DESC")
.setParameters({ origin: JSON.stringify(origin) })
.getMany(); Having to stringify geometry objects and wrap them in I looked into automatically stringifying objects when passed to |
Thanks, did not know about |
Same here ;-) It's been good exploring it with you! |
Have you figured out how to npm install --save "github:mojodna/typeorm#postgis" |
It doesn't build when you do that. I had to change the https://github.com/OKNoah/typeorm/blob/e65ef1bcb30184e1c618e4870fa7701310a49064/package.json Note I put a It's on npm as |
@mojodna Hope you're enjoying your weekend, you deserve to on account of your capable hands' work on this! I have found another interesting project that goes hand-in-hand with PostGIS/ {"city": "victoria", "road": "first ave", "state": "bc", "house_number": "412"} Caveat: It requires a few GB of (machine learning?) data and high RAM usage (possibly negated by including postgres config stuff). But where one or both of us to create install arguments, or Combined, it makes an even greeter suite of spatial and address functions right within postgres. |
libpostal is pretty sweet. Fortunately, Paul's bindings expose it as a set of Postgres functions that return standard types, so I don't think there's a need to do anything within typeorm to specifically support it. As for maintaining |
@mojodna I'm sure it will make it into a release soon, it's working well for me. If this isn't a maxim already, it should be: "you you want to get a busy project maintained, get a busy project maintainer to maintain it". |
No description provided.