# Live Queries

{% hint style="success" %}
This is the official documentation of the `@forestadmin/agent` Node.js agent.
{% endhint %}

{% hint style="info" %}
Due to popular demand, Live Query Charts and Live Query Segments are reintroduced in ForestAdmin agents since version `@forestadmin/agent>=1.56.0`
{% endhint %}

ForestAdmin still recommends using [smart charts](https://docs.forestadmin.com/developer-guide-agents-nodejs/getting-started/migrating/steps/code-transformations/api-charts) and [smart segments](https://docs.forestadmin.com/developer-guide-agents-nodejs/getting-started/migrating/steps/code-transformations/smart-segments) over LiveQueries.

As new agents support multiple datasources, a new property is required when defining a LiveQuery component in the UI. This property will allow the agent to reconcile the query with the proper execution context.

### Enabling the feature on the datasources

To make use of LiveQuery feature, you will need to enable the nativeQuery on your datasource. This ensures a coherent naming scheme for your native query connections as well as only enabling LiveQuery on a restricted set of datasources. Refer to the following documentation to enable nativeQuery on your desired datasources.

* [Sequelize Datasource](https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/provided-data-sources/sequelize#enable-support-of-live-queries)
* [SQL Datasource](https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/provided-data-sources/sql#enable-support-of-live-queries)

### Migrate your UI components

You will have to configure the native query connection on each Live Query component defined in `collection segments`, `analytics chart`, `dashboard charts` and `workspace charts`.

![Select connection on chart](https://3861847666-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9UN5oBJhgzLadOqi7jx6%2Fuploads%2Fgit-blob-ad6ee569131253656cd16d5e79c4de37b4358c93%2Flive_query_connection_on_chart.png?alt=media) *Select connection on chart*

![Select connection on segments](https://3861847666-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9UN5oBJhgzLadOqi7jx6%2Fuploads%2Fgit-blob-b1db2ba0dbabd4cfc4336a89c06495553748b280%2Flive_query_connection_on_segments.png?alt=media) *Select connection on segments*

### Changes in the SQL requests

#### Segments

Previously the segment query must return a list of fields named `id`.Now the field must be named by the `primary key` field.

#### Analytics charts

Previously the analytics charts could use `?` in the request, which will be replaced by the value of the current record id. Now you must use `{{recordId}}` instead.
