sequelize-fastify

a simple and lightweight Sequelize plugin for Fastify.

Usage no npm install needed!

<script type="module">
  import sequelizeFastify from 'https://cdn.skypack.dev/sequelize-fastify';
</script>

README

sequelize-fastify

A simple and lightweight Sequelize plugin for Fastify.

Downloads install size

sequelize-fastify has great support of sequelize v6.x. I will support that simple repository in future as much as I can. So will track any major Sequelize plugin update to give support of each updates as well.

What is Sequelize?

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

Please check official website for more information and developer documentation.

Installation

$ npm install sequelize-fastify

Usage

fastify.register(
  require('sequelize-fastify'),
  {
    instance: 'db',
    sequelizeOptions: {
      dialect: 'DIALECT_NAME', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
      database: 'DATABASE_NAME',
      username: 'DATABASE_USER_NAME',
      password: 'DATABASE_USER_PASSWORD',
      options: {
        host: 'DATABASE_HOST_OR_SERVER',
        port: 'DATABASE_PORT'
      }
    }
  }
)
  .ready(async () => {
    try {
      // first connection
      const result = await fastify.db.authenticate()

      console.log(
        chalk.green('Database connection is successfully established.')
      )
    } catch(err) {
      console.log(
        chalk.red(`Connection could not established: ${err}`)
      )
    } finally {
      fastify.close()
    }
  })

Options

Name Type Default Description
instance string sequelize A decorator instance name which will be available anywhere in the fastify server.
sequelizeOptions object {} Sequelize configuration object which will be passed to Sequelize instance while creating. Please see API Reference doc.