PG View Grabber
Grab view information from a Postgres database.
Use
Install the module with:
npm install pg-view-grabber --save
Configuration
You’ll need to pass in Postgres connection info that will be passed to pg’s Client
constructor. This can either be a connection string (Ex: postgres://username:password@localhost/database
) or an object:
var myConfig = {
database: 'postgres',
host: 'localhost',
password: '',
port: 5432,
user: 'root',
};
Then, pass it in like so:
var pgViewGrabber = require('pg-view-grabber');
pgViewGrabber.config(myConfig);
You’re ready to get started!
API
These methods hang off the main pg-view-grabber
module:
pgViewGrabber.config(clientConfig)
- Arguments:
clientConfig
(object or string): database configuration passed to pg’s Client
- Returns:
pgViewGrabber.fromTable(tableName)
- Arguments:
tableName
(string): name of table for which to find dependent views
- Returns:
Promise
that resolves to an array of ‘view data’ objects with the following keys:
viewData.definition
: the view's SQL definitionviewData.permissions
: the view's owner and permissions SQLviewData.schema
: the view's schema nameviewData.viewName
: the view name itself
pgViewGrabber.fromView(viewName)
- Arguments:
viewName
(string): name of view for which to find dependent views
- Returns:
Promise
that resolves to an array of 'view data' objects
Liquibase Migration Methods
All Liquibase methods have the same argument object:
- Arguments:
options
(object):
options.name
(string): Name of table or viewoptions.author
(optional string): “author” for the migration fileoptions.formatFilename
(optional function): a function responsible for formatting each migration file's filename. It’s passed a filenameOptions
object with the following keys:
filenameOptions.author
filenameOptions.id
filenameOptions.schema
filenameOptions.viewName
options.id
(optional string or number): changeset “id” for the migration file
pgViewGrabber.getTableMigration(options)
- Returns:
Promise
that resolves to an array of Liquibase migration templates
pgViewGrabber.getViewMigration(options)
- Returns:
Promise
that resolves to an array of Liquibase migration templates
pgViewGrabber.saveTableMigration(options)
- Returns:
Promise
that resolves to an array of empty values when all migration files are written
pgViewGrabber.saveViewMigration(options)
- Returns:
Promise
that resolves to an array of empty values when all migration files are written
Testing
Testing assumes you’re on the MRN VPN and you have a valid database map in /coins/coins_auth/conn/dbmap.json. Run tests with npm test
. Run linting with npm run lint
.