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

prostgles-client

v4.0.264

Published

Reactive client for Postgres

Readme

prostgles-client

Isomorphic TypeScript client for PostgreSQL

GitHub license npm version Known Vulnerabilities Tests

Features

  • 🔄 Real-time data synchronization - Subscribe to database changes with WebSocket support
  • 🔒 End-to-end type safety - Auto-generated TypeScript types from your database schema
  • ⚛️ React hooks - First-class React support with useFind, useSubscribe and useSync
  • 🌐 Isomorphic - Works in Node.js and browsers
  • 🚀 Zero boilerplate - Direct database access without writing SQL
  • 🔗 Relational queries - Join tables with intuitive syntax

Installation

npm/yarn

$ npm install prostgles-client socket.io-client

CDN

<head>
  <script
    src="https://unpkg.com/[email protected]/dist/socket.io.min.js"
    type="text/javascript"
  ></script>
  <script
    src="https://unpkg.com/prostgles-client@latest/dist/index.js"
    type="text/javascript"
  ></script>
</head>

Quick Start

React hooks

Subscribe to data changes with automatic re-renders:

import { useProstglesClient } from "prostgles-client/dist/prostgles";
import type { DBGeneratedSchema } from "@common/DBGeneratedSchema";

const App = () => {
  const client = useProstglesClient<DBGeneratedSchema>({ socketOptions: { path: "/ws-api" } });

  if(client.isLoading) return "Loading...";
  if(client.hasError) return <>Error: {client.error}</>;

  return <UserPosts dbo={client.dbo} />
}

const UserPosts = ({ dbo }: { dbo:  }) => {

  const { data: user, isLoading } = dbo.users.useSubscribeOne(
    { id: 1 },
    {
      select: {
        id: 1,
        first_name: 1,
        email: 1,
        latest_posts: {
          $leftJoin: ["posts"],
          orderBy: { created: -1 }
        }
      }
    }
  );

  if(isLoading) return "Loading ..."

  return (
    <div>
      <h1>{user.first_name}</h1>
      <p>{user.email}</p>
      <h2>Latest Posts</h2>
      <ul>
        {user.latest_posts.map(post => (
          <li key={post.id}>{post.title}</li>
        ))}
      </ul>
    </div>
  );
}

Vanilla JavaScript

prostgles({
  socket: io(),
  onReady: async (db) => {
    const latest_posts = await db.posts.find({}, { orderBy: { created: -1 } });

    // Insert data
    await dbo.posts.insert({
      title: "Hello World",
      content: "My first post",
      published: true,
    });
  },
});

Type Safety

Paired with prostgles-server, types are automatically generated from your database schema:

Learn more in the Prostgles documentation.

API Overview

Query Methods

  • find() - Fetch multiple records
  • findOne() - Fetch a single record
  • useFind() - React hook for find()
  • useFindOne() - React hook for findOne()
  • count() - Count records
  • useCount() - React hook for count()
  • insert() - Insert new records
  • update() - Update existing records
  • delete() - Delete records
  • upsert() - Insert or update records

Real-time Methods

  • subscribe() - Subscribe to multiple records
  • subscribeOne() - Subscribe to a single record
  • sync() - Two-way sync for multiple records (local changes pushed to server)
  • syncOne() - Two-way sync for a single record (local changes pushed to server)
  • useSubscribe() - React hook for subscribe()
  • useSubscribeOne() - React hook for subscribeOne()
  • useSync() - React hook for sync()
  • useSyncOne() - React hook for syncOne()

Sync vs Subscribe

The key difference between sync and subscribe methods:

  • Subscribe (subscribe, subscribeOne) - One-way data flow from server to client. Receives updates when data changes on the server.
  • Sync (sync, syncOne) - Two-way data flow. Allows local optimistic updates that are automatically synced back to the server, while also receiving server updates.
// Sync: locally modified data is propagated instantly to the client
const { data: draftPost, isLoading } = dbo.posts.useSyncOne(
  { published: false },
  { handlesOnData: true },
);
if (isLoading) return "Loading...";
if (!draftPost) {
  return <button onClick={() => dbo.posts.insert({ published: false })}>Create new post</button>;
}
return (
  <form>
    <input
      type="text"
      placeholder="Title"
      value={draftPost.title}
      onChange={(e) => draftPost.$update({ title: e.target.value })}
    />
    <input
      type="text"
      placeholder="Content"
      value={draftPost.content}
      onChange={(e) => draftPost.$update({ content: e.target.value })}
    />
    <button onClick={() => draftPost.$update({ published: true })}>Publish</button>
  </form>
);

Documentation

Full API Documentation Examples Server Setup Guide

License

MIT