Connect to PostgreSQL

Jinaga persists facts on the server in a PostgreSQL database. Install Postgres for your platform. This step will show you how to create a new database instance for the application.

Log on to your PostgreSQL database as the postgres user. You can do this with the following psql command.

psql -h localhost postgres postgres

Create a new database named for your application.

CREATE DATABASE myapplication;

Create a user specifically for your application.

CREATE USER dev WITH
  LOGIN
  ENCRYPTED PASSWORD 'devpw'
  NOSUPERUSER
  INHERIT
  NOCREATEDB
  NOCREATEROLE
  NOREPLICATION
  VALID UNTIL 'infinity';

This user will be granted limited permissions to the application database. It will only be able to SELECT and INSERT particular tables.

Log off of the session (Ctrl+D) so that you can run the setup script. Switch to the application database and run the script in node_modules/jinaga/setup.sql.

psql -h localhost -f node_modules/jinaga/setup.sql -U postgres myapplication

You will need to install the NPM package in order to retrieve this file.

Once you have created the PostgreSQL database, configure the application to use it. Modify the JinagaServer line in jinaga-config.js so that it specifies the PostgreSQL connection string.

    const pgConnection = process.env.JINAGA_POSTGRESQL ||
      'postgresql://dev:devpw@localhost:5432/myapplication';
    const { handler } = JinagaServer.create({
        pgKeystore: pgConnection,
        pgStore: pgConnection
    });

Start the application, and it will persist all of your user's facts. If you stop and restart it, you will see that all of the data is still there.

Continue With

React Steps