You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Jorge Godoy 03e8a8fb4c bump version to 0.14.1 3 months ago
examples avoid knex warning on deprecated dialect option 2 years ago
lib replace deprecated @mapbox/geojsonhint with @placemarkio/check-geojson 3 months ago
tests replace deprecated @mapbox/geojsonhint with @placemarkio/check-geojson 3 months ago
types update type definition (#50) 3 months ago
.editorconfig basic postgis functions 7 years ago
.eslintrc replace .jscsrc and .jshintrc with .eslintrc 5 years ago
.gitignore add st_multi function (#44) 7 months ago
.travis.yml update supported node versions in travis 3 months ago
CHANGELOG.md bump version to 0.14.1 3 months ago
LICENSE basic postgis functions 7 years ago
README.md update travis badget 3 months ago
package.json bump version to 0.14.1 3 months ago

README.md

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

Define extra 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