flexgres
Flexibly change your Postgres schemas with Flexgres
By Chris Cates :star:
Installation
npm install flexgres --save
Usage
You will need to use the pg
driver.
You can install it by writing:
npm install pg --save
Configuring your table is really simple all you have to do is define your table structure in JSON.
An example usage is:
var name = "chris", password = "12345", host = "localhost", port = "5432", db = "flexgres";
var client = require("pg");
var queryConn = "postgres://"+name+":"+password+"@"+host+":"+port+"/"+db+"";
client = new pg.Client(queryConn);
require("flexgres")({
"driver": client,
"logging": true,
"tables": [
{
"tableName": "test",
"columns": [
{
"name": "id",
"type": "INT",
"primary": true,
"null": false
},
{
"name": "name",
"type": "text",
"primary": true,
"null": false
}
]
},
{
"tableName": "testTable",
"columns": [
{
"name": "test",
"type": "INT",
"primary": true,
"null": false
},
{
"name": "test2",
"type": "text",
"primary": false,
"null": false
}
]
}
]
})
So pretty much there are three JSON key values:
- driver: this is the
pg
object with query connection string. - logging: enable this is if you want to keep track of the SQL queries executed on your database.
- tables: This is an array of the tables in your JSON object. See above demo to see how to structure
your tables.