1. <legend id='BRDvX'><style id='BRDvX'><dir id='BRDvX'><q id='BRDvX'></q></dir></style></legend>
      <i id='BRDvX'><tr id='BRDvX'><dt id='BRDvX'><q id='BRDvX'><span id='BRDvX'><b id='BRDvX'><form id='BRDvX'><ins id='BRDvX'></ins><ul id='BRDvX'></ul><sub id='BRDvX'></sub></form><legend id='BRDvX'></legend><bdo id='BRDvX'><pre id='BRDvX'><center id='BRDvX'></center></pre></bdo></b><th id='BRDvX'></th></span></q></dt></tr></i><div id='BRDvX'><tfoot id='BRDvX'></tfoot><dl id='BRDvX'><fieldset id='BRDvX'></fieldset></dl></div>
      1. <small id='BRDvX'></small><noframes id='BRDvX'>

        <tfoot id='BRDvX'></tfoot>

          <bdo id='BRDvX'></bdo><ul id='BRDvX'></ul>

        Laravel Eloquent 与查询构建器 - 为什么使用 eloquent 来降低性能

        Laravel Eloquent vs query builder - Why use eloquent to decrease performance(Laravel Eloquent 与查询构建器 - 为什么使用 eloquent 来降低性能)

        <legend id='DpxjX'><style id='DpxjX'><dir id='DpxjX'><q id='DpxjX'></q></dir></style></legend>

          <tbody id='DpxjX'></tbody>
          <bdo id='DpxjX'></bdo><ul id='DpxjX'></ul>
              <tfoot id='DpxjX'></tfoot>

                <small id='DpxjX'></small><noframes id='DpxjX'>

              1. <i id='DpxjX'><tr id='DpxjX'><dt id='DpxjX'><q id='DpxjX'><span id='DpxjX'><b id='DpxjX'><form id='DpxjX'><ins id='DpxjX'></ins><ul id='DpxjX'></ul><sub id='DpxjX'></sub></form><legend id='DpxjX'></legend><bdo id='DpxjX'><pre id='DpxjX'><center id='DpxjX'></center></pre></bdo></b><th id='DpxjX'></th></span></q></dt></tr></i><div id='DpxjX'><tfoot id='DpxjX'></tfoot><dl id='DpxjX'><fieldset id='DpxjX'></fieldset></dl></div>
                1. 本文介绍了Laravel Eloquent 与查询构建器 - 为什么使用 eloquent 来降低性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Laravel 查询构建器和 eloquent 之间做了一些性能测试.使用各种 sql 语句(select-update-delete-insert)查询生成器要快得多.

                  I did some performance test between Laravel query builder and eloquent. Query builder was much faster with various of sql statement (select-update-delete-insert).

                  所以我的问题是:为什么有人使用 Laravel Eloquent 来对抗普通查询构建器?

                  So my question is: Why someone uses Laravel Eloquent against plain query builder?

                  推荐答案

                  Eloquent 是 Laravel 对 Active Record 模式的实现,它具有所有优点和缺点.

                  Eloquent is Laravel's implementation of Active Record pattern and it comes with all its strengths and weaknesses.

                  Active Record 是以 CRUD 方式处理单个实体的一个很好的解决方案 - 即,创建一个具有填充属性的新实体,然后将其保存到数据库,从数据库加载记录或删除.

                  Active Record is a good solution for processing a single entity in CRUD manner - that is, create a new entity with filled properties and then save it to a database, load a record from a database, or delete.

                  您将从 Eloquent 的功能中受益匪浅,例如脏检查(仅针对已更改的字段发送 SQL 更新)、模型事件(例如,在有人创建新帐户时发送管理警报或更新统计计数器), 特征(时间戳、软删除、您的自定义特征)急切/延迟加载等.您还可以应用域驱动模式并在您的 Active Record 实体中实现一些业务逻辑,例如,验证、管理关系、计算等.

                  You will benefit a lot from Eloquent's features such as dirty checking (to send SQL UPDATE only for the fields which have been changed), model events (e.g. to send administrative alerts or update statistics counters when someone has created a new account), traits (timestamps, soft deletes, your custom traits) eager/lazy loading etc. You can also apply domain-driven pattern and implement some pieces of business logic in your Active Record entities, for example, validation, managing relations, calculations etc.

                  但是,正如您已经知道的,Active Record 带来了一些性能代价.

                  But, as you already know, Active Record comes with some performance price.

                  当你处理单条记录或几条记录时,没有什么可担心的.但是对于读取大量记录的情况(例如对于数据网格、报表、批处理等),普通的 Laravel DB 方法是更好的方法.

                  When you process a single record or a few records, there is nothing to worry about. But for cases when you read lots of records (e.g. for datagrids, for reports, for batch processing etc.) the plain Laravel DB methods is a better approach.

                  对于基于 Laravel 的应用程序,我们将使用两种我们认为合适的方法.我们使用 Laravel 的 Eloquent for UI 表单来处理单个记录并使用 DB 方法(由 SQL 视图支持,并具有额外的数据库引擎特定性能调整)来检索 UI 表、导出任务等的数据.它也可以工作RESTful API 很好 - Eloquent for GET, PUT, POST, DELETE with a key and DB for GET without key but with filters and sorts and paging.

                  For our Laravel based applications we are using both approaches as we see appropriate. We use Laravel's Eloquent for UI forms to process a single record and use DB methods (backed by SQL views with additional database engine specific performance tweaks) to retrieve data for UI tables, export tasks etc. It also works well with RESTful APIs - Eloquent for GET, PUT, POST, DELETE with a key and DB for GET without key but with filters and sorting and paging.

                  这篇关于Laravel Eloquent 与查询构建器 - 为什么使用 eloquent 来降低性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)
                2. <small id='ictkL'></small><noframes id='ictkL'>

                    <tfoot id='ictkL'></tfoot>
                      <tbody id='ictkL'></tbody>
                  1. <legend id='ictkL'><style id='ictkL'><dir id='ictkL'><q id='ictkL'></q></dir></style></legend>

                      <i id='ictkL'><tr id='ictkL'><dt id='ictkL'><q id='ictkL'><span id='ictkL'><b id='ictkL'><form id='ictkL'><ins id='ictkL'></ins><ul id='ictkL'></ul><sub id='ictkL'></sub></form><legend id='ictkL'></legend><bdo id='ictkL'><pre id='ictkL'><center id='ictkL'></center></pre></bdo></b><th id='ictkL'></th></span></q></dt></tr></i><div id='ictkL'><tfoot id='ictkL'></tfoot><dl id='ictkL'><fieldset id='ictkL'></fieldset></dl></div>
                            <bdo id='ictkL'></bdo><ul id='ictkL'></ul>