Overview
Client-side API for interacting with a PostgreSQL database.
Installation
To install the package, run:
npm install prostgles-clientConfiguration
Example react configuration and usage:
import prostgles from "prostgles-client";
import { DBGeneratedSchema } from "./DBGeneratedSchema";
export const App = () => {
const prgl = useProstglesClient("/ws-api");
if(prgl.isLoading) return <div>Loading...</div>;
return <MyComponent prgl={prgl} />;
}Example configuration:
import prostgles from "prostgles-client";
import { DBGeneratedSchema } from "./DBGeneratedSchema";
import io from "socket.io-client";
const socket = io({ path: "/ws-api" });
const prostglesClient = prostgles<DBGeneratedSchema>
socket,
onReady: async (dbs, methods, schema, auth) => {
console.log(dbs.items.find());
}
})Configuration options
InitOptions
-
socket required Socket<DefaultEventsMap, DefaultEventsMap>
Socket.io client instance
-
onReload optional () => void
Execute this when requesting user reload (due to session expiring authGuard) Otherwise window will reload
-
onSchemaChange optional () => void
Callback called when schema changes. “onReady” will be called after this callback
-
onReady required OnReadyCallback
Callback called when:
- the client connects for the first time
- the schema changes
- the client reconnects
- server requests a reload
-
onReconnect optional (socket: any, error?: any) => void
Custom handler in case of websocket re-connection. If not provided will fire onReady
-
onDisconnect optional () => void
On disconnect handler. It is recommended to use this callback instead of socket.on(“disconnect”)
-
onDebug optional (event: DebugEvent) => void | Promise<void>
Awaited debug callback. Allows greater granularity during debugging.
Client-only Methods
The following table/view methods are available on client-side only.
useSync, sync, syncOne, useSyncOne, useSubscribe, useSubscribeOne, useFind, useFindOne, useCount, useSize