# Write basic queries · Tic Tac Toe on Chromia with Rell and Unity · Learn Chromia

> Here you query game data stored on the Chromia blockchain: you fetch games by their status and look up an individual game by its ID.

Source: https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/write-queries/

Tic Tac Toe on Chromia with Rell and UnityLesson 7 of 20

1. [01Tic Tac Toe on Chromia with Rell and Unity](https://chromia.com/learn/tic-tac-toe/introduction/)
2. [02Set up your project](https://chromia.com/learn/tic-tac-toe/setup/)

Module 1: A Rell backend with FT4 accounts

1. [03Overview](https://chromia.com/learn/tic-tac-toe/module-one/)
2. [04Part 1: Database design, operations and queries](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/)
3. [05Design the data model](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/tables/)
4. [06Perform basic operations](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/basic-operations/)
5. [07Write basic queries](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/write-queries/)
6. [08Part 2: Set up accounts](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/)
7. [09Configure FT4 accounts](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/install-configure-ft4/)
8. [10Authentication with FT4 accounts](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/authentication/)
9. [11Update tests](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/update-tests/)
10. [12Part 3: How the dapp project is organized](https://chromia.com/learn/tic-tac-toe/module-one/project-structure/)
11. [13Work with Rell modules](https://chromia.com/learn/tic-tac-toe/module-one/project-structure/modules/)
12. [14Add modules to your dapp](https://chromia.com/learn/tic-tac-toe/module-one/project-structure/incorporate-modules/)

Module 2: The Unity project

1. [15Overview](https://chromia.com/learn/tic-tac-toe/module-two/)
2. [16Set up the project](https://chromia.com/learn/tic-tac-toe/module-two/setup/)
3. [17Project scaffold](https://chromia.com/learn/tic-tac-toe/module-two/scaffold/)
4. [18Link the client to the blockchain](https://chromia.com/learn/tic-tac-toe/module-two/connecting-the-client/)
5. [19Summary and manual testing](https://chromia.com/learn/tic-tac-toe/module-two/summary-and-tests/)

1. [20What next?](https://chromia.com/learn/tic-tac-toe/what-next/)

[Learn](https://chromia.com/learn/)[Tic Tac Toe on Chromia with Rell and Unity](https://chromia.com/learn/tic-tac-toe/)

07 / 20Module 1: A Rell backend with FT4 accounts

# Write basic queries

Here you query game data stored on the Chromia blockchain: you fetch games by their status and look up an individual game by its ID.

## Queries

### Get games by status

Use this query to fetch games in a particular state, such as created, active, or completed:

src/main/queries.rell

```
query get_games_by_status(status: enums.game_status) {
    return functions.get_games_by_status(status);
}
```

**How it works:**

* `get_games_by_status(status)` returns every game whose state equals the `status` argument.
* Filter games with it according to where they stand, for example to list games waiting for a second player or games still being played.

**Example:**

Call `get_games_by_status` with `game_status.created` to get every game that has the `created` status.

### Get a game by ID

Use this query to look up one game by its unique ID:

src/main/queries.rell

```
query get_game_by_id(id: integer) {
    return functions.get_game_by_id(id);
}
```

**How it works:**

* `get_game_by_id(id)` returns the game whose unique identifier matches `id`.
* It gives you the full record for that game, covering the players, the moves made, and its current state.

**Example:**

Call `get_game_by_id` with the game's unique integer ID to get its details.

## Manually test the dapp

To try the queries by hand, start a local test node and send requests to it through the Chromia CLI.

### Starting a test node

From your project folder, start a local test node with:

bash

```nolines
chr node start
```

The node prints logs as it builds blocks.

With the node running, you can call your queries from the Chromia CLI.

#### Test the get games by status query manually

Run the following to call `get_games_by_status`:

bash

```nolines
chr query get_games_by_status status='active'
```

#### Test the get game by ID query manually

Run the following to call `get_game_by_id`:

bash

```nolines
chr query get_game_by_id id='GAME_ID'
```

**Example output:**

A call to `get_game_by_id` returns something like this:

json

```
{
  "id": 5,
  "created_by": "bob_account_id",
  "created_at": "TIMESTAMP",
  "player1_account_id": "bob_account_id",
  "player2_account_id": "eve_account_id",
  "status": "game_status.active",
  "moves": [
    { "player": "bob", "position": 4 },
    { "player": "eve", "position": 5 }
  ],
  "winner": null
}
```

The result shows the participating players, when the game was created, the moves played, and the winner once one exists.

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Perform basic operations**](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/basic-operations/)[Next →**Part 2: Set up accounts**](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/)

On this page

* [Queries](#queries)
* [Manually test the dapp](#manually-test-the-dapp)
