GameSparks().DynamoDB().QueryIndex example please

0

Can someone provide a working example of using QueryIndex in GameSparks cloud code for handler in an Event. I'm attempting to return a list of players in a lobby querying my table named BattleRoyalePlayerLobbyTable, with lobbyId, playerId as complex key, and index named lobbyId-index with primary key as lobbyId, using message.lobbyId passed in the request message.

try
{
  const tableName = "BattleRoyalePlayerLobbyTable";
  const indexName = 'lobbyId-index';
  const keyConditionExpression = "lobbyId = :lobbyid";
  const expressionAttributeNames = null;
  const expressionAttributeValues = { ":lobbyid": {"S": message.lobbyId} };
  const exclusiveStartKey = null;
  
  let queryResult = GameSparks().DynamoDB().QueryIndex(
    tableName,
    indexName,
    keyConditionExpression,
    expressionAttributeNames,
    expressionAttributeValues,
    exclusiveStartKey);
  
  GameSparks().Logging().Info(queryResult.ToString());
  
  return GameSparks().Messaging.Response({ "players": queryResult.Items });
}
catch (ex)
{
  return GameSparks().Messaging().Response({ "players": [], "error": ex.message });
}
Response received
Id: 56f05f7b-65ed-43b7-a8e4-8390dc9faf0e
 Type: Custom.Game.GetPlayersInLobby
 Category: Response
 ResponseTo: 92f4562c-cf9e-4f7a-ac13-444e31b1c93b
 
 {"players":[],"error":"javaException.getCustomerFacingExceptionDetails is not a function"}
Request sent
Id: 92f4562c-cf9e-4f7a-ac13-444e31b1c93b
 Type: Custom.Game.GetPlayersInLobby
 Category: Request
 
 {"lobbyId":"fb3578b6797848448d5facca5555d12c"}

Thank you

gefragt vor 2 Jahren321 Aufrufe
1 Antwort
0
Akzeptierte Antwort

I figured it out. Attribute Values are type MAP.

try
{
  const tableName = 'BattleRoyalePlayerLobbyTable';
  const indexName = 'lobbyId-index';
  const keyConditionExpression = '#lobbyId = :lobbyid';
  const expressionAttributeNames = {'#lobbyId': 'lobbyId'};
  const expressionAttributeValues = { ':lobbyid': message.lobbyId };
  const exclusiveStartKey = {};
  
  let queryResult = GameSparks().DynamoDB().QueryIndex(
    tableName,
    indexName,
    keyConditionExpression,
    expressionAttributeNames,
    expressionAttributeValues,
    exclusiveStartKey);
  
  return GameSparks().Messaging().Response({ 'players': queryResult.Items });
}
catch (ex)
{
  return GameSparks().Messaging().Response({ "players": [], "error": ex.message });
}
beantwortet vor 2 Jahren
  • @Kirkules hi can you help me? I made a query just like yours but its gives me this error "Content does not match constraints applied by annotation [PatternConstraint]"

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen