typeorm-to-json
v1.0.7
Published
Convert all typeorm entities to javascript model definition objects
Downloads
27
Readme
Description
This package allows to generate an object of all entities that are registered to the current typeorm connection.
It is required to pass the typeorm connection object in the first argument.
Installation
npm install typeorm-to-json#Usage
###Import
const {generateObjectFromTypeormEntities} = require('typeorm-to-json')or
import {generateObjectFromTypeormEntities} from'typeorm-to-json'###Use
const typeormConnection = await createConnection();
const models = await generateObjectFromTypeormEntities(typeormConnection)The generateObjectFromTypeormEntities will return an array of ModelDefinition[]:
export type ModelDefinition = {
name: string,
tableName: string,
schema: string,
fields: Array<{
name: string,
dbType: ColumnType | string,
dbColumnName: string,
isPrimary: boolean,
isNullable: boolean,
isUnique: boolean
}>
constraints: Array<{
type: string,
name: string,
columns: Array<{ name: string, dbColumnName: string }>
}>
relations: Array<{
fromModel: string,
fields: string[],
referencedModel: string,
references: string[]
key?: string,
type: string,
name: string,
onUpdate?: string,
onDelete?: string
}>,
}