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
}
}
Badges
View all badges
1
gold badge
-
Famous QuestionFeb 21, 2024
9
silver badges
-
EnthusiastMar 1, 2023
-
Necromancer
× 3Apr 1 -
Yearling
× 3Sep 16
Top tags
View all tags9
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 %

