npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-sequelize

v2.2.9

Published

Easily bootstrap sequelize on a project.

Downloads

194

Readme

easy-sequelize

Easily bootstrap sequelize on a project.

Installation

Steps

  1. Install the library
  2. Add models as needed
  3. Add business logic as needed
  4. Configure the database backend

Done!

Details

  1. Install the library
npm install --save easy-sequelize
# the folder `node_modules/easy-sequelize/sample`
# has sample files for models and business layer
# there is a utility to create the sample folder `install-sample.js`

# (optional)
# We'll use ./db for the tutorial, but substitute with your preferred location
node node_modules/easy-sequelize/install-sample.js ./db
#
# The sample files will have the following structure
# db
#   models
#     Product.js
#     Category.js
#   business-layer
#     bl-Products.js
#   migrations
#     20220205-01-addTables.js
#   config.json
  1. Add models as needed Product.js and Category.js can be used as models to create your own, their content is pretty self explanatory. For a more detailed discussion of the model definition syntax, please follow sequelize's documentation. For the tables to be created on the database, you will need to provide a migration, but they will be added automatically to the in-memory models.
const DB = require('./db');

const db = await DB.getDB();
console.log(db.Tables);
// { Categories: Categories, Products: Products }
// All the models are automatically loaded in the Tables array and connected with 
// the Tables on the backend Database
let products = await db.Tables.Products.findAll();
console.log(products);
// []
  1. Add business logic as needed The business-layer folder is where you add functions to abstract the complexities of the database structure into business functions. easy-sequelize will load any files under the business-layer folder and merge their functionality into the main database object. That is if you add a file here called bl-myfunctions.js with two functions exported addProduct and deleteProduct, once you instantiate your database, you will be able to access those functions directly on the database. For example:
/* In bl-myfunctions.js */

module.exports.addProduct = async function (productID,productName,categoryID){
  // notice *this*, because your function will run in the
  // context of the database object
  return this.Tables.Products.create({
    ProductID: productID,
    ProductName: productName,
    CategoryID: categoryID
  });
}
...

/* In your code */

const DB = require('./db');

const db = await DB.getDB();
await db.addProduct('1234','Test',1);

let products = await db.Tables.Products.findAll();
console.log(products[0]);
// Product
// { ProductID: '1234', ProductName: 'Test', CategoryID: 1 }
  1. Configure your database backend Any migration file in the migrations folder will be run automatically once per database. If you are not familiar with the migrations concept, this should be your time to head to the sequelize documentation. You can ignore any of the mechanics and command line instructions, since that is all provided auto-magically by easy-sequelize. By default, the config file is set to use sqlite, override for your needs.

  2. Enjoy the ready-to-use code AND diagram of your database structure located in the db folder (uml.puml).

You can even embed it in your README.md file by adding the following: ```plantuml 'db/uml.puml\n``` somewhere in your README.md file.