This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { StudentDA } from "../DA"; | |
import { IStudent } from "../types/types"; | |
import shortid from "shortid"; | |
export class StudentService { | |
constructor(private studentDA: StudentDA) { } | |
public async GetStudents() { | |
try { | |
const data = await this.studentDA.GetStudents(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { StudentService } from '../service'; | |
import { Router, Response, Request } from 'express'; | |
export const StudentRouter = (router: Router, service: StudentService): void => { | |
router.get('/', async (req: Request, res: Response) => { | |
try { | |
const data = await service.GetStudents(); | |
res.status(200).send(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express'; | |
import dotenv from 'dotenv'; | |
import { StudentDA } from './DA/index'; | |
import { StudentService } from './service/index'; | |
import { StudentRouter } from "./routes/index"; | |
dotenv.config(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DBManager } from "./DBManager"; | |
import { IStudent } from "../types/types"; | |
export class StudentDA extends DBManager { | |
public async GetStudents() { | |
const query = "select * from student" | |
try { | |
const data = await this.ReadData(query); | |
return data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create table student(id varchar(10), name varchar(50), email varchar(100), age int(5)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "es6", | |
"module": "commonjs", | |
"sourceMap": true, | |
"outDir": "./build", | |
"rootDir": "./src", | |
/* Strict Type-Checking Options */ | |
"strict": true, | |
/* Module Resolution Options */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=3000 | |
HOST='localhost' | |
USER='root' | |
PASSWORD='root' | |
DATABASE='onion' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MysqlError } from "mysql"; | |
export interface IDBManager { | |
ReadData(query: string, paramCollection: (number | string | boolean)[]): Promise<any | MysqlError> | |
InsertOrUpdateData(query: string, paramCollection: (number | string | boolean)[]): Promise<any | MysqlError> | |
DeleteData(query: string, paramCollection: (number | string | boolean)[]): Promise<any | MysqlError> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mysql from 'mysql'; | |
import dotenv from 'dotenv' | |
dotenv.config(); | |
const connection = mysql.createPool({ | |
host: process.env.HOST, | |
user: process.env.USER, | |
password: process.env.PASSWORD, | |
database: process.env.DATABASE, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IDBManager, MySqlType } from "../types/types"; | |
import { connection } from "./DBConnection"; | |
export class DBManager implements IDBManager { | |
public ReadData(query: string, paramCollection: (string | number | boolean)[] = []): Promise<MySqlType> { | |
return new Promise((resolve, reject) => { | |
connection.query(query, paramCollection, (err, result) => { | |
if (err) { | |
return reject(err) |
OlderNewer