npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nuxt-sequelize

v0.0.5

Published

Integrate Nuxt with Sequelize

Downloads

77

Readme

nuxt-sequelize

Sequelize module for Nuxt

Quick Start

  1. Add nuxt-sequelize, sequelize, and inflection dependencies to your project

    npm install nuxt-sequelize sequelize inflection
  2. Add nuxt-sequelize to the modules section of nuxt.config.ts

    export default defineNuxtConfig({
      modules: ["nuxt-sequelize"],
    });
  3. Start the development server:

    npm run dev

Usage

Configuration

  1. Configure Nuxt Sequelize with the sequelize property.

    export default defineNuxtConfig({
      sequelize: {
        dir: "server/models",
        options: {},
      },
    });

    | Key | Type | Required | Description | | ------- | ----------- | -------- | -------------------------------------------------------------------------------- | | dir | string | false | Use the dir/ directory to automatically register models within your application. | | options | UserOptions | false | Sequelize options |

  2. Configure Sequelize secret via .env

    NUXT_SEQUELIZE_DIALECT='mysql'
    NUXT_SEQUELIZE_DATABASE=''
    NUXT_SEQUELIZE_HOST=""
    NUXT_SEQUELIZE_PORT=3306
    NUXT_SEQUELIZE_USERNAME="admin"
    NUXT_SEQUELIZE_PASSWORD="admin"

Define Model

Files created under the model directory will be automatically registered under the sequelize object. The filename will be used as the model name.

// models/user.ts
import { DataTypes } from "sequelize";

export default defineSequelizeModel({
  // ...ModelAttributes
});

Define Association

To define associations between models, create and configure the associations in the associations.ts file located in the model directory.

// model/associations.ts

export default defineSequelizeAssociation([
  // user - profile
  {
    type: "1to1",
    modelA: {
      name: "user",
      options: {
        foreignKey: "user_id",
        as: "profile",
      },
    },
    modelB: {
      name: "profile",
      options: {
        foreignKey: "user_id",
        as: "user",
      },
    },
  },
  // user -> article
  {
    type: "1toN",
    modelA: {
      name: "user",
      options: {
        foreignKey: "user_id",
        as: "articles",
      },
    },
    modelB: {
      name: "article",
      options: {
        foreignKey: "user_id",
        as: "user",
      },
    },
  },
  // article <-> tag
  {
    type: "NtoM",
    through: "articleTag",
    modelA: {
      name: "article",
      options: {
        foreignKey: "article_id",
        as: "tags",
      },
    },
    modelB: {
      name: "tag",
      options: {
        foreignKey: "tag_id",
        as: "articles",
      },
    },
  },
]);

Use

Get the model collection through useSequelize, and then use its attributes directly

// server/routes/hello.get.ts
export default defineEventHandler(async () => {
  const sequelize = useSequelize();
  const result = await sequelize.user.findAll();
  return result;
});

Composables

defineSequelizeModel

This function helps to create a new Sequelize model. Example usage:

Using sequelize.define:

// models/user.ts
import { DataTypes } from "sequelize";

export default defineSequelizeModel({
  // ...ModelAttributes
});

Extending Model

// models/user.ts
import { DataTypes, Model } from "sequelize";

export default defineSequelizeModel((modelName, sequelize) => {
  class User extends Model {}
  User.init(
    {
      // ...ModelAttributes
    },
    {
      sequelize,
      modelName,
    }
  );

  return User;
});

defineSequelizeAssociation

Define associations between models

// models/association.ts
export default defineSequelizeAssociation([
  // ...Associations
])

useSequelize

Access the model collection of sequelize

export default defineEventHandler(async () => {
  const sequelize = useSequelize();
});

useSequelizeClient

Access the instance of sequelize

export default defineEventHandler(async () => {
  const client = useSequelizeClient();
});