diesel-rs/diesel

`into_boxed` equivalent for INTERSECT

Open

#2.620 geöffnet am 12. Jan. 2021

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (1.003 Forks)batch import
enhancementhelp wantedhole in api

Repository-Metriken

Stars
 (12.054 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 30T 16h) (30 gemergte PRs in 30 T)

Beschreibung

I was looking to handle code that would generate INTERSECT clauses in a loop based on some input. For instance:

SELECT t.* FROM t WHERE t.foo = 'a'

INTERSECT

SELECT t.* FROM t WHERE t.foo = 'b'

INTERSECT
-- ...

(except more complicated to make the INTERSECT actually worth it)

Since https://github.com/diesel-rs/diesel/pull/2514 landed I tried this out but I think I'm running into the same issue one gets when adding filter clauses in a loop - the type of the fold accumulator changes each iteration. Specifically the two methods I tried were:

// This gets me "expected `BoxedSelectStatement`
// found `CombinationClause`"
let query_base = t.into_boxed();
let attempt_1 = (0..10).fold(query_base, |query, _| {
    query.intersect(t.filter(t::foo.eq(1)))
});

// This gets me "expected `CombinationClause<one thing>`
// found `CombinationClause<other thing>`"
let query_base = t.intersect(t.filter(t::foo.eq(1)));
let attempt_2 = (0..10).fold(query_base, |query, _| {
    query.intersect(t.filter(t::foo.eq(1)))
});

Would it be useful to have an into_boxed equivalent for intersect? Or is there already one and I just couldn't find it? Or is there another better way to achieve this functionality?

Contributor Guide