mikro-orm-entity

MikroORM Entity Guide

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "mikro-orm-entity" with this command: npx skills add bloominggrace/create-fullstack-service/bloominggrace-create-fullstack-service-mikro-orm-entity

MikroORM Entity Guide

Use this skill when creating or modifying MikroORM entity files (*.entity.ts ).

Basic Entity Structure

import { Entity, PrimaryKey, Property, Unique } from '@mikro-orm/core'; import { uuidv7 } from 'uuidv7';

import { EntityEnum } from '../entity.enums';

@Entity() export class EntityName { @PrimaryKey({ type: 'uuid' }) id: string = uuidv7();

@Property() @Unique() uniqueField!: string;

@Property({ length: 30, nullable: true }) optionalField?: string;

@Property({ type: 'date', nullable: true }) dateField?: Date;

@Property({ type: 'string', nullable: true }) enumField?: EntityEnum;

@Property({ onCreate: () => new Date() }) createdAt?: Date;

@Property({ onCreate: () => new Date(), onUpdate: () => new Date() }) updatedAt?: Date; }

Core Rules

  1. Primary Key
  • Use UUID v7: Use uuidv7 package for time-ordered UUIDs

  • Assign default value directly in class field (= uuidv7() )

  1. Property Decorators
  • Required fields: Use ! (definite assignment assertion)

  • Optional fields: Use ? (optional) with nullable: true option

  • String length limits: Use length option

  • Date type: Explicitly specify { type: 'date' }

  1. Enum Fields
  • Use @Property({ type: 'string' })

  • Define enums in separate .enums.ts file

  1. Timestamps
  • onCreate : Auto-set on creation

  • onUpdate : Auto-update on modification

  • Both fields declared as optional (? )

  1. Unique Constraints
  • Place @Unique() decorator below @Property()

Enum File Structure (*.enums.ts)

export enum EntityStatus { ACTIVE = 'ACTIVE', INACTIVE = 'INACTIVE', DELETED = 'DELETED', }

export enum EntityType { TYPE_A = 'TYPE_A', TYPE_B = 'TYPE_B', }

  • Values in uppercase SNAKE_CASE

  • Keep key and value identical

File Naming Conventions

  • Entity file: {entity-name}.entity.ts

  • Enum file: {module-name}.enums.ts

  • Folder structure: src/{module}/entities/

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

dto-response

No summary provided by upstream source.

Repository SourceNeeds Review
General

pr-title

No summary provided by upstream source.

Repository SourceNeeds Review
General

testing-vitest

No summary provided by upstream source.

Repository SourceNeeds Review