Entity๋?
Entity๋ ๋ค์์ ํฌํจํ๋ ๋ฐ์ดํฐ ๋ชจ๋ธ ์ ์์ ๋๋ค:- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์คํค๋ง - ํ ์ด๋ธ ๊ตฌ์กฐ, ์ปฌ๋ผ, ์ธ๋ฑ์ค
- TypeScript ํ์ - ํ์ ์์ ์ฑ์ ์ํ ํ์ ์ ์
- ๊ด๊ณ(Relations) - ๋ค๋ฅธ Entity์์ ์ฐ๊ฒฐ
- Subset - API ์๋ต์ ์ํ ํ๋ ์กฐํฉ
- Enum - ์ด๊ฑฐํ ํ์ ๊ณผ ๋ ์ด๋ธ
Entity ์ ์ ๋ฐฉ๋ฒ
Entity๋ Sonamu UI(
http://localhost:1028/sonamu-ui)์์ ์๊ฐ์ ์ผ๋ก ์ ์ํ๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค. Sonamu UI๋ ์๋ ์์ฑ, ์ ํจ์ฑ ๊ฒ์ฌ, ์ค์๊ฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.entity.json ํ์ผ ๊ตฌ์กฐ
Entity๋entity.json ํ์ผ๋ก ์ ์ฅ๋๋ฉฐ, ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๋๋ค:
api/src/application/{entity}/{entity}.entity.json
ํ์ ํ๋
id
Entity์ ๊ณ ์ ์๋ณ์์ ๋๋ค. PascalCase๋ก ์์ฑํฉ๋๋ค.- Entity ํด๋์ค๋ช , ํ์ ๋ช ์ ์ฌ์ฉ๋ฉ๋๋ค
- ์:
UserModel,User,UserBaseSchema
table
๋ฐ์ดํฐ๋ฒ ์ด์ค ํ ์ด๋ธ ์ด๋ฆ์ ๋๋ค. snake_case๋ก ์์ฑํฉ๋๋ค.title
Entity์ ํ๊ธ ๋๋ ํ์์ฉ ์ด๋ฆ์ ๋๋ค.props
Entity์ ์์ฑ(์ปฌ๋ผ) ๋ฐฐ์ด์ ๋๋ค. ๊ฐ ์์ฑ์ ํ์ ๊ณผ ์ต์ ์ ์ ์ํฉ๋๋ค.| ์ต์ | ํ์ | ์ค๋ช | ๊ธฐ๋ณธ๊ฐ |
|---|---|---|---|
name | string | ์์ฑ๋ช (snake_case) | ํ์ |
type | string | ๋ฐ์ดํฐ ํ์ | ํ์ |
desc | string | ์ค๋ช | - |
nullable | boolean | NULL ํ์ฉ ์ฌ๋ถ | false |
dbDefault | string | DB ๊ธฐ๋ณธ๊ฐ | - |
๋ ์์๋ณด๊ธฐ
- Field Types - ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ ๋ฐ์ดํฐ ํ์
- Relations - Entity ๊ฐ ๊ด๊ณ ์ ์
์ ํ ํ๋
parentId
๋ค๋ฅธ Entity๋ฅผ ์์ํ ๋ ์ฌ์ฉํฉ๋๋ค.indexes
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ธ๋ฑ์ค๋ฅผ ์ ์ํฉ๋๋ค.index- ์ผ๋ฐ ์ธ๋ฑ์ค (๊ฒ์ ์ฑ๋ฅ ํฅ์)unique- ์ ๋ํฌ ์ธ๋ฑ์ค (์ค๋ณต ๋ฐฉ์ง)hnsw- Vector ๊ฒ์์ฉ HNSW ์ธ๋ฑ์คivfflat- Vector ๊ฒ์์ฉ IVFFlat ์ธ๋ฑ์ค
subsets
API ์๋ต์์ ์ฌ์ฉํ ํ๋ ์กฐํฉ์ ์ ์ํฉ๋๋ค.Subset์
. ํ๊ธฐ๋ฒ์ผ๋ก ์ฐ๊ด Entity์ ํ๋๋ฅผ ํฌํจํ ์ ์์ต๋๋ค. Sonamu๊ฐ ์๋์ผ๋ก JOIN์ ์์ฑํฉ๋๋ค.enums
์ด๊ฑฐํ ํ์ ๊ณผ ๋ ์ด๋ธ์ ์ ์ํฉ๋๋ค.์ค์ ์์
๊ธฐ๋ณธ Entity ์์
user.entity.json
Relation ํฌํจ ์์
employee.entity.json
Sonamu UI์์ Entity ์ ์ํ๊ธฐ
-
Sonamu UI ์ ์
-
Entity ์์ฑ
- โEntitiesโ ํญ ํด๋ฆญ
- โCreate Entityโ ๋ฒํผ ํด๋ฆญ
- Entity ID, ํ ์ด๋ธ๋ช , Title ์ ๋ ฅ
-
์์ฑ(Props) ์ถ๊ฐ
- โAdd Propertyโ ๋ฒํผ์ผ๋ก ์ ์์ฑ ์ถ๊ฐ
- ํ์ ์ ํ ๋ฐ ์ต์ ์ค์
- ๋๋๊ทธ ์ค ๋๋กญ์ผ๋ก ์์ ๋ณ๊ฒฝ
-
Subset ์ ์
- โSubsetsโ ํญ์์ subset ํค ์ถ๊ฐ
- ์ฒดํฌ๋ฐ์ค๋ก ํฌํจํ ํ๋ ์ ํ
- Relation ํ๋๋ ํธ๋ฆฌ ํํ๋ก ํผ์ณ์ ์ ํ
-
์ ์ฅ ๋ฐ ์์ฑ
- โSaveโ ๋ฒํผ ํด๋ฆญ
- Entity ํ์ผ ์๋ ์์ฑ
- Migration ์๋ ์์ฑ
๐ธ ํ์: Sonamu UI์์ Entity ์์ฑํ๋ ์ ์ฒด ๊ณผ์ (์คํฌ๋ฆฐ์ท ๋๋ GIF)
๋ ์์๋ณด๊ธฐ
- Sonamu UI ์ฌ์ฉํ๊ธฐ - UI ์์ธ ๊ฐ์ด๋
Entity ์ ์ ํ ์๋ ์์ฑ๋๋ ๊ฒ๋ค
Entity๋ฅผ ์ ์ํ๊ณ ์ ์ฅํ๋ฉด Sonamu๊ฐ ์๋์ผ๋ก ๋ค์์ ์์ฑํฉ๋๋ค:TypeScript ํ์
{entity}.types.ts ํ์ผ์ ํ์
๊ณผ Zod ์คํค๋ง ์์ฑ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง์ด๊ทธ๋ ์ด์
ํ
์ด๋ธ ์์ฑ SQL์ด ํฌํจ๋ ๋ง์ด๊ทธ๋ ์ด์
ํ์ผ ์์ฑ
Base ์คํค๋ง
sonamu.generated.ts์ Base ์คํค๋ง์ Enum ์ถ๊ฐModel Scaffold
{entity}.model.ts ํ
ํ๋ฆฟ ์์ฑ (์ ํ ์)