• Stars
    star
    116
  • Rank 294,368 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Non-interactive PostgreSQL query tool.

pgcmd

Non-interactive PostgreSQL query tool.

By default, it outputs JSON which means that you can process and view the results with tools like jq or catj.

Install

npm install -g pgcmd

Usage

pgcmd -h localhost \
      -u postgres \
      -p p@ssw0rd \
      -d postgres \
      'select * from pg_database where datname = $1' \
      -m template0

If no script is specified, pgcmd reads from the standard input:

echo 'select * from pg_database where datname = $1' | pgcmd -m template0

Output:

[
  {
    "datname": "template0",
    "datdba": 10,
    "encoding": 6,
    "datcollate": "en_US.utf8",
    "datctype": "en_US.utf8",
    "datistemplate": true,
    "datallowconn": false,
    "datconnlimit": -1,
    "datlastsysoid": 13066,
    "datfrozenxid": "562",
    "datminmxid": "1",
    "dattablespace": 1663,
    "datacl": "{=c/postgres,postgres=CTc/postgres}"
  }
]

It can also output CSV:

pgcmd 'select * from pg_database' --csv

Output:

datname,datdba,encoding,datcollate,datctype,datistemplate,datallowconn,datconnlimit,datlastsysoid,datfrozenxid,datminmxid,dattablespace,datacl
postgres,10,6,en_US.utf8,en_US.utf8,,1,-1,13066,562,1,1663,
template1,10,6,en_US.utf8,en_US.utf8,1,1,-1,13066,562,1,1663,"{=c/postgres,postgres=CTc/postgres}"
template0,10,6,en_US.utf8,en_US.utf8,1,,-1,13066,562,1,1663,"{=c/postgres,postgres=CTc/postgres}"

Environment Variables

The following environment variables are supported:

  • PGHOST
  • PGPORT
  • PGUSER
  • PGPASSWORD
  • PGDATABASE

Version History

  • 1.2
    • Removed the default timeout.
  • 1.1
    • Added --csv output option.
    • Added support for Node 14. (Thanks darky)
    • Set exit code on errors. (Thanks darky)
  • 1.0
    • Initial release.

Author

Soheil Rashidi

Copyright and License

Copyright 2020 Soheil Rashidi.

Licensed under the The MIT License (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.opensource.org/licenses/mit-license.php

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

mailwind

Use Tailwind CSS to design HTML emails.
JavaScript
3,110
star
2

catj

Displays JSON files in a flat format.
1,324
star
3

mon

Painless performance monitoring for Windows.
JavaScript
77
star
4

traq

Super simple email open/click tracking server.
JavaScript
67
star
5

sqltop

Find the most resource consuming SQL Server queries.
JavaScript
37
star
6

mann

With mann you will never forget command line options again.
JavaScript
35
star
7

sqlmon

Collects events from SQL Server and saves them to Elasticsearch for further analysis.
JavaScript
35
star
8

sqlcmd

sqlcmd for Mac and Linux.
JavaScript
21
star
9

Sherlock-iOS

A simple password and personal information manager for iOS with Dropbox and Google Drive support.
Objective-C
16
star
10

Clipboard

Cross-platform clipboard library for .NET Core.
C#
14
star
11

Ledger

Interactive CLI double-entry accounting application.
C#
10
star
12

zsh-vi-search

Adds support for searching the current line (in normal vi mode) to zsh.
Shell
10
star
13

buno

Run custom scripts before and after executing a command.
JavaScript
10
star
14

Xinq

Easily manage database queries inside Visual Studio.
C#
8
star
15

DueNext

An iPhone app that displays upcoming events from your calendars in a simple and easy-to-read list.
Objective-C
7
star
16

nautilus

Modern issue tracker.
TypeScript
6
star
17

nestbreak

A Twitter API proxy in Node.js
JavaScript
5
star
18

youtrack2gitlab

Import YouTrack issues into GitLab.
JavaScript
4
star
19

jalalify

Detects and converts dates in the input stream from Gregorian to Jalali and vice versa.
JavaScript
4
star
20

HTTPKit

A simple and extremely lightweight asynchronous HTTP library for Objective-C.
Objective-C
3
star
21

tweetever

Keep your tweets forever with this little Node.js app.
JavaScript
2
star
22

deligle

An extention for Google Chrome that displays matching links from your Delicious bookmarks in Google search results.
JavaScript
2
star
23

Rhapsody

An easy to use ID3 Tag editor for Windows.
C#
2
star
24

Sherlock-MacCLI

A simple console password and personal information manager for Mac.
Objective-C
2
star
25

concert-finder

An alternative user interface for songkick.com.
JavaScript
2
star
26

postchi

Send email from the command line using SMTP or major service providers.
JavaScript
1
star
27

Sherlock-CLI

Cross-platform password and personal information manager.
C#
1
star
28

swing

C
1
star
29

xformat

Simple templating for the command line.
JavaScript
1
star
30

Sherlock-Win

A simple password and personal information manager for Windows.
C#
1
star
31

xcodefly

Speeds up Xcode builds by moving the DerivedData folder to a RAM disk.
Shell
1
star