Get
public BackendReturnObject Get(string tableName, Where where); public BackendReturnObject Get(string tableName, Where where, int limit); public BackendReturnObject Get(string tableName, Where where, int limit, string firstKey); public BackendReturnObject Get(string tableName, Where where, int limit, string firstKey, TableSortOrder tableSortOrder); public BackendReturnObject Get(string tableName, Where where, string[] select); public BackendReturnObject Get(string tableName, Where where, string[] select, int limit); public BackendReturnObject Get(string tableName, Where where, string[] select, int limit, string firstKey); public BackendReturnObject Get(string tableName, Where where, string[] select, int limit, string firstKey, TableSortOrder tableSortOrder);
Parameters
Value | Type | Description | Default |
---|---|---|---|
tableName | string | Name of table to look up | - |
where | Where | The where clause to search | - |
limit | int | (Optional) Number of game information rows to load. Minimum 1, maximum 100. | 10 |
select | string[] | (Optional) Columns to include among existing columns in the row | Includes all columns |
firstKey | string | (Optional) Starting point of data lookup | Data that was inserted last |
sortOrder | TableSortOrder | (Optional) TableSortOrder.DESC(descending order) or TableSortOrder.ASC(ascending order) | TableSortOrder.DESC(descending order) |
Description
The data stored in the table is looked up.
- The data can be looked up regardless of schema definition status.
- Both public and private data can be looked up.
- In the case of a private table, you can look up only your own data.
- The throughput of the data is the same regardless of whether the select clause is used.
Look up all data without conditions
To search all data without conditions, declare 'where,' which is passed as a parameter value, as new Where().
Look up only the data of a specific user
To only look up the public table of a specific user, you can declare a where condition as shown below:
Where where = new Where();
where.Equal("owner_inDate", "user's gamerInDate");
- In the case of owner_inDate, as the search is performed using the user's key value, the search process may be accelerated if this condition is added to the conditional statement.
- gamerIndate can be checked with the GetUserInfoByNickName method or via the user information returned from methods such as friend or guild member lookup.
Example 1
Search all data without conditions
Synchronous
// Look up all data without conditions
var bro = Backend.GameData.Get("tableName", new Where(), 10);
if(bro.IsSuccess() == false)
{
// Request handled as failure
Debug.Log(bro);
return;
}
if(bro.GetReturnValuetoJSON()["rows"].Count <= 0)
{
// Even if the request succeeds, there might not be a piece of data that meets the where condition
// Therefore, you must confirm that the corresponding piece of data exists
// In the case of the new Where() condition example above, the Count may be 0 or less if there is no row in the table.
Debug.Log(bro);
return;
}
// Checks the inDate value of all rows for the searched data
for(int i=0; i<bro.Rows().Count; ++i)
{
var inDate = bro.Rows()[i]["inDate"]["S"].ToString();
Debug.Log(inDate);
}
Asynchronous
// Look up all data without conditions
Backend.GameData.Get("tableName", new Where(), 10, bro =>
{
if(bro.IsSuccess() == false)
{
// Request handled as failure
Debug.Log(bro);
return;
}
if(bro.GetReturnValuetoJSON()["rows"].Count <= 0)
{
// Even if the request succeeds, there might not be a piece of data that meets the where condition
// Therefore, you must confirm that the corresponding piece of data exists
// In the case of the new Where() condition example above, the Count may be 0 or less if there is no row in the table.
Debug.Log(bro);
return;
}
// Checks the inDate value of all rows for the searched data
for(int i = 0; i < bro.Rows().Count; ++i)
{
var inDate = bro.Rows()[i]["inDate"]["S"].ToString();
Debug.Log(inDate);
}
});
SendQueue
// Look up all data without conditions
SendQueue.Enqueue(Backend.GameData.Get, "tableName", new Where(), 10, bro =>
{
if(bro.IsSuccess() == false)
{
// Request handled as failure
Debug.Log(bro);
return;
}
if(bro.GetReturnValuetoJSON()["rows"].Count <= 0)
{
// Even if the request succeeds, there might not be a piece of data that meets the where condition
// Therefore, you must confirm that the corresponding piece of data exists
// In the case of the new Where() condition example above, the Count may be 0 or less if there is no row in the table.
Debug.Log(bro);
return;
}
// Checks the inDate value of all rows for the searched data
for(int i = 0; i < bro.Rows().Count; ++i)
{
var inDate = bro.Rows()[i]["inDate"]["S"].ToString();
Debug.Log(inDate);
}
});
Example 2
Look up only the deck and score columns in a specific user's data
Synchronous
// When returning through the use of select[], set to print only deck and score
string[] select = { "deck", "score" };
// Where clause for searching data of a specific user
Where where = new Where();
where.Equal("owner_inDate", "user's inDate value(user key value)");
// Look up only the deck and score columns in a specific user's data
var bro = Backend.GameData.Get("tableName", where, select, 10);
if(bro.IsSuccess() == false)
{
// Request handled as failure
Debug.Log(bro);
return;
}
if(bro.GetReturnValuetoJSON()["rows"].Count <= 0)
{
// Even if the request succeeds, there might not be a piece of data that meets the where condition
// Therefore, you must confirm that the corresponding piece of data exists
Debug.Log(bro);
return;
}
// Checks the score of the first row from the searched conditions
int score = (int)bro.Rows()[0]["score"]["N"];
Asynchronous
// When returning through the use of select[], set to print only deck and score
string[] select = { "deck", "score" };
// Where clause for searching data of a specific user
Where where = new Where();
where.Equal("owner_inDate", "user's inDate value(user key value)");
// Look up only the deck and score columns in a specific user's data
Backend.GameData.Get("tableName", where, select, 10, bro =>
{
if(bro.IsSuccess() == false)
{
// Request handled as failure
Debug.Log(bro);
return;
} if(bro.GetReturnValuetoJSON()["rows"].Count <= 0)
{
// Even if the request succeeds, there might not be a piece of data that meets the where condition
// Therefore, you must confirm that the corresponding piece of data exists
Debug.Log(bro);
return;
} // Checks the score of the first row from the searched conditions
int score = (int)bro.Rows()[0]["score"]["N"];
});
SendQueue
// When returning through the use of select[], set to print only deck and score
string[] select = { "deck", "score" };
// Where clause for searching data of a specific user
Where where = new Where();
where.Equal("owner_inDate", "user's inDate value(user key value)");
// Look up only the deck and score columns in a specific user's data
SendQueue.Enqueue(Backend.GameData.Get, "tableName", where, select, 10, bro =>
{
if(bro.IsSuccess() == false)
{
// Request handled as failure
Debug.Log(bro);
return;
}
if(bro.GetReturnValuetoJSON()["rows"].Count <= 0)
{
// Even if the request succeeds, there might not be a piece of data that meets the where condition
// Therefore, you must confirm that the corresponding piece of data exists
Debug.Log(bro);
return;
}
// Checks the score of the first row from the searched conditions
int score = (int)bro.Rows()[0]["score"]["N"];
});
Return cases
Success cases
When the lookup is successful
statusCode : 200
returnValue : refer to GetReturnValuetoJSON
When the lookup succeeds but there is no data meeting the relevant 'where' search condition
statusCode : 200
returnValue : {"serverTime":"2021-03-23T07:07:01.235Z","rows":[],"firstKey":null}
Error cases
When Get is attempted on a non-existent table
statusCode : 404
errorCode : NotFoundException
When an attempt is made to load to an inactive tableName
statusCode : 412
errorCode : PreconditionFailed
GetReturnValuetoJSON
{
// Server time when the server processed the request
"serverTime":"2021-03-23T06:39:46.519Z",
// Returned data
"rows":[
{
// inDate of the user who owns the row
"owner_inDate":{
"S":"2019-07-31T06:15:35.691Z"
},
// Time when the row was inserted
"client_date":{
"S":"2021-03-23T04:54:45.709Z"
},
// inDate of the row
"inDate":{
"S":"2021-03-23T04:54:45.849Z"
},
// Time when the row was last updated
"updatedAt":{
"S":"2021-03-23T04:54:45.849Z"
},
... // Data stored in the client
},
// and etc...
],
// null when firstKey does not exist
"firstKey":null
// When firstKey exists
// "firstKey" : {"inDate":{"S":"2021-03-23T04:54:45.849Z"}}}
}
Sample code
public class GameDataItem
{
public string nickName = Backend.UserNickName;
public string ownerIndate = Backend.UserInDate;
public string inDate;
public int hp;
public int mp;
public float atk;
public long money;
public Dictionary<string, string> equip = new Dictionary<string, string>();
public List<string> items = new List<string>();
public DateTime lastUpdate;
public GameDataItem()
{
}
public GameDataItem(LitJson.JsonData json)
{
hp = int.Parse(json["hp"].ToString());
mp = int.Parse(json["mp"].ToString());
atk = float.Parse(json["atk"].ToString());
money = long.Parse(json["money"].ToString());
foreach(var column in json["equip"].Keys)
{
equip.Add(column, json["equip"][column].ToString());
}
for(int i = 0; i < json["items"].Count; i++)
{
items.Add(json["items"][i].ToString());
}
inDate = json["inDate"].ToString();
lastUpdate = DateTime.Parse(json["lastUpdate"].ToString());
}
public Param ToParam()
{
Param param = new Param();
param.Add("nickName", nickName);
param.Add("hp", hp);
param.Add("mp", mp);
param.Add("atk", atk);
param.Add("money", money);
param.Add("equip", equip);
param.Add("items", items);
param.Add("lastUpdate", DateTime.UtcNow);
return param;
}
public override string ToString()
{
string equipString = "equip\n";
foreach(var dic in equip)
{
equipString += $"-{dic.Key} : {dic.Value}\n";
}
string itemString = "items : ";
for(int i = 0; i < items.Count; i++)
{
itemString += $"{items[i]}, ";
}
return $"hp : {hp}\n" +
$"mp : {mp}\n" +
$"atk : {atk}\n" +
$"money : {money}\n" +
$"lastUpdate : {lastUpdate}\n" +
equipString + "\n" + itemString + "\n";
}
}
public void GetWhereTest()
{
var bro = Backend.GameData.Get("PlayerInfo", new Where());
if(!bro.IsSuccess())
{
Debug.LogError(bro.ToString());
return;
}
LitJson.JsonData gameDataListJson = bro.FlattenRows();
if(gameDataListJson.Count <= 0)
{
Debug.Log("The data does not exist");
return;
}
GameDataItem gameDataItem = new GameDataItem(gameDataListJson[0]);
Debug.Log(gameDataItem.ToString());
}