Skip to main content
The 2024 Developer Survey results are live! See the results
Felix Olszewski's user avatar
Felix Olszewski's user avatar
Felix Olszewski's user avatar
Felix Olszewski
  • Member for 1 year, 10 months
  • Last seen this week
Stats
581
reputation
85k
reached
22
answers
28
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
5
silver badges
21
bronze badges
4
Score
9
Posts
18
Posts %
3
Score
19
Posts
38
Posts %
2
Score
17
Posts
34
Posts %
2
Score
10
Posts
20
Posts %
2
Score
6
Posts
12
Posts %
1
Score
21
Posts
42
Posts %