Rails Query Database Without ActiveRecord

The official logo of the database query MySQL ...
The official logo of the database query MySQL Slovenčina: Oficiálne logo dotazovací databázy MySQL (Photo credit: Wikipedia)
Hi all,

I want to share to query Mysql without ActiveRecord (find_by_sql, or where, or connection).
Please follow me to query
1. Please go to rails console
2. And and the this line.

    config = ActiveRecord::Base.configurations[Rails.env]

    connect = Mysql2::Client.new(config)

    data = connect.query("SELECT * FROM users")

    data.map {|user| user["email"]}
SQL Humor
SQL Humor (Photo credit: travis_warren123)

I hope this article can help you.
Enhanced by Zemanta

Comments

Popular posts from this blog

Pengembang Perangkat Lunak Membangun Karya untuk UMKM

Kesalahan Pindah Blogspot ke Domain Pribadi Berujung Domain Blogspot Lenyap

Episode 5 - Meramu Nilai - Nilai Inti pada Produk