Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.61 KB

File metadata and controls

58 lines (40 loc) · 1.61 KB

TypeORM

Derive TypeORM schemas (or relational ORM schemas in general) from JSON schema.

Resources

Please look at these resources. Use the graphGenTypeorm approach, creating a JS structure that can be fed directly into typeorm to create an entity schema.

We can use an approach similar to:

This "gateway library" can take a JSON schema model and generate a TypeORM schema entities definition

graph-schema-json-writer

Alternatively use the ClassType writer in graph-schema-json-writer to write a TypeScript class source file for a TypeORM entity from a JS schema definition object.

Relationships

Example

Ideal source code export:

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToMany,
  JoinTable
} from "typeorm";
import { Category } from "./Category";

@Entity()
export class Question {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  title: string;

  @Column({ type: "int" })
  value: number;

  @ManyToMany(type => Category, category => category.questions, {
    cascade: true
  })
  @JoinTable() // required/implicit for M-M
  categories: Category[];
}