DB에서 Index를 만들자 DB는 potato를 찾아달라고 해서 기본적으로 a부터 찾기 시작함. 이게 기본 동작임. 하지만 index를 만들면 I부터 시작하는 식. 기본적으로 MsSQL DB는 relation이 생길 때마다 index 자동 생성해줌.
그러나 pscale은 이렇게 동작하지 않고, index를 생성하지 않기 때문에 User의 모든 Product를 보여달라고 하면 pscale은 DB에서 Product테이블 가서 모든 product를 뒤져서 해당 USER의 id를 가진 product를 골라온다. 너무 느리겠지. 그리고 테이블 읽을 때마다 돈 내기 때문에 비용문제도 생김. 다시말하지만 MySQL은 이런 인덱스를 알아서 생성한다. 인덱스를 통해 DB에 어떤 상품이 있는지 알 수있다. 그래서 새 상품 만들면 DB에 새 상품 데이터가 추가될거고, 추가로 index도 업데이트가 된다. 인덱스는 DB와 분리된 것이라 보면 됨. 그래서 id가 1인 유저가 상품을 등록하면 상품이 DB에 추가되고, 인덱스도 업데이트 된다. 그래서 아이디가 1인 유저의 상품을 조회하면 시간이 오래 걸리는 DB를 검색하는 대신 바로 인덱스를 조회한다.
14.0 Upload Form 늘 하던 패턴의 반복. Model -> Form(useForm()) -> useMutation() 14.1 Detail Page 14.2 Send Message 14.3 See Message 14.4 Mutations and Refresh 14.5 Seeding - prisma의 seeding 가짜 데이트베이스 많이 생성 하는 법.
3. npm i ts-node 설치(https://www.npmjs.com/package/ts-node) 이게 뭐냐? TypeScript execution and REPL for node.js, with source map and native ESM support. REPL이란 : Node. js Read-Eval-Print-Loop (REPL) is an easy-to-use command-line tool, used for processing Node. js expressions. It captures the user's JavaScript code inputs, interprets, and evaluates the result of this code. It displays the result to the screen, and repeats the process till the user quits the shell. 브라우저 개발자 모드에 있는 console대신 쓸수 있는 듯
5. package.json맨 아래에 해당 명령어 추
6. 그리고 바로 npx prisma db seed 명령어 치면 에러 남. SyntaxError: Cannot use import statement outside a module
대신, pool time out 때문에 그렇다. Pool은 데이터 모으는거고, pool timeout은 이게 정해진 시간 넘도록 특정 쿼리 처리 못하면 exception을 던지고 다음 쿼리로 감. The default connection pool timeout is 10 seconds. If the query engine does not process a particular query within that time, it throws an exception and moves on to the next query in the queue. 근데 serverless가 아닌 일반 서버는 데이터베이스가 허용하는 연결의 수 제한이 매우 작음 근데 우리는 planetscale이 1000개의 동시연결이 가능하단걸 prisma에게 알려주지 않았다. 그래서 prisma에서 시간 초과가 되었다. 우린 일반 DB보다 훨씬 빨랐기 때문에!
SELECT `carrot-market`.`Stream`.`id`, `carrot-market`.`Stream`.`created`, `carrot-market`.`Stream`.`updated`, `carrot-market`.`Stream`.`name`, `carrot-market`.`Stream`.`description`, `carrot-market`.`Stream`.`price`, `carrot-market`.`Stream`.`userId` FROM `carrot-market`.`Stream` WHERE 1=1 ORDER BY `carrot-market`.`Stream`.`id` ASC LIMIT ? OFFSET ?
model Post {
id Int @id @default(autoincrement())
created DateTime @default(now())
updated DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
question String @db.MediumText
answers Answer[]
wonderings Wondering[]
@@index([userId])
}
model Answer {
id Int @id @default(autoincrement())
created DateTime @default(now())
updated DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
postId Int
answer String @db.MediumText
@@index([userId])
@@index([postId])
}
model Wondering {
id Int @id @default(autoincrement())
created DateTime @default(now())
updated DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
postId Int
@@index([userId])
@@index([postId])
}
12.1 Forms and Handlers 12.2 Post Detail 12.3 궁금해요 12.4 Answer 12.5 All Posts 12.6 useCoords 12.7 Geo Search 12.8 Geo Bug
9.0 Introduction authentication = 유저가 누구인지 알아내는 것. authorization = 유저가 권한이 있는지 알아내는 것.
이 섹션에서 구현할 로직 1. Phone Number Sended to Backend --> User? Login : Sign in 2. Create Token -- Connect to User with Random Number 3. Enter Phone Number(Twillo) --> User receive Token(Random Number) by SMS 4. Enter Token --> Send Token to Backend --> Token? Log the user In!
Update or create records (upsert) upsert()는 기존 데이터를 업데이트하거나 새 데이터베이스 레코드를 생성합니다. 다음 쿼리는 upsert를 사용하여 특정 이메일 주소로 사용자 레코드를 업데이트하거나, 존재하지 않는 경우 해당 사용자 레코드를 생성합니다. 출처: 사용자 sugar댓글
VSCode의 block 주석 하는 법: Shift + Alt + A or 상단메뉴 Edit -> Toggle block comment
9.2 Token Logic
9.3 Twilo Setup 9.4 Sending SMS https://console.twilio.com/us1/develop/sms/try-it-out/send-an-sms?frameUrl=%2Fconsole%2Fsms%2Fgetting-started%2Fbuild%3Fx-target-region%3Dus1 npm i twilio 트윌로는 현재 node 16까지밖에 지원 안함. 그래서 nvm에서 노드 16으로 바꿔서 하니 잘 깔림.
9.5 Sending Email npm install --save @sendgrid/mail //아직 메일 인증되지 않아서 에러가 뜨는 것 같음 일단 넘어가자.
9.6 Token UI
prisma stuio에서
User삭제하려고 하면 안됨. User가 지워질 때, Token 물고있어서 그러면 어떻게 하냐?.( onDelete ) Cascade: 부모도 삭제해라. SetNull: user값을 null로 둔다. 근데 여기선 그런 것은 필요없으니 Cascade로 두자.