Registry / database / ganjiang-middleware

ganjiang-middleware

JSON →
library3.8.9jsnpmunverified

Middleware for Express to auto-generate REST APIs from SQL queries against GeoEngineDS (a geo-spatial data service). Version 3.8.9 requires Node >= 8.9.0 and uses ESM imports. Supports dynamic SQL assembly with query parameterization for injection prevention, multiple output formats (origin, GeoJSON), and lifecycle hooks (beforeSend, afterSend, onError). Differentiator: maps data source IDs to SQL endpoints declaratively with built-in SQL injection protection using context.format.

npm install ganjiang-middleware
INSTALL
IMPORT
SIG · GANJIANG-MIDDLEWAR
G
ganjiang-middleware
databasejavascriptv3.8.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import GeoEngineDS from 'GeoEngineDS'
const GeoEngineDS = require('GeoEngineDS')
Package is ESM-only; CommonJS require is not supported.
bodyParser
import bodyParser from 'body-parser'
const bodyParser = require('body-parser')
body-parser is a separate package, not bundled. Use ESM import for consistency.
express
import express from 'express'
Cannot use as default export without 'default'
Express is a peer dependency and must be imported as ESM.

Sets up an Express app with GeoEngineDS middleware to auto-generate an API endpoint /api/data that executes a SQL query.

import GeoEngineDS from 'GeoEngineDS'; import bodyParser from 'body-parser'; import express from 'express'; const app = express(); const config = { host: 'http://your-geoengine-ds-host', token: 'your-token', DEBUG: false, dsMap: { myds: 1 }, apiList: { myds: [ { ds: 'myds', path: '/api/data', sql: async (req) => `SELECT * FROM mytable WHERE id = ${req.query.id}`, type: 'origin', token: 'optional-endpoint-token' } ] } }; app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(GeoEngineDS(app, config)); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
gotchaSQL injection risk if using string interpolation in sql function instead of context.format
fix
Use context.format(sql, params) to safely parameterize queries.
affects: *
gotchabody-parser must be applied before GeoEngineDS middleware
fix
Ensure app.use(bodyParser...) comes before app.use(GeoEngineDS(...)).
affects: *
gotchaGeoEngineDS middleware expects a single configuration object; missing dsMap or apiList will throw errors.
fix
Provide both dsMap (object with ds name to id mapping) and apiList (array of route definitions).
affects: *
deprecatedNode.js versions below 8.9.0 are no longer supported.
fix
Upgrade Node.js to >=8.9.0.
affects: <3.0
Errors
Common errors & fixes
Error: Cannot find module 'GeoEngineDS'
Package name is case-sensitive; actual npm package name may differ.
fix
Install using 'npm install ganjiang-middleware' then import from 'ganjiang-middleware'.
TypeError: GeoEngineDS is not a function
Using CommonJS require instead of ESM import.
fix
Use import GeoEngineDS from 'GeoEngineDS' in ESM module.
Error: dsMap must be an object
Configuration missing dsMap property or it is not an object.
fix
Ensure config.dsMap is defined as an object with string keys and numeric values.
Upgrade
Version history
3.8.9latest on npm
Audit
Dependencies
expressrequiredpeer dependency - middleware is designed for Express
body-parserrequiredrequired for parsing JSON/URL-encoded request bodies
Agent activity
6 hits · last 30 days
node
6
Resources
ganjiang-middleware — npm install ganjiang-middleware · libregistry