npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pg_servicefile_util

v1.0.1

Published

CLI and library for utilizing Postgres Service Files

Downloads

20

Readme

pg_servicefile_util

CLI and library for utilizing Postgres Service Files

Install

CLI

npm install -g pg_servicefile_util pg_servicefile_util --help

Library

npm install pg_servicefile_util import {toConnectionUri, toEnv, getServiceConfig} from 'pg_servicefile_util'

CLI Usage

> pg_servicefile_util --help
pg_servicefile_util <service>


Get parameters for specified Postgres service from well-known service file locations.

Example locations:
  ./.pg_service.conf
  ~/.pg_service.conf
  %APPDATA%\postgresql\.pg_service.conf
  /etc/postgresql/.pg_service.conf
  $PGSERVICEFILE

For more details, see:
  https://www.postgresql.org/docs/current/libpq-pgservice.html


Positionals:
  service  Service name to use within service file  [default: "postgres"]

Options:
      --help      Show help  [boolean]
      --version   Show version number  [boolean]
      --uri       Return service file parameters formatted as a connection uri  [boolean]
      --env       Sets environmental variables from service file parameters (as their Postgres-equivalent)  [boolean]
  -p, --printenv  Prints the Postgres-equivalent environmental variables formatted for passing to `eval` or `source`  [boolean]

File Locations

  • Windows

%APPDATA%\postgresql.pg_service.conf

  • Unix

~/.pg_service.conf

  • Local

./.pg_service.conf

  • Environment

$PGSERVICEFILE

  • System

$PGSYSCONFDIR/pg_service.conf

Examples

This is an example .pg_service.conf file (that should exist in one of the locations above)

[postgres]
host=localhost
port=5432
user=postgres
dbname=postgres

[sandbox]
host=sandbox.example.com
port=5435
user=sandbox
password=sandbox
dbname=postgres

Note: The service names don't have to be postgres or sandbox -- these are just examples. They can be anything you want (though, postgres is the default service name when one isn't passed to the cli).

For more details, see libpq-connect.

Print connection uri string for postgres service

pg_servicefile_util postgres

postgresql://postgres@localhost:5432/postgres

Print connection uri string for sandbox service

pg_servicefile_util sandbox

postgresql://sandbox:[email protected]:5435/postgres

Set env variables for sandbox service

pg_servicefile_util sandbox --env

echo $PGHOST # sandbox.example.com

Eval (or source) env variables for sandbox service in current session

eval $(pg_servicefile_util sandbox --printenv)

echo $PGHOST # sandbox.example.com

Pass to psql (and run sql query)

echo "SELECT 1" | psql $(pg_servicefile_util postgres)

?column?
----------
       1
(1 row)

Api examples

import {toConnectionUri, toEnv, getServiceConfig} from 'pg_servicefile_util'

// TODO...

TODO

  • [ ] Finish README
  • [ ] Document support and extensions (e.g., "recursive" service name keys)
  • [ ] Add examples of api usage for common pg clients
  • [ ] Add support for an init command that will generate a .pg_service.conf file
  • [ ] Default to using postgres (or possibly default) as the default "service name" and allow the binary/cli to be run w/o any arguments!