# Query

### **Understanding Querying**

Querying is a process employed to extract data from a database or access state information. The available query messages are typically located in either msg.rs or query.rs, depending on the structure chosen by the contract author.

### **Performing Queries**

Queries can be executed using an external client, such as an API or through the CLI, or within a contract. For further insights into this process, refer to the section on Querying contract state.

### **Querying in Read-Only Mode**

Queries interact with a contract's data store exclusively in a read-only mode. They can retrieve data and conduct additional processing as necessary. However, it's important to note that there is a gas limit associated with query operations.

### **Managing Queries**

Queries are represented as entries within the [QueryMsg](https://github.com/deus-labs/cw-contracts/blob/main/contracts/nameservice/src/msg.rs#L20) enum and are handled within the contract's Query function.

```
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
  // ResolveAddress returns the current address that the name resolves to
  ResolveRecord { name: String },
  Config {},
}
```

Subsequently, the contract proceeds to handle this within the query function.

```
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
  match msg {
    QueryMsg::ResolveRecord { name } => query_resolver(deps, env, name),
    QueryMsg::Config {} => to_binary(&config_read(deps.storage).load()?),
  }
}
```

In this context, query\_resolver serves as just another function, while config\_read acts as a helper function that encapsulates data store access.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.burnt.com/xion/others/archived/cosmwasm-resources/contract-semantics/query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
