forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIQuery.cs
More file actions
177 lines (142 loc) · 5.45 KB
/
IQuery.cs
File metadata and controls
177 lines (142 loc) · 5.45 KB
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
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace ServiceStack
{
//Interfaces and DTO's used in AutoQuery
public interface IQuery : IMeta
{
/// <summary>
/// How many results to skip
/// </summary>
int? Skip { get; set; }
/// <summary>
/// How many results to return
/// </summary>
int? Take { get; set; }
/// <summary>
/// List of fields to sort by, can order by multiple fields and inverse order, e.g: Id,-Amount
/// </summary>
string OrderBy { get; set; }
/// <summary>
/// List of fields to sort by descending, can order by multiple fields and inverse order, e.g: -Id,Amount
/// </summary>
string OrderByDesc { get; set; }
/// <summary>
/// Include aggregate data like Total, COUNT(*), COUNT(DISTINCT Field), Sum(Amount), etc
/// </summary>
string Include { get; set; }
/// <summary>
/// The fields to return
/// </summary>
string Fields { get; set; }
}
public interface IQueryDb : IQuery { }
public interface IQueryData : IQuery { }
public interface IQueryDb<From> : IQueryDb { }
public interface IQueryDb<From, Into> : IQueryDb { }
public interface IQueryData<From> : IQueryData { }
public interface IQueryData<From, Into> : IQueryData { }
public interface IJoin { }
public interface IJoin<Source, Join1> : IJoin { }
public interface IJoin<Source, Join1, Join2> : IJoin { }
public interface IJoin<Source, Join1, Join2, Join3> : IJoin { }
public interface IJoin<Source, Join1, Join2, Join3, Join4> : IJoin { }
public interface ILeftJoin<Source, Join1> : IJoin { }
public interface ILeftJoin<Source, Join1, Join2> : IJoin { }
public interface ILeftJoin<Source, Join1, Join2, Join3> : IJoin { }
public interface ILeftJoin<Source, Join1, Join2, Join3, Join4> : IJoin { }
public enum QueryTerm
{
Default = 0,
And = 1,
Or = 2,
}
public enum ValueStyle
{
Single = 0,
Multiple = 1,
List = 2,
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class QueryDbAttribute : AttributeBase
{
public QueryDbAttribute() { }
public QueryDbAttribute(QueryTerm defaultTerm)
{
DefaultTerm = defaultTerm;
}
public QueryTerm DefaultTerm { get; set; }
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class QueryDataAttribute : AttributeBase
{
public QueryDataAttribute() { }
public QueryDataAttribute(QueryTerm defaultTerm)
{
DefaultTerm = defaultTerm;
}
public QueryTerm DefaultTerm { get; set; }
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class QueryDbFieldAttribute : AttributeBase
{
public QueryTerm Term { get; set; }
public string Operand { get; set; }
public string Template { get; set; }
public string Field { get; set; }
public string ValueFormat { get; set; }
public ValueStyle ValueStyle { get; set; }
public int ValueArity { get; set; }
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class QueryDataFieldAttribute : AttributeBase
{
public QueryTerm Term { get; set; }
public string Condition { get; set; }
public string Field { get; set; }
}
public abstract class QueryBase : IQuery
{
[DataMember(Order = 1)]
public virtual int? Skip { get; set; }
[DataMember(Order = 2)]
public virtual int? Take { get; set; }
[DataMember(Order = 3)]
public virtual string OrderBy { get; set; }
[DataMember(Order = 4)]
public virtual string OrderByDesc { get; set; }
[DataMember(Order = 5)]
public virtual string Include { get; set; }
[DataMember(Order = 6)]
public virtual string Fields { get; set; }
[DataMember(Order = 7)]
public virtual Dictionary<string, string> Meta { get; set; }
}
public abstract class QueryDb<T> : QueryBase, IQueryDb<T>, IReturn<QueryResponse<T>> { }
public abstract class QueryDb<From, Into> : QueryBase, IQueryDb<From, Into>, IReturn<QueryResponse<Into>> { }
public abstract class QueryData<T> : QueryBase, IQueryData<T>, IReturn<QueryResponse<T>> { }
public abstract class QueryData<From, Into> : QueryBase, IQueryData<From, Into>, IReturn<QueryResponse<Into>> { }
public interface IQueryResponse : IHasResponseStatus, IMeta
{
int Offset { get; set; }
int Total { get; set; }
}
[DataContract]
public class QueryResponse<T> : IQueryResponse
{
[DataMember(Order = 1)]
public virtual int Offset { get; set; }
/// <summary>
/// Populate with Include=Total or if registered with: AutoQueryFeature { IncludeTotal = true }
/// </summary>
[DataMember(Order = 2)]
public virtual int Total { get; set; }
[DataMember(Order = 3)]
public virtual List<T> Results { get; set; }
[DataMember(Order = 4)]
public virtual Dictionary<string, string> Meta { get; set; }
[DataMember(Order = 5)]
public virtual ResponseStatus ResponseStatus { get; set; }
}
}