Skip to content

Commit 506d821

Browse files
committed
🔍 Paging query support added. Fixes #25
1 parent cbed358 commit 506d821

30 files changed

+1641
-440
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.ComponentModel;
3+
using Pathfinding.Serialization.JsonFx;
4+
5+
namespace Unity3dAzure.AppServices
6+
{
7+
[Serializable]
8+
[CLSCompliant(false)]
9+
public abstract class DataModel : IDataModel
10+
{
11+
public string id { get; internal set; }
12+
13+
// system properties
14+
[JsonIgnore] public DateTime createdAt { get; private set; }
15+
[JsonIgnore] public DateTime updatedAt { get; private set; }
16+
[JsonIgnore] public string version { get; private set; }
17+
[JsonIgnore] public bool deleted { get; private set; }
18+
19+
// `$inlinecount=allpages` property
20+
[EditorBrowsable(EditorBrowsableState.Never)]
21+
[JsonIgnore] public uint ROW_NUMBER { get; private set; }
22+
public uint GetIndex()
23+
{
24+
return ROW_NUMBER;
25+
}
26+
27+
public string GetId()
28+
{
29+
return id;
30+
}
31+
32+
public void SetId(string id)
33+
{
34+
this.id = id;
35+
}
36+
37+
public override string ToString ()
38+
{
39+
return string.Format ("id:{0}, createdAt:{1}, updatedAt:{2}, version:{3}, deleted:{4}, index:{5}", id, createdAt, updatedAt, version, deleted, GetIndex());
40+
}
41+
}
42+
}

