sequelize
БесплатноБез исполняемых скриптовНе проверенSequelize is a promise-based ORM for Node.js supporting PostgreSQL, MySQL, MariaDB, SQLite, and MS SQL. Use when a user asks to define Sequelize models, write…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Sequelize — Node.js SQL ORM
Overview
Sequelize is a mature, promise-based ORM for Node.js supporting PostgreSQL, MySQL, MariaDB, SQLite, and MS SQL Server. The stable line is v6 (sequelize 6.37.x on npm, with sequelize-cli 6.6.x for migrations). Version 7 is published as @sequelize/core but is still an alpha (7.0.0-alpha.x): it has a different package layout (one @sequelize/<dialect> package per database) and decorator-based models, so use v6 for production unless the user asks for v7. Docs: https://sequelize.org/docs/v6/.
Instructions
Core Capabilities
Model Definition
import { Model, DataTypes, Sequelize, QueryTypes, InferAttributes, InferCreationAttributes, CreationOptional } from "sequelize";
const sequelize = new Sequelize(process.env.DATABASE_URL!, {
dialect: "postgres",
pool: { max: 20, min: 5, acquire: 30000, idle: 10000 },
logging: process.env.NODE_ENV === "development" ? console.log : false,
});
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
declare id: CreationOptional<number>;
declare name: string;
declare email: string;
declare role: CreationOptional<"user" | "admin">;
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;
}
User.init({
id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true },
name: { type: DataTypes.STRING(100), allowNull: false, validate: { len: [2, 100] } },
email: { type: DataTypes.STRING, allowNull: false, unique: true, validate: { isEmail: true } },
role: { type: DataTypes.ENUM("user", "admin"), defaultValue: "user" },
}, {
sequelize, tableName: "users", timestamps: true,
hooks: {
beforeCreate: (user) => { user.email = user.email.toLowerCase(); },
},
});
class Post extends Model<InferAttributes<Post>, InferCreationAttributes<Post>> {
declare id: CreationOptional<number>;
declare title: string;
declare body: string;
declare published: CreationOptional<boolean>;
declare authorId: number;
}
Post.init({
id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true },
title: { type: DataTypes.STRING, allowNull: false },
body: { type: DataTypes.TEXT, allowNull: false },
published: { type: DataTypes.BOOLEAN, defaultValue: false },
authorId: { type: DataTypes.INTEGER, allowNull: false },
}, { sequelize, tableName: "posts" });
// Associations
User.hasMany(Post, { foreignKey: "authorId", as: "posts" });
Post.belongsTo(User, { foreignKey: "authorId", as: "author" });
Queries
// Find with eager loading
const users = await User.findAll({
where: { role: "user" },
include: [{ model: Post, as: "posts", where: { published: true }, required: false }],
order: "createdAt", "DESC",
limit: 10, offset: 20,
});
// Raw query for complex operations; pass values with replacements/bind, never string concatenation
const rows = await sequelize.query(`
SELECT u.name, COUNT(p.id) AS post_count
FROM users u LEFT JOIN posts p ON u.id = p."authorId" AND p.published = :published
GROUP BY u.id ORDER BY post_count DESC LIMIT 10
`, { replacements: { published: true }, type: QueryTypes.SELECT });
// Transaction
// Managed transaction: commits on return, rolls back on throw
await sequelize.transaction(async (t) => {
const user = await User.create({ name: "Alice Moreau", email: "[email protected]" }, { transaction: t });
await Post.create({ title: "First Post", body: "Hello", authorId: user.id }, { transaction: t });
});
// Bulk operations
await User.bulkCreate(usersData, { validate: true, updateOnDuplicate: ["name"] }); // upsert on the unique key (not supported on every dialect)
Installation
npm install sequelize
npm install pg pg-hstore # PostgreSQL (or mysql2, mariadb, sqlite3, tedious)
npm install --save-dev sequelize-cli # Migrations CLI
npx sequelize-cli init # Creates config/, models/, migrations/, seeders/
Migrations with the CLI (npx sequelize-cli ...; the default config/config.json is created with mysql, so edit dialect and credentials first):
npx sequelize-cli model:generate --name Task --attributes title:string,done:boolean
npx sequelize-cli db:migrate # apply pending migrations
npx sequelize-cli db:migrate:status
npx sequelize-cli db:migrate:undo # revert the last one
Examples
Example 1: Blog backend with users and posts
User request: "Set up Sequelize with Postgres for a blog: users have many posts, I want the latest 10 users with their published posts."
The agent installs sequelize pg pg-hstore, creates the User and Post models and the hasMany/belongsTo pair above, generates migrations with sequelize-cli instead of sync(), and runs User.findAll({ include: [{ model: Post, as: "posts", where: { published: true }, required: false }], order: "createdAt", "DESC", limit: 10 }). Result: an array of User instances, each with a `p
Установить sequelize в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл sequelize?
Sequelize is a promise-based ORM for Node.js supporting PostgreSQL, MySQL, MariaDB, SQLite, and MS SQL. Use when a user asks to define Sequelize models, write queries with associations and eager loading, create or run migrations with sequelize-cli, use transactions, or tune connection pooling in a Node.js or TypeScript backend.
Как установить скилл sequelize?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sequelize запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic