Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
moleculer-postgis
Advanced tools
@moleculer/database
projectThe moleculer-postgis
is designed to support Postgis functions for @moleculer/database
mixin.
To get started, install moleculer-postgis
package to your project.
npm i moleculer-postgis
yarn add moleculer-postgis
import PostgisMixin, { GeometryType } from 'moleculer-postgis';
module.exports = {
mixins: [
PostgisMixin({
srid: 3346,
}),
],
settings: {
fields: {
// example with geom and validating types
geom: {
type: 'any',
geom: {
types: [GeometryType.POINT, GeometryType.LINE_STRING],
},
},
area: {
type: 'number',
virtual: true,
geom: {
type: 'area',
},
},
},
},
};
Using mixin is simple. Import and define it as a function. To the function you can pass opts
such as global srid
.
import PostgisMixin from 'moleculer-postgis';
module.exports = {
mixins: [
PostgisMixin({
srid: 3346,
}),
],
};
module.exports = {
settings: {
fields: {
geom: {
columnName: 'geomfield', // optional
geom: {
type: 'geom', // define type - defaults to "geom"
types: [], // defining types,
multi: true, // defines handling multi geometries
validate({ ctx, params, value, field }) {
// validation function (same as @moleculer/database)
return true;
},
},
},
},
defaultPopulates: ['geom'],
},
};
module.exports = {
settings: {
fields: {
geom: {
geom: true,
},
},
},
};
Options:
Option | Default value | Type (available values) |
---|---|---|
type | geom | String - area , geom |
multi | false | Boolean |
types | All types | Array<string> or string |
validate | - | Function or string |
Types - Point
, LineString
, Polygon
, MultiLineString
, MultiPoint
, MultiPolygon
Query | |
---|---|
areaQuery | More info |
distanceQuery | More info |
asGeoJsonQuery | More info |
geometriesAsTextQuery | More info |
geomFromText | More info |
intersectsQuery | More info |
import { areaQuery } from 'moleculer-postgis';
const field = 'geomfield';
const fieldAs = 'geom';
// optional
const srid = 3346;
// ROUND(ST_Area("geomfield")) as "geom"
// If srid is passed, ST_Transform is applied
areaQuery(geom, fieldAs, srid);
import { distanceQuery } from 'moleculer-postgis';
const field1 = 'geomfield';
const field2 = 'geomfield2';
const resultAs = 'distance';
// optional
const srid = 3346;
// ROUND(ST_Distance("geomfield", "geomfield2")) as "distance"
// If srid is passed, ST_Transform is applied for each field
distanceQuery(field1, field2, resultAs, srid);
import { asGeoJsonQuery } from 'moleculer-postgis';
const field = 'geomfield';
const resultAs = 'geom';
// optional
const srid = 3346;
const opts = {
digits: 0,
options: 0,
};
// ST_AsGeoJSON("geomfield")::json as "geom"
// If srid is passed, ST_Transform is applied for each field. Options are not applied if not passed
asGeoJsonQuery(field, resultAs, srid, opts);
import { geometriesAsTextQuery } from 'moleculer-postgis';
const geometry = {
type: 'Point',
coordinates: [11, 22],
};
// ST_AsText(...)
// If passed multi geometries - it will use ST_Collect
geometriesAsTextQuery(geometry);
import { geomFromText, geometriesAsTextQuery } from 'moleculer-postgis';
const geometry = {
type: 'Point',
coordinates: [11, 22],
};
const srid = 3346;
// ST_AsText(...)
const text = geometriesAsTextQuery(geometry);
// ST_GeomFromText(...)
// If srid is passed - ST_Transform is applied
geomFromText(text, srid);
import { intersectsQuery } from 'moleculer-postgis';
// any type of geometry can be passed (feature collection, feature, array of feature collections, etc)
const geometry = {
type: 'Point',
coordinates: [11, 22],
};
const field = 'geomfield';
const srid = 3346;
// ST_intersects(...)
// If srid is passed - ST_Transform is applied
intersectsQuery(field, geometry, srid);
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request. For more information, see the contribution guidelines.
This project is licensed under the MIT License.
FAQs
Postgis mixin and functions for @moleculer/database
The npm package moleculer-postgis receives a total of 4 weekly downloads. As such, moleculer-postgis popularity was classified as not popular.
We found that moleculer-postgis demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.