Generate TypeORM Entity
TalkingSchema's AI copilot generates TypeORM entity classes with the full decorator API — @Entity, @PrimaryGeneratedColumn, @Column, @ManyToOne, @OneToMany, @ManyToMany, @JoinColumn, @Index, and @Check. Output is compatible with NestJS, standard TypeORM v0.3+, and any Node.js TypeScript backend.
Outputs are provided as TypeScript code blocks, with an option to download a .ts file coming soon
Example Output
// entities/supplier.entity.ts
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
OneToMany,
Index,
} from "typeorm";
import { Product } from "./product.entity";
import { PurchaseOrder } from "./purchase-order.entity";
export enum CarbonTier {
A = "A",
B = "B",
C = "C",
D = "D",
}
@Entity("suppliers")
export class Supplier {
@PrimaryGeneratedColumn("uuid")
supplier_id: string;
@Column({ type: "varchar", length: 200 })
company_name: string;
@Index()
@Column({ type: "varchar", length: 100 })
country: string;
@Column({ type: "enum", enum: CarbonTier })
carbon_tier: CarbonTier;
@Column({ type: "varchar", length: 100, nullable: true })
certification: string | null;
@Column({ type: "boolean", default: true })
is_active: boolean;
@CreateDateColumn({ type: "timestamptz" })
created_at: Date;
@UpdateDateColumn({ type: "timestamptz" })
updated_at: Date;
@OneToMany(() => Product, (product) => product.supplier)
products: Product[];
@OneToMany(() => PurchaseOrder, (po) => po.supplier)
purchase_orders: PurchaseOrder[];
}
// entities/product.entity.ts
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
OneToMany,
JoinColumn,
CreateDateColumn,
UpdateDateColumn,
Index,
} from "typeorm";
import { Supplier } from "./supplier.entity";
import { PurchaseOrderItem } from "./purchase-order-item.entity";
@Entity("products")
@Index(["supplier_id"])
export class Product {
@PrimaryGeneratedColumn("uuid")
product_id: string;
@Column({ type: "varchar", length: 50, unique: true })
sku: string;
@Column({ type: "varchar", length: 200 })
name: string;
@Column({ type: "varchar", length: 100 })
category: string;
@Column({ type: "decimal", precision: 8, scale: 3, nullable: true })
unit_weight_kg: number | null;
@Column({ type: "decimal", precision: 12, scale: 4 })
unit_cost_usd: number;
@Column({ type: "decimal", precision: 5, scale: 2, nullable: true })
carbon_intensity_score: number | null;
@Column({ type: "uuid" })
supplier_id: string;
@Column({ type: "boolean", default: true })
is_active: boolean;
@CreateDateColumn({ type: "timestamptz" })
created_at: Date;
@UpdateDateColumn({ type: "timestamptz" })
updated_at: Date;
@ManyToOne(() => Supplier, (supplier) => supplier.products)
@JoinColumn({ name: "supplier_id" })
supplier: Supplier;
@OneToMany(() => PurchaseOrderItem, (item) => item.product)
purchase_order_items: PurchaseOrderItem[];
}
Customizing the Output
| Requirement | Prompt addition |
|---|---|
| NestJS module structure | "Organize as a NestJS module with entity, service, repository, and module files" |
| TypeORM migration file | "Generate a TypeORM migration file (CreateInitialSchema1000000000000) for these entities" |
| Repository pattern | "Add a custom repository class extending Repository for each entity" |
| Lazy loading relations | "Use lazy: true for all @OneToMany relations" |
Frequently Asked Questions
Is the output compatible with NestJS?
Yes. The entities work directly with TypeOrmModule.forFeature([...]). Ask for NestJS module scaffolding including service and repository injection for complete module boilerplate.
Can I get a DataSource configuration too?
Yes. Ask: "Generate a TypeORM DataSource configuration for PostgreSQL using these entities." The AI produces a complete data-source.ts file with the correct entities array.