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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@idempotix/postgres

v1.0.0

Published

PostgreSQL storage adapter for Idempotix idempotency

Readme

@idempotix/postgres

PostgreSQL storage adapter for Idempotix.

npm version

Installation

npm install @idempotix/core @idempotix/postgres pg

Quick Start

import { postgres } from '@idempotix/postgres';
import { express as idempotent } from '@idempotix/express';

// From environment variable (IDEMPOTIX_POSTGRES_URL)
app.post('/orders', idempotent({ storage: postgres() }), handler);

Why PostgreSQL?

If your app already uses PostgreSQL, you don't need additional infrastructure:

  • ✅ No Redis/Upstash to manage
  • ✅ Uses your existing database
  • ✅ ACID transactions for atomic locking
  • ✅ Works with any PostgreSQL-compatible DB

Configuration

import { postgres } from '@idempotix/postgres';

// From environment variable
const storage = postgres();

// From URL
const storage = postgres('postgres://user:pass@localhost:5432/mydb');

// With options
const storage = postgres({
  url: 'postgres://localhost:5432/mydb',
  tableName: 'my_idempotency_keys', // default: 'idempotix_keys'
  schema: 'app', // default: 'public'
  autoCreateTable: true, // default: true
});

// With existing pg Pool
import { Pool } from 'pg';
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const storage = postgres({ pool });

Environment Variables

| Variable | Description | | ------------------------ | ------------------------- | | IDEMPOTIX_POSTGRES_URL | PostgreSQL connection URL |

Table Schema

The adapter auto-creates this table (disable with autoCreateTable: false):

CREATE TABLE IF NOT EXISTS idempotix_keys (
  key TEXT PRIMARY KEY,
  status TEXT NOT NULL CHECK (status IN ('in_progress', 'completed')),
  hash TEXT,
  data JSONB,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  expires_at TIMESTAMPTZ NOT NULL
);

CREATE INDEX idempotix_keys_expires_at_idx ON idempotix_keys (expires_at);

Cleanup

Unlike Redis, PostgreSQL doesn't auto-expire rows. Call cleanup() periodically:

import { postgres } from '@idempotix/postgres';

const storage = postgres();

// In a cron job or scheduled task
const deleted = await storage.cleanup();
console.log(`Cleaned up ${deleted} expired entries`);

Or set up a PostgreSQL cron extension (pg_cron):

SELECT cron.schedule('cleanup-idempotix', '0 * * * *',
  $$DELETE FROM idempotix_keys WHERE expires_at < NOW()$$
);

Cloud Providers

Supabase

const storage = postgres(process.env.SUPABASE_DB_URL);

Neon

const storage = postgres(process.env.DATABASE_URL);

AWS RDS

const storage = postgres('postgres://user:[email protected]:5432/mydb');

Vercel Postgres

import { postgres } from '@idempotix/postgres';

const storage = postgres(process.env.POSTGRES_URL);

Usage with Express

import { express as idempotent, configure } from '@idempotix/express';
import { postgres } from '@idempotix/postgres';

const idempotent = configure({
  storage: postgres(),
  ttl: '1h',
});

app.post('/orders', idempotent(), orderHandler);
app.post('/payments', idempotent({ required: true }), paymentHandler);

Usage with Next.js

import { next } from '@idempotix/next';
import { postgres } from '@idempotix/postgres';

export const POST = next({ storage: postgres() })(handler);

Performance Considerations

PostgreSQL is excellent for idempotency but has different characteristics than Redis:

| Aspect | PostgreSQL | Redis | | -------------- | ------------------- | --------------- | | Latency | ~1-5ms | ~0.1-1ms | | Throughput | Good | Excellent | | Persistence | Built-in | Optional | | Infrastructure | Likely already have | May need to add |

For most applications, PostgreSQL is fast enough. Use Redis if you need sub-millisecond latency at very high throughput.

Connection Pooling

The adapter uses a connection pool. For serverless environments, consider using a pooler:

// With PgBouncer or Supabase pooler
const storage = postgres('postgres://user:[email protected]:6543/mydb?pgbouncer=true');

License

MIT