Created
July 25, 2018 12:08
-
-
Save raimohanska/7119db9dcf3deebd96601e711a421506 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
if (process.argv.length != 3) { | |
console.error("Usage: psqlurl <url>") | |
console.error("Expected one argument, got " + (process.argv.length - 2)) | |
process.exit(1) | |
} | |
var input = process.argv[2] | |
var URL = require("url") | |
var ps = require("child_process") | |
var url = URL.parse(input) | |
var command = "psql -h " + url.hostname + " -p " + url.port | |
if (url.auth) { | |
var username = url.auth.split(":")[0] | |
var password = url.auth.split(":")[1] | |
command = "PGPASSWORD=" + password + " " + command + " -U " + username | |
} | |
if (url.path) { | |
var dbname = url.path.substring(1) | |
command = command + " -d " + dbname | |
} | |
console.log("running: " + command) | |
result = ps.execSync(command, {stdio:[0,1,2]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment