Bot Builder PostgreSQL Storage
This is a simple storage adapter for PostgreSQL.
Installation
npm install pg-storage --save
Usage
import { PostgreSQLStorage } from 'pg-storage';
const storage = new PostgreSQLStorage({
host: <DATABASE_HOST>,
user: <DATABASE_USERNAME>,
password: <DATABASE_PASSWORD>,
server: <DATABASE_SERVER>,
database: <DATABASE_NAME>,
table: <DATABASE_TABLE>,
port: <DATABASE_PORT>
});
const conversationState = new ConversationState(storage);
const userState = new UserState(storage);
If you intend to use a PostgreSQL database other than localhost
, ensure that the ssl
key is set to true.
import { PostgreSQLStorage } from 'pg-storage';
import { PostgreSQLOptions } from "pg-storage/lib/schema";
const options: PostgreSQLOptions = {
host: <DATABASE_HOST>,
user: <DATABASE_USERNAME>,
password: <DATABASE_PASSWORD>,
server: <DATABASE_SERVER>,
database: <DATABASE_NAME>,
table: <DATABASE_TABLE>,
port: <DATABASE_PORT>,
ssl: true
};
const storage = new PostgreSQLStorage(options);
This module uses the node-pg package for SQL connectivity. The
PostgreSQLOptions
that is passed to thePostgreSQLStorage
object extends theconfig
object of that package. All options from thatconfig
option can be passed in.
This module assumes two columns in your database table:
id
with datatypeVARCHAR(255)
anddata
withJSONB
respectively.