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
Parameter | Type | Description |
---|---|---|
db_config | { database : string ; host : string ; password : string ; port : number ; user : string ; } | Configuration of database to which to connect. |
db_config.database | string | Name of database to which to connect. |
db_config.host | string | Host serving database. |
db_config.password | string | Password for user. |
db_config.port | number | Port on which database server listens. |
db_config.user | string | User as whom to authenticate. |
Returns
Methods
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
Parameter | Type | Description |
---|---|---|
instance | string | Instance identifier of the external resource. |
resource | string | Name 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.col | string | Postgres column whose value is to be used as the collection key |
params.key.type | PostgresPKey | Postgres 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 ) => void | Error 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
Parameter | Type | Description |
---|---|---|
instance | string | Instance identifier of the external resource. |
Returns
void
Implementation of
ExternalService.unsubscribe