Home > Blockchain >  How to create a MySQL stored procedure from Ruby?
How to create a MySQL stored procedure from Ruby?

Time:11-22

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.

CodePudding user response:

Yes, you can write raw SQL in Rails:

query = "SELECT * FROM table";
mysql_query = ActiveRecord::Base.connection.execute(query)
  • Related