Skip to content

Query Builder

Implemented in: EasyGameLobby.Infrastructure

Query Builder allows you to easily filter lobbies based on any lobby value including custom values. The query builder can be used to filter lobbies on the GetLobbies and GetLobbiesAsLocal methods, as well as used to quickly join a lobby with the QuickJoinLobby method.

Every Query Builder method returns itself, allowing you to chain multiple filters together.

To enable a Lobby Custom Value to be filtered, an index must be defined in the Custom Lobby Values window.

Properties

  • SampleResults - bool
    If true, results will be randomly sampled and no continuation token will be returned.
  • Count - int
    The number of results to return (Min: 1, Max: 100).
  • Skip - int
    The number of results to skip.
  • ContinuationToken - string
    The continuation token to use for pagination, automatically setted after first GetLobbies call. It's used to get the next page after calling the NextPage method and calling GetLobbies.

Filterable Properties

Those properties are used to filter and order the lobbies results and can be accessed either by the property name or by their FieldOptions (Unity's Lobby Enum, in case of custom values, use the index of the custom value).

QueryBuilder queryBuilder = new QueryBuilder();

queryBuilder
  .Name.Contains("My Lobby")
  [QueryFilter.FieldOptions.N2].LessThan("10") // Custom Value of index number 2
  [QueryFilter.FieldOptions.AvailableSlots].GreaterThan("0")
  .MyCustomValue.GreaterThan("5");

List<LocalLobby> results = await LobbyManager.Instance.GetLobbiesAsLocal(queryBuilder);

Methods

Every method return the QueryBuilder instance, allowing you to chain all methods together.

  • QueryBuilder Reset( )
    Reset the query builder to its default values.
  • QueryBuilder FirstPage( )
    Set the ContinuationToken to null in order to get the first page of results.
  • QueryBuilder NextPage( )
    Set the ContinuationToken to the next available token (only available after the first GetLobbies call using this instance of query builder).
QueryBuilder queryBuilder = new QueryBuilder();

queryBuilder
  .HasPassword.Equals("false")
  .SetCount(10);

// Returns the first 10 lobbies
List<LocalLobby> firstResults = await LobbyManager.Instance.GetLobbiesAsLocal(queryBuilder);

queryBuilder.NextPage();

// Returns the next 10 lobbies
List<LocalLobby> nextResults = await LobbyManager.Instance.GetLobbiesAsLocal(queryBuilder);

Properties setters:

Useful to set properties and continue chaining methods.

  • QueryBuilder SetSampleResults(bool value)
  • QueryBuilder SetCount(int value)
  • QueryBuilder SetSkip(int value)
  • QueryBuilder SetContinuationToken(string value)