Skip to content

Postgres

GrandLineX Postgresql Bundle

Postgresql support GrandLineX using pg

Description

img

GitHub NPM TS

Status

Quality Gate Status Security Rating Maintainability Rating Reliability Rating Coverage

Issues

Bugs Vulnerabilities Code Smells

Documentation

Installation

Install the package.

npm install @grandlinex/bundle-postgresql

Add the database configuration to your .env file or directly in kernel config store.

POSTGRES_PASSWORD=<** password **>
POSTGRES_USER=<** user **>
DBPATH=<** ip or host **>
DBPORT=<** port **>

Create a new DatabaseConnector Class: ExampleDb.ts

import { CoreKernelModule } from '@grandlinex/core';
// Import the DatabaseConnector Class.
import PGCon from '@grandlinex/bundle-postgresql';

export default class ExampleDb extends PGCon {

    constructor(mod: CoreKernelModule<any, any, any, any, any>) {
        super(mod, '0'); // pass the module and the version of the database
        // register entities or migrations here
    }

    async initNewDB() {
        // init stuff 
    }
}

Register the DatabaseConnector in module :ExampleModule.ts

import { CoreKernelModule, ICoreKernel } from '@grandlinex/core';
import ExampleDb from './ExampleDb';

export default class ExampleModule extends CoreKernelModule<any, ExampleDb, any, any, any> {
    constructor(kernel:ICoreKernel) {
        super('example_module', kernel);
        // add other services or actions 
    }

    async initModule() :Promise<void> {
        // register the database connector
        this.setDb(new ExampleDb(this));
        // register other resources

    }
}
Finally register ExampleModule to the kernel.