是否有可能在续集中批量更新?

时间:2021-01-14 00:02:47

Is it possible to make many updates in a single call using Sequel?

使用Sequel可以在一次通话中进行多次更新吗?

For instance, making about 200 updates could take several minutes on my server, but if I forge a single SQL query it runs in a matter of seconds. I wonder if Sequel could be used to forge that SQL query or even better, do the whole operation one shot by itself.

例如,在我的服务器上进行大约200次更新可能需要几分钟,但如果我伪造一个SQL查询,它将在几秒钟内运行。我想知道Sequel是否可以用来伪造那个SQL查询甚至更好,单独完成整个操作。

3 个解决方案

#1


5  

You can use Datset#import http://sequel.jeremyevans.net/rdoc/classes/Sequel/Dataset.html#method-i-import "Inserts multiple records into the associated table. This method can be used to efficiently insert a large number of records into a table in a single query if the database supports it. Inserts are automatically wrapped in a transaction."

您可以使用Datset#import http://sequel.jeremyevans.net/rdoc/classes/Sequel/Dataset.html#method-i-import“将多个记录插入到关联的表中。此方法可用于高效插入大型如果数据库支持单个查询中的表中记录的数量。插入将自动包装在事务中。“

here's an example of how to use it:

这是一个如何使用它的例子:

DB = Sequel.connect(...)
DB[:movies].import([:id, :director, :title, :year], [[1, "Orson Welles", "Citizen Kane", 1941],[2, "Robert Wiene", "Cabinet of Dr. Caligari, The", 1920]])

#2


3  

The solution I've come across involves the update_sql method. Instead of doing the operation itself, it output raw SQL queries. To batch multiple updates, just join these with ; in between, call the run method with the resulting string and you're all set.

我遇到的解决方案涉及update_sql方法。它不是自己进行操作,而是输出原始SQL查询。要批量处理多个更新,只需加入这些更新;在中间,用生成的字符串调用run方法,你就完成了所有设置。

The batching solution is WAY faster than multiple updates.

批处理解决方案比多次更新更快。

#3


-1  

Dataset#update doesn't work for you?

数据集#update对您不起作用?

http://sequel.jeremyevans.net/rdoc/classes/Sequel/Dataset.html#method-i-update

#1


5  

You can use Datset#import http://sequel.jeremyevans.net/rdoc/classes/Sequel/Dataset.html#method-i-import "Inserts multiple records into the associated table. This method can be used to efficiently insert a large number of records into a table in a single query if the database supports it. Inserts are automatically wrapped in a transaction."

您可以使用Datset#import http://sequel.jeremyevans.net/rdoc/classes/Sequel/Dataset.html#method-i-import“将多个记录插入到关联的表中。此方法可用于高效插入大型如果数据库支持单个查询中的表中记录的数量。插入将自动包装在事务中。“

here's an example of how to use it:

这是一个如何使用它的例子:

DB = Sequel.connect(...)
DB[:movies].import([:id, :director, :title, :year], [[1, "Orson Welles", "Citizen Kane", 1941],[2, "Robert Wiene", "Cabinet of Dr. Caligari, The", 1920]])

#2


3  

The solution I've come across involves the update_sql method. Instead of doing the operation itself, it output raw SQL queries. To batch multiple updates, just join these with ; in between, call the run method with the resulting string and you're all set.

我遇到的解决方案涉及update_sql方法。它不是自己进行操作,而是输出原始SQL查询。要批量处理多个更新,只需加入这些更新;在中间,用生成的字符串调用run方法,你就完成了所有设置。

The batching solution is WAY faster than multiple updates.

批处理解决方案比多次更新更快。

#3


-1  

Dataset#update doesn't work for you?

数据集#update对您不起作用?

http://sequel.jeremyevans.net/rdoc/classes/Sequel/Dataset.html#method-i-update