-
Notifications
You must be signed in to change notification settings - Fork 5
TypeORM
TypeORM์ Active Record ํจํด๊ณผ Data Mapper ํจํด ๋ชจ๋ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
์ด ํจํด์ ๋ฐ๋ฅด๋ ๊ฐ์ฒด์ ์ธํฐํ์ด์ค์๋ ์ฝ์ , ๊ฐฑ์ , ์ญ์ ์ ๊ฐ์ ํจ์์ ํ ์ด๋ธ์ ์ด์ ํด๋นํ๋ ํ๋กํผํฐ๊ฐ ์๋ค. ์ดํดํ๊ธฐ ์ด๋ ต๋ค๋ฉด ์๋์ ๊ด๊ณ๋ฅผ ํตํด ์ดํดํด๋ณด์.
- ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ํ ์ด๋ธ(๋๋ ๋ทฐ)๊ฐ ํด๋์ค์ ํด๋นํ๋ค.
- ํ ์ด๋ธ์ ํ์ ํด๋์ค์ ์ธ์คํด์ค์ ํด๋นํ๋ค.
// example how to save AR entity
const user = new User();
user.firstName = "Timber";
user.lastName = "Saw";
user.isActive = true;
await user.save();
// example how to remove AR entity
await user.remove();
// example how to load AR entities
const users = await User.find({ skip: 2, take: 5 });
const newUsers = await User.find({ isActive: true });
const timber = await User.findOne({ firstName: "Timber", lastName: "Saw" });
(User
ํด๋์ค์ static ๋ฉ์๋๋ฅผ ์ถ๊ฐํ์ฌ ์ปค์คํ
find ๋ฉ์๋๋ฅผ ๋ง๋ค ์๋ ์๋ค.)
์ด ํจํด์ ๋ฆฌํฌ์งํฐ๋ฆฌ๋ผ๊ณ ๋ถ๋ฆฌ๋ ๋ณ๊ฐ์ ํด๋์ค์ ์ฟผ๋ฆฌ ๋ฉ์๋๋ฅผ ์ ์ํ๋ ํจํด์ด๋ค. ๋ชจ๋ธ ์์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ทผํ๋ ๊ฒ์ด ์๋๋ผ ๋ฆฌํฌ์งํฐ๋ฆฌ ์์์ ์ ๊ทผํ๋ ๊ฒ์ด๋ค.
const userRepository = connection.getRepository(User);
// example how to save DM entity
const user = new User();
user.firstName = "Timber";
user.lastName = "Saw";
user.isActive = true;
await userRepository.save(user);
// example how to remove DM entity
await userRepository.remove(user);
// example how to load DM entities
const users = await userRepository.find({ skip: 2, take: 5 });
const newUsers = await userRepository.find({ isActive: true });
const timber = await userRepository.findOne({ firstName: "Timber", lastName: "Saw" });
AR: ๊ฐ๋จํ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ์ (๊ฐ๋จํจ)
DM: ์ํฐํ๋ผ์ด์ฆ ๊ธ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ์ (ํ์ฅ์ฑ)
- https://typeorm.io/#/active-record-data-mapper
- https://en.wikipedia.org/wiki/Active_record_pattern
- https://en.wikipedia.org/wiki/Data_mapper_pattern
-
์ํ๋ผ์ด์ฆ๋ณด๋ค type ORM ์ด ์ข์์
- ์ํฐํฐ ์ ์ธ์ด ์ฌ์
- ํธ๋์ญ์ ์ ์ฝ๊ฒ ๊ด๋ฆฌํ ์ ์๊ณ
- ๋ ํฌ์งํ ๋ฆฌ ํจํด ์ฌ์ฉํ ์ ์์ด์ ๋น์ฆ๋์ค ๋ก์ง์ ์ข๋ ์ง์คํ ์ ์๋ค.
-
๋ ํฌ์งํ ๋ฆฌ ์ฌ์ฉํ๋ ํจํด์ ์ฅ์ ๋ชจ๋ธ์ ์ง์ค๋๊ฒ ๋๋๋ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ทผํ๋ ์์ญ์ ๋ ํฌ์งํ ๋ฆฌ์ ์์ํจ์ผ๋ก์จ ์ฑ ์์ ํ์คํ ๋ถ๋ฆฌํ ์ ์๋ค๋ ์ฅ์
-
ํธ๋ ์ง์ ๋ฐ์ฝ๋ ์ด์ ? ํด๋์ค์ ํน์ ๋ฉ์๋์ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ๋ถ์ด๋ฉด ๋ด๋ถ ์๊ฒ๋ค์ด ํ ํธ๋์ญ์ ์์ ์คํ์ด ๋จ.
-
์๊น ๋ ํผ์งํ ๋ฆฌ ํจํด์ ์ฐ๊ธฐ ์ํด์๋ ์ํ๋ผ์ด์ฆ๋ ๋๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์จ์ผํ๋๊น ํ์ ORM์ ์ฐ์ ๋ค๊ณ ํ๋๋ฐ, ํธ๋์ญ์ ์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ํ์ ORM๋ ๋๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ผํ์ง ์๋์?
- ์ํ๋ผ์ด์ฆ ๊ฐ์ ๊ฒฝ์ฐ๋ ๋๋ถ๋ถ์ ์ค์ ๋ก์ง๋ค์ด ์ํ๋ผ์ด์ฆ ํ์ ์คํฌ๋ฆฝํธ์ ์ฐ๊ด๋์ด์์ด์ ํ์ ์ค์์ ์ ์ฌ์ฉํจ.
โ 2020. Project01-C-User-Event-Collector [J028_๊น๋๊ท , J089_๋ฐ์งํ, J139_์ด์๊ฒฝ, S059_์ต๊ดํ, S060_์ต๋๊ท] all rights reserved.