MySQL will not allow you to execute multiple queries on a trip (which mitigates some of the unpleasant features of SQL injection, such as small bobby tables ;)
If your database supports it, you can in theory send everything in one go:
ActiveRecord::Base.connection.execute(["BEGIN",*query,"COMMIT",""]*";\n")
Pay attention to "theoretically." Don't really try to do this.
If someone wonders what is going on there.
query = array of queries
arr = ["BEGIN",*query,"COMMIT",""] just aligns the request in an array.
arr*";\n" is the same as arr.join(";\n") blank at the end of the array provides the final ";" for COMMIT.
It's fun for something like Ruby Golf, but don't use it in production. You will only be ill if you try to read your code in the future (even in the future.)
source share