Registry / database / prostgles-client

prostgles-client

JSON →
library4.0.347jsnpmunverified

prostgles-client v4.0.347 is a reactive isomorphic TypeScript client for PostgreSQL that provides real-time data synchronization via WebSocket, relational queries, and auto-generated TypeScript types from database schemas. It offers zero-boilerplate direct database access with first-class React hooks (useSubscribe, useFind, useSync) and works in both Node.js and browser environments. Released under MIT license. Key differentiator: tight integration with prostgles-server for end-to-end type safety and real-time sync without writing SQL. 3-4 minor releases per month.

npm install prostgles-client
INSTALL
IMPORT
SIG · PROSTGLES-CLIENT
P
prostgles-client
databasejavascriptv4.0.347
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ProstglesClient
import { ProstglesClient } from 'prostgles-client'
const { ProstglesClient } = require('prostgles-client')
ESM-only import for class-based client use without React.
useProstglesClient
import { useProstglesClient } from 'prostgles-client/dist/prostgles'
import { useProstglesClient } from 'prostgles-client'
React hook is not exported from the main entry; must import from 'prostgles-client/dist/prostgles'.
prostgles
import prostgles from 'prostgles-client'
import { prostgles } from 'prostgles-client'
The standalone 'prostgles' function is the default export from the main package; named import fails.
useSync
import { useSync } from 'prostgles-client/dist/prostgles'
import { useSync } from 'prostgles-client'
All React hooks are only available from the subpath 'prostgles-client/dist/prostgles'.

React component using useProstglesClient hook to subscribe to published posts with real-time updates.

import { useProstglesClient } from "prostgles-client/dist/prostgles"; import { useEffect, useState } from "react"; // Define your database types (auto-generated by prostgles-server) interface DBGeneratedSchema { users: { id: number; name: string; email: string; }; posts: { id: number; title: string; content: string; published: boolean; user_id: number; }; } function App() { const client = useProstglesClient<DBGeneratedSchema>({ socketOptions: { path: "/ws-api" } }); if (client.isLoading) return <div>Loading...</div>; if (client.hasError) return <div>Error: {client.error}</div>; return <PostsList dbo={client.dbo} />; } function PostsList({ dbo }: { dbo: ReturnType<typeof useProstglesClient>['dbo'] }) { const { data: posts, isLoading } = dbo.posts.useSubscribe( { published: true }, { orderBy: { created: -1 }, limit: 10 } ); if (isLoading) return <div>Loading posts...</div>; return ( <ul> {posts.map(post => ( <li key={post.id}>{post.title}</li> ))} </ul> ); }
Debug
Known issues
breakingReact hooks must be imported from 'prostgles-client/dist/prostgles', not from the main 'prostgles-client' entry.
fix
Change import path to 'prostgles-client/dist/prostgles' for all React hooks.
affects: >=4.0.0
gotchaThe standalone 'prostgles' function is the default export. Named import { prostgles } fails with 'The requested module does not provide an export named prostgles'.
fix
Use default import: import prostgles from 'prostgles-client'
affects: >=4.0.0
gotchaProstglesClient constructor expects a socket.io client instance. Using a different WebSocket library will not work.
fix
Install socket.io-client and pass the io() instance as the 'socket' option.
affects: >=4.0.0
deprecatedThe 'useFind' hook is deprecated in favor of 'useSubscribe' for better real-time support.
fix
Replace useFind with useSubscribe (or useFindOne with useSubscribeOne).
affects: >=4.0.0
Errors
Common errors & fixes
Uncaught SyntaxError: The requested module 'prostgles-client' does not provide an export named 'useProstglesClient'
Importing React hooks from wrong path (main entry instead of dist/prostgles).
fix
Use: import { useProstglesClient } from 'prostgles-client/dist/prostgles'
Uncaught TypeError: prostgles_client_1.prostgles is not a function
Using named import { prostgles } instead of default import.
fix
Use: import prostgles from 'prostgles-client'
Error: Cannot find module 'prostgles-client/dist/prostgles' or its corresponding type declarations.
Missing subpath export 'dist/prostgles' in older version or misconfigured TypeScript paths.
fix
Ensure prostgles-client is at least v4.0.0 or configure moduleResolution to 'node16' or 'bundler'.
WebSocket connection to 'wss://...' failed: Error during WebSocket handshake: Unexpected response code: 400
Missing or incorrect socketOptions path; server expects specific WebSocket endpoint.
fix
Pass 'path' option matching your prostgles-server configuration, e.g., socketOptions: { path: '/ws-api' }
Upgrade
Version history
4.0.347latest on npm
Audit
Dependencies
reactoptionalPeer dependency for React hooks (useProstglesClient, useFind, useSubscribe, useSync); must be installed for React usage.
socket.io-clientoptionalRequired for WebSocket-based real-time synchronization (socket.io). Not a direct dependency but listed in installation instructions.
Agent activity
10 hits · last 30 days
node
8
Resources
prostgles-client — npm install prostgles-client · libregistry