TypeORM should using repository or query buider ?

TypeORM should using repository or query buider ?

Both repository and query builder approaches can be used to query data in TypeORM, depending on the situation and your preference. The repository pattern in TypeORM provides a more intuitive and straightforward approach to interacting with the database. It allows you to define methods in the repository to perform CRUD (create, read, update, delete) operations on objects in the database. These methods can also be used to perform more complex queries, such as using JOIN or GROUP BY queries. 

The repository pattern

The repository pattern also allows you to focus on the object rather than the query. The query builder in TypeORM provides a more flexible approach to building database queries. It allows you to build complex queries by combining multiple statements and enables you to create more interactive queries with the database. 

The query builder

The query builder also allows you to have more control over creating queries and can optimize queries better than repositories in some cases. 

Therefore, whether to use a repository or a query builder depends on specific requirements and situations. If you want to focus on the object and perform CRUD operations, the repository pattern may be a better choice. If you need to build more complex and interactive queries with the database, the query builder may be a better option.


Source: ChatGPT

Nhận xét

Bài đăng phổ biến từ blog này

Type of children prop in React Typescript

Why we should Avoid using UNSAFE componentWillMount, componentWillReceiveProps, componentWillUpdate