0.14.3 • Published 3 years ago
knex-postgis v0.14.3
knex-postgis
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
- area(geom), see postgis documentation
- asText(column), see postgis documentation
- asGeoJSON(column), see postgis documentation
- asEWKT(column), see postgis documentation
- buffer(geom, radius), see postgis documentation
- centroid(geom), see postgis documentation
- distance(geom, geom), see postgis documentation
- distanceSphere(geom, geom), see postgis documentation
- dwithin(geom, geom, distance, / optional bool spheroid /), see postgis documentation
- intersection(geom1, geom2), see postgis documentation
- intersects(geom1, geom2), see postgis documentation
- geography(geom)
- geographyFromText(ewkt), see postgis documentation
- geometry(geography)
- geomFromText(geom, srid), see postgis documentation
- geomFromGeoJSON(geojson /object, string or column name/), see postgis documentation
- makeEnvelope(minlon, minlat, maxlon, maxlat, / optional integer SRID /), see postgis documentation
- makePoint(lon, lat, / optional z /, / optional measure /), see postgis documentation
- makeValid(geom), see postgis documentation
- point(lon, lat), see postgis documentation
- transform(geom, srid), see postgis documentation
- within(geom, geom), see postgis documentation
- setSRID(geom, srid), see postgis documentation
- x, see postgis documentation
- y, see postgis documentation
- z, see postgis documentation
- m, see postgis documentation
- boundingBoxIntersects(geom a, geom b), represented as
a && b
, see postgis documentation - boundingBoxContained(geom a, geom b), represented as
a @ b
, see postgis documentation - boundingBoxContains(geom a, geom b), represented as
a ~ b
, see postgis documentation - multi(geom), see postgis documentation
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
0.14.2
3 years ago
0.14.3
3 years ago
0.14.1
3 years ago
0.14.0
3 years ago
0.13.0
4 years ago
0.12.0
5 years ago
0.11.0
5 years ago
0.10.0
5 years ago
0.9.0
5 years ago
0.8.1
5 years ago
0.8.0
6 years ago
0.7.0
6 years ago
0.6.0
7 years ago
0.5.0
7 years ago
0.4.0
7 years ago
0.3.0
7 years ago
0.2.2
8 years ago
0.2.1
8 years ago
0.2.0
8 years ago
0.1.11
8 years ago
0.1.10
8 years ago
0.1.9
8 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago
0.1.5
10 years ago
0.1.4
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago
0.0.1
10 years ago