forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoQueryServices.cs
More file actions
263 lines (216 loc) · 7.94 KB
/
AutoQueryServices.cs
File metadata and controls
263 lines (216 loc) · 7.94 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
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
using System;
using System.Collections.Generic;
using Check.ServiceModel;
using ServiceStack;
using ServiceStack.DataAnnotations;
namespace Check.ServiceInterface
{
[Route("/querydata/rockstars")]
public class QueryDataRockstars : QueryData<Rockstar>
{
public int? Age { get; set; }
}
[Route("/query/rockstars")]
public class QueryRockstars : QueryDb<Rockstar>
{
public int? Age { get; set; }
}
[Route("/query/rockstars/cached")]
public class QueryRockstarsCached : QueryDb<Rockstar>
{
public int? Age { get; set; }
}
[ConnectionInfo(NamedConnection = "pgsql")]
[Route("/pgsql/rockstars")]
public class QueryPostgresRockstars : QueryDb<Rockstar>
{
public int? Age { get; set; }
}
[NamedConnection("pgsql")]
public class PgRockstar : Rockstar {}
[Route("/pgsql/pgrockstars")]
public class QueryPostgresPgRockstars : QueryDb<PgRockstar>
{
public int? Age { get; set; }
}
public class QueryRockstarsConventions : QueryDb<Rockstar>
{
public int[] Ids { get; set; }
public int? AgeOlderThan { get; set; }
public int? AgeGreaterThanOrEqualTo { get; set; }
public int? AgeGreaterThan { get; set; }
public int? GreaterThanAge { get; set; }
public string FirstNameStartsWith { get; set; }
public string LastNameEndsWith { get; set; }
public string LastNameContains { get; set; }
public string RockstarAlbumNameContains { get; set; }
public int? RockstarIdAfter { get; set; }
public int? RockstarIdOnOrAfter { get; set; }
}
[AutoQueryViewer(Title = "Search for Rockstars", Description = "Use this option to search for Rockstars!")]
public class QueryCustomRockstars : QueryDb<Rockstar, CustomRockstar>
{
public int? Age { get; set; }
}
[Route("/customrockstars")]
public class QueryRockstarAlbums : QueryDb<Rockstar, CustomRockstar>, IJoin<Rockstar, RockstarAlbum>
{
public int? Age { get; set; }
public string RockstarAlbumName { get; set; }
}
public class QueryRockstarAlbumsImplicit : QueryDb<Rockstar, CustomRockstar>, IJoin<Rockstar, RockstarAlbum>
{
}
public class QueryRockstarAlbumsLeftJoin : QueryDb<Rockstar, CustomRockstar>, ILeftJoin<Rockstar, RockstarAlbum>
{
public int? Age { get; set; }
public string AlbumName { get; set; }
}
public class QueryOverridedRockstars : QueryDb<Rockstar>
{
public int? Age { get; set; }
}
public class QueryOverridedCustomRockstars : QueryDb<Rockstar, CustomRockstar>
{
public int? Age { get; set; }
}
[Route("/query-custom/rockstars")]
public class QueryFieldRockstars : QueryDb<Rockstar>
{
public string FirstName { get; set; } //default to 'AND FirstName = {Value}'
public string[] FirstNames { get; set; } //Collections default to 'FirstName IN ({Values})
[QueryDbField(Operand = ">=")]
public int? Age { get; set; }
[QueryDbField(Template = "UPPER({Field}) LIKE UPPER({Value})", Field = "FirstName")]
public string FirstNameCaseInsensitive { get; set; }
[QueryDbField(Template = "{Field} LIKE {Value}", Field = "FirstName", ValueFormat = "{0}%")]
public string FirstNameStartsWith { get; set; }
[QueryDbField(Template = "{Field} LIKE {Value}", Field = "LastName", ValueFormat = "%{0}")]
public string LastNameEndsWith { get; set; }
[QueryDbField(Template = "{Field} BETWEEN {Value1} AND {Value2}", Field = "FirstName")]
public string[] FirstNameBetween { get; set; }
[QueryDbField(Term = QueryTerm.Or, Template = "UPPER({Field}) LIKE UPPER({Value})", Field = "LastName")]
public string OrLastName { get; set; }
[QueryDbField(Template = "{Field} LIKE {Value1} OR {Field} LIKE {Value2}", Field = "FirstName", ValueFormat = "%{0}%")]
public string[] FirstNameContainsMulti { get; set; }
}
public class QueryFieldRockstarsDynamic : QueryDb<Rockstar>
{
public int? Age { get; set; }
}
public class QueryRockstarsFilter : QueryDb<Rockstar>
{
public int? Age { get; set; }
}
public class QueryCustomRockstarsFilter : QueryDb<Rockstar, CustomRockstar>
{
public int? Age { get; set; }
}
public interface IFilterRockstars { }
public class QueryRockstarsIFilter : QueryDb<Rockstar>, IFilterRockstars
{
public int? Age { get; set; }
}
[QueryDb(QueryTerm.Or)]
[Route("/OrRockstars")]
public class QueryOrRockstars : QueryDb<Rockstar>
{
public int? Age { get; set; }
public string FirstName { get; set; }
}
[QueryDb(QueryTerm.Or)]
public class QueryGetRockstars : QueryDb<Rockstar>
{
public int[] Ids { get; set; }
public List<int> Ages { get; set; }
public List<string> FirstNames { get; set; }
public int[] IdsBetween { get; set; }
}
[QueryDb(QueryTerm.Or)]
public class QueryGetRockstarsDynamic : QueryDb<Rockstar> { }
public class RockstarAlbum
{
[AutoIncrement]
public int Id { get; set; }
public int RockstarId { get; set; }
public string Name { get; set; }
}
public class CustomRockstar
{
[AutoQueryViewerField(Title = "Name")]
public string FirstName { get; set; }
[AutoQueryViewerField(HideInSummary = true)]
public string LastName { get; set; }
public int? Age { get; set; }
[AutoQueryViewerField(Title = "Album")]
public string RockstarAlbumName { get; set; }
[AutoQueryViewerField(Title = "Genre")]
public string RockstarGenreName { get; set; }
}
[Route("/movies/search")]
[QueryDb(QueryTerm.And)] //Default
public class SearchMovies : QueryDb<Movie> { }
[Route("/movies")]
[QueryDb(QueryTerm.Or)]
public class QueryMovies : QueryDb<Movie>
{
public int[] Ids { get; set; }
public string[] ImdbIds { get; set; }
public string[] Ratings { get; set; }
}
public class Movie
{
[AutoIncrement]
public int Id { get; set; }
public string ImdbId { get; set; }
public string Title { get; set; }
public string Rating { get; set; }
public decimal Score { get; set; }
public string Director { get; set; }
public DateTime ReleaseDate { get; set; }
public string TagLine { get; set; }
public List<string> Genres { get; set; }
}
public class StreamMovies : QueryDb<Movie>
{
public string[] Ratings { get; set; }
}
public class QueryUnknownRockstars : QueryDb<Rockstar>
{
public int UnknownInt { get; set; }
public string UnknownProperty { get; set; }
}
[Route("/query/rockstar-references")]
public class QueryRockstarsWithReferences : QueryDb<RockstarReference>
{
public int? Age { get; set; }
}
[Alias("Rockstar")]
public class RockstarReference
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int? Age { get; set; }
[Reference]
public List<RockstarAlbum> Albums { get; set; }
}
public class AutoQueryService : Service
{
public IAutoQueryDb AutoQuery { get; set; }
//Override with custom impl
public QueryResponse<Rockstar> Any(QueryRockstars dto)
{
var q = AutoQuery.CreateQuery(dto, Request.GetRequestParams(), Request);
//q.Take(1);
return AutoQuery.Execute(dto, q);
}
}
[CacheResponse(Duration = 3600)]
public class AutoQueryCachedServices : Service
{
public IAutoQueryDb AutoQuery { get; set; }
public QueryResponse<Rockstar> Any(QueryRockstarsCached request) =>
AutoQuery.Execute(request, AutoQuery.CreateQuery(request, Request.GetRequestParams()));
}
}