Need help with knex-postgis?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

jfgodoy
144 Stars 20 Forks MIT License 125 Commits 2 Opened issues

Description

postgis extension for knex

Services available

!
?

Need anything else?

Contributors list

# 265,239
HTML
socket-...
Shell
Node.js
87 commits
# 9,846
Ruby
Shell
Node.js
coffees...
12 commits
# 137,737
HTML
React
Webpack
webpack...
2 commits
# 414,991
Ruby
Shell
Heroku
rake
2 commits
# 97,145
vuejs
axios
c-plus-...
jira
1 commit
# 269,545
actionc...
Rails
Elixir
Shell
1 commit
# 671,794
JavaScr...
knex
postgis
1 commit
# 709,146
JavaScr...
knex
postgis
1 commit
# 30,229
JavaScr...
HTML
React
Algolia
1 commit

knex-postgis

npm version npm downloads Build Status Dependencies Status License

Extension for use postgis functions in knex SQL query builder.

Example

This example show the sql generated by the extension.

const knex = require('knex');
const knexPostgis = require('knex-postgis');

const db = knex({ client: 'postgres' });

// install postgis functions in knex.postgis; const st = knexPostgis(db); /* or:

  • knexPostgis(db);
  • const st = db.postgis;
  • /

// insert a point const sql1 = db.insert({ id: 1, geom: st.geomFromText('Point(0 0)', 4326) }).into('points').toString(); console.log(sql1); // insert into "points" ("geom", "id") values (ST_geomFromText('Point(0 0)'), '1')

// find all points return point in wkt format const sql2 = db.select('id', st.asText('geom')).from('points').toString(); console.log(sql2); // select "id", ST_asText("geom") as "geom" from "points"

// all methods support alias const sql3 = db.select('id', st.asText(st.centroid('geom')).as('centroid')).from('geometries').toString(); console.log(sql3); // select "id", ST_asText(ST_centroid("geom")) as "centroid" from "geometries"

Currently supported functions

const knex = require('knex');
const knexPostgis = require('knex-postgis');

const db = knex({ client: 'postgres' });

knexPostgis(db);

db.postgisDefineExtras((knex, formatter) => ({ utmzone(geom) { return knex.raw('utmzone(?)', [formatter.wrapWKT(geom)]); } })); //now you can use st.utmzone function in the same way as predefined functions

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.