-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fixes #4349 #4350
base: master
Are you sure you want to change the base?
Fixes #4349 #4350
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -264,6 +264,36 @@ fn filter_by_in() { | |||||||||||||
); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#[test] | ||||||||||||||
#[cfg(feature = "postgres")] | ||||||||||||||
fn filter_array_by_in() { | ||||||||||||||
use crate::schema::posts::dsl::*; | ||||||||||||||
|
||||||||||||||
let connection: &mut PgConnection = &mut connection(); | ||||||||||||||
let tag_combinations_to_look_for: &[&[&str]] = &[&["foo"], &["foo", "bar"], &["baz"]]; | ||||||||||||||
let result: Vec<i32> = posts | ||||||||||||||
.filter(tags.eq_any(tag_combinations_to_look_for)) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably want to document this behavior in these places: diesel/diesel/src/expression/array_comparison.rs Lines 31 to 32 in 5a2940e
diesel/diesel/src/expression/array_comparison.rs Lines 51 to 52 in 5a2940e
diesel/diesel/src/expression_methods/global_expression_methods.rs Lines 109 to 110 in 5a2940e
|
||||||||||||||
.select(id) | ||||||||||||||
.load(connection) | ||||||||||||||
.unwrap(); | ||||||||||||||
assert_eq!(result, &[] as &[i32]); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#[test] | ||||||||||||||
#[cfg(feature = "postgres")] | ||||||||||||||
fn filter_array_by_not_in() { | ||||||||||||||
use crate::schema::posts::dsl::*; | ||||||||||||||
|
||||||||||||||
let connection: &mut PgConnection = &mut connection(); | ||||||||||||||
let tag_combinations_to_look_for: &[&[&str]] = &[&["foo"], &["foo", "bar"], &["baz"]]; | ||||||||||||||
let result: Vec<i32> = posts | ||||||||||||||
.filter(tags.ne_all(tag_combinations_to_look_for)) | ||||||||||||||
.select(id) | ||||||||||||||
.load(connection) | ||||||||||||||
.unwrap(); | ||||||||||||||
assert_eq!(result, &[] as &[i32]); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn connection_with_3_users() -> TestConnection { | ||||||||||||||
let mut connection = connection_with_sean_and_tess_in_users_table(); | ||||||||||||||
diesel::sql_query("INSERT INTO users (id, name) VALUES (3, 'Jim')") | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this got me thinking (long-term changes thoughts): maybe
QueryId
should be generic on the backend as well, so that we can properly express that this variant could in fact use static query id. If we added the option forHAS_STATIC_QUERY_ID = false
to theQueryId
derive maybe it wouldn't be that verbose in general.But maybe that's not worth. In any case that would be a separate change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like an reasonable idea for the long run.
Although I remember that the benchmarks have shown at some point that the cost of query construction for looking up statements in the prepared statement cache is only relevant for SQLite. It's not relevant for postgresql due to the network roundtrips.