이전 글
- [nestjs] 표준 단어 관리 API 만들기 02 / 모델 만들기
- [nestjs] 표준 단어 관리 API 만들기 01 / 프로젝트 환경 구성
typescript 빌드 환경 구성
tsconfig.buiild.json 및 tsconfig.json 을 작성하여 빌드 환경을 구성한다
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
tsconfig.buiild.json
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
seed.ts
초기 데이터 적재 하기
import { PrismaClient } from '@prisma/client';
// 클라이언트 초기화
const prisma = new PrismaClient();
// 진입점
async function main() {
let items = [
{
ngls_name: 'creation',
ngls_bbrv_name: 'crtn',
krn_name: '생성',
},
{
ngls_name: 'modification',
ngls_bbrv_name: 'mdfc',
krn_name: '수정',
},
{ ngls_name: 'datetime', ngls_bbrv_name: 'dttm', krn_name: '일시' },
{ ngls_name: 'date', ngls_bbrv_name: 'date', krn_name: '일자' },
{ ngls_name: 'id', ngls_bbrv_name: 'id', krn_name: '아이디' },
{ ngls_name: 'name', ngls_bbrv_name: 'name', krn_name: '명' },
{ ngls_name: 'korean', ngls_bbrv_name: 'krn', krn_name: '한글' },
{ ngls_name: 'english', ngls_bbrv_name: 'ngls', krn_name: '영문' },
{ ngls_name: 'abbreviation', ngls_bbrv_name: 'bbrv', krn_name: '약어' },
{ ngls_name: 'term', ngls_bbrv_name: 'term', krn_name: '용어' },
{ ngls_name: 'domain', ngls_bbrv_name: 'dmn', krn_name: '도메인' },
{ ngls_name: 'standard', ngls_bbrv_name: 'stnd', krn_name: '표준' },
{ ngls_name: 'word', ngls_bbrv_name: 'word', krn_name: '단어' },
{ ngls_name: 'list', ngls_bbrv_name: 'list', krn_name: '목록' },
{ ngls_name: 'code', ngls_bbrv_name: 'code', krn_name: '코드' },
{ ngls_name: 'value', ngls_bbrv_name: 'vl', krn_name: '값' },
{ ngls_name: 'use', ngls_bbrv_name: 'use', krn_name: '사용' },
{ ngls_name: 'yn', ngls_bbrv_name: 'yn', krn_name: '여부' },
{ ngls_name: 'dictionary', ngls_bbrv_name: 'dctn', krn_name: '사전' },
{ ngls_name: 'type', ngls_bbrv_name: 'type', krn_name: '타입' },
];
let list = [];
items.forEach(async ({ ngls_name, ngls_bbrv_name, krn_name }) => {
list.push(
prisma.stnd_word_dctn.upsert({
where: { ngls_name }, // 영문명
update: {},
create: {
ngls_name, // 영문명
ngls_bbrv_name, // 영문약어명
krn_name, // 한글명
},
}),
);
});
Promise.all(list).then((results) => {
console.log(results);
});
}
// execute the main function
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
// 클라이언트 종료 처리
await prisma.$disconnect();
});
package.json 커맨드 추가
seed 커맨드를 추가하여 초기 데이터 적재를 원활하게 할 수 있도록 구성
package.json
{
...
"prisma": {
"seed": "ts-node prisma/seed.ts"
}
}
초기데이터 적재
npx prisma db seed
커맨드를 실행하여 초기 데이터를 적재할 수 있다.
[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted! Thank you for supporting witness @jswit.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit