Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a MySQL stored procedure from Ruby?

I know that in php you can make a function or procedure in the code itself like this


$query = "CREATE FUNCTION Example (x INT)
    RETURNS BOOLEAN
       BEGIN
          
       END";
mysql_query($query);

$query = "SELECT * FROM table";
mysql_query($query);

Is it possible to do something similar in Ruby?

At the moment, I need to make some kind of project in ruby, but I don’t know and can’t find whether it’s possible to write exactly this inside the code there. I know that everything there is based on Active Record, but is it possible to write the same code as in PHP? This moment is very important for me.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, you can write raw SQL in Rails:

query = "SELECT * FROM table";
mysql_query = ActiveRecord::Base.connection.execute(query)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading