使用Laravel的Fluent插入IGNORE [英] INSERT IGNORE using Laravel's Fluent

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

问题描述

是否可以快速修改由 Laravel的Fluent 生成的SQL查询,使其具有INSERT IGNORE而不是通常的INSERT?

Is there a quick way to modify a SQL query generated by Laravel's Fluent to have an INSERT IGNORE instead of the usual INSERT?

我正在尝试插入包含五十个元素的数组.手动写出整个查询将使代码膨胀,并使它更容易受到人为错误的影响.

I'm trying to insert an array with fifty elements. Writing out the entire query manually will bloat up the code and make it more susceptible to human errors.

推荐答案

对于这项工作,您需要创建一个新的语法,其中将包含正确的字符串:

For the job you need to create a new Grammar that will have the right string in there:

grammar.php (1)

语法是DB或在这种情况下Database存储的连接的公共属性.这并不是很简单,但是从属性的可见性来看,您应该可以将特殊的语法注入数据库层.

The grammar is a public property of the DB or in this case Database stored connection. This is not really straight forward, but from the visibility of the properties you should be able to inject your special grammar into the database layer.

我还建议您在项目中提出这个问题,他们可能对如何在此类情况下更加灵活有一个更好的主意.

I also suggest you bring the issue up with the project, they probably have got a better idea how to make that more flexible for cases like these.

(1)这是答案参考书的发布日期.如果今天看到此消息,则需要采用您使用的Laravel版本,例如 Grammar.php for 4.0 ,这些类已移至laravel/framework.

(1) This was a former, to the date of the answer reference. If you see this today, you need to adopt to the Laravel version you use, e.g. Grammar.php for 4.0, these classes have moved into laravel/framework.

这篇关于使用Laravel的Fluent插入IGNORE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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