
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
koa-postgresql-pool-connector
Advanced tools
it's wrapper ready to use for making query to a postgresql database very easy and simple.
The MIT License (MIT)
koa-postgresql-pool-connector is a wrapper on top of koa-pg ready to use.
Practical information
Files tree
Installation
API documentation
Example
Acknowledgement
Other project
You must be familiar with :
./
├── examples // Contain one working example.
│ └── index.js
├── .gitignore
├── index.js // Current npm module sources
├── LICENSE
├── package.json
├── README.md
└── __tests__ // Jest Unit Tests
│ └── index-test.js
└── .travis.yml
$ npm install koa-postgresql-pool-connector
This is a simple code overview of how to use koa-postgresql-pool-connector.
After you added the module to your nodeJs app, this.sqlQuery
will be available from every koa generator scope functions.
Param name | Description | Mandatory |
---|---|---|
databaseUrl | string which should contain the database connection info | YES |
query | string which should contain the query to execute on PG db | YES |
Return | promise which you could use as you want for callback | always present |
/**
* module for db pool connection
* @param databaseUrl key
* @param query to execute by client
* @return promise
*/
const app = require( 'koa' )(),
router = require( 'koa-joi-router' )(),
dbCo = require( 'koa-postgresql-pool-connector' );
app.use( dbCo );
app.use( router.middleware() );
router.post('/example',function* (next){
const query = 'postegresql query';
this.sqlQuery("urlDb",query)
.then(function( respData ){
//do your stuf after query execution
})
});
Following example could be found inside /examples
directory.
Live test it by doing npm run devExample
, which will start nodejs instance with koa/koaPostgres api with 3 working path.
Don't forget to set a postgresSql Db on your local computer to make the example server work.
*current db url connection : postgres://postgres:postgres@localhost:5432/postgres
const
we will need.// const dbCo is our koa-postgresql-pool-connector
const koa = require( 'koa' ),
dbCo = require( '../index.js' ),
dbUrl = '',
router = require( 'koa-joi-router' )(),
bodyParser = require( 'koa-bodyparser' ),
app = koa();
// add our koa-postgresql-pool-connector module to nodeJs app as middleware.
app.use( dbCo );
// use a koa bodyparser to get form data as middleware.
app.use( bodyParser() );
// declare a koa joi router as middleware.
app.use( router.middleware() );
router
.post( '/createFilmTable', function* ( next ) {
'use strict';
// just call this.sqlQuery and you will get you function to request database with a query and a callback to execute at the end
this.sqlQuery( 'postgres://postgres:postgres@localhost:5432/postgres',
"CREATE TABLE films (" +
"id serial NOT NULL, CONSTRAINT films_pkey PRIMARY KEY (id)," +
"title varchar(40) NOT NULL," +
"kind varchar(10)," +
");"
)
} )
.get( '/films/', function* ( next ) {
'use strict';
let that = this;
yield this.sqlQuery( 'postgres://postgres:postgres@localhost:5432/postgres',
"SELECT * FROM films;"
).then( function ( data ) {
if ( data.name === "error" ) {
that.status = 500;
that.body = data;
}
if ( data.rowCount !== 0 ) {
that.status = 200;
that.body = { data: data.rows }
}
else {
that.status = 204
}
} );
} )
.post( '/films/', function* ( next ) {
'use strict';
let data = this.request.body,
that = this;
if ( data.title && data.kind ) {
yield this.sqlQuery( 'postgres://postgres:postgres@localhost:5432/postgres',
'INSERT INTO films (title,kind) VALUES (\'' + data.title + '\',\'' + data.kind + '\')' )
.then( function ( data ) {
console.log( arguments );
if ( data.name === "error" ) {
that.status = 500;
that.body = data;
}
if ( data && data.rowCount !== 0 ) {
that.status = 200;
that.body = { data: data.rows };
}
else {
that.status = 204;
}
} );
}
else {
this.status = 400;
this.body = { error: 'missing title or kind key with values' };
}
} );
3000
app.listen( 3000 );
Thanks to @Companeo for let me post this module I developped for work under open source license. Thanks to @MathRobin for his help and introduction to Koa.
You may also like this project : git-hooks-versionned
FAQs
it's wrapper ready to use for making query to a postgresql database very easy and simple.
We found that koa-postgresql-pool-connector demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.