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

Help translate sql to diesel #1176

Closed
xinghun92 opened this Issue Sep 19, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@xinghun92

xinghun92 commented Sep 19, 2017

I have many messages and many chats, one message belongs to only one chat and has a unique position in this chat. And I want to get messages in different chats with different positions. Does diesel support query like this?

select * from messages where chat_id=1 and position in (1,2,3) or chat_id=2 and position in (3,4,5) or chat_id=3 and position in (6,7,8) ...
@sgrif

This comment has been minimized.

Member

sgrif commented Sep 19, 2017

let case_1 = chat_id.eq(1).and(position.eq_any(vec![1, 2, 3]));
let case_2 = chat_id.eq(2).and(position.eq_any(vec![3, 4, 5]));
let case_3 = chat_id.eq(3).and(position.eq_any(vec![6, 7, 8]));

messages.filter(case_1.or(case_2).or(case_3))

@sgrif sgrif closed this Sep 19, 2017

@xinghun92

This comment has been minimized.

xinghun92 commented Sep 19, 2017

How can I use it dynamically?

let mut Initial = ...
for sub_case in cases {
    Initial = Initial.or(sub_case)
}

and what the Initial should be?

@sgrif

This comment has been minimized.

Member

sgrif commented Sep 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment