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.
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
}>,
}