使用 ORM 有什么好处? [英] What are the advantages of using an ORM?

查看:24
本文介绍了使用 ORM 有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一名希望从手动编码的 PHP 站点转向基于框架的站点的 Web 开发人员,我看到了很多关于 ORM 相对于另一个 ORM 优势的讨论.它似乎对特定 (?) 规模的项目很有用,对于企业级应用程序甚至更重要.

As a web developer looking to move from hand-coded PHP sites to framework-based sites, I have seen a lot of discussion about the advantages of one ORM over another. It seems to be useful for projects of a certain (?) size, and even more important for enterprise-level applications.

作为开发人员,它给了我什么?我的代码与我现在使用的各个 SELECT 语句有何不同?它将如何帮助数据库访问和安全?它如何了解数据库架构和用户凭据?

What does it give me as a developer? How will my code differ from the individual SELECT statements that I use now? How will it help with DB access and security? How does it find out about the DB schema and user credentials?

@duffymo 指出了对我来说应该是显而易见的:ORM 仅对 OOP 代码有用.我的代码不是OO,所以我没有遇到ORM解决的问题.

推荐答案

我想说的是,如果您不处理对象,那么使用 ORM 就没有意义了.

I'd say that if you aren't dealing with objects there's little point in using an ORM.

如果您的关系表/列与对象/属性按 1:1 映射,则使用 ORM 没有多大意义.

If your relational tables/columns map 1:1 with objects/attributes, there's not much point in using an ORM.

如果您的对象与其他对象没有任何 1:1、1:m 或 m:n 关系,那么使用 ORM 就没有多大意义.

If your objects don't have any 1:1, 1:m or m:n relationships with other objects, there's not much point in using an ORM.

如果您有复杂的、手动调整的 SQL,那么使用 ORM 就没有多大意义.

If you have complex, hand-tuned SQL, there's not much point in using an ORM.

如果您已经决定您的数据库将使用存储过程作为其接口,那么使用 ORM 就没有多大意义了.

If you've decided that your database will have stored procedures as its interface, there's not much point in using an ORM.

如果您有一个无法重构的复杂遗留架构,那么使用 ORM 就没有多大意义.

If you have a complex legacy schema that can't be refactored, there's not much point in using an ORM.

相反:

如果你有一个实体对象模型,对象之间的关系是 1:1、1:m 和 m:n,没有存储过程,并且像 ORM 解决方案会给你的动态 SQL,一定要使用 ORM.

If you have a solid object model, with relationships between objects that are 1:1, 1:m, and m:n, don't have stored procedures, and like the dynamic SQL that an ORM solution will give you, by all means use an ORM.

像这样的决定总是一种选择.选择、实施、衡量、评估.

Decisions like these are always a choice. Choose, implement, measure, evaluate.

这篇关于使用 ORM 有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