1.0.7 • Published 3 years ago

typeorm-to-json v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago