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
}
}
Badges
View all badges
1
gold badge
-
Famous QuestionFeb 21
5
silver badges
-
EnthusiastMar 1, 2023
-
NecromancerJan 19
-
YearlingDec 22
Top tags
View all tags
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 %