Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions spec/interro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,25 @@ describe Interro do
users.should_not contain excluded
end

it "can run INTERSECT queries" do
both = create_user(name: "Both")
only_lhs = create_user(name: "Both", email: "lhs-only-#{UUID.random}@example.com")

users = (query.with_name("Both") & query.with_id(both.id)).to_a

users.should contain both
users.should_not contain only_lhs
end

it "can limit compound queries" do
Array.new(2) { create_user(name: "Limit LHS") }
Array.new(2) { create_user(name: "Limit RHS") }

users = (query.with_name("Limit LHS") | query.with_name("Limit RHS")).first(3).to_a

users.size.should eq 3
end

describe "subqueries" do
it "queries on membership in a set" do
included = create_user(email: "included-#{UUID.random}")
Expand Down
4 changes: 2 additions & 2 deletions src/query_builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ module Interro
end

def &(other : self) : CompoundQuery
CompoundQuery.new(self, "INTERSECTION", other, connection(CONFIG.read_db))
CompoundQuery.new(self, "INTERSECT", other, connection(CONFIG.read_db))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I make this exact mistake every time I need an INTERSECT query. Well, at least I'm consistent.

I'm surprised I've never needed to do it with Interro, though.

end

def -(other : self) : CompoundQuery
Expand Down Expand Up @@ -1052,7 +1052,7 @@ module Interro
str << ' ' << @combinator << ' '
str << rhs
if @limit
str << "LIMIT $" << (arg_count += 1)
str << " LIMIT $" << (arg_count += 1)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

💯

end
end
end
Expand Down
Loading