Executing arbitrary SQL queries in Ruby

I was simply instructed to automate the task of reporting at work. Someone used to run large, arbitrary SELECTin a MySQL database using a GUI tool, and then used the same tool to export the results to CSV. Now I want to write a Ruby script to do this.

I know about FasterCSV in Ruby, but for SQL queries, I used only ActiveRecord, where you don't write queries at all, but use models and associations. The last time I wrote the full SQL code in the code, I encoded PHP.

What is the easiest way to do such things in Ruby? Should I use ActiveRecord?

+3
source share
3 answers

, ActiveRecord. , .

script ActiveRecord, mysql mysql2 gems.

+3

Sequel. documentation, , , (IMHO) , ActiveRecord, , , ,.

README, Cheat SQL.

+2

, , , ORM, ActiveRecord, . , , raw SQL ( Sequel) .

0
source

Source: https://habr.com/ru/post/1795916/


All Articles