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

Add exists to expression DSL functions #414

Closed
jimmycuadra opened this issue Aug 19, 2016 · 3 comments
Closed

Add exists to expression DSL functions #414

jimmycuadra opened this issue Aug 19, 2016 · 3 comments
Milestone

Comments

@jimmycuadra
Copy link
Contributor

This will allow the user to check for the existence of a record without loading it.

@sgrif sgrif added this to the 0.8 milestone Aug 19, 2016
@shssoichiro
Copy link
Contributor

I'd like to work on this, if no one else has started it.

@killercup
Copy link
Member

Sure, go ahead. I don't think anyone is working on this. Have you seen
any? The implementation might be similar.

Josh Holmer notifications@github.com schrieb am Do. 15. Sep. 2016 um
13:43:

I'd like to work on this, if no one else has started it.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#414 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABOX3tTUd9Xkx85waFmpLUW4LP96Jknks5qqS9PgaJpZM4Jot2m
.

@shssoichiro
Copy link
Contributor

I'm struggling a bit getting my initial test to pass. I have an implementation which compiles, which is based off of how count works, but my ExistsDsl trait doesn't seem to be implemented for the correct traits. I'm getting:

---- query_dsl::exists_dsl::ExistsDsl_0 stdout ----
    error: no method named `exists` found for type `users::table` in the current scope
  --> <anon>:15:20
   |
15 | let exists = users.exists().first(&connection);
   |                    ^^^^^^
   |
   = note: the method `exists` exists but the following trait bounds were not satisfied: `diesel::query_builder::SelectStatement<(diesel::types::Integer, diesel::types::Text), (users::columns::id, users::columns::name), users::table> : diesel::exists_dsl::ExistsDsl`, `&users::table : diesel::QuerySource`, `&users::table : diesel::query_builder::AsQuery`, `_ : diesel::exists_dsl::ExistsDsl`, `_ : diesel::Expression`, `&users::table : diesel::query_builder::Query`, `&mut users::table : diesel::QuerySource`, `&mut users::table : diesel::query_builder::AsQuery`, `_ : diesel::exists_dsl::ExistsDsl`, `_ : diesel::Expression`, `&mut users::table : diesel::query_builder::Query`
   = help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `exists`, perhaps you need to implement it:
   = help: candidate #1: `diesel::exists_dsl::ExistsDsl`

When currently my ExistsDsl implementation looks like this:

pub trait ExistsDsl: AsQuery {
    type Output;

    fn exists(self) -> Self::Output;
}

impl<T, ST> ExistsDsl for T
    where T: QuerySource + AsQuery<SqlType=ST>,
          T::Query: ExistsDsl + Expression {
    type Output = SelectStatement<Bool, Exists<T::Query>, ()>;

    fn exists(self) -> Self::Output {
        select(exists(self.as_query()))
    }
}

sgrif added a commit that referenced this issue Dec 8, 2016
While this is useful for some cases where you don't want to load the
rows, this won't fill every use case for the expression, as right now
you wouldn't be able to build a query that references the outer table.
For us to do that and have it be type safe we'd need overlapping impls
for `SelectableExpression` (story of my life), which requires
rust-lang/rust#29864 being implemented.

Fixes #414.
sgrif added a commit that referenced this issue Dec 8, 2016
While this is useful for some cases where you don't want to load the
rows, this won't fill every use case for the expression, as right now
you wouldn't be able to build a query that references the outer table.
For us to do that and have it be type safe we'd need overlapping impls
for `SelectableExpression` (story of my life), which requires
rust-lang/rust#29864 being implemented.

Fixes #414.
@sgrif sgrif closed this as completed in #534 Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants