> ## Documentation Index
> Fetch the complete documentation index at: https://forest-chore-open-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sequelize datasource

> Connect Forest to your existing Sequelize models with support for scopes, hooks, and associations

The Sequelize datasource allows importing collections from a Sequelize instance, preserving your ORM configuration including scopes, hooks, associations, and validations.

<Warning>
  Sequelize datasource is only available for Node.js. For Ruby, check the [ActiveRecord datasource](/get-started/connect/data-sources/active-record).
</Warning>

## Basic usage

```javascript theme={null}
import { createAgent } from '@forestadmin/agent';
import { createSequelizeDataSource } from '@forestadmin/datasource-sequelize';
import { Sequelize, Model, DataTypes } from 'sequelize';

// Initialize Sequelize
const sequelize = new Sequelize('postgresql://user:pass@localhost:5432/mydb');

// Define your models
class User extends Model {}
User.init(
  {
    username: DataTypes.STRING,
    birthday: DataTypes.DATE,
  },
  { sequelize, modelName: 'user' }
);

// Add to agent
const agent = createAgent(options);
agent.addDataSource(createSequelizeDataSource(sequelize));
```

## Features

The Sequelize datasource automatically preserves your ORM configuration:

* **Sequelize scopes** - Mapped to Forest segments
* **Sequelize hooks** - Continue to execute as configured
* **Associations** - Relationships are automatically recognized
* **Validations** - Model validations are enforced

## Live Query support

Enable SQL-based reporting by setting a connection identifier:

```javascript theme={null}
agent.addDataSource(
  createSequelizeDataSource(sequelize, {
    liveQueryConnections: 'main_database'
  })
);
```

This allows authorized users to create Live Query charts, analytics, and segments that execute custom SQL directly against your database.

<Warning>
  Live Queries execute raw SQL. Ensure proper access controls and review queries before deploying to production.
</Warning>

## Source code

This connector is open source. Browse the code or contribute on GitHub: [`@forestadmin/datasource-sequelize`](https://github.com/ForestAdmin/agent-nodejs/tree/main/packages/datasource-sequelize).
