Skip to content

serkansahinBE/typeorm-to-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Tool to create json from typeorm entities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%