55
66namespace SQLitePCL . pretty . Orm
77{
8- public static partial class QueryBuilder
8+ public static partial class SqlQuery
99 {
10- public sealed class WhereQuery < T >
10+ public sealed class WhereClause < T > : ISqlQuery
1111 {
12- private const string selection = "*" ;
1312 private readonly string table ;
13+ private readonly string selection ;
1414 private readonly Expression where ;
1515
16- internal WhereQuery ( string table , Expression where )
16+ internal WhereClause ( string table , string selection , Expression where )
1717 {
1818 this . table = table ;
19+ this . selection = selection ;
1920 this . where = where ;
2021 }
2122
22- public OrderByQuery < T > OrderBy < TValue > ( Expression < Func < T , TValue > > orderExpr )
23+ public OrderByClause < T > OrderBy < TValue > ( Expression < Func < T , TValue > > orderExpr )
2324 {
2425 return CreateOrderBy ( orderExpr , true ) ;
2526 }
2627
27- public OrderByQuery < T > OrderByDescending < TValue > ( Expression < Func < T , TValue > > orderExpr )
28+ public OrderByClause < T > OrderByDescending < TValue > ( Expression < Func < T , TValue > > orderExpr )
2829 {
2930 return CreateOrderBy ( orderExpr , false ) ;
3031 }
3132
32- private OrderByQuery < T > CreateOrderBy < TValue > ( Expression < Func < T , TValue > > orderExpr , bool asc )
33+ private OrderByClause < T > CreateOrderBy < TValue > ( Expression < Func < T , TValue > > orderExpr , bool asc )
3334 {
3435 var orderBy = new List < Tuple < string , bool > > ( ) ;
3536 orderBy . Add ( orderExpr . CompileOrderByExpression ( asc ) ) ;
36- return new OrderByQuery < T > ( table , selection , where , orderBy ) ;
37+ return new OrderByClause < T > ( table , selection , where , orderBy ) ;
3738 }
3839
39- public WhereQuery < T > Where < U , V , W , X , Y , Z > ( Expression < Func < T , U , V , W , X , Y , Z , bool > > predExpr )
40+ public WhereClause < T > Where < U , V , W , X , Y , Z > ( Expression < Func < T , U , V , W , X , Y , Z , bool > > predExpr )
4041 {
4142 return this . Where ( ( LambdaExpression ) predExpr ) ;
4243 }
4344
44- public WhereQuery < T > Where < U , V , W , X , Y > ( Expression < Func < T , U , V , W , X , Y , bool > > predExpr )
45+ public WhereClause < T > Where < U , V , W , X , Y > ( Expression < Func < T , U , V , W , X , Y , bool > > predExpr )
4546 {
4647 return this . Where ( ( LambdaExpression ) predExpr ) ;
4748 }
4849
49- public WhereQuery < T > Where < U , V , W , X > ( Expression < Func < T , U , V , W , X , bool > > predExpr )
50+ public WhereClause < T > Where < U , V , W , X > ( Expression < Func < T , U , V , W , X , bool > > predExpr )
5051 {
5152 return this . Where ( ( LambdaExpression ) predExpr ) ;
5253 }
5354
54- public WhereQuery < T > Where < U , V , W > ( Expression < Func < T , U , V , W , bool > > predExpr )
55+ public WhereClause < T > Where < U , V , W > ( Expression < Func < T , U , V , W , bool > > predExpr )
5556 {
5657 return this . Where ( ( LambdaExpression ) predExpr ) ;
5758 }
5859
59- public WhereQuery < T > Where < U , V > ( Expression < Func < T , U , V , bool > > predExpr )
60+ public WhereClause < T > Where < U , V > ( Expression < Func < T , U , V , bool > > predExpr )
6061 {
6162 return this . Where ( ( LambdaExpression ) predExpr ) ;
6263 }
6364
64- public WhereQuery < T > Where < U > ( Expression < Func < T , U , bool > > predExpr )
65+ public WhereClause < T > Where < U > ( Expression < Func < T , U , bool > > predExpr )
6566 {
6667 return this . Where ( ( LambdaExpression ) predExpr ) ;
6768 }
6869
69- public WhereQuery < T > Where ( Expression < Func < T , bool > > predExpr )
70+ public WhereClause < T > Where ( Expression < Func < T , bool > > predExpr )
7071 {
7172 return this . Where ( ( LambdaExpression ) predExpr ) ;
7273 }
7374
74- private WhereQuery < T > Where ( LambdaExpression lambda )
75+ private WhereClause < T > Where ( LambdaExpression lambda )
7576 {
7677 var pred = lambda . Body ;
7778 var where = this . where == null ? pred : Expression . AndAlso ( this . where , pred ) ;
78- return new WhereQuery < T > ( table , where ) ;
79+ return new WhereClause < T > ( table , selection , where ) ;
7980 }
8081
8182 /// <summary>
8283 /// Returns a <see cref="TableQuery<T>"/> that limits the result set to a specified number of contiguous elements.
8384 /// </summary>
8485 /// <param name="n">The number of elements to return.</param>
8586 /// <returns>A new <see cref="SQLitePCL.pretty.Orm.TableQuery<T>"/>.</returns>
86- public LimitQuery Take ( int n )
87+ public LimitClause Take ( int n )
8788 {
88- return new LimitQuery ( table , selection , where , new List < Tuple < string , bool > > ( ) , n , null ) ;
89+ return new LimitClause ( table , selection , where , new List < Tuple < string , bool > > ( ) , n , null ) ;
8990 }
9091
9192 /// <summary>
9293 /// Returns a <see cref="TableQuery<T>"/> that skips a specified number of elements in the result set and then returns the remaining elements.
9394 /// </summary>
9495 /// <param name="n">The number of elements to skip before returning the remaining elements.</param>
9596 /// <returns>A new <see cref="SQLitePCL.pretty.Orm.TableQuery<T>"/>.</returns>
96- public LimitQuery Skip ( int n )
97+ public LimitClause Skip ( int n )
9798 {
98- return new LimitQuery ( table , selection , where , new List < Tuple < string , bool > > ( ) , null , n ) ;
99+ return new LimitClause ( table , selection , where , new List < Tuple < string , bool > > ( ) , null , n ) ;
99100 }
100101
101102 /// <summary>
@@ -104,14 +105,19 @@ public LimitQuery Skip(int n)
104105 /// <returns>The <see cref="SQLitePCL.pretty.Orm.TableQuery<T>"/>.</returns>
105106 /// <param name="index">Index.</param>
106107 /// <returns>A new <see cref="SQLitePCL.pretty.Orm.TableQuery<T>"/>.</returns>
107- public string ElementAt ( int index )
108+ public LimitClause ElementAt ( int index )
108109 {
109- return Skip ( index ) . Take ( 1 ) . ToString ( ) ;
110+ return Skip ( index ) . Take ( 1 ) ;
110111 }
111112
112113 public override string ToString ( )
113114 {
114- return QueryBuilder . ToString ( selection , table , where , Enumerable . Empty < Tuple < string , bool > > ( ) , null , null ) ;
115+ return SqlQuery . ToString ( selection , table , where , Enumerable . Empty < Tuple < string , bool > > ( ) , null , null ) ;
116+ }
117+
118+ public string ToSql ( )
119+ {
120+ return this . ToString ( ) ;
115121 }
116122 }
117123 }
0 commit comments