Skip to content
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

Support array IN queries with query builder #313

Merged
merged 2 commits into from
Jan 7, 2019

Conversation

Blacksmoke16
Copy link
Contributor

Allows for the query builder to handle params that are arrays. It auto casts them to an :in query.

Courier.where(date_completed: nil, status: ["outstanding", "in_progress"]).select

SELECT contract_id, status, date_completed FROM couriers WHERE date_completed IS NULL AND status IN ('outstanding','in_progress') ORDER BY contract_id DESC

I had some trouble using placeholder vars in this context. Both ["('outstanding','in_progress')"] and [["outstanding", "in_progress"]] caused a syntax error. To get around this i just build out the IN statement and plop in the value into the query. Any ideas on how to better handle this?

@@ -23,6 +23,16 @@ require "../spec_helper"
assembler.where
assembler.numbered_parameters.should eq ["bob", "23"]
end

it "property defines IN query" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of Ints, Floats and bools would it have single quotes? I ask because I don't see tests for those cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah crap. No they wouldn't. I'll get that fixed up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eliasjpr Fixed. This did expose an issue with Float32 types. I'll look into it later and make a separate PR for that. Not sure if its a Granite issue or DB/adapter shard issue yet.

Fix env var for PG tests
Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@drujensen drujensen merged commit f593cf0 into amberframework:master Jan 7, 2019
@Blacksmoke16 Blacksmoke16 deleted the query-builder-array branch January 7, 2019 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants