I'm struggling with ruby's mysql gem and prepares statements.
I want to end up with the same as I would do with each_hash
over the result, but it's nor supported in prepares statements.
So I came with this horrible mess.
stmt = @db.prepare("SELECT mat_id, name, qty FROM materials WHERE mat_id = ? ")
#those 3 lines hurt my eyes
res = stmt.execute(params[:id])
mat_id, name, qty = res.bind_result(Integer, String, Integer).fetch
@material = [mat_id: mat_id, name: name, qty: qty]
There has to be a better way to fetch the results and get an array of hashes.
A better mysql gem could be a valid answer. An ORM is NOT.
mysql2
gem?