Back to Skills

sequelize-models

verified

Sequelize ORM model definition patterns and best practices for PostgreSQL. Use when defining models, setting up associations, configuring validations, or optimizing Sequelize usage.

View on GitHub

Marketplace

fran-marketplace

francanete/fran-marketplace

Plugin

database-expert

development

Repository

francanete/fran-marketplace

database-expert/skills/sequelize-models/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/francanete/fran-marketplace/blob/main/database-expert/skills/sequelize-models/SKILL.md -a claude-code --skill sequelize-models

Installation paths:

Claude
.claude/skills/sequelize-models/
Powered by add-skill CLI

Instructions

# Sequelize Model Patterns

## Model Definition

### Basic Model Structure
```javascript
const { DataTypes, Model } = require('sequelize');

class User extends Model {
  // Instance methods
  getFullName() {
    return `${this.firstName} ${this.lastName}`;
  }

  // Class methods
  static async findByEmail(email) {
    return this.findOne({ where: { email: email.toLowerCase() } });
  }
}

User.init({
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true,
  },
  email: {
    type: DataTypes.TEXT,
    allowNull: false,
    unique: true,
    validate: {
      isEmail: true,
      notEmpty: true,
    },
    set(value) {
      this.setDataValue('email', value.toLowerCase());
    },
  },
  firstName: {
    type: DataTypes.TEXT,
    allowNull: false,
    field: 'first_name', // Maps to snake_case column
  },
  lastName: {
    type: DataTypes.TEXT,
    allowNull: false,
    field: 'last_name',
  },
  status: {
    type: DataTypes.TEXT,
    allowNull: false,
    defaultValue: 'active',
    validate: {
      isIn: [['active', 'inactive', 'suspended']],
    },
  },
  metadata: {
    type: DataTypes.JSONB,
    allowNull: false,
    defaultValue: {},
  },
}, {
  sequelize,
  modelName: 'User',
  tableName: 'users',
  underscored: true, // Automatically use snake_case for columns
  timestamps: true,  // Adds createdAt, updatedAt
  paranoid: false,   // Set true for soft deletes (adds deletedAt)
  indexes: [
    { fields: ['email'], unique: true },
    { fields: ['status'] },
    { fields: ['created_at'] },
  ],
});

module.exports = User;
```

## Data Type Mappings

### PostgreSQL ↔ Sequelize

| PostgreSQL | Sequelize DataType | Notes |
|------------|-------------------|-------|
| `BIGINT` | `DataTypes.BIGINT` | Use for IDs and large numbers |
| `INTEGER` | `DataTypes.INTEGER` | Standard integers |
| `NUMERIC(p,s)` | `DataTypes.DECIMAL(p,s)` | Money, precise decimals |
| `DOUBLE PRECISION` | `DataTypes.DOUBLE` | Floating point |
| `TEXT` | `DataTypes.T

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
13115 chars