Sequelize model for the Notes application

Let's create a new file, models/notes-sequelize.mjs:

import fs from 'fs-extra';import util from 'util';import jsyaml from 'js-yaml';import Note from './Note';import Sequelize from 'sequelize';import DBG from 'debug';const debug = DBG('notes:notes-sequelize'); const error = DBG('notes:error-sequelize'); var SQNote; var sequlz;async function connectDB() {   if (typeof sequlz === 'undefined') {    const YAML = await fs.readFile(process.env.SEQUELIZE_CONNECT,'utf8');    const params = jsyaml.safeLoad(YAML, 'utf8');     sequlz = new Sequelize(params.dbname, params.username,                           params.password, params.params);   }  if (SQNote) return SQNote.sync();   SQNote = sequlz.define('Note', {  notekey: { type: Sequelize.STRING, ...

Get Node.js Web Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.