1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
//! AST types representing various typed SQL expressions.
//!
//! Almost all types implement either [`Expression`] or
//! [`AsExpression`].
//!
//! The most common expression to work with is a
//! [`Column`](crate::query_source::Column). There are various methods
//! that you can call on these, found in
//! [`expression_methods`](crate::expression_methods).
//!
//! You can also use numeric operators such as `+` on expressions of the
//! appropriate type.
//!
//! Any primitive which implements [`ToSql`](crate::serialize::ToSql) will
//! also implement [`AsExpression`], allowing it to be
//! used as an argument to any of the methods described here.
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub use Concat;
// we allow unreachable_pub here
// as rustc otherwise shows false positives
// for every item in this module. We reexport
// everything from `crate::helper_types::`
pub
pub use CaseWhen;
pub use ;
pub use ;
use crateBackend;
use crate;
use crate;
/// Represents a typed fragment of SQL.
///
/// Apps should not need to implement this type directly, but it may be common
/// to use this in where clauses. Libraries should consider using
/// [`infix_operator!`](crate::infix_operator!) or
/// [`postfix_operator!`](crate::postfix_operator!) instead of
/// implementing this directly.
/// Marker trait for possible types of [`Expression::SqlType`]
/// Possible types for []`Expression::SqlType`]
/// A helper to translate type level sql type information into
/// runtime type information for specific queries
///
/// If you do not implement a custom backend implementation
/// this trait is likely not relevant for you.
/// Converts a type to its representation for use in Diesel's query builder.
///
/// This trait is used directly. Apps should typically use [`IntoSql`] instead.
///
/// Implementations of this trait will generally do one of 3 things:
///
/// - Return `self` for types which are already parts of Diesel's query builder
/// - Perform some implicit coercion (for example, allowing [`now`] to be used as
/// both [`Timestamp`] and [`Timestamptz`].
/// - Indicate that the type has data which will be sent separately from the
/// query. This is generally referred as a "bind parameter". Types which
/// implement [`ToSql`] will generally implement `AsExpression` this way.
///
/// [`IntoSql`]: crate::IntoSql
/// [`now`]: crate::dsl::now
/// [`Timestamp`]: crate::sql_types::Timestamp
/// [`Timestamptz`]: ../pg/types/sql_types/struct.Timestamptz.html
/// [`ToSql`]: crate::serialize::ToSql
///
/// This trait could be [derived](derive@AsExpression)
pub use AsExpression;
/// Converts a type to its representation for use in Diesel's query builder.
///
/// This trait only exists to make usage of `AsExpression` more ergonomic when
/// the `SqlType` cannot be inferred. It is generally used when you need to use
/// a Rust value as the left hand side of an expression, or when you want to
/// select a constant value.
///
/// # Example
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// # use schema::users;
/// #
/// # fn main() {
/// use diesel::sql_types::Text;
/// # let conn = &mut establish_connection();
/// let names = users::table
/// .select("The Amazing ".into_sql::<Text>().concat(users::name))
/// .load(conn);
/// let expected_names = vec![
/// "The Amazing Sean".to_string(),
/// "The Amazing Tess".to_string(),
/// ];
/// assert_eq!(Ok(expected_names), names);
/// # }
/// ```
/// Indicates that all elements of an expression are valid given a from clause.
///
/// This is used to ensure that `users.filter(posts::id.eq(1))` fails to
/// compile. This constraint is only used in places where the nullability of a
/// SQL type doesn't matter (everything except `select` and `returning`). For
/// places where nullability is important, `SelectableExpression` is used
/// instead.
/// Indicates that an expression can be selected from a source.
///
/// Columns will implement this for their table. Certain special types, like
/// `CountStar` and `Bound` will implement this for all sources. Most compound
/// expressions will implement this if each of their parts implement it.
///
/// Notably, columns will not implement this trait for the right side of a left
/// join. To select a column or expression using a column from the right side of
/// a left join, you must call `.nullable()` on it.
/// Trait indicating that a record can be selected and queried from the database.
///
/// Types which implement `Selectable` represent the select clause of a SQL query.
/// Use [`SelectableHelper::as_select()`] to construct the select clause. Once you
/// called `.select(YourType::as_select())` we enforce at the type system level that you
/// use the same type to load the query result into.
///
/// The constructed select clause can contain arbitrary expressions coming from different
/// tables. The corresponding [derive](derive@Selectable) provides a simple way to
/// construct a select clause matching fields to the corresponding table columns.
///
/// # Examples
///
/// If you just want to construct a select clause using an existing struct, you can use
/// `#[derive(Selectable)]`, See [`#[derive(Selectable)]`](derive@Selectable) for details.
///
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// #
/// use schema::users;
///
/// #[derive(Queryable, PartialEq, Debug, Selectable)]
/// struct User {
/// id: i32,
/// name: String,
/// }
///
/// # fn main() {
/// # run_test();
/// # }
/// #
/// # fn run_test() -> QueryResult<()> {
/// # use schema::users::dsl::*;
/// # let connection = &mut establish_connection();
/// let first_user = users.select(User::as_select()).first(connection)?;
/// let expected = User {
/// id: 1,
/// name: "Sean".into(),
/// };
/// assert_eq!(expected, first_user);
/// # Ok(())
/// # }
/// ```
///
/// Alternatively, we can implement the trait for our struct manually.
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// #
/// use diesel::backend::Backend;
/// use diesel::prelude::{Queryable, Selectable};
/// use schema::users;
///
/// #[derive(Queryable, PartialEq, Debug)]
/// struct User {
/// id: i32,
/// name: String,
/// }
///
/// impl<DB> Selectable<DB> for User
/// where
/// DB: Backend,
/// {
/// type SelectExpression = (users::id, users::name);
///
/// fn construct_selection() -> Self::SelectExpression {
/// (users::id, users::name)
/// }
/// }
///
/// # fn main() {
/// # run_test();
/// # }
/// #
/// # fn run_test() -> QueryResult<()> {
/// # use schema::users::dsl::*;
/// # let connection = &mut establish_connection();
/// let first_user = users.select(User::as_select()).first(connection)?;
/// let expected = User {
/// id: 1,
/// name: "Sean".into(),
/// };
/// assert_eq!(expected, first_user);
/// # Ok(())
/// # }
/// ```
///
/// When selecting from joined tables, you can select from a
/// composition of types that implement `Selectable`. The simplest way
/// is to use a tuple of all the types you wish to select.
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// use schema::{posts, users};
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// struct User {
/// id: i32,
/// name: String,
/// }
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// struct Post {
/// id: i32,
/// user_id: i32,
/// title: String,
/// }
///
/// # fn main() -> QueryResult<()> {
/// # let connection = &mut establish_connection();
/// #
/// let (first_user, first_post) = users::table
/// .inner_join(posts::table)
/// .select(<(User, Post)>::as_select())
/// .first(connection)?;
///
/// let expected_user = User {
/// id: 1,
/// name: "Sean".into(),
/// };
/// assert_eq!(expected_user, first_user);
///
/// let expected_post = Post {
/// id: 1,
/// user_id: 1,
/// title: "My first post".into(),
/// };
/// assert_eq!(expected_post, first_post);
/// #
/// # Ok(())
/// # }
/// ```
///
/// If you want to load only a subset of fields, you can create types
/// with those fields and use them in the composition.
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// use schema::{posts, users};
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// struct User {
/// id: i32,
/// name: String,
/// }
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// #[diesel(table_name = posts)]
/// struct PostTitle {
/// title: String,
/// }
///
/// # fn main() -> QueryResult<()> {
/// # let connection = &mut establish_connection();
/// #
/// let (first_user, first_post_title) = users::table
/// .inner_join(posts::table)
/// .select(<(User, PostTitle)>::as_select())
/// .first(connection)?;
///
/// let expected_user = User {
/// id: 1,
/// name: "Sean".into(),
/// };
/// assert_eq!(expected_user, first_user);
///
/// let expected_post_title = PostTitle {
/// title: "My first post".into(),
/// };
/// assert_eq!(expected_post_title, first_post_title);
/// #
/// # Ok(())
/// # }
/// ```
///
/// You are not limited to using only tuples to build the composed
/// type. The [`Selectable`](derive@Selectable) derive macro allows
/// you to *embed* other types. This is useful when you want to
/// implement methods or traits on the composed type.
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// use schema::{posts, users};
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// struct User {
/// id: i32,
/// name: String,
/// }
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// #[diesel(table_name = posts)]
/// struct PostTitle {
/// title: String,
/// }
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// struct UserPost {
/// #[diesel(embed)]
/// user: User,
/// #[diesel(embed)]
/// post_title: PostTitle,
/// }
///
/// # fn main() -> QueryResult<()> {
/// # let connection = &mut establish_connection();
/// #
/// let first_user_post = users::table
/// .inner_join(posts::table)
/// .select(UserPost::as_select())
/// .first(connection)?;
///
/// let expected_user_post = UserPost {
/// user: User {
/// id: 1,
/// name: "Sean".into(),
/// },
/// post_title: PostTitle {
/// title: "My first post".into(),
/// },
/// };
/// assert_eq!(expected_user_post, first_user_post);
/// #
/// # Ok(())
/// # }
/// ```
///
/// It is also possible to specify an entirely custom select expression
/// for fields when deriving [`Selectable`](derive@Selectable).
/// This is useful for example to
///
/// * avoid nesting types, or to
/// * populate fields with values other than table columns, such as
/// the result of an SQL function like `CURRENT_TIMESTAMP()`
/// or a custom SQL function.
///
/// The select expression is specified via the `select_expression` parameter.
///
/// Query fragments created using [`dsl::auto_type`](crate::dsl::auto_type) are supported, which
/// may be useful as the select expression gets large: it may not be practical to inline it in
/// the attribute then.
///
/// The type of the expression is usually inferred. If it can't be fully inferred automatically,
/// one may either:
/// - Put type annotations in inline blocks in the query fragment itself
/// - Use a dedicated [`dsl::auto_type`](crate::dsl::auto_type) function as `select_expression`
/// and use [`dsl::auto_type`'s type annotation features](crate::dsl::auto_type)
/// - Specify the type of the expression using the `select_expression_type` attribute
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// use diesel::dsl;
/// use schema::{posts, users};
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// struct User {
/// id: i32,
/// name: String,
/// }
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// #[diesel(table_name = posts)]
/// struct PostTitle {
/// title: String,
/// }
///
/// #[derive(Debug, PartialEq, Queryable, Selectable)]
/// struct UserPost {
/// #[diesel(select_expression = users::columns::id)]
/// #[diesel(select_expression_type = users::columns::id)]
/// id: i32,
/// #[diesel(select_expression = users::columns::name)]
/// name: String,
/// #[diesel(select_expression = complex_fragment_for_title())]
/// title: String,
/// # #[cfg(feature = "chrono")]
/// #[diesel(select_expression = diesel::dsl::now)]
/// access_time: chrono::NaiveDateTime,
/// #[diesel(select_expression = users::columns::id.eq({let id: i32 = FOO; id}))]
/// user_id_is_foo: bool,
/// }
/// const FOO: i32 = 42; // Type of FOO can't be inferred automatically in the select_expression
/// #[dsl::auto_type]
/// fn complex_fragment_for_title() -> _ {
/// // See the `#[dsl::auto_type]` documentation for examples of more complex usage
/// posts::columns::title
/// }
///
/// # fn main() -> QueryResult<()> {
/// # let connection = &mut establish_connection();
/// #
/// let first_user_post = users::table
/// .inner_join(posts::table)
/// .select(UserPost::as_select())
/// .first(connection)?;
///
/// let expected_user_post = UserPost {
/// id: 1,
/// name: "Sean".into(),
/// title: "My first post".into(),
/// # #[cfg(feature = "chrono")]
/// access_time: first_user_post.access_time,
/// user_id_is_foo: false,
/// };
/// assert_eq!(expected_user_post, first_user_post);
/// #
/// # Ok(())
/// # }
/// ```
pub use Selectable;
/// This helper trait provides several methods for
/// constructing a select or returning clause based on a
/// [`Selectable`] implementation.
/// Is this expression valid for a given group by clause?
///
/// Implementations of this trait must ensure that aggregate expressions are
/// not mixed with non-aggregate expressions.
///
/// For generic types, you can determine if your sub-expressions can appear
/// together using the [`MixedAggregates`] trait.
///
/// `GroupByClause` will be a tuple containing the set of expressions appearing
/// in the `GROUP BY` portion of the query. If there is no `GROUP BY`, it will
/// be `()`.
///
/// This trait can be [derived]
///
/// [derived]: derive@ValidGrouping
pub use ValidGrouping;
/// Can two `IsAggregate` types appear in the same expression?
///
/// You should never implement this trait. It will eventually become a trait
/// alias.
///
/// [`is_aggregate::Yes`] and [`is_aggregate::No`] can only appear with
/// themselves or [`is_aggregate::Never`]. [`is_aggregate::Never`] can appear
/// with anything.
/// Possible values for `ValidGrouping::IsAggregate`
// this needs to be a separate module for the reasons given in
// https://github.com/rust-lang/rust/issues/65860
pub use NonAggregate;
// Note that these docs are similar to but slightly different than the unstable
// docs above. Make sure if you change these that you also change the docs
// above.
/// Trait alias to represent an expression that isn't aggregate by default.
///
/// This trait should never be implemented directly. It is replaced with a
/// trait alias when the `unstable` feature is enabled.
///
/// This alias represents a type which is not aggregate if there is no group by
/// clause. More specifically, it represents for types which implement
/// [`ValidGrouping<()>`] where `IsAggregate` is [`is_aggregate::No`] or
/// [`is_aggregate::Yes`].
///
/// While this trait is a useful stand-in for common cases, `T: NonAggregate`
/// cannot always be used when `T: ValidGrouping<(), IsAggregate = No>` or
/// `T: ValidGrouping<(), IsAggregate = Never>` could be. For that reason,
/// unless you need to abstract over both columns and literals, you should
/// prefer to use [`ValidGrouping<()>`] in your bounds instead.
///
/// [`ValidGrouping<()>`]: ValidGrouping
use crate;
/// Helper trait used when boxing expressions.
///
/// In Rust you cannot create a trait object with more than one trait.
/// This type has all of the additional traits you would want when using
/// `Box<Expression>` as a single trait object.
///
/// By default `BoxableExpression` is not usable in queries that have a custom
/// group by clause. Setting the generic parameters `GB` and `IsAggregate` allows
/// to configure the expression to be used with a specific group by clause.
///
/// This is typically used as the return type of a function.
/// For cases where you want to dynamically construct a query,
/// [boxing the query] is usually more ergonomic.
///
/// [boxing the query]: crate::query_dsl::QueryDsl::into_boxed()
///
/// # Examples
///
/// ## Usage without group by clause
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// # use schema::users;
/// use diesel::sql_types::Bool;
///
/// # fn main() {
/// # run_test().unwrap();
/// # }
/// #
/// # fn run_test() -> QueryResult<()> {
/// # let conn = &mut establish_connection();
/// enum Search {
/// Id(i32),
/// Name(String),
/// }
///
/// # /*
/// type DB = diesel::sqlite::Sqlite;
/// # */
/// fn find_user(search: Search) -> Box<dyn BoxableExpression<users::table, DB, SqlType = Bool>> {
/// match search {
/// Search::Id(id) => Box::new(users::id.eq(id)),
/// Search::Name(name) => Box::new(users::name.eq(name)),
/// }
/// }
///
/// let user_one = users::table.filter(find_user(Search::Id(1))).first(conn)?;
/// assert_eq!((1, String::from("Sean")), user_one);
///
/// let tess = users::table
/// .filter(find_user(Search::Name("Tess".into())))
/// .first(conn)?;
/// assert_eq!((2, String::from("Tess")), tess);
/// # Ok(())
/// # }
/// ```
///
/// ## Allow usage with group by clause
///
/// ```rust
/// # include!("../doctest_setup.rs");
///
/// # use schema::users;
/// use diesel::dsl;
/// use diesel::expression::ValidGrouping;
/// use diesel::sql_types::Text;
///
/// # fn main() {
/// # run_test().unwrap();
/// # }
/// #
/// # fn run_test() -> QueryResult<()> {
/// # let conn = &mut establish_connection();
/// enum NameOrConst {
/// Name,
/// Const(String),
/// }
///
/// # /*
/// type DB = diesel::sqlite::Sqlite;
/// # */
/// fn selection<GB>(
/// selection: NameOrConst,
/// ) -> Box<
/// dyn BoxableExpression<
/// users::table,
/// DB,
/// GB,
/// <users::name as ValidGrouping<GB>>::IsAggregate,
/// SqlType = Text,
/// >,
/// >
/// where
/// users::name: BoxableExpression<
/// users::table,
/// DB,
/// GB,
/// <users::name as ValidGrouping<GB>>::IsAggregate,
/// SqlType = Text,
/// > + ValidGrouping<GB>,
/// {
/// match selection {
/// NameOrConst::Name => Box::new(users::name),
/// NameOrConst::Const(name) => Box::new(name.into_sql::<Text>()),
/// }
/// }
///
/// let user_one = users::table
/// .select(selection(NameOrConst::Name))
/// .first::<String>(conn)?;
/// assert_eq!(String::from("Sean"), user_one);
///
/// let with_name = users::table
/// .group_by(users::name)
/// .select(selection(NameOrConst::Const("Jane Doe".into())))
/// .first::<String>(conn)?;
/// assert_eq!(String::from("Jane Doe"), with_name);
/// # Ok(())
/// # }
/// ```
///
/// ## More advanced query source
///
/// This example is a bit contrived, but in general, if you want to for example filter based on
/// different criteria on a joined table, you can use `InnerJoinQuerySource` and
/// `LeftJoinQuerySource` in the QS parameter of `BoxableExpression`.
///
/// ```rust
/// # include!("../doctest_setup.rs");
/// # use schema::{users, posts};
/// use diesel::dsl::InnerJoinQuerySource;
/// use diesel::sql_types::Bool;
///
/// # fn main() {
/// # run_test().unwrap();
/// # }
/// #
/// # fn run_test() -> QueryResult<()> {
/// # let conn = &mut establish_connection();
/// enum UserPostFilter {
/// User(i32),
/// Post(i32),
/// }
///
/// # /*
/// type DB = diesel::sqlite::Sqlite;
/// # */
/// fn filter_user_posts(
/// filter: UserPostFilter,
/// ) -> Box<
/// dyn BoxableExpression<InnerJoinQuerySource<users::table, posts::table>, DB, SqlType = Bool>,
/// > {
/// match filter {
/// UserPostFilter::User(user_id) => Box::new(users::id.eq(user_id)),
/// UserPostFilter::Post(post_id) => Box::new(posts::id.eq(post_id)),
/// }
/// }
///
/// let post_by_user_one = users::table
/// .inner_join(posts::table)
/// .filter(filter_user_posts(UserPostFilter::User(2)))
/// .select((posts::title, users::name))
/// .first::<(String, String)>(conn)?;
///
/// assert_eq!(
/// ("My first post too".to_string(), "Tess".to_string()),
/// post_by_user_one
/// );
/// # Ok(())
/// # }
/// ```
/// Converts a tuple of values into a tuple of Diesel expressions.