-
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: ์ํฐํ๋ผ์ด์ฆ ๊ธ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ์ (ํ์ฅ์ฑ)
โ 2020. Project01-C-User-Event-Collector [J028_๊น๋๊ท , J089_๋ฐ์งํ, J139_์ด์๊ฒฝ, S059_์ต๊ดํ, S060_์ต๋๊ท] all rights reserved.