#Sequelize #JavaScript #node

Sequelize Data Types: a practical guide

DataTypes are core to the Sequelize 4 library. This is a practical and complete guide to make up for the sparse Sequelize official documentation on the subject. First of all, DataTypes contains both the types and generators for default values: eg. NOW, UUIDV1 and UUIDV4 are special default values. The places where you’re likely to encounter DataTypes are in the model field definition and in the migration definitions. Note that for a given model and field, the data type should be the same in the model and in the migration. ...

  • Hugo Di Francesco
    Author
3 min read
#sequelize #node #git #cli #JavaScript

Progress and roadblocks: a journey into open-source

Enhancing generators for ES6 in the Sequelize CLI This is the story of my discovery of ES6-class style model definitions with Sequelize (see Using ES6 classes for Sequelize 4 models). The realisation that the current Sequelize CLI model generator didn’t support it (as is expected since it’s not the most common way of doing it). Finally, the impetus to just implement it myself. In other words, I started using a style of Sequelize models that the Sequelize CLI didn’t support. ...

  • Hugo Di Francesco
    Author
6 min read
#JavaScript #Sequelize #testing #Node

Mocking/stubbing ES6 classes in tests with examples of Sequelize model unit tests

This post goes through some patterns that can be used to unit test ES6 classes. The examples will use Jest module auto-mocking but should be portable to other module mocking libraries (eg. Proxyquire) with some modifications. In “Using ES6 classes for Sequelize 4 models” we explored how to define Sequelize models using ES6 classes. One of the benefits of such an approach is that it allows easy unit testing, it allows you to instantiate the model without the baggage of all of Sequelize (and/or a database). ...

  • Hugo Di Francesco
    Author
2 min read
#JavaScript #Sequelize #Node #productivity

Using ES6 classes for Sequelize 4 models

The ES2015 or ES6 specification introduced class to JavaScript. Libraries like React went from React.createClass to class MyComponent extends React.Component, ie went from rolling their own constructor to leveraging a language built-in to convey the programmer’s intent. For a Node.js web application’s persistence layer, a few databases come to mind like MongoDB (possibly paired with mongoose), or a key-value store like Redis. To run a relational database with a Node application, Sequelize, “An easy-to-use multi SQL dialect ORM for Node. ...

  • Hugo Di Francesco
    Author
4 min read