Assets/AppServices/model/optional/IAzureDataModel.cs renamed to Assets/AppServices/model/base/IDataModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Unity3dAzure.AppServices
22
{
3-
public interface IAzureDataModel
3+
public interface IDataModel
44
{
55
string GetId();
66
}

Assets/AppServices/model/INestedResults.cs renamed to Assets/AppServices/model/nested/INestedResults.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
namespace Unity3dAzure.AppServices
77
{
8-
[CLSCompliant(false)]
8+
/// <summary>
9+
/// Interface to support table Query with `$inlinecount=allpages`
10+
/// </summary>
911
public interface INestedResults
1012
{
1113
}

Assets/AppServices/model/NestedResults.cs renamed to Assets/AppServices/model/nested/NestedResults.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Unity3dAzure.AppServices
55
{
6+
/// <summary>
7+
/// Wrap your data model with this object to call the table Query with `$inlinecount=allpages` param.
8+
/// </summary>
69
[CLSCompliant(false)]
710
[Serializable]
811
public class NestedResults<T> : INestedResults

Assets/AppServices/model/optional/AzureDataModel.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Assets/AppServices/table/IAzureMobileServiceTable.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public interface IAzureMobileServiceTable
4141
/// https://msdn.microsoft.com/en-us/library/azure/jj677199.aspx
4242
/// </summary>
4343
void Query<T>(CustomQuery query, Action<IRestResponse<List<T>>> callback = null) where T : new();
44-
void NestedQuery<T>(CustomQuery query, Action<IRestResponse<T>> callback = null) where T : INestedResults, new();
44+
45+
/// <summary>
46+
/// Returns a 'count' and nested list of 'results' (appends `$inlinecount=allpages` parameter to the query)
47+
/// </summary>
48+
void Query<T>(CustomQuery query, Action<IRestResponse<T>> callback = null) where T : INestedResults, new();
4549

4650
/// <summary>
4751
/// Get an item's data using id property.

Assets/AppServices/table/MobileServiceTable.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ public override string ToString()
4646
{
4747
string uri = string.Format("{0}{1}{2}", URI_TABLES, _name, query);
4848
ZumoRequest request = new ZumoRequest(_client, uri, Method.GET);
49-
Debug.Log( "Query Request: " + uri );
49+
Debug.Log( "Query Request: " + uri +" Query:"+ query );
5050
_client.ExecuteAsync<List<T>> (request, callback);
5151
}
5252

53-
public void NestedQuery<T>(CustomQuery query, Action<IRestResponse<T>> callback = null) where T : INestedResults, new()
53+
public void Query<T>(CustomQuery query, Action<IRestResponse<T>> callback = null) where T : INestedResults, new()
5454
{
5555
string queryResults = query.ToString ();
5656
string q = queryResults.Length > 0 ? "&" : "?";
5757
queryResults += string.Format("{0}$inlinecount=allpages", q);
5858
string uri = string.Format("{0}{1}{2}", URI_TABLES, _name, queryResults);
5959
ZumoRequest request = new ZumoRequest(_client, uri, Method.GET);
60-
Debug.Log( "Query Request: " + uri +" Query:"+ queryResults );
60+
Debug.Log( "Query Request: " + uri +" Query with inlinecount:"+ queryResults );
6161
_client.ExecuteAsync<T> (request, callback);
6262
}
6363

Assets/AppServices/table/query/CustomQuery.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/// <summary>
66
/// Query records operation https://msdn.microsoft.com/en-us/library/azure/jj677199.aspx
77
/// There is a maximum of 50 records returned in a query - use top and skip params to return additional pages of results.
8+
/// NB: `$inlinecount` (which returns count of all items without paging applied) is not set here as it changes the data model and the way the REST decode callback works makes it intangible to decode.
9+
/// Rather the '$inlinecount=allpages' param is automically set when using the table's Query method and wrapping your data model with the NestedResults object wrapper.
810
/// </summary>
911
namespace Unity3dAzure.AppServices
1012
{
@@ -26,7 +28,6 @@ public class CustomQuery
2628
private string _orderBy;
2729
private uint _top;
2830
private uint _skip;
29-
// private bool _inlineCount; // NB: removed this as it changes the data model which is linked to rest
3031
private string _select;
3132
// other params
3233
private MobileServiceSystemProperty _systemProperties;
@@ -38,7 +39,6 @@ public CustomQuery(string filter, string orderBy=null, uint top=0, uint skip=0,
3839
_orderBy = orderBy; // sort column by one or more columns: order can be specified in 'desc' or 'asc' order ('asc' is default)
3940
_top = top; // return the top n entities for any query
4041
_skip = skip; // the n of records to skip (used for paging results)
41-
//_inlineCount = inlineCount; // returns count of all items (without paging applied)
4242
_select = select; // defines new projection of data by specifying the columns
4343
_systemProperties = systemProperties; // list of system properties to be included in the response
4444
_includeDeleted = includeDeleted; // if table has soft delete enabled then deleted records will be included in the results
@@ -68,10 +68,6 @@ public override string ToString()
6868
queryString += string.Format("{0}$skip={1}", q, _skip.ToString());
6969
q = "&";
7070
}
71-
// if (_inlineCount) {
72-
// queryString += string.Format("{0}$inlinecount=allpages", q);
73-
// q = "&";
74-
// }
7571
if (!string.IsNullOrEmpty(_select)) {
7672
queryString += string.Format("{0}$select={1}", q, _select);
7773
q = "&";
@@ -110,14 +106,5 @@ private string SystemPropertiesValues(MobileServiceSystemProperty systemProperti
110106
}
111107
return systemProperties.ToString().Replace(", ","%2C"); // remove spaces from string and escape comma
112108
}
113-
114-
/// <summary>
115-
/// If _inlineCount is true, then results will be nested inside "results" array
116-
/// </summary>
117-
// public bool IsNestedResults()
118-
// {
119-
// return _inlineCount;
120-
// }
121-
122109
}
123110
}

Assets/Prefabs/InventoryCellPrefab.prefab

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ GameObject:
3737
serializedVersion: 4
3838
m_Component:
3939
- 224: {fileID: 224000010748435472}
40-
- 114: {fileID: 114000010894356006}
40+
- 114: {fileID: 114000012629349416}
4141
m_Layer: 5
4242
m_Name: InventoryCellPrefab
4343
m_TagString: Untagged
@@ -96,21 +96,6 @@ GameObject:
9696
m_NavMeshLayer: 0
9797
m_StaticEditorFlags: 0
9898
m_IsActive: 1
99-
--- !u!114 &114000010894356006
100-
MonoBehaviour:
101-
m_ObjectHideFlags: 1
102-
m_PrefabParentObject: {fileID: 0}
103-
m_PrefabInternal: {fileID: 100100000}
104-
m_GameObject: {fileID: 1000012312357288}
105-
m_Enabled: 1
106-
m_EditorHideFlags: 0
107-
m_Script: {fileID: 11500000, guid: 833090a17290e4c3f83e448026c0ccf4, type: 3}
108-
m_Name:
109-
m_EditorClassIdentifier:
110-
Icon: {fileID: 114000013534120506}
111-
Name: {fileID: 114000013939998824}
112-
Amount: {fileID: 114000011077488226}
113-
Btn: {fileID: 114000011147225522}
11499
--- !u!114 &114000011077488226
115100
MonoBehaviour:
116101
m_ObjectHideFlags: 1
@@ -196,6 +181,21 @@ MonoBehaviour:
196181
m_CallState: 2
197182
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
198183
Culture=neutral, PublicKeyToken=null
184+
--- !u!114 &114000012629349416
185+
MonoBehaviour:
186+
m_ObjectHideFlags: 1
187+
m_PrefabParentObject: {fileID: 0}
188+
m_PrefabInternal: {fileID: 100100000}
189+
m_GameObject: {fileID: 1000012312357288}
190+
m_Enabled: 1
191+
m_EditorHideFlags: 0
192+
m_Script: {fileID: 11500000, guid: 177d64a8e263e4ca990b0b5b61fd989a, type: 3}
193+
m_Name:
194+
m_EditorClassIdentifier:
195+
Icon: {fileID: 114000013534120506}
196+
Name: {fileID: 114000013939998824}
197+
Amount: {fileID: 114000011077488226}
198+
Btn: {fileID: 114000011147225522}
199199
--- !u!114 &114000013534120506
200200
MonoBehaviour:
201201
m_ObjectHideFlags: 1

0 commit comments

Comments
 (0)