API

Our Isomorphic Typescript API allows subscribing to data and schema changes and performing CRUD operations with full end-to-end type safety.

Server

The server-side library prostgles-server (opens in a new tab) uses Node.JS (opens in a new tab) and communicates with the client over websockets.

It can be used by itself just for querying or within an existing express app (opens in a new tab) to allow connecting from the client library (opens in a new tab)

Installation

To install the server-side library, run:

npm install prostgles-server

Getting started

Example minimal configuration for the server client allows it to be used for querying data:

import prostgles from "prostgles-server";
 
prostgles({
  dbConnection: {
    connectionString: process.env.DATABASE_CONNECTION_STRING
  },
  onReady: async ({ dbo }) => {
    const latestUser = await dbo.users.findOne({}, { orderBy: { created: -1 } });
  }
});

'watchSchema',

Configuration options


  • dbConnectionrequiredDbConnection
    Database connection info
  • tsGeneratedTypesDiroptionalstring
    Location where the generated schema definitions (DBoGenerated.d.ts) will be saved. Nothing is generated by default
  • watchSchemaoptionalboolean | EventTriggerTagFilter | "hotReloadMode" | OnSchemaChangeCallback | undefined
    If truthy then on each schema change DBoGenerated.d.ts will be updated and "onReady" will be called with dbo reflecting new schema on both client and server.
    If a function is provided then it will be triggered on schema changes and no other actions will be taken
  • watchSchemaTypeoptional"DDL_trigger" | "prostgles_queries"
    Has no effect without watchSchema enabled. Defaults to "DDL_trigger". If set to "DDL_trigger" will try to setup database event triggers (opens in a new tab)
    If set to "prostgles_queries" or fails setting up event triggers when it will fallback to

Client

The client-side library prostgles-client (opens in a new tab) provides the same querying functionality as the server and also includes optimistic data replication

Installation

To install the client-side library, run:

npm install prostgles-client