DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlQueryBuilder.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 
21 using Deveel.Data.Sql.Fluid;
22 
23 namespace Deveel.Data.Sql.Expressions {
24  public static class SqlQueryBuilder {
25  public static IQueryConfiguration Configure() {
26  return new QueryConfiguration();
27  }
28 
29  #region QueryConfiguration
30 
32  public QueryConfiguration() {
33  ItemList = new SelectListConfiguration();
34  }
35 
36  public bool IsAll { get; private set; }
37 
38  public bool IsDistinct { get; private set; }
39 
40  public ISelectListConfiguration ItemList { get; private set; }
41 
42  public SqlExpression HavingExpression { get; private set; }
43 
44  public SqlExpression WhereExpression { get; private set; }
45 
46  public IQueryConfiguration All(bool flag) {
47  IsAll = flag;
48  return this;
49  }
50 
51  public IQueryConfiguration Distinct(bool flag) {
52  IsDistinct = flag;
53  return this;
54  }
55 
56  public IQueryConfiguration Items(Action<ISelectListConfiguration> config) {
57  if (config != null)
58  config(ItemList);
59 
60  return this;
61  }
62 
63  public IQueryConfiguration From(Action<IFromSourceConfiguration> config) {
64  throw new NotImplementedException();
65  }
66 
67  public IQueryConfiguration Where(SqlExpression whereExpression) {
68  WhereExpression = whereExpression;
69  return this;
70  }
71 
72  public IQueryConfiguration Having(SqlExpression havingExpression) {
73  HavingExpression = havingExpression;
74  return this;
75  }
76 
77  public IQueryConfiguration GroupBy(Action<IGroupByConfiguration> config) {
78  throw new NotImplementedException();
79  }
80 
81  public IQueryConfiguration OrderBy(Action<IOrderByConfiguration> config) {
82  throw new NotImplementedException();
83  }
84 
86  throw new NotImplementedException();
87  }
88  }
89 
90  #endregion
91 
92  #region ISelectListConfiguration
93 
95  private readonly List<SelectItemConfiguration> items;
96 
98  items = new List<SelectItemConfiguration>();
99  }
100 
101  public ISelectListConfiguration Item(Action<ISelectItemConfiguration> config) {
102  if (config != null) {
103  var item = new SelectItemConfiguration();
104  config(item);
105  items.Add(item);
106  }
107 
108  return this;
109  }
110 
111  public IEnumerable<ISelectItemConfiguration> Items {
112  get { return items.Cast<ISelectItemConfiguration>().AsEnumerable(); }
113  }
114  }
115 
116  #endregion
117 
118  #region SelectItemConfiguration
119 
122  ItemExpression = itemExpression;
123  return this;
124  }
125 
126  public SqlExpression ItemExpression { get; private set; }
127 
128  public string ItemAlias { get; private set; }
129 
130  public void As(string alias) {
131  ItemAlias = alias;
132  }
133  }
134 
135  #endregion
136  }
137 }
ISelectItemWithExpressionConfiguration Expression(SqlExpression itemExpression)
IQueryConfiguration Items(Action< ISelectListConfiguration > config)
IQueryConfiguration Where(SqlExpression whereExpression)
IQueryConfiguration From(Action< IFromSourceConfiguration > config)
static IQueryConfiguration Configure()
IQueryConfiguration Having(SqlExpression havingExpression)
IQueryConfiguration GroupBy(Action< IGroupByConfiguration > config)
ISelectListConfiguration Item(Action< ISelectItemConfiguration > config)
IQueryConfiguration OrderBy(Action< IOrderByConfiguration > config)
Defines the base class for instances that represent SQL expression tree nodes.