반응형
- 2024-09-24 : First posting.
.env 파일 설정을 다음과 같이 하자.
User
```[.scrollable]
model User {
id String @id @default(uuid()) // * Can be used by salt in encryption.
email String @unique
nickname String
password String
pwdIter Int @default(10000)
ssnIter Int @default(1000)
articles Article[]
articleComments ArticleComment[]
productComments ProductComment[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
Product
```[.scrollable]
model Product {
id String @id @default(uuid())
name String
description String
price Float
tags String[]
images String[]
favoriteCount Int
productComments ProductComment[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
Article
```[.scrollable]
model Article {
id String @id @default(uuid())
title String
authorId String
author User @relation(fields: [authorId], references: [id], onDelete: Restrict)
content String
articleComments ArticleComment[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
ProductComment
```[.scrollable]
model ProductComment {
id String @id @default(uuid())
content String
productId String
product Product @relation(fields: [productId], references: [id], onDelete: Restrict)
commenterId String
commenter User @relation(fields: [commenterId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
ArticleComment
```[.scrollable]
model ArticleComment {
id String @id @default(uuid())
content String
articleId String
article Article @relation(fields: [articleId], references: [id])
commenterId String
commenter User @relation(fields: [commenterId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
struct-Product
```[.scrollable]
import * as s from 'superstruct';
import isUuid from 'is-uuid';
const Uuid = s.define('Uuid', (value) => isUuid.v4(value));
export const CreateProduct = s.object({
name: s.size(s.string(), 1, 10),
description: s.size(s.string(), 10, 100),
price: s.min(s.number(), 0),
tags: s.array(s.string()),
images: s.array(s.string()),
favoriteCount: s.min(s.integer(), 0),
});
export const PatchProduct = s.object({
id: Uuid,
...s.partial(CreateProduct),
});
```/
s.set(s.string()) 은 어떻게 데이터를 보내는지 모르겠어서 못썼음. 그냥 array 방식으로 묶으면 될줄 알았는데... =ㅇ=;; ["가", "나", "다"] 는 Set 가 아니라고 함.
define 은
```[.scrollable]
import * as s from 'superstruct';
import isEmail from 'is-email';
import isUuid from 'is-uuid';
const Uuid = s.define('Uuid', (value) => isUuid.v4(value));
const email = s.define('email', (value) => isEmail(value));
```/
struct-User
```[.scrollable]
export const CreateUser = s.object({
email: email,
nickname: s.size(s.string(), 1, 20),
password: s.string()
});
export const PatchUser = s.partial(CreateUser);
// * User id 는 따로 받아야 함.
```/
struct-Product
```[.scrollable]
export const CreateProduct = s.object({
name: s.size(s.string(), 1, 10),
description: s.size(s.string(), 10, 100),
price: s.min(s.number(), 0),
tags: s.size(s.array(s.string()), 0, 15),
images: s.size(s.array(s.string()), 1, 2),
favoriteCount: s.min(s.integer(), 0),
});
export const PatchProduct = s.partial(CreateProduct);
// * Product id 는 따로 받아야 함.
```/
struct-Article
```[.scrollable]
export const CreateArticle = s.object({
title: s.size(s.string(), 1, 20),
authorId: Uuid,
content: s.size(s.string(), 10, 500),
});
export const PatchArticle = s.partial(CreateArticle);
// * Article id 는 따로 받아야 함.
```/
struct-ProductComment
```[.scrollable]
export const CreateProductComment = s.object({
productId: Uuid,
commenterId: Uuid,
content: s.size(s.string(), 1, 255),
});
// * Patch 는 위 데이터에 id 추가.
```/
struct-ArticleComment
```[.scrollable]
export const CreateArticleComment = s.object({
articleId: Uuid,
commenterId: Uuid,
content: s.size(s.string(), 1, 255),
});
// * Patch 는 위 데이터에 id 추가.
```/
반응형
'[IT|Programming] > Algorithm|Database' 카테고리의 다른 글
| MySQL SQLException in Ubuntu, Linux (0) | 2025.08.04 |
|---|---|
| Learning SQL (Structured Query Language) | MySQL (SQL | MySQL 을 배워보자.) :: MySQL, JDBC (Java DataBase Connector) (2) | 2025.08.02 |
| prisma with PostgreSQL - cursor based pagination (2) | 2025.07.27 |
| prisma with PostgreSQL 를 배워봅시다. (12) | 2024.09.25 |
| Java Serializable Object to Byte Array (byte[] or SQL BLOB) (0) | 2024.09.22 |
| week8 위클리 페이퍼 (데이터베이스 정규화에 대해 설명, 관계형 데이터베이스를 사용하는 이유를 설명) (1) | 2024.09.20 |
| Regular Expression (정규 표현식), and match/replace method in JavaScript, JAVA, and Python (4) | 2024.08.29 |
http/https 링크및 수식 (\ [ Outline 수식 \ ],\ ( inline 수식 \ )::\이후 띄어쓰기 없이) 을 넣으실 수 있습니다. 또한 code 는```시작,```/마지막으로 감싸 주시면 pretty-printed 되어서 나타납니다.```[.lang-js.scrollable.no-linenums]같이 언어를 선택해 주실수도 있고, 긴 수식의 경우 scroll bar 가 생기게 만드실 수도 있습니다. .no-linenums 로 line numbering 을 없앨수도 있습니다.댓글 입력 후 rendering 된 형태를 보시려면, Handle CmtZ (단축키: N) 버튼을 눌러주세요. 오른쪽 아래 Floating Keys 에 있습니다. 아니면 댓글 젤 아래에 버튼이 있습니다.