LukeClancy / dynamic-records-meritfront

Dynamic Records Meritfront was built to allow you to make full use of your database's capabilites, while utilizing ruby on rails & Active Record. It contains a better way to write sql queries for rails, and includes other tips and tricks to take advantage of. Perfect for all your dynamic applications, optimizations and weird edge cases!
MIT License
7 stars 0 forks source link

QueryAttribute stringification issue #4

Open LukeClancy opened 7 months ago

LukeClancy commented 7 months ago

see: https://github.com/rails/rails/issues/51250

LukeClancy commented 6 months ago

I am not sure how widespread this is, as I only recently updated to the latest version of postgresql and ruby on rails. To make the long story short, all data-types sent to the database are now inferred. For instance sending a value of 5 will become a string if it is not obviously in the context of being an integer. AKA dynamic_sql("select :x", x: 5) will return x as "5". This is the same for where statements and such.

I do not see any obvious way of solving this issue without a deep dive on the 'pg' gem and its interactions with ActiveRecord. For instance, maybe I could call the pg gem directly, but then I would be bypassing stored procedures on the ActiveRecord side.

Luckily, inferred variables work most of the time. I suggest mitigation.

  1. Make sure to have good error tracking for your website
  2. Make sure to cast vauge parameters (::timestamp for datetime objects etc.)

At some point I will be removing the QueryAttribute class, which seems to do little now. I will be putting that in a new major version change since it did work well on some past combination of technologies.