TypeORM Visual is an interactive CLI tool that helps you create TypeORM entities for NestJS applications visually.
npm install -g typeorm-visualAfter installation, you can use the typeorm-visual command from anywhere.
npm install typeorm-visualWhen installed locally, you can use the tool with npx:
npx typeorm-visual <command>The interactive entity creator guides you through the process of creating your database entities:
typeorm-visual createThis will:
- Prompt you to create one or more entities
- For each entity, you can define columns with their data types and constraints
- Define relationships between entities (one-to-one, one-to-many, many-to-one, many-to-many)
- Generate TypeORM entity files in the
output/entitiesdirectory
You can also generate entities from a JSON schema file:
typeorm-visual generate --file schema.jsonThe schema file should follow this format:
{
"entities": [
{
"name": "User",
"tableName": "users",
"columns": [
{
"name": "id",
"type": "uuid",
"isPrimary": true,
"isGenerated": true,
"isNullable": false,
"isUnique": true,
"comment": "Primary key"
},
{
"name": "username",
"type": "varchar",
"isPrimary": false,
"isGenerated": false,
"isNullable": false,
"isUnique": true,
"length": "100",
"comment": "User's unique username"
}
]
}
],
"relations": [
{
"sourceEntity": "Post",
"targetEntity": "User",
"relationType": "many-to-one",
"sourceField": "author",
"targetField": "posts",
"isBidirectional": true,
"joinColumn": "user_id",
"isEager": false,
"hasCascade": false
}
]
}See the blog-example.json for a complete example schema.
The generated entity files are TypeORM entity classes ready to use in your NestJS application. They include:
- 🏷️ Entity decorators with the correct table name
- 📊 Column definitions with types, constraints, and comments
- 🔗 Relationship decorators (OneToOne, OneToMany, ManyToOne, ManyToMany)
- 🔄 Join column and join table decorators when needed
TypeORM Visual supports all common SQL data types:
- 🔢 integer, bigint, smallint
- 📊 float, double, decimal
- ✅ boolean
- 📝 varchar, char, text
- 📅 date, datetime, timestamp, time
- 🧩 enum, json, uuid
- Create a new NestJS project
- Install TypeORM Visual:
npm install -g typeorm-visual - Run the interactive creator:
typeorm-visual create - Define your entities and relationships
- Copy the generated entity files to your NestJS project's entity directory
- Use the entities in your NestJS modules and services
- Make sure to define sensible primary keys for your entities
- When defining relationships, consider which side should be the owner of the relationship
- For bidirectional relationships, pay attention to the inverse property names
- Use cascade options carefully, especially for delete operations