Skip to main content

PostgresExternalService

An ExternalService wrapping a PostgreSQL database.

Expose the tables of a PostgreSQL database as collections in the Skip runtime.

For a usage example, refer here.

Remarks​

Subscription params must include a field key of type { col: string, type: PostgresPKey } specifying the Postgres column to serve as key in Skip collections

Subscription params may also specify syncHistoricData: false to receive only new rows as they are created, for use with append-only tables whose history is not needed.

Implements​

  • ExternalService

Constructors​

new PostgresExternalService()​

new PostgresExternalService(db_config): PostgresExternalService

Parameters​

ParameterTypeDescription
db_config{ database: string; host: string; password: string; port: number; user: string; }Configuration of database to which to connect.
db_config.databasestringName of database to which to connect.
db_config.hoststringHost serving database.
db_config.passwordstringPassword for user.
db_config.portnumberPort on which database server listens.
db_config.userstringUser as whom to authenticate.

Returns​

PostgresExternalService

Methods​

getClient()​

getClient(): Client

The underlying PostgreSQL client, exposed for monitoring and diagnostics.

Returns​

Client

The pg.Client used by this service.


getOpenInstances()​

getOpenInstances(): Set<string>

Resource instances whose change-notification channels are currently set up.

Returns​

Set<string>

A copy of the set of open resource instance identifiers.


isConnected()​

isConnected(): boolean

Returns​

boolean


shutdown()​

shutdown(): Promise<void>

Shutdown the external service.

Returns​

Promise<void>

Implementation of​

ExternalService.shutdown

subscribe()​

subscribe(
instance,
resource,
params,
callbacks): Promise<void>

Subscribe to a resource provided by the external service.

Parameters​

ParameterTypeDescription
instancestringInstance identifier of the external resource.
resourcestringName of the PostgreSQL table to expose as a resource.
params{ key: { col: string; type: PostgresPKey; }; syncHistoricData: boolean; }Parameters of the external resource.
params.key{ col: string; type: PostgresPKey; }(Required) Object describing the Postgres column that should be used as the key in the resulting collection
params.key.colstringPostgres column whose value is to be used as the collection key
params.key.typePostgresPKeyPostgres data type of col, which must be a text, integer, or serial type. (i.e. one of TEXT, SERIAL, SERIAL2, SERIAL4, SERIAL8, BIGSERIAL, SMALLSERIAL, INTEGER, INT, INT2, INT4, INT8, BIGINT, or SMALLINT)
params.syncHistoricData?boolean(Optional) Boolean flag, true by default. If false, Skip will ignore pre-existing data and only synchronize updates after subscription.
callbacks{ error: (error) => void; update: (updates, isInit) => Promise<void>; }Callbacks to react on error/loading/update.
callbacks.error(error) => voidError callback.
callbacks.update(updates, isInit) => Promise<void>Update callback.

Returns​

Promise<void>

Implementation of​

ExternalService.subscribe

unsubscribe()​

unsubscribe(instance): void

Unsubscribe from a resource provided by the external service.

Parameters​

ParameterTypeDescription
instancestringInstance identifier of the external resource.

Returns​

void

Implementation of​

ExternalService.unsubscribe