-
Notifications
You must be signed in to change notification settings - Fork 2
Home
pg-manati is an advanced access to a PostgreSQL database using REST API. It is based on Node.js.
Most development of web application involves a frontend programmer and a backend developer, sometime a Database Administrator. Most backend development often consists of creating simple CRUD access to the database, and for that most programmer will use an ORM. One of the main feature is this abstraction of the SQL language that allows you to manipulate row easily and change database like you change configuration.
However this bring an important problem, you cannot use your database to its fullest because the ORM abstraction is based on a common denominator of all the databases it supports, and you have to learn the ORM documentation. Besides you actually never change database. In fact this should be the last thing you change in your application, as it would require a major migration and code refactoring (even with an ORM!).
- Bring PostgreSQL powerfulness directly to the Frontend developer through the REST paradigm.
- Allow maximum freedom of development and design for the database programmer.
npm install pg-manati --save
var manati = require('pg-manati');
var app = manati(
process.env.DATABASE_URL || 'postgres://user@localhost/database', // your database connection string
'info' // the minumum log level that will be output
);
You can extend Koa.js with your own generator. To add CORS for instance. See http://koajs.com/ for more info
app.koa.use(require('koa-cors')());
Add plugins, a single
// add authentication routes to the list
app.addPlugin('authentication');
// add authentication middleware for all routes in the data router (route starting with /data)
app.addPlugin('authorization');
// add your own plugin
app.addPlugin(require('manati-plugin'));
Setup manati
if (process.argv[2] === '--setup') {
app.setup().then(() => {
console.log('Installation successfull');
process.exit(0);
})
}
Initialize manati
app.init();
Start manati
app.start();
GET /data/users?limit=2&name=like::J*
[{"name": "John", "age": 22}, {"name": "Jessie", "age": 30}]
PATCH /data/users?name=eq::Jessie
Content-Type application/json
{
"age": 23
}
[{"name": "John", "age": 22}, {"name": "Jessie", "age": 23}]
POST /data/users
Content-Type application/json
{
"name": "Joe",
"age": 21
}
[{"name": "Joe", "age": 21}]
DELETE /data/users?name=eq::John
[{"name": "John", "age": 22}]