All files / src/datasources logchain.datasource.ts

92.31% Statements 12/13
0% Branches 0/1
50% Functions 1/2
91.67% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411x 1x 1x 1x   1x       1x   1x                               1x     1x 1x           1x      
import { inject, lifeCycleObserver, LifeCycleObserver } from '@loopback/core';
import { juggler } from '@loopback/repository';
import * as dotenv from 'dotenv';
import pg from 'pg';
// set parser for NUMERIC type
pg.types.setTypeParser(pg.types.builtins.NUMERIC, (value: string) => {
  return parseFloat(value);
});
 
dotenv.config();
 
const config = {
  name: 'logchain',
  connector: 'postgresql',
  url: '',
  host: process.env.POSTGRES_HOST,
  port: process.env.POSTGRES_PORT,
  user: process.env.POSTGRES_USER,
  password: process.env.POSTGRES_PASSWORD,
  database: process.env.POSTGRES_DB,
};
 
// Observe application's life cycle to disconnect the datasource when
// application is stopped. This allows the application to be shut down
// gracefully. The `stop()` method is inherited from `juggler.DataSource`.
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
@lifeCycleObserver('datasource')
export class LogChainDataSource
  extends juggler.DataSource
  implements LifeCycleObserver {
  static dataSourceName = 'logchain';
  static readonly defaultConfig = config;
 
  constructor(
    @inject('datasources.config.logchain', { optional: true })
    dsConfig: object = config,
  ) {
    super(dsConfig);
  }
}