question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for custom column types

See original GitHub issue

Hi 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:closed
  • Created 10 years ago
  • Comments:24 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Mar 23, 2016

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).

var newPhysical = Physical
  .query('insert', {
    geo: 'SRID=4326; POINT (' + x + ' ' + y)'
  })
  .save()
  .then(...)

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]

0reactions
crunchtime-alicommented, Jul 19, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a custom column (Power Query) - Microsoft Support
Add a custom column ; To open a query, locate one previously loaded from the Power Query Editor, select a cell in the...
Read more >
Support for Custom Column Types? · Issue #53 - GitHub
Is there a way to handle these custom column types? Do I need to just subclass SQLAlchemyObjectType and make it understand what that...
Read more >
Create a Custom Data Type - Salesforce Developers
The default layout for custom data types is the bare layout. See Customize Data Type Layout and Styles. You can use the standardCellLayout...
Read more >
Model Entity with Custom Column Types
Right click on the column and select Open Specification from popup menu. Specify the custom column type in the User Type. Press OK...
Read more >
Define Data Type in the Custom Column step in Power Query
In this post you learn how to define the Data Type in the same step in which you add a custom column. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found