ruby - Reconnect everytime to mysql with Grape -


i ruby beginner , have question how use mysql grape.

do have call mysql.new() everytime want use database or there better way this?

i tried make new in initialize of class api < grape::api doesn't seem work...

any suggestion?

edit: here code of did , works fine, improve not connecting sql everytime if possible:

class api < grape::api    before    header "access-control-allow-origin", "*"    @db_co = mysql.new("localhost", "root", "toto", "youfight_userapp")   end   resource :users    :toto    result = @db_co.query("select username users id = 104")    result.fetch_row   end   end end 

i recommend use kind of orm. ran lot of issues when trying write ours api way yours , in end switched orm. choose datamapper, there lots of other choices. example sequel seems quite solid.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -