Back to Sequelize

Sequelize v7 (alpha)

docs/index.mdx

latest3.9 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import DecoratorInfo from './_fragments/_decorator-info.mdx';

Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Amazon Redshift and Snowflake’s Data Cloud. It features solid transaction support, relations, eager and lazy loading, read replication and more.

Sequelize follows Semantic Versioning and the official Node.js LTS schedule. Version 7 of Sequelize officially supports the Node.js versions >=18.0.0.

You are currently looking at the Tutorials and Guides for Sequelize. You might also be interested in the API Reference.

Quick example

<Tabs groupId="ts-js"> <TabItem value="ts" label="TypeScript">
typescript
import {
  Sequelize,
  Model,
  DataTypes,
  InferAttributes,
  InferCreationAttributes,
} from '@sequelize/core';
import { Attribute } from '@sequelize/core/decorators-legacy';
import { SqliteDialect } from '@sequelize/sqlite3';

class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
  @Attribute(DataTypes.STRING)
  declare username: string | null;

  @Attribute(DataTypes.DATE)
  declare birthday: Date | null;
}

const sequelize = new Sequelize({
  dialect: SqliteDialect,
  models: [User],
});

await sequelize.sync();

const jane = await User.create({
  username: 'janedoe',
  birthday: new Date(1980, 6, 20),
});

console.log(jane.toJSON());
</TabItem> <TabItem value="js" label="JavaScript">
typescript
import { Sequelize, Model, DataTypes } from '@sequelize/core';
import { Attribute } from '@sequelize/core/decorators-legacy';
import { SqliteDialect } from '@sequelize/sqlite3';

class User extends Model {
  @Attribute(DataTypes.STRING)
  username;

  @Attribute(DataTypes.DATE)
  birthday;
}

const sequelize = new Sequelize({
  dialect: SqliteDialect,
  models: [User],
});

await sequelize.sync();

const jane = await User.create({
  username: 'janedoe',
  birthday: new Date(1980, 6, 20),
});

console.log(jane.toJSON());
</TabItem> </Tabs> <DecoratorInfo />

To learn more about how to use Sequelize, read the tutorials available in the left menu. Begin with Getting Started.

Supporting the project

Do you like Sequelize and would like to give back to the engineering team behind it?

We have recently created an OpenCollective based money pool which is shared amongst all core maintainers based on their contributions. Every support is wholeheartedly welcome. ❤️