Skip to content

Commit 170e1f2

Browse files
committed
[FEAT]#36 프리즈마 연결, 프리즈마 모델 구축, --목업데이터 디비 insert완료
1 parent 3a3ad44 commit 170e1f2

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

prisma/schema.prisma

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
generator client {
5+
provider = "prisma-client-js"
6+
}
7+
8+
datasource db {
9+
provider = "mysql"
10+
url = env("DATABASE_URL")
11+
}
12+
13+
model Typhoon {
14+
typhoon_id Int @id
15+
name String @db.VarChar(30)
16+
start_date DateTime
17+
end_date DateTime?
18+
created_at DateTime @default(now())
19+
updated_at DateTime @default(now()) @updatedAt
20+
21+
historical_details TyphoonDetail[]
22+
arrounds TyphoonArroundWeather[]
23+
24+
@@map("typhoons")
25+
}
26+
27+
model TyphoonDetail {
28+
typhoon_id Int
29+
observation_date DateTime
30+
central_longitude Float
31+
central_latitude Float
32+
central_pressure Float
33+
maximum_wind_speed Float
34+
wind_radius Float?
35+
grade Int
36+
created_at DateTime @default(now())
37+
updated_at DateTime @default(now()) @updatedAt
38+
39+
typhoon Typhoon @relation(fields: [typhoon_id], references: [typhoon_id])
40+
41+
@@id([typhoon_id, observation_date])
42+
@@map("typhoon_details")
43+
}
44+
45+
model TyphoonArroundWeather {
46+
typhoon_id Int
47+
observation_date DateTime
48+
point Int
49+
temperature_2m Float?
50+
relativehumidity_2m Float?
51+
apparent_temperature Float?
52+
pressure_msl Float?
53+
cloudcover Float?
54+
cloudcover_low Float?
55+
cloudcover_mid Float?
56+
direct_normal_irradiance Float?
57+
windspeed_10m Float?
58+
windspeed_100m Float?
59+
winddirection_10m Float?
60+
winddirection_100m Float?
61+
windgusts_10m Float?
62+
created_at DateTime @default(now())
63+
updated_at DateTime @default(now()) @updatedAt
64+
65+
typhoon Typhoon @relation(fields: [typhoon_id], references: [typhoon_id])
66+
67+
@@id([typhoon_id, observation_date, point])
68+
@@map("typhoon_arround_weathers")
69+
}

src/app.module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
77
import { AppController } from './app.controller';
88
import { AppService } from './app.service';
99
import { configOption } from './common/option/config.option';
10+
import { PrismaModule } from './prisma/prisma.module';
1011
@Module({
1112
imports: [
1213
// config module
1314
ConfigModule.forRoot(configOption),
14-
1515
//이벤트 모듈
1616
EventEmitterModule.forRoot(),
17+
// Prisam module
18+
PrismaModule,
1719
TyphoonModule,
1820
WeatherModule,
1921
],

src/prisma/prisma.module.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Global, Module } from '@nestjs/common';
2+
import { PrismaService } from './prisma.service';
3+
4+
@Global()
5+
@Module({
6+
providers: [PrismaService],
7+
exports: [PrismaService],
8+
})
9+
export class PrismaModule {}

src/prisma/prisma.service.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
2+
import { PrismaClient } from '@prisma/client';
3+
4+
@Injectable()
5+
export class PrismaService extends PrismaClient implements OnModuleInit {
6+
constructor() {
7+
super({ log: [{ emit: 'stdout', level: 'query' }], errorFormat: 'pretty' });
8+
}
9+
10+
async onModuleInit() {
11+
await this.$connect();
12+
13+
this.$use(async (params, next) => {
14+
console.log(params);
15+
16+
const result = await next(params);
17+
return result;
18+
});
19+
}
20+
21+
async enableShutdownHooks(app: INestApplication) {
22+
this.$on('beforeExit', async () => {
23+
await app.close();
24+
});
25+
}
26+
}

0 commit comments

Comments
 (0)