Skip to content

Sqlite

GrandLineX SQLight Bundle

SQLight support GrandLineX using better-sqlite3

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-sqlight

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 SQLCon from '@grandlinex/bundle-sqlight';

export default class ExampleDb extends SQLCon {

    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.