add typeorm

This commit is contained in:
João Geonizeli
2022-07-08 17:20:24 -03:00
parent df113c34ee
commit 1ca42be8ae
7 changed files with 401 additions and 114 deletions

View File

@@ -0,0 +1,14 @@
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number
@Column()
email: string
@Column()
encryptedPassword: string
}

View File

@@ -1,15 +1,20 @@
import dotenv from 'dotenv';
import express, { Express } from 'express';
import "reflect-metadata"
import * as dotenv from 'dotenv';
import * as express from 'express';
import { AppDataSource } from "./infra/dataSource";
dotenv.config();
const app: Express = express();
const app = express();
const port = process.env.PORT;
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Server is running at ${port}`);
});
AppDataSource.initialize().then(() => {
app.listen(port, () => {
console.log(`Server is running at ${port} 🚀`);
});
})

View File

@@ -0,0 +1,16 @@
import "reflect-metadata"
import { DataSource } from "typeorm"
import { User } from "../entity/user.entity";
export const AppDataSource = new DataSource({
type: "postgres",
host: "localhost",
port: 5432,
username: "joao",
database: "todoListDev",
synchronize: true,
logging: false,
entities: [User],
migrations: [],
subscribers: [],
})

View File