add typeorm
This commit is contained in:
14
server/src/entity/user.entity.ts
Normal file
14
server/src/entity/user.entity.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
email: string
|
||||
|
||||
@Column()
|
||||
encryptedPassword: string
|
||||
}
|
||||
@@ -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} 🚀`);
|
||||
});
|
||||
})
|
||||
16
server/src/infra/dataSource.ts
Normal file
16
server/src/infra/dataSource.ts
Normal 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: [],
|
||||
})
|
||||
0
server/src/migration/.keep
Normal file
0
server/src/migration/.keep
Normal file
Reference in New Issue
Block a user