Coder Social home page Coder Social logo

lyquocnam / fastify-sequelize Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 12.0 11 KB

Fastity plugin work with Sequelize (adapter for NodeJS -> Sqlite, Mysql, Mssql, Posgres)

JavaScript 100.00%
fastify fastifyjs-plugin sequelize sqlite mysql mssql postgres nodejs

fastify-sequelize's Introduction

fastify-sequelize

Fastity plugin work with Sequelize (adapter for NodeJS -> Sqlite, Mysql, Mssql, Posgres)

install

npm install fastify-sequelize

Usage

const fastify = require('fastify')()
const fsequelize = require('fastify-sequelize')

const sequelizeConfig = {
    instance: 'sequelize', // the name of fastify plugin instance.
    autoConnect: true, // auto authentication and test connection on first run

    // other sequelize config goes here
    dialect: 'sqlite',

    // SQLite only
    storage: 'path/to/db.sqlite'
}

fastify
    .register(fsequelize, sequelizeConfig)
    .ready()

fastify.listen(3000, () => {
  console.log('> listening on port 3000')
})
  • instance: (optional) the name of instance will be mapped to fastify, default is sequelize
  • autoConnect: default: true auto authentication and test connection on first run.
  • sequelizeConfig: all sequelize configurations, you can see here.

fastify-sequelize's People

Contributors

g-ongenae avatar lyquocnam avatar mcollina avatar smukkejohan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fastify-sequelize's Issues

Problems with fastify.close with fastify-sequelize

Hello,
I have strange problem with fastify-sequelize in tests - fastify.close throw an exception on app.close. And I have that problem only with fastify-sequelize. I made small test and put it on github - [email protected]:mitry1974/testFSP.git
Can you help me - what is going wrong in that case?

const fastify = require('fastify');
const fastifySequelize = require('fastify-sequelize');
const config = require('../dbconfig');

let app;

beforeEach(async () => {
try {
app = fastify ();
app.register(fastifySequelize, config);
await app.ready();
} catch(e) {
console.log('application start throw an error');
console.log(e);
}
});

afterEach(async () => {
try{
await app.close();
} catch (e) {
console.log('app.close throw an error');
console.log(e);
}
app = null;
});

test('1', () => {
expect(5).toBe(5);
});

test('2', () => {
expect(6).toBe(6);
});

Please update the sequelize version

During installation, npm issues a warning:

npm WARN deprecated [email protected]: This version will no longer receive security fixes per our security policy. Please update to sequelize@5 or above.

Please consider updating the Sequelize version to 5.

plugins can return a promise

as sequelize is promise-based, you can return a promise instead of calling next.

Currently you are not handling the error correctly, as catch() is just console.logging.

Add some basic example for usage

Hi I am totally fresh to NodeJS environment. I have been using fastify-seuqlize for some REST API development. If possible please add some example of usage basically how to define models in different folders and export them as module to be used in other models for relations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.