Sonamu UIμ Entity κ΄λ¦¬ κΈ°λ₯μ μ¬μ©νλ©΄ μκ°μ μΈν°νμ΄μ€λ‘ Entityλ₯Ό μ½κ² μμ±νκ³ νΈμ§ν μ μμ΅λλ€. CLIλ‘ νμΌμ μ§μ μμ νλ κ²λ³΄λ€ ν¨μ¬ λΉ λ₯΄κ³ μ§κ΄μ μ
λλ€.
Entity ν ꡬ쑰
Entity νμ λ κ°μ§ μ£Όμ μμμΌλ‘ ꡬμ±λ©λλ€:
- μΌμͺ½ Sidebar: Entity λͺ©λ‘κ³Ό μ Entity μΆκ° λ²νΌ
- μ€λ₯Έμͺ½ Content: μ νν Entityμ μμΈ μ 보 (Properties, Indexes, Relations, Subsets, Enums)
Entity μμ±νκΈ°
1. New Entity λ²νΌ ν΄λ¦
μ¬μ΄λλ° νλ¨μ [+ New Entity] λ²νΌμ ν΄λ¦ν©λλ€.
2. Entity μ 보 μ
λ ₯
λͺ¨λ¬μ΄ μ΄λ¦¬λ©΄ λ€μ μ 보λ₯Ό μ
λ ₯ν©λλ€:
| νλ | μ€λͺ
| μμ |
|---|
| Entity ID | Entity μλ³μ (PascalCase) | Product, OrderItem |
| Title | νκΈ μ λͺ© | μν, μ£Όλ¬Έ νλͺ© |
| Parent Entity | λΆλͺ¨ Entity (μ ν) | Order |
Parent Entityλ₯Ό μ§μ νλ©΄ λΆλͺ¨ Entityμ νμ Entityκ° λ©λλ€. μ: Order β OrderItem
3. κΈ°λ³Έ Properties μΆκ°
μμ±λ Entityλ κΈ°λ³Έμ μΌλ‘ λ€μ νλλ₯Ό ν¬ν¨ν©λλ€:
{
properties: [
{ name: "id", type: "int", primaryKey: true, autoIncrement: true },
{ name: "title", type: "string", length: 255 },
{ name: "created_at", type: "datetime", default: "CURRENT_TIMESTAMP" },
];
}
Properties νΈμ§
Property μΆκ°
- [+ Add Property] λ²νΌ ν΄λ¦
- Property μ 보 μ
λ ₯:
| νλ | νμ | μ€λͺ
| μμ |
|---|
| Name | β
| νλλͺ
(snake_case) | email, phone_number |
| Type | β
| λ°μ΄ν° νμ
| string, int, decimal |
| Length | μ‘°κ±΄λΆ | λ¬Έμμ΄ κΈΈμ΄ | 255 |
| Nullable | | NULL νμ© μ¬λΆ | true |
| Default | | κΈ°λ³Έκ° | 0, CURRENT_TIMESTAMP |
| Comment | | μ€λͺ
| μ¬μ©μ μ΄λ©μΌ |
μ§μνλ λ°μ΄ν° νμ
:
- λ¬Έμμ΄:
string, text, mediumtext, longtext
- μ«μ:
int, bigint, float, double, decimal
- λ μ§:
date, datetime, timestamp
- κΈ°ν:
boolean, json, enum
Property μμ
- Property νμ ν΄λ¦νμ¬ νΈμ§ λͺ¨λλ‘ μ ν
- κ°μ μμ
- λ€λ₯Έ κ³³μ ν΄λ¦νκ±°λ Enterλ₯Ό λλ¬ μ μ₯
Property μμ
Property νμ [Γ] λ²νΌμ ν΄λ¦ν©λλ€.
λ°μ΄ν° μμ€ μ£Όμ: Propertyλ₯Ό μμ νλ©΄ ν΄λΉ 컬λΌμ λͺ¨λ λ°μ΄ν°κ° μμ λ©λλ€. λ§μ΄κ·Έλ μ΄μ
μ
μ€ννκΈ° μ μ λ°λμ λ°μ΄ν°λ₯Ό λ°±μ
νμΈμ.
Indexes κ΄λ¦¬
Index μΆκ°
- Indexes μΉμ
μΌλ‘ μ€ν¬λ‘€
- [+ Add Index] λ²νΌ ν΄λ¦
- Index μ 보 μ
λ ₯:
| νλ | μ€λͺ
| μμ |
|---|
| Fields | μΈλ±μ€ λμ νλ (볡μ μ ν κ°λ₯) | email, created_at |
| Type | μΈλ±μ€ νμ
| index, unique, fulltext |
Index νμ
:
- index: μΌλ° μΈλ±μ€ (κ²μ μ±λ₯ ν₯μ)
- unique: μ λν¬ μΈλ±μ€ (μ€λ³΅ λ°©μ§)
- fulltext: μ λ¬Έ κ²μ μΈλ±μ€ (ν
μ€νΈ κ²μ)
λ³΅ν© Index
μ¬λ¬ νλλ₯Ό μ ννμ¬ λ³΅ν© μΈλ±μ€λ₯Ό μμ±ν μ μμ΅λλ€:
indexes: [
{ fields: ["user_id", "created_at"], type: "index" },
{ fields: ["email"], type: "unique" },
];
Relations κ΄λ¦¬
belongsTo (N:1 κ΄κ³)
μλ―Έ: βμ΄ Entityλ λ€λ₯Έ Entityμ μνλ€β
μμ: Postλ Userμ μν¨
- belongsTo μΉμ
μ [+ Add] λ²νΌ ν΄λ¦
- μ 보 μ
λ ₯:
| νλ | μ€λͺ
| μμ |
|---|
| Entity | μ°Έμ‘°ν Entity | User |
| As | κ΄κ³ λ³μΉ | author |
| Foreign Key | μΈλν€ νλλͺ
(μ ν) | author_id |
μμ±λλ μ½λ:
belongsTo: [{ entityId: "User", as: "author" }];
hasMany (1:N κ΄κ³)
μλ―Έ: βμ΄ Entityλ μ¬λ¬ κ°μ λ€λ₯Έ Entityλ₯Ό κ°μ§λ€β
μμ: Userλ μ¬λ¬ Postλ₯Ό κ°μ§
- hasMany μΉμ
μ [+ Add] λ²νΌ ν΄λ¦
- μ 보 μ
λ ₯:
| νλ | μ€λͺ
| μμ |
|---|
| Entity | λμ Entity | Post |
| As | κ΄κ³ λ³μΉ | posts |
μμ±λλ μ½λ:
hasMany: [{ entityId: "Post", as: "posts" }];
Enums κ΄λ¦¬
νΉμ νλκ° μ νλ κ°λ§ κ°μ§ μ μμ λ Enumμ μ¬μ©ν©λλ€.
Enum μΆκ°
- Enums μΉμ
μ [+ Add Enum] λ²νΌ ν΄λ¦
- Enum μ 보 μ
λ ₯:
| νλ | μ€λͺ
| μμ |
|---|
| Name | Enum μ΄λ¦ | UserRole |
| Values | κ° λͺ©λ‘ (μΌνλ‘ κ΅¬λΆ) | admin, user, guest |
μμ±λλ μ½λ:
enums: [
{
name: "UserRole",
values: ["admin", "user", "guest"],
},
];
Propertyμμ μ¬μ©:
{
name: "role",
type: "enum",
enum: "UserRole",
default: "user"
}
AI μ§μ Entity μμ±
μ¬μ΄λλ° νλ¨μ [π¬ AI] λ²νΌμ ν΄λ¦νλ©΄ AI μ±ν
μΈν°νμ΄μ€κ° μ΄λ¦½λλ€.
AIλ‘ Entity μμ±
μμ ν둬ννΈ:
λΈλ‘κ·Έ κ²μκΈμ μν Post Entityλ₯Ό λ§λ€μ΄μ€.
μ λͺ©, λ΄μ©, μμ±μ, μμ±μΌ, μ‘°νμκ° νμν΄.
AIκ° Entity μ μλ₯Ό μμ±νκ³ μλμΌλ‘ μΆκ°ν΄μ€λλ€.
AIλ‘ Entity μμ
μμ ν둬ννΈ:
User Entityμ νλ‘ν μ΄λ―Έμ§ νλλ₯Ό μΆκ°ν΄μ€.
AIκ° κΈ°μ‘΄ Entityλ₯Ό λΆμνκ³ μμ μ¬νμ μ μ©ν©λλ€.
ꡬ체μ μΌλ‘ μμ²νμΈμ: νλ νμ
, μ μ½ μ‘°κ±΄, κ΄κ³ λ±μ λͺ
νν μ€λͺ
ν μλ‘ λ μ νν κ²°κ³Όλ₯Ό μ»μ
μ μμ΅λλ€.
μ€μ μμ
μ μμκ±°λ Product Entity
export const ProductEntity = {
properties: [
{ name: "id", type: "int", primaryKey: true, autoIncrement: true },
{ name: "title", type: "string", length: 255 },
{ name: "description", type: "text", nullable: true },
{ name: "price", type: "decimal", precision: 10, scale: 2 },
{ name: "stock", type: "int", default: 0 },
{ name: "category_id", type: "int" },
{ name: "status", type: "enum", enum: "ProductStatus" },
{ name: "created_at", type: "datetime", default: "CURRENT_TIMESTAMP" },
{ name: "updated_at", type: "datetime", onUpdate: "CURRENT_TIMESTAMP" },
],
indexes: [
{ fields: ["category_id"] },
{ fields: ["title"], type: "fulltext" },
{ fields: ["status", "created_at"] },
],
belongsTo: [{ entityId: "Category", as: "category" }],
hasMany: [{ entityId: "Review", as: "reviews" }],
enums: [
{
name: "ProductStatus",
values: ["active", "inactive", "soldout"],
},
],
} satisfies EntityType;
λ³κ²½μ¬ν μ μ©
Entityλ₯Ό μμ ν νμλ λ§μ΄κ·Έλ μ΄μ
μ μμ±νκ³ μ€νν΄μΌ λ°μ΄ν°λ² μ΄μ€μ λ°μλ©λλ€.
μν¬νλ‘μ°
- Entity νΈμ§: UIμμ Entity μμ
- Migration μμ±: Migration νμμ λ§μ΄κ·Έλ μ΄μ
μμ±
- Migration μ€ν: λ§μ΄κ·Έλ μ΄μ
μ€ννμ¬ DB λ°μ
- Scaffolding: Modelκ³Ό ν
μ€νΈ μ½λ μμ±
Entity νμΌ(.entity.ts)μ UIμμ μμ μ μλμΌλ‘ μ μ₯λ©λλ€.
λ€μ λ¨κ³
Migration ν
λ§μ΄κ·Έλ μ΄μ
μμ± λ° μ€ν
Scaffolding ν
Model μ½λ μλ μμ±