@@ -2,6 +2,7 @@ use super::BoxedSelectStatement;
22use associations:: HasTable ;
33use backend:: Backend ;
44use dsl:: AsExprOf ;
5+ use expression:: nullable:: Nullable ;
56use expression:: * ;
67use insertable:: Insertable ;
78use query_builder:: distinct_clause:: * ;
@@ -19,7 +20,8 @@ use query_dsl::boxed_dsl::BoxedDsl;
1920use query_dsl:: methods:: * ;
2021use query_dsl:: * ;
2122use query_source:: joins:: { Join , JoinOn , JoinTo } ;
22- use sql_types:: { BigInt , Bool } ;
23+ use query_source:: QuerySource ;
24+ use sql_types:: { BigInt , Bool , NotNull } ;
2325
2426impl < F , S , D , W , O , L , Of , G , LC , Rhs , Kind , On > InternalJoinDsl < Rhs , Kind , On >
2527 for SelectStatement < F , S , D , W , O , L , Of , G , LC >
@@ -337,23 +339,52 @@ impl<F, S, D, W, O, L, Of, G, LC, LM, Modifier> ModifyLockDsl<Modifier>
337339 }
338340}
339341
340- impl < ' a , F , S , D , W , O , L , Of , G , DB > BoxedDsl < ' a , DB > for SelectStatement < F , S , D , W , O , L , Of , G >
342+ impl < ' a , F , S , D , W , O , L , Of , G , DB > BoxedDsl < ' a , DB >
343+ for SelectStatement < F , SelectClause < S > , D , W , O , L , Of , G >
341344where
342345 Self : AsQuery ,
343346 DB : Backend ,
344- S : BoxSelectClause < ' a , F , DB > + SelectClauseExpression < F > ,
347+ S : QueryFragment < DB > + SelectableExpression < F > + ' a ,
345348 D : QueryFragment < DB > + ' a ,
346349 W : Into < BoxedWhereClause < ' a , DB > > ,
347350 O : Into < Option < Box < QueryFragment < DB > + ' a > > > ,
348351 L : QueryFragment < DB > + ' a ,
349352 Of : QueryFragment < DB > + ' a ,
350353 G : QueryFragment < DB > + ' a ,
351354{
352- type Output = BoxedSelectStatement < ' a , S :: SelectClauseSqlType , F , DB > ;
355+ type Output = BoxedSelectStatement < ' a , S :: SqlType , F , DB > ;
353356
354357 fn internal_into_boxed ( self ) -> Self :: Output {
355358 BoxedSelectStatement :: new (
356- self . select . box_select_clause ( & self . from ) ,
359+ Box :: new ( self . select . 0 ) ,
360+ self . from ,
361+ Box :: new ( self . distinct ) ,
362+ self . where_clause . into ( ) ,
363+ self . order . into ( ) ,
364+ Box :: new ( self . limit ) ,
365+ Box :: new ( self . offset ) ,
366+ Box :: new ( self . group_by ) ,
367+ )
368+ }
369+ }
370+ impl < ' a , F , D , W , O , L , Of , G , DB > BoxedDsl < ' a , DB >
371+ for SelectStatement < F , DefaultSelectClause , D , W , O , L , Of , G >
372+ where
373+ Self : AsQuery ,
374+ DB : Backend ,
375+ F : QuerySource ,
376+ F :: DefaultSelection : QueryFragment < DB > + ' a ,
377+ D : QueryFragment < DB > + ' a ,
378+ W : Into < BoxedWhereClause < ' a , DB > > ,
379+ O : Into < Option < Box < QueryFragment < DB > + ' a > > > ,
380+ L : QueryFragment < DB > + ' a ,
381+ Of : QueryFragment < DB > + ' a ,
382+ G : QueryFragment < DB > + ' a ,
383+ {
384+ type Output = BoxedSelectStatement < ' a , <F :: DefaultSelection as Expression >:: SqlType , F , DB > ;
385+ fn internal_into_boxed ( self ) -> Self :: Output {
386+ BoxedSelectStatement :: new (
387+ Box :: new ( self . from . default_selection ( ) ) ,
357388 self . from ,
358389 Box :: new ( self . distinct ) ,
359390 self . where_clause . into ( ) ,
@@ -438,3 +469,51 @@ where
438469 InsertFromSelect :: new ( self )
439470 }
440471}
472+
473+ impl < ' a , F , S , D , W , O , L , Of , G > NullableSelectDsl
474+ for SelectStatement < F , SelectClause < S > , D , W , O , L , Of , G >
475+ where
476+ SelectClause < S > : SelectClauseExpression < F > ,
477+ <SelectClause < S > as SelectClauseExpression < F > >:: SelectClauseSqlType : NotNull ,
478+ {
479+ type Output = SelectStatement < F , SelectClause < Nullable < S > > , D , W , O , L , Of , G > ;
480+
481+ fn nullable ( self ) -> Self :: Output {
482+ SelectStatement :: new (
483+ SelectClause ( Nullable :: new ( self . select . 0 ) ) ,
484+ self . from ,
485+ self . distinct ,
486+ self . where_clause ,
487+ self . order ,
488+ self . limit ,
489+ self . offset ,
490+ self . group_by ,
491+ self . locking ,
492+ )
493+ }
494+ }
495+
496+ impl < ' a , F , D , W , O , L , Of , G > NullableSelectDsl
497+ for SelectStatement < F , DefaultSelectClause , D , W , O , L , Of , G >
498+ where
499+ F : QuerySource ,
500+ DefaultSelectClause : SelectClauseExpression < F > ,
501+ <DefaultSelectClause as SelectClauseExpression < F > >:: SelectClauseSqlType : NotNull ,
502+ {
503+ type Output =
504+ SelectStatement < F , SelectClause < Nullable < F :: DefaultSelection > > , D , W , O , L , Of , G > ;
505+
506+ fn nullable ( self ) -> Self :: Output {
507+ SelectStatement :: new (
508+ SelectClause ( Nullable :: new ( self . from . default_selection ( ) ) ) ,
509+ self . from ,
510+ self . distinct ,
511+ self . where_clause ,
512+ self . order ,
513+ self . limit ,
514+ self . offset ,
515+ self . group_by ,
516+ self . locking ,
517+ )
518+ }
519+ }
0 commit comments