John Davidson

javascript - Migrate codebase from PHP to Nest JS

0 comments
Message:


I want to migrate my old PHP application to Nest Js and for database I want to use TypeORM, the real problem I am facing is my old PHP code uses raw queries for database operations and doesn't have any ORM model. Is there some way so that TypeORM entities can be created automatically without me writing for each table manually as I have a lot of data in tables, I can't afford to lose it.



My Answer:
Unfortunately, there is no direct way to automatically generate TypeORM entities from existing raw SQL queries in your PHP code. You will need to manually create TypeORM entities for each table in your database.

However, you can use tools like TypeORM CLI to generate initial entity files based on your existing database schema. You can run the following command to generate entities for all tables in your database:


typeorm-model-generator -h -d -u -x -e mysql


This command will generate TypeORM entity files for all tables in your database. You can then customize these generated files as needed to match your application's requirements.

Alternatively, you can also consider using a code generator tool like TypeORM Entity Generator (https://github.com/daifu/typeorm-entity-generator) to automatically generate TypeORM entities based on your existing database schema.

Overall, while there is no automatic way to generate TypeORM entities from raw SQL queries, there are tools and utilities available that can help streamline the process of creating entities for your existing database tables.

Rate this post

4 of 5 based on 6253 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us