TypeORM: How to Limit Query Execution Time
When performing CRUD operations with TypeORM, you can set timeout (maximum execution time) for a certain query like so:
const productRepository = dataSource.getRepository(Product); const products = await productRepository .createQueryBuilder('product') .orderBy('product.id', 'DESC') .maxExecutionTime(3000) // 3000 milliseconds .getMany()
If the query above takes more than 3000 milliseconds, it will be dropped to avoid crashing the server. You can set another amount of time that makes sense to you.
- TypeORM: 2 Ways to Exclude a Column from being Selected
- Using ENUM Type in TypeORM
- Node.js: Use Async Imports (Dynamic Imports) with ES Modules
- Node.js: How to Use “Import” and “Require” in the Same File
- Best Node.js frameworks to build backend APIs
You can also check out our Node.js category page for the latest tutorials and examples.
View all comments