1.0.2 • Published 12 months ago

@chatbot-ui/rdbms v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Chatbot UI Relational Database Management System Extension

This extension provides PostgreSQL, MySQL, MariaDB, and CockroachDB support to Chatbot UI.

Installation

Step 1

Add the database extension with npm:

npm i @chatbot-ui/rdbms@latest

Step 2

Install the corresponding database driver. See the corresponding drivers here.

Step 3

Update /utils/app/extensions/database.ts to use the new database.

import { Database } from '@chatbot-ui/core';
// Import the client-side of the database
import { ClientSideDatabase } from '@chatbot-ui/rdbms/client-side';

let database: Database | null = null;

export const getDatabase = async () => {
  if (database) {
    return database;
  } else {
    // Create a new instance of the client-side
    database = new ClientSideDatabase();
    await database.connect();
    return database;
  }
};

Step 4

Create or update /utils/server/extensions/database.ts so it used the server side of the database.

import { ServerDatabase } from '@chatbot-ui/core';
// Import the server-side of the database
import { ServerSideDatabase } from '@chatbot-ui/rdbms/server-side';

export const getServerDatabase = async () => {
  // Create a new instance of the server-side
  const database: ServerDatabase = new ServerSideDatabase();
  await database.connect();
  return database;
};

Configuration

Note: Google Cloud may require the RDBMS_SSL_HOST env variable, which will look something like this: 9-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.us-west1.sql.goog. Which will be displayed in an error message returned by the server.

Use the following env variables to configure your connection:

Environment VariableDefault valueDescription
RDBMS_DB_TYPEpostgresType of database. Either postgres, cockroachdb, mysql, or mariadb. See here.
RDBMS_HOST127.0.0.1The host of the RDBMS instance
RDBMS_PORT5432The port of the RDBMS instance
RDBMS_DBpostgresThe database name of the RDBMS instance
RDBMS_USERpostgresThe username of the RDBMS instance
RDBMS_PASSpasswordThe password of the RDBMS instance
RDBMS_SYNCHRONIZEtrueWhether to create tables from entities. Should be false in production.
RDBMS_SSL_ENABLEDfalseWhether to require SSL to connect to the database.
RDBMS_SSL_HOSTThe hostname of the database server you are connecting to. Google Cloud may require this.
RDBMS_SSL_CAThe Server CA certificate used for SSL connections, in the form of a single line string.
RDBMS_SSL_CERTThe Client certificate used for SSL connections, in the form of a single line string.
RDBMS_SSL_KEYThe Client certificate key used for SSL connections, in the form of a single line string.
RDBMS_COCKROACHDB_TIME_TRAVEL_QUERIESfalseWether to user time travel queries features in CockroachDB
1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago