@mhmdzaien/nuxt-sequelize
TypeScript icon, indicating that this package has built-in type declarations

1.0.18 • Public • Published

Nuxt Sequelize

npm version npm downloads License Nuxt

Nuxt module to integrate sequelize and model at server api

Features

  •  Integrate with sequelize model
  •  Add controller support on server handler
  •  Authentication using token header

Quick Setup

1.Install the module to your Nuxt application with one command:

npx nuxi@latest module add @mhmdzaien/nuxt-sequelize

2.Add @mhmdzaien/nuxt-sequelize, models path and nitro support decorator in nuxt.config.ts

export default defineNuxtConfig({
  modules: [@mhmdzaien/nuxt-sequelize],
  nitro: {
    esbuild: {
      options: {
        tsconfigRaw: {
          compilerOptions: {
            experimentalDecorators: true,
          },
        },
      },
    },
  },
  nuxtSequelize: {
    modelPath: './server/models',
  },
})

3.Create index.js inside 'modelPath' that contain loader to model

export function initModels(sequelize: Sequelize) {
  User.initModel(sequelize)
}

4.Create .env file contain database configuration

DB_NAME=
DB_USER=root
DB_PASSWORD=
DB_HOST=localhost
DB_DRIVER=

DB_DRIVER is one of sequelize supported dialect

That's it! You can now use My Module in your Nuxt app ✨

Server utils

defineMyEventHandler(handler, authorizeRequest?)

  • handler : Function(event) => callback handler with event parameter
  • authorizeRequest : "*" | Array => if set handler check authentication in token header accepted role number

Contribution

Local development
# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release

Readme

Keywords

Package Sidebar

Install

npm i @mhmdzaien/nuxt-sequelize

Weekly Downloads

7

Version

1.0.18

License

MIT

Unpacked Size

40 kB

Total Files

36

Last publish

Collaborators

  • mhmdzaien