Shouldn't I Use ORM in the project?

Source: Internet
Author: User
I recently used python to write a payment system. I am struggling with whether to Use ORM to restrict my recent use of python to write a payment system. I am also struggling with whether to Use ORM to restrict my personal experience, various projects that are determined to be concise and don't Use orm at the beginning. As the business complexity increases, their own big project with a defective version of orm is also recommended. If you write SQL in bare mode, you will try to encapsulate the Modules connected to the database as the business and personnel increase, so congratulations, you have written An ORM yourself. Benefits of Using ORM:

1. Avoid writing SQL statements naked. One is concise, and the other is preventing SQL Injection by using the ORM framework.

2. abstract Data into objects, which can be integrated into existing OO programming methods.

Disadvantages:

1. It is said that the ORM performance is not good

However, in my own posture level, I haven't considered the performance consumption of ORM. In addition, from the experience of our predecessors, I also recommend Using ORM as the best practice why not?
Besides, the object can still be used in mvc.

For complex logic
You can write SQL by yourself.
Then let mapper do or ing and decide not to use ORM at the beginning, and eventually they are forced to re-create a lame ORM wheel;
At the beginning, I decided to use the ORM. Eventually, I was forced to bypass the ORM and roll up my sleeves to write SQL.
Pill! I don't need ......

Then I created the wheel ......

Now, my principle is that the background system is firmly used, so it is best not to use websites that are hanging on the front.
It's hard to use the orm, and a lot of abuse cascade operations,
Originally, an object was serialized in json format, and a database was serialized ......
So, when you don't know how to use cascading, it's better not to use it ...... I think a project that is a little bigger must be used. The business model is complicated. If I want to modify a project, it is easy to make mistakes.
With regard to efficiency, sqlalchemy has already done a good job for us, which is more efficient than the SQL statements written by many of us. If you are worried about efficiency, you can use common interfaces, hand-writing SQL statements, and orm for others.
As mentioned above, Internet companies do not need to use it, but are even more nonsense. Internet companies have fast product iterations and many changes. If there are 200 interfaces, all of them are written in SQL, you will easily encounter errors.
I currently use the flask framework as the http front-end, sqlalchemy as the orm, and twisted as the tcp server. For twisted, I only access redis, that is, I think that the dbpool of twisted itself is basically written with SQL, A slight modification to the business model takes half a day for SQL statements, which is a waste of time.
As mentioned above, multiple databases, or read/write splitting, please, Big Brother. sqlalchemy does not know which year to solve this problem.
There is also the cache problem. Now I basically use redis as the cache. Put one copy in the basic data redis, one copy in the SQL, and change at the same time. Normally used queries, you can make a cache by yourself. Is this difficult? Originally, SQL statements tend to be highly efficient. Now there are more people who begin to use simple ORM to improve development efficiency and solve database switching problems.
As for performance, cache can be used. Choose an ORM with flexible control over SQL, who knows who to use. Do not waste time. It is not recommended.
SQLAlchemy is not complex to use. Handwriting is more complex.
======
Do not write less code. In any case, this policy cannot be wrong.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.