koa-postgresql-pool-connector
The MIT License (MIT)
koa-postgresql-pool-connector is a wrapper on top of koa-pg ready to use.
Table of Contents
Practical information
Files tree
Installation
API documentation
Example
Acknowledgement
Other project
Practical information
You must be familiar with :
Files tree
./
├── 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
Installation
$ npm install koa-postgresql-pool-connector
API documentation
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.
this.sqlQuery
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 */
code simplification
const app = router = dbCo = ; app;app; router;
Example
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
Example overview
- set every
const
we will need.
// const dbCo is our koa-postgresql-pool-connectorconst koa = dbCo = dbUrl = '' router = bodyParser = app = ;
- add middlewares to Nodejs app.
// add our koa-postgresql-pool-connector module to nodeJs app as middleware.app;// use a koa bodyparser to get form data as middleware.app;// declare a koa joi router as middleware.app;
- create specifiques routes via koi-joi-router. We see that i passed callbacks to every routes
router ;
- register start nodejs server on port
3000
app;
Acknowledgement
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.
Other project
You may also like this project : git-hooks-versionned