Derive TypeORM schemas (or relational ORM schemas in general) from JSON schema.
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
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.
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[];
}