Hi everyone! I'm working on an app that has numerous model files, each representing a business entity. These models are later used as ORMs to perform CRUD operations. I'm searching for a way to create all these models at once and use them across app restarts. My goal is to find a solution that works with JavaScript, but I'm also curious about the underlying concepts. Is this feasible?
4 Answers
Consider loading all your model files into memory at startup. Keep track of the file handles, make necessary edits to the in-memory files, and save those changes back to the disk as needed. You could even create a temporary file containing all the current edits combined into one.
You might want to clarify what you're aiming for. Typically, when you use an ORM, models are defined in your codebase. You write and deploy them once, so they're instantiated whenever your app starts up.
If you're working with something like ERP systems, having 200-400 tables is common. For smaller projects, around 20 tables is typical. It's important to evaluate the need for loading so many models at startup.
I'm not sure why you need to persist models across app restarts. Normally, you create and destroy model instances based on your business logic. While it's possible to create many instances quickly, it's generally better to load them from the database on demand rather than all at once when the app starts. You might want to explore optimizing your database or even implementing some caching solutions.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically