# read-model

The `read-model` exports four methods: `repositoryBuilder`, `eventServiceBuilder`, `queryServiceBuilder`, and `refreshServiceBuilder`.

The query service is used to query the cached projection state of an entity. You can lookup entity by `id`, an array of `ids`, or whatever search parameters that are supported by your `adapter`.

The event service is used to handle incoming events from a write model subscription, and use those events to update the cached projection state. This the **push** approach we spoke about in [Eventual Consistency](/advanced/eventual-consistency.md).

The refresh service is used to manually load new events from the write model's datastore. This is the **pull** approach we spoke about in [Eventual Consistency](/advanced/eventual-consistency.md).

### Example

{% code title="readModel.js" %}

```javascript
const {
  repositoryBuilder,
  eventServiceBuilder,
  queryServiceBuilder,
  refreshServiceBuilder,
} = require('serverless-cqrs.read-model')

const reducer = require('./reducer')
const adapter = require('./adapter')
const eventAdapter = require('./eventAdapter')

const repository = repositoryBuilder({
  reducer,
  adapter,
})

const {
  getById,
  getByIds,
  search,
} = queryServiceBuilder.build({
  repository,
  //no eventAdapter because we don't need access to the write-models events
})

const {
  refresh,
} = refreshServiceBuilder.build({
  repository,
  eventAdapter,
})

const {
  handleEvent,
} = eventServiceBuilder.build({
  repository,
  eventAdapter,
})

module.exports = {
  getById,
  getByIds,
  search,
  refresh,
  handleEvent,
}



```

{% endcode %}


---

# 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://www.serverless-cqrs.com/components/read-model.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.
