Skip to content

Instantly share code, notes, and snippets.

View ochko's full-sized avatar
🏠
Working from home

Ochko ochko

🏠
Working from home
View GitHub Profile
@ochko
ochko / arel.rb
Last active April 6, 2022 18:39 — forked from janko/arel.rb
Insert statement in Arel
def insert_sql_for(table_name, data)
stmt = Arel::Nodes::InsertStatement.new
stmt.relation = Arel::Table.new(table_name)
stmt.columns = data.keys.map { |k| Arel::Table.new(table_name)[k] }
stmt.values = Arel::Nodes::Values.new(data.values, stmt.columns)
stmt.to_sql
end
require "active_record"
ActiveRecord::Base.establish_connection("postgres:///db")