Creating our own adapter
Sequelize is fairly extensible through its class properties, lifecycle events, and configurations. For the example of creating our own adapter for Sequelize, we will integrate a new data type that will automatically convert values, using a specific set of rules, to what is called a “slug URL.” A slug URL usually consists of hyphens instead of spaces, lowercase lettering, and removes all special characters.
Let’s look at the steps to create our adapter:
- We’ll begin by installing any necessary packages. Keeping a copy of a character map of special characters can be a daunting task, so we will use an
npm
package called,github-slugger
to help us:npm i --save github-slugger
- Next, we will want to create a couple of directories and a file with
plugins/slug/index.js
as the path from the project’s root directory. Before we can begin coding within that file, we will need to add theslug
column to a table within the...