TypeORM basic
์๋ํฌ์ธํธ ์ฃผ์๋ฅผ posts/:id
์ ๊ฐ์ ํํ๋ก ์์ฑํ๋ฉด, ํด๋น id ๊ฐ์ req.params.id
๋ก ๋ฐ์์ฌ ์ ์๋ค.
const post = await myDataBase.getRepository(Post).findOneBy({
id: Number(req.params.id) // ์์ฒญ ํ๋ผ๋ฏธํฐ์ ์๋ id ๊ฐ์ ๊ฐ์ ธ์์ ์กฐ๊ฑด์ผ๋ก ๋ช
์
})
POST
const post = new Post() // entity ์ ์์ฑํ๋๋ก Post ๊ฐ์ฒด ์์ฑ
post.title = req.body.title // ์์ฒญ ๋ฐ์ดํฐ ๋ด๋ถ์ title ๊ฐ๋๋ก ๊ฐ์ฒด ๊ฐ ์ง์
post.body = req.body.body // ์์ฒญ ๋ฐ์ดํฐ ๋ด๋ถ์ body ๊ฐ๋๋ก ๊ฐ์ฒด ๊ฐ ์ง์
์ญํ
๋ฉ์๋ ์ด๋ฆ
QueryBuilder ๊ฐ์ฒด ์์ฑ
createQueryBuilder()
๊ฐ์ ธ์ฌ ์ด ์ ํ
select()
๊ฐ์ ธ์ฌ ํ ์ด๋ธ ์ ํ
from()
๋ ํ ์ด๋ธ์ ์กฐ์ธ
leftJoin()
๊ทธ๋ฃนํํ ์ด ์ ํ
groupBy()
์ ๋ ฌํ ์ด ์ ํ
orderBy()
๊ฐ์ ธ์ฌ ํ์ ์ ์ ํ
limit()
SQL ์ฟผ๋ฆฌ ์คํ ๋ฐ ๊ฒฐ๊ณผ ๋ฐํ
execute()
Last updated