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

busgres

v2.0.3

Published

Busgres is an NPM package for receiving messages from Service Bus and saving them into a PostgreSQL database.

Downloads

110

Readme

busgres

Busgres is a Node.js package that will receieve a message from an Azure Service Bus queue and save it into a PostgreSQL database. It utilises the @azure/service-bus package for Service Bus integration and the pg (node-postgres) package for PostgreSQL connectivity.

Installation

This package can be installed using NPM:

npm i busgres

Usage

BusgresClient set-up & configuration:

const { BusgresClient } = require('busgres`)

const sbConnectionString = process.env.CONNECTION_STRING 

const sbEntity = process.env.QUEUE 

const pgClient = {
  user: process.env.USERNAME,
  database: process.env.DATABASE,
  host: process.env.HOST,
  port: process.env.PORT
}

const bgClient = new BusgresClient(sbConnectionString, sbEntity, pgClient)

Connecting to BusgresClient:

bgClient
  .connect()
  .then(async () => {
    console.log(
      `You are now connected to the ${process.env.DATABASE} database in PostgreSQL.`
    )

    const query = 'SELECT * FROM TABLE_NAME'
    const result = await bgClient.pgClient.query(query)
    console.log('All messages in the database:')

    result.rows.forEach((row, index) => {
      console.log(`Row ${index + 1}:`, row)
    })
  })
  .catch((error) => {
    console.error(
      `There has been an error connecting to your PostgreSQL database: ${error}`
    )
  })

The above example will confirm a connection has been established via the BusgresClient and will select all content from any table in the PostgreSQL database to then log it into the console (not necessary, just further confirms the PostgreSQL connection is active). Receiving and saving messages via receiveMessage:

const tableName = 'TABLE_NAME'
const columnNames = ['COLUMN_NAME']

bgClient.receiveMessage(tableName, columnNames)

tableName and columnNames must be defined so that they can be passed into the receieveMessage function. Disconnecting from BusgresClient:

bgClient.disconnect()

When called the connection to PostgreSQL will be terminated and will also close the Service Bus client & queue. Messages can no longer be received from Service Bus nor saved to the PostgreSQL database.

Configuration

BusgresClient - Client that contains the configuration for both Azure Service Bus & PostgreSQL. Arguments passed into the constructor of the BusgresClient include the Service Bus connection string (sbConnectionString), Service Bus entity (sbEntity) i.e. name of the queue, and the PostgreSQL client configuration (pgClient). connect - When called will establish connection to the PostgreSQL database. saveMessage & receiveMessage - Logic for inserting messages received from a Service Bus queue into a table within a PostgreSQL database. disconnect - When called will terminate the connection to PostgreSQL and close the Service Bus client and entity.

Demo

A simple demo Node.js application called busgres-demo was created to test the functionality of this package during its development and to provide further example of usage.

License

This package is licensed under the MIT License. Refer to the LICENSE file for more details.

Feedback

Feel free to reach out if you have any suggestions for improvement.

Dependencies

This package has a total of 2 dependencies on the following:

Author

Rana Salem