# query

The query() method for the SurrealDB Mojo SDK runs one or more SurrealQL statements against the database.

Runs one or more SurrealQL statements against the database and returns an `RpcResponse`.

```python title="Method Syntax"
client.query(query, bindings_json, session, txn)
```

## Arguments

<table>
    <thead>
        <tr>
            <th colspan="2" scope="col">Argument</th>
            <th colspan="2" scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>query</code></td>
            <td colspan="2" scope="row" data-label="Description">The SurrealQL statements to run.</td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>bindings_json</code></td>
            <td colspan="2" scope="row" data-label="Description">Optional bindings as a JSON string. Defaults to <code>"{}"</code>.</td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>session</code></td>
            <td colspan="2" scope="row" data-label="Description">An optional session id.</td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Argument"><code>txn</code></td>
            <td colspan="2" scope="row" data-label="Description">An optional transaction id.</td>
        </tr>
    </tbody>
</table>

## Example usage

```python
var resp = client.query("SELECT * FROM person WHERE age > 18;")

if resp.is_ok():
    if resp.result:
        print(resp.result.value())
else:
    print("error:", resp.error_message().value())
```

> [!NOTE]
> A dedicated API for passing arbitrary CBOR bindings is on the roadmap. Today, CBOR connections support the default `"{}"`, while JSON-RPC connections accept raw JSON strings via `bindings_json`.

## See also

- [Executing queries](/docs/reference/mojo/concepts/executing-queries.md)
