@nautoguide/grunt-pgsql v0.1.7
grunt-pgsql
Postgresql sql runner
Note this is an early release package, its functional but lacks tests, welcome issues reporting but please be aware releases may change config layout.
Getting Started
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install @nautoguide/grunt-pgsql --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('@nautoguide/grunt-pgsql');
The "pgsql" task
Overview
In your project's Gruntfile, add a section named pgsql
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
pgsql: {
options: {
configFile: '../db_creds.json',
configSection: 'myDatabase'
},
tables: [
'path/to/my.sql'
]
},
});
Options
options.configFile
Type: String
Default value: null
Location of your config file in the json format:
{
"live":"pg://user:pass@localhost:5432/myDatabase",
"test":"pg://user:pass@localhost:5432/myDatabase",
"default":"pg://user:pass@localhost:5432/myDatabase"
}
Or yaml:
dev:
foo: bar
postgres: pg://user:pass@localhost:5432/myDatabase
localhost:
bar: foo
postgres: pg://user:pass@localhost:5432/myDatabase
See options.configObjectName for how to specify the object path EG: configObjectName:"postgres" from this example
You would normally store this outside your code repo so avoid your credentials ending up in in version control
options.configSection
Type: String
Default value: 'default'
Section of the config file to use options.configFile
options.configType
Type: String
Default value: 'json'
Format type of the options.configFile. We support json (default) or yaml. Yaml was added to support loading of credentials from serverless env.yml files and should be used with options.configObjectName
options.configObjectName
Type: String
Default value: 'undefined'
If you config file contains a further level of depth, EG as per the yaml example then add the object path here.
options.connection
Type: String
Default value: 'default'
Connect string to use. DO NOT USE THIS IF YOU DONT WANT DB CREDS IN YOUR GIT REPO
Usage Examples
Default Options
Load our creds from '../db_creds.json' using section 'live' to connect and run all .sql files in configuration/reports/**/
grunt.initConfig({
pgsql: {
options: {
configFile: '../db_creds.json',
configSection: 'live'
},
tables: [
'configuration/reports/**/*.sql'
]
}
});
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
(Nothing yet)
Development
Deploy package
Ensure you have incremented the version number and created a github release to match that version number then run
npm login
npm publish