diff --git a/spec/interro_spec.cr b/spec/interro_spec.cr index 280efee..7d7daca 100644 --- a/spec/interro_spec.cr +++ b/spec/interro_spec.cr @@ -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}") diff --git a/src/query_builder.cr b/src/query_builder.cr index 04815f7..8dd7d3a 100644 --- a/src/query_builder.cr +++ b/src/query_builder.cr @@ -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)) end def -(other : self) : CompoundQuery @@ -1052,7 +1052,7 @@ module Interro str << ' ' << @combinator << ' ' str << rhs if @limit - str << "LIMIT $" << (arg_count += 1) + str << " LIMIT $" << (arg_count += 1) end end end