📝Sqlite

This service is used to interact with the Redis database.

Imports

import { SqliteService } from 'niro-health';

Method of Use

To use this module, you need to inject it into the desired service.

import { Module } from '@nestjs/common';
import {
  AppHostService,
  SqliteService,
  ConfigurationService,
  ValidatorRegexpService,
  StringExService,
  DebugService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IAppHostService',
      useClass: AppHostService,
    },
    {
      provide: 'ISqliteService',
      useClass: SqliteService,
    },
    {
      provide: 'IConfigurationService',
      useClass: ConfigurationService,
    },
    {
      provide: 'IValidatorRegexpService',
      useClass: ValidatorRegexpService,
    },
    {
      provide: 'IStringExService',
      useClass: StringExService,
    },
    {
      provide: 'IDebugService',
      useClass: DebugService,
    },
  ],
})
export class AppModule {}

Injecting the module into our service.

import { Inject, Injectable } from '@nestjs/common';
import type { IAppHostService, ISqliteService } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IAppHostService')
    private readonly appHostService: IAppHostService,
    @Inject('ISqliteService')
    private readonly sqliteService: ISqliteService,
  ) {}

  async enableShutdownHooks() {
    await this.sqliteService.enableShutdownHooks(this.appHostService.app);
  }
}

Modifying our main.ts

main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from '@/app.module';
import { Logger } from '@nestjs/common';
import { AppHostModule, AppHostService } from 'niro-health';
import { AppModule } from './app.module';
import { AppService } from './app.service';

(async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: new Logger('NestApplication', {
      timestamp: true,
    }),
    cors: true,
  });
  app.select(AppHostModule).get(AppHostService).setApp(app);
  app.select(AppModule).get(AppService).enableShutdownHooks();
})();

With dependencies

You will need to inject the following interfaces.

Interface
Service

Properties

Property
Scope
Description

app

public

This is instance of application.

_db

private

This is the major component of sqlite3. Use it to connect to a standalone Sqlite server or Sentinels.

get _dbName

private

This method is used to get database name.

get db

public

This method is used to get database instance.

Methods

Method
Scope
Description

_connectionLogs

private

This method is used to log connection events.

shutdown

public

This method is used to shutdown application.

onApplicationShutdown

public

This method is called before the application shutdown.

enableShutdownHooks

public

This method is used to enable shutdown hooks.

Last updated