Laravel QueryBuilder到DB :: select [英] Laravel QueryBuilder to DB::select

查看:146
本文介绍了Laravel QueryBuilder到DB :: select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Laravel雄辩的瓶颈问题。当运行构建查询的逻辑时,使用雄辩时非常快速和简单,但是最终使用 $ query-> get()(由于行数和关系行数),它会停止并命中最大执行时间。我显然不想只是增加时间...而且我不想重写所有的功能来使用原始查询(虽然我会的,如果我必须)。



我的问题是,有没有办法将 QueryBuilder sql命令传递给 DB :: select DB :: raw



我知道你可以使用 $ query-> toSql() - 但是我缺少数据绑定值得,如果我可以得到这些,我可以在几秒钟内解决这个问题。

解决方案

您可以通过调用查询构建器获取绑定 $ query-> getBindings()


I've got an issue with a bottleneck in Laravel eloquent. When running the logic to build the query it's very quick and simple while using eloquent, however, when it finally comes to use $query->get() (due to the number of rows, and the number of relational rows), it grinds to a halt and hits max execution time. I obviously don't want to just increase the time... And I'd prefer not to re-write all my functions to use raw queries (although I will, if I have to).

My question is, is there a way to pass a QueryBuilder sql command to DB::select or DB::raw.

I know you can use $query->toSql() - but I'm lacking the data bound values, if I could get those, I could solve this in seconds.

解决方案

You can get bindings from a query builder by calling $query->getBindings().

这篇关于Laravel QueryBuilder到DB :: select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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