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

@rxifyjs/pg

v1.2.2

Published

RxJS wrapper for "pg"

Downloads

14

Readme

@rxifyjs/pg

Provides RxJS wrappers for node-postgres and a cli for executing local Postgres files and scripts.

We have attempted to create wrappers for most of the functionality that is required for the middle tier of an application, including connection pooling, cursors, query streaming, and one-off client creation.

If you identify a missing features or bug, open a PR or submit a feature request or bug report.

For detailed documentation, visit our GitHub page.

CLI

pg-runner is a lightweight alternative to Postgres IDEs. It provides developers with the ability to run SQL scripts and queries directly from their VSCode terminal.

Options

| Option | Alias | Description | | ----------- | ----- | --------------------------------------------------- | | --script | -s | Execute a script wrapped in double quotes. | | --path | -p | Provide a path to a local .sql script to execute. | | --format | -f | The format of the results printed to the console. | | --values | -v | Provide dynamic values. | | --cursors | | Flag indicating that -s or -p returns cursors. | | --psql | | Opens a psql session. |

Examples

--script

$ pg-runner --script "SELECT * FROM my_table"
SELECT RETURNED n rows.
┌─────────┬────────────┬───────────┬──────────┐
│ (index) │  column_a  │ column_b  │ column_n │
├─────────┼────────────┼───────────┼──────────┤
│    1    │  'aa_val'  │ 'ab_val'  │ 'an_val' │
│    2    │  'ba_val'  │ 'bb_val'  │ 'bn_val' │
│    n    │  'na_val'  │ 'nb_val'  │ 'nn_val' │
└─────────┴────────────┴───────────┴──────────┘

--path

$ pg-runner --path "./my-script.sql"
SELECT RETURNED n rows.
┌─────────┬────────────┬───────────┬──────────┐
│ (index) │  column_a  │ column_b  │ column_n │
├─────────┼────────────┼───────────┼──────────┤
│    1    │  'aa_val'  │ 'ab_val'  │ 'an_val' │
│    2    │  'ba_val'  │ 'bb_val'  │ 'bn_val' │
│    n    │  'na_val'  │ 'nb_val'  │ 'nn_val' │
└─────────┴────────────┴───────────┴──────────┘

--cursors

When you include the --cursors flag, the pg-runner assums that the query's initial result set is the cursors. It then calls FETCH ALL on each cursor returned by the initial query.

$ sql-runner --script "SELECT * FROM get_all_users()" --cursors

--values

For scripts that accept arguments, you pass parameters with the --values option, which accepts a list of space-separated values:

$ sql-runner --script "SELECT * FROM get_user_by_lastname(\$1)" --values Smith
$ sql-runner --script "SELECT * FROM get_user_by_lastname_firstname(\$1, \$2)" --values Smith John

It is important to note that you must escape the parameters; for example, do not enter "$1", enter "\$1".

Installation

You can use pg-runner globally by running the following command:

$ npm install -g @rxifyjs/pg

If you only want to use pg-runner in your application, you can run...

$ npm install --save @rxifyjs/pg
$ npx pg-runner ...

Testing

This library uses the @databases/pg library to test. Before testing, you need to run the following commands to start and initialize the test database:

$ npm run db:start
$ npm run db:init

This will spin up a docker database instance and run an init script that creates test tables, inserts their data, and creates test functions.

Note on Unit Testing

When we implemented the Jest hooks outlined in the @databases/pg docs, we ran into an issue where the database is spun down before tests complete. While we're working on fixing this issue, run the following command before running unit tests:

$ npm run db:start

After tests have completed, run...

$ npm run db:stop

These commands will spin up and spin down a test Postgres database.