Support for custom column types
See original GitHub issueHi Tim, I have been using your framework for couple of months and I still pretty much like it. Once the project become public( within two months), I will send you a link 😃
In my project I need geo spatial indexing, I am using postgis with postgres for this.
My problem is that I wasn’t able to push native db method calls inside query.
This a naive pseudo code, I did try a lot of different approaches inside Bookshelf and than also just Knex
new User({name: 'Jakub', location: ' st_GeographyFromText('SRID=4326;POINT(%s %s)')", lng, lat)' })
I think it’s even not possible to do this with Knex query builder as it pass arguments via sql binding (prepated statements) which will escape it into unreadable format.
So i had to workaround with a separate query through knex.raw
Bookshelf.knex.raw(_.string.sprintf("select * from st_GeographyFromText('SRID=4326;POINT(%s %s)')", long, lat)).then(function(result) {var location = result.rows[0].st_geographyfromtext
// do something more with location
new User({name: 'Jakub', location: location})
})
Which is somehow sub optimal for me. Another important issue is when I am doing query:
right now I have something like this
Knex.raw('select id, iso2, name, "continentCode", ST_AsGeoJSON(location) from countries where id in ('+countryIds.join(',')+');')
I think I can not force Object in Bookshelf or Knex Query Builder to append a transformer function on select… so I end up with what you see above…
Or maybe I have overlooked something, and you can point me in right direction how to implement somehow more smooth integration?
Thanks a lot!
Jakub
Issue Analytics
- State:
- Created 10 years ago
- Comments:24 (13 by maintainers)
You can insert spatial data using the EWKT format as a simple string literal and it is inserted and handled without error (See http://postgis.net/docs/manual-1.3/ch04.html#id435014).
This is stored in postgres as a hashed geometry object that is converted back to the appropriate lat/lon using ST_AsText using
SELECT ST_ASText(geo) as geo from [tablename]
The project leadership of Bookshelf recently changed. In an effort to advance the project we close all issues older than one year.
If you think this issue needs to be re-evaluated please post a comment on why this is still important and we will re-open it.
We also started an open discussion about the future of Bookshelf.js here https://github.com/bookshelf/bookshelf/issues/1600. Feel free to drop by and give us your opinion. Let’s make Bookshelf great again