Skip to main content
Felix Olszewski's user avatar
Felix Olszewski's user avatar
Felix Olszewski's user avatar
Felix Olszewski
  • Member for 3 years, 2 months
  • Last seen this week

Stats

925
reputation
131k
reached
28
answers
29
questions
Loading…

About

database.service.ts

import { Injectable } from '@nestjs/common';
import { Pool } from 'pg';

@Injectable()
export class DatabaseService {
  private client: Pool;

  constructor() {
    this.client = new Pool({
      host: 'localhost',
      port: 5432,
      user: 'felixolszewski',
      database: 'postgres',
    });
  }

  async query(text: string, params?: any[]) {
    return this.client.query(text, params);
  }

  async getAllDepartment() {
    const queryResult = await this.query('SELECT * FROM department');
    return queryResult.rows
  }

  async getDepartment(name: string) {
    const queryResult = await this.query('SELECT * FROM department WHERE name = $1', [name]);
    return queryResult.rows
  }

  async getAllEmployeesByDepartment(id: string) {
    console.log(id);
    const queryResult = await this.query('SELECT * FROM employee WHERE departmentid = $1', [id]);
    return queryResult.rows
  }

}

database.service.ts

import { Injectable } from '@nestjs/common';
import { Pool } from 'pg';

@Injectable()
export class DatabaseService {
  private client: Pool;

  constructor() {
    this.client = new Pool({
      host: 'localhost',
      port: 5432,
      user: 'felixolszewski',
      database: 'postgres',
    });
  }

  async query(text: string, params?: any[]) {
    return this.client.query(text, params);
  }

  async getAllDepartment() {
    const queryResult = await this.query('SELECT * FROM department');
    return queryResult.rows
  }

  async getDepartment(name: string) {
    const queryResult = await this.query('SELECT * FROM department WHERE name = $1', [name]);
    return queryResult.rows
  }

  async getAllEmployeesByDepartment(id: string) {
    console.log(id);
    const queryResult = await this.query('SELECT * FROM employee WHERE departmentid = $1', [id]);
    return queryResult.rows
  }

}

database.service.ts

import { Injectable } from '@nestjs/common';
import { Pool } from 'pg';

@Injectable()
export class DatabaseService {
  private client: Pool;

  constructor() {
    this.client = new Pool({
      host: 'localhost',
      port: 5432,
      user: 'felixolszewski',
      database: 'postgres',
    });
  }

  async query(text: string, params?: any[]) {
    return this.client.query(text, params);
  }

  async getAllDepartment() {
    const queryResult = await this.query('SELECT * FROM department');
    return queryResult.rows
  }

  async getDepartment(name: string) {
    const queryResult = await this.query('SELECT * FROM department WHERE name = $1', [name]);
    return queryResult.rows
  }

  async getAllEmployeesByDepartment(id: string) {
    console.log(id);
    const queryResult = await this.query('SELECT * FROM employee WHERE departmentid = $1', [id]);
    return queryResult.rows
  }

}

1
gold badge
9
silver badges
25
bronze badges
9
Score
9
Posts
16
Posts %
6
Score
24
Posts
42
Posts %
4
Score
25
Posts
44
Posts %
4
Score
21
Posts
37
Posts %
3
Score
18
Posts
32
Posts %
3
Score
10
Posts
18
Posts %

Top posts

View all questions, answers, and articles