Rails Query Database Without ActiveRecord

11.59 Muhamad Akbar Bin Widayat 0 Comments

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

0 komentar:

terimakasih komentarnya