-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ActiveRecord methods to generate INSERT SQLs #26
Use ActiveRecord methods to generate INSERT SQLs #26
Conversation
values.each do |attribute, value| | ||
column = record.column_for_attribute(attribute.name) | ||
values[attribute] = connection.type_cast(value, column) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish this block could be avoided and have that done automatically, but I couldn't figure out how.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks alright. It's ok since this code is extracted into its own method.
It might be worth writing some docs for this method
/module
now that things are getting a little more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nettofarah Done! Let me know if it looks alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic.
Use ActiveRecord methods to generate INSERT SQLs
I was trying to use Polo with PostgreSQL but ran into couple of issues (I using it from Master with the PR related to Postgres that was merged couple of days ago):
hstore
(http://www.postgresql.org/docs/9.4/static/hstore.html), and that wasn't being serialized with the correct syntax.To get that fixed I went ahead and changed the code to use ActiveRecord methods to generate SQL, and after checking it manually, I could see it working fine for both PostgreSQL and MySQL.
The reason why I had to change all SQLs on the specs to be double-quoted is because that is the standard for SQLite, as it only supports backticks to the compatible with MySQL (see https://www.sqlite.org/lang_keywords.html)
I personally believe that these changes really need the work on #23 to be done. And additionally it would be nice to test DBMS specifics, like the different data types each one has (e.g.
hstore
,json
orarray
on PostgreSQL) and different syntaxes. But I'm not sure what would be the best practices to structure and organize those tests.