chatHistory
for the serverless PostgreSQL-compatible Amazon Aurora DSQL Database.
This is very similar to the PostgreSQL integration with a few differences to make it compatible with DSQL:
- The
id
column in PostgreSQL is SERIAL auto-incrementent, and DSQL is UUID using the database functiongen_random_uuid
. - A
created_at
column is created to track the order and history of the messages. - The
message
column in PostgreSQL is JSONB, and DSQL is TEXT with Javascript parsing handling
Setup
Go to you AWS Console and create an Aurora DSQL Cluster, https://console.aws.amazon.com/dsql/clustersnpm
Usage
Each chat history session is stored in a Aurora DSQL (Postgres-compatible) database and requires a session id. The connection to Aurora DSQL is handled through a PostgreSQL pool. You can either pass an instance of a pool via thepool
parameter or pass a pool config via the poolConfig
parameter. See pg-node docs on pools
for more information. A provided pool takes precedence, thus if both a pool instance and a pool config are passed, only the pool will be used.
For options on how to do the authentication and authorization for DSQL please check https://docs.aws.amazon.com/aurora-dsql/latest/userguide/authentication-authorization.html.
The following example uses the AWS-SDK to generate an authentication token that is passed to the pool configuration: