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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@baz-scm/pgmq-ts

v0.3.5

Published

Typescript wrapper equivalent for pgmq-rs

Downloads

363

Readme

PGMQ-TS

npm version License: MIT

PGMQ-TS is a TypeScript library that provides a message queue implementation using PostgreSQL as the backend. It's the TypeScript equivalent of pgmq-rs, offering a robust and type-safe way to implement message queues in your Node.js applications.

Features

  • 🔒 Type-safe: Full TypeScript support with generics for message types
  • 🎯 Simple API: Easy-to-use interface for queue operations
  • 📦 PostgreSQL-backed: Leverages PostgreSQL's reliability and ACID properties
  • 🔄 Message Visibility: Configurable visibility timeout for message processing
  • 📚 Message Archives: Built-in support for archiving processed messages
  • 🔌 Connection Pooling: Efficient database connection management

Installation

npm install @baz-scm/pgmq-ts
# or
yarn add @baz-scm/pgmq-ts
# or
pnpm add @baz-scm/pgmq-ts

Quick Start

import { PGMQ } from '@baz-scm/pgmq-ts';

// Initialize PGMQ with your PostgreSQL connection string
const pgmq = new PGMQ('postgresql://user:password@localhost:5432/dbname');

// Create the PGMQ schema and a queue
await pgmq.createSchema();
await pgmq.createQueue('my_queue');

// Define your message type
interface MyMessage {
  id: string;
  data: {
    value: string;
  };
}

// Send a message
await pgmq.sendMessage<MyMessage>('my_queue', {
  id: '123',
  data: {
    value: 'Hello PGMQ!'
  }
}, 0);

// Read a message (with 60 second visibility timeout)
const message = await pgmq.readMessage<MyMessage>('my_queue', 60);

if (message) {
  // Process the message
  console.log(message.message); // Access the typed message content
  
  // After processing, either delete or archive the message
  await pgmq.deleteMessage('my_queue', message.msgId);
  // or
  await pgmq.archiveMessage('my_queue', message.msgId);
}

Queue Operations

Creating a Queue

await pgmq.createQueue('my_queue');

Using Queue Objects

You can also get a Queue object for more focused operations:

const queue = pgmq.getQueue('my_queue');

// Read messages from the queue
const message = await queue.readMessage<MyMessage>();

// Delete a message
await queue.deleteMessage(messageId);

// Archive a message
await queue.archiveMessage(messageId);

Message Visibility

The visibility timeout determines how long a message stays hidden after being read. This prevents other consumers from processing the same message during this period:

// Message will be hidden for 60 seconds after being read
const message = await pgmq.readMessage<MyMessage>('my_queue', 60);

Best Practices

  1. Always define TypeScript interfaces for your message types
  2. Handle connection cleanup by calling pgmq.end() when shutting down
  3. Use appropriate visibility timeouts based on your processing needs
  4. Consider archiving important messages instead of deleting them
  5. Validate queue names (alphanumeric and underscore characters only)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.