Use Arel to read and write
Use Arel to read and write

We had an issue where by changing to using an instance of a model to read from the staging database instead of a pure `connection.select_one` SQL statement, we would unintentionally read from the wrong table because Rails would cache prepared `find_by` statements. This was fixed in f4ddbcc0b7f3e3386f8a7b0b4f10a115af53937f by resetting column information after we pointed the reader at a different table, however, this solution seemed to further complicate the reading process and suggested that our original idea to move away from low-level reads in order to fix JSON column typcasting was flawed.

Instead, we double down on low-level database manipulation. We revert to low-level, un-typecast reads, and ensure that we also write using low-level methods that expect un-typecast data. This ensures that even though a JSON object comes out of the database as a string of JSON, when we write it back we don’t unintentionally typecast it to a JSON string of JSON, and instead treat it as though it is a raw value going back into the database as we did when it came out.

culturecode/stagehand