Skip to content

Commit

Permalink
Blog update
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeps committed Jul 31, 2024
1 parent 2d897e2 commit 031a3de
Show file tree
Hide file tree
Showing 10 changed files with 1,139 additions and 1,160 deletions.
393 changes: 194 additions & 199 deletions public/blogs/cicd-foundations/blog.md

Large diffs are not rendered by default.

284 changes: 143 additions & 141 deletions public/blogs/devops-foundations/blog.md

Large diffs are not rendered by default.

331 changes: 162 additions & 169 deletions public/blogs/docker-and-containers/blog.md

Large diffs are not rendered by default.

282 changes: 148 additions & 134 deletions public/blogs/javascript-vs-typescript/blog.md

Large diffs are not rendered by default.

342 changes: 167 additions & 175 deletions public/blogs/kubernetes/blog.md

Large diffs are not rendered by default.

367 changes: 179 additions & 188 deletions public/blogs/machine-learning-foundations/blog.md

Large diffs are not rendered by default.

59 changes: 28 additions & 31 deletions public/blogs/orm/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [**Examples of ORMs**](#examples-of-orms)
- [**Evaluating the Advantages and Disadvantages of ORMs**](#evaluating-the-advantages-and-disadvantages-of-orms)
- [**Advantages of ORMs**](#advantages-of-orms)
- [**Disadvantages of ORMs**](#disadvantages-of-orms)
- [**ORMs: Disadvantages**](#orms-disadvantages)
- [**Conclusion**](#conclusion)
- [**Sources**](#sources)

Expand All @@ -18,48 +18,45 @@

## **Defining ORM: A Deep Dive**

Object-Relational Mapping (ORM) is a pivotal technique in programming that bridges the gap between object-oriented programming languages and relational databases. It operates by virtually mapping database tables to classes in an application, facilitating the conversion of incompatible type systems.
Object-Relational Mapping is a technique of real importance in programming. It bridges OOPLs to relational databases. It works by virtually mapping database tables to classes in an application; this enables the conversion of the type systems, which are otherwise incompatible.

Through ORM, developers can interact with databases using familiar object-oriented paradigms, while the ORM system automatically translates these operations into SQL commands under the hood. The objective here is to offer a high-level and more natural interface to the developer, thereby abstracting the complexities of the database operations.
Via ORM, developers are given the capability to use familiar object-oriented paradigms in interacting with a database, while the ORM system automatically translates these operations into SQL commands under the hood. This is supposed to provide a high-level—thereby, more naturalinterface to the developer, abstracting away most of the complexities of database operations.

## **Advantages of Using ORMs Over Raw SQL**

The primary benefit of using an ORM over raw SQL is abstraction. ORMs enable developers to work with databases using their preferred programming language, thereby freeing them from the intricacies and potential errors that come with writing SQL queries manually. This enhances the readability and maintainability of the code.
Abstraction is the principal advantage an ORM offers over raw SQL. ORMs enable the developer to manipulate the database using their favorite language in coding, hence freeing them from all intricacies and possible errors of writing SQL queries by hand. By doing this, it improves readability and maintainability of the code.

Moreover, ORMs come packed with an array of useful features, including:
One more important aspect is that ORMs offer a lot of useful features like:

- **Automatic Schema Migration**: This feature facilitates changes in the database schema in a systematic way, mirroring changes in the application's objects.
- **CRUD Operations**: Most ORMs come with pre-built functions for Create, Read, Update, and Delete (CRUD) operations, thereby simplifying data manipulation.
- **Caching**: This can help boost performance by storing the results of a query in a cache to avoid repeated database hits for the same query.
- **Transaction Management**: ORMs provide support for transactions, a vital feature that ensures data integrity.
- **Security**: ORMs tend to offer protection against SQL injection attacks by using prepared statements or parameterized queries.
- **Automatic Schema Migration**: It enables changes in the database schema in an organized manner, reflecting changes in application-level objects.
- **CRUD Operations**: Most ORMs have built-in functions for Create, Read, Update, and Delete (CRUD) operations, which lessen this burden of data manipulation to a great extent.
- **Caching**: This can improve performance by storing the results of a query in a cache, preventing the database from being hit again and again on the same query.
- **Transaction Management**: ORMs also support transactions, a significant feature to be sure of data integrity.
- **Security**: Most of the current ORMs offer protection from SQL injection attacks via prepared statements or parameterized queries.

## **ORMs Design Patterns: ActiveRecord and DataMapper**

There are two prevalent design patterns that ORMs typically adopt: ActiveRecord and DataMapper.
There are two common design patterns that most ORMs follow: ActiveRecord and DataMapper.

### **ActiveRecord**
The ActiveRecord pattern treats each row in a database table as an instance of a class, essentially merging the object model and the database model. This implies that the object in the application not only carries the data but is also responsible for its own persistence, thereby serving as both a business entity and a data access object. ORM frameworks like Ruby on Rails' ActiveRecord and Django ORM for Python use this pattern. The simplicity and convention-over-configuration philosophy of ActiveRecord make it an easy choice for straightforward database schemas.
The ActiveRecord pattern treats each and every row in the Database table as an instance of a class; this blurs the line between the Object model and the Database model. This means that the very object, in the application, not only holds the data but also brings with itself the responsibility for its own persistence; hence, it becomes a business entity as well as a data access object. This pattern is in active use in ORM frameworks like Ruby on Rails' ActiveRecord and Django ORM for Python. The ease and convention-over-configuration philosophy of ActiveRecord make it an easy choice for simple database schemata.

### **DataMapper**
The DataMapper pattern, on the other hand, firmly separates the object model and the database model. It employs a mediator, the Data Mapper, to transfer data between the two while keeping them independent of each other. This approach can handle complex and diverse data models more gracefully, providing the flexibility to shape the object model independently of the database schema. Examples of ORM frameworks using the DataMapper pattern include SQL Alchemy for Python and Hibernate for Java.
The Data Mapper pattern firmly separates the object model and the database model. It uses a mediator, the Data Mapper, who transfers data between them keeping them independent of each other. This, in effect, graceful handling of complex and diverse data models, allows for flexibility in terms of the capability to shape the object model independent of the database schema. Some examples of ORM frameworks following the DataMapper pattern include Python's SQL Alchemy and Java's Hibernate.

## **The Role of ORMs in Software Development**

In software development, ORMs present an efficient and more intuitive way to create, retrieve, update, and delete records in a database. By abstracting database operations, they enable developers to adhere to the DRY (Don't Repeat Yourself) principle, one of the core philosophies in software development. In addition to promoting code reusability, ORMs also encourage good practices like database abstraction and code modularity.
ORMs are essentially designed to effectively create, retrieve, update, and delete records in a database within a software development setting. They abstract database operations, hence helping a developer adhere to the DRY principleone of the core philosophies in software development. Other than reusing code, ORMs also encourage other good practices, such as keeping the database abstract and modularizing the code.

## **Choosing an ORM: Factors to Consider**

Choosing whether to use an ORM, and which one to use, depends on several factors:

- **Programming Language**: The programming language of your application will dictate which ORMs are available to you.
- **Query Complexity**: For complex, custom queries, a raw SQL might be more effective or easier to optimize. However, for regular CRUD operations, ORMs can significantly simplify the process.
- **Application Scale**: For larger applications, an ORM's features, such as caching, schema migration, and CRUD operations, could be invaluable.
- **Team Expertise**: If your team is already familiar with a specific ORM, it might be more beneficial to use that one, even if it's not the most powerful or flexible.
The choice of whether to use an ORM, and which to use, depends on several factors. First, the ORM choices available are already dictated by the programming language of your application. Second, if queries are very complex or custom in nature, raw SQL might be more effective or easier to optimize. Regular CRUD operations, though, can be significantly simplified with ORMs.
- **Application Scale**: In larger applications, an ORM would be invaluable due to its features related to caching, schema migration, and CRUD operations.
- **Team Expertise**: In case your team is already familiar with any specific ORM, it will be more beneficial to use that one instead, even if it's not the most powerful or flexible.

## **Examples of ORMs**

There is a wide variety of ORMs available that cater to different programming languages. Some notable examples include:
There is a broad spectrum of ORMs available, purpose-built for different programming languages. Some examples are:

- **JavaScript/TypeScript**: Prisma, Sequelize, TypeORM, and Mongoose (for MongoDB)
- **Python**: SQLAlchemy, Django ORM, and Peewee
Expand All @@ -70,20 +67,20 @@ There is a wide variety of ORMs available that cater to different programming la

### **Advantages of ORMs**

1. **Enhanced Productivity**: ORMs allow developers to spend more time on business logic and less time on constructing SQL queries.
2. **Abstraction and Versatility**: By providing an abstraction layer, ORMs allow developers to switch between different database systems with minimal code changes.
3. **Security Features**: ORMs provide built-in protection against common vulnerabilities such as SQL injection attacks.
4. **Reduction in Boilerplate Code**: By automating common tasks associated with database interactions, ORMs reduce the need for repetitive code.
1. **More Productive**: Much of a developer's time is focused on business logic, not on constructing SQL queries, when using ORMs.
2. **Abstraction and Flexibility**: The abstraction layer that ORMs provide enables developers to change between different database systems with very few code changes.
3. **Security Features**: ORMs prevent common vulnerabilities like SQL injection by default.
4. **Reduced Boilerplate Code**: This is due to the fact that ORMs automatically generate the most boilerplate code associated with the most common tasks at hand for database interaction.

### **Disadvantages of ORMs**
### **ORMs: Disadvantages**

1. **Potential Performance Issues**: Since ORMs automatically generate SQL queries, these might not be as optimized as hand-written queries, leading to potential performance issues.
2. **Added Complexity**: ORMs add an extra layer of complexity, which might be unnecessary for simpler projects or create obstacles when troubleshooting.
3. **Learning Curve**: While ORMs provide many conveniences, each one has its unique features and conventions that require time and effort to learn.
1. **Potential for Performance Issues**: Since ORMs auto-generate these SQL queries, these queries might not be quite as efficient as they would be if hand-written. This may raise performance issues.
2. **Additional Complexity**: ORMs add one more layer of complexity, which in some instances—especially with smaller applications—may be needless or even hinder your debugging process.
3. **Learning Curve**: While all of the ORMs introduce a great deal of convenience, each of them comes with their unique features and conventions that take time and effort to learn.

## **Conclusion**
## **Conclusion**

Object-Relational Mapping (ORM) has become a cornerstone in modern web application development. It drastically enhances productivity by eliminating boilerplate code and introducing a valuable abstraction layer over the database. However, like any tool, it is not without its caveats, introducing a potential for overhead and complexity. Therefore, the decision to use an ORM should be made judiciously, considering the project's specific requirements, the complexity of the tasks at hand, and the expertise of the development team.
Object-Relational Mapping has become one of the cornerstones in contemporary web application development. It brings a huge productivity boost by eliminating boilerplate code and introducing a very valuable abstraction layer over the database. The truth of the matter is that it is just a tool; it does not come without its caveats—in particular, introducing some possible overhead and added complexity. Therefore, applying an ORM shall be done thoughtfully, taking into consideration the specific requirements of the project at hand, the complexity of the tasks, and the expertise of the development team.

# **Sources**

Expand Down
Loading

0 comments on commit 031a3de

Please sign in to comment.