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

sequelize-models-postgis

v1.6.5

Published

Node.js SequelizeJS ORM model utilities

Downloads

9

Readme

sequelize-models

NPM version Build Status Dependency Status Coverage Status bitHound Code

Node.js SequelizeJS ORM model utilities.

sequelize-models will try to load all your database tables and associations as Sequelize JS models automatically, but if you want define your models explicitly, just need to create a model file and sequelize-models will skip the models automatic definition for that table and will use your model file, use models.path to specify the models directory to read.

Warnings

Node.js 4.0 or latest is required to use this module.

Sequelize Models Version 1.4.0 uses SequelizeJS 4.37.x which is the current stable version

sequelize-models is a bit old project, and i'm planning rewrite from scratch to use the latest language features, feel free to suggest features creating a issue with the respective description.

Installation

$ npm install --save sequelize-models

# MySQL
$ npm install --save mysql2

# PostgreSQL
$ npm install --save pg
$ npm install --save pg-hstore

Features

  • Auto load of Sequelize models from database schema.

  • Auto load models associations from database schema.

  • Simplified and meaningful model files syntax.

  • One place models and associations definitions.

  • MySQL and PSQL support for now (support for MSSQL as soon as possible).

Usage

Config and get schema


const SequelizeModels = require("sequelize-models");

var seqModels  = new SequelizeModels({
  // Database connection options
  connection : {
    host     : "127.0.0.1",
    dialect  : "mysql",
    username : "root",
    schema   : "sequelize_test",
    password : ""
  },

  // Models loading options
  models : {
    autoLoad : true,
    path     : "/models"
  },

  // Sequelize options passed directly to Sequelize constructor
  sequelizeOptions : {
    define : {
      freezeTableName : true,
      underscored     : true
    }
  }
});


seqModels.getSchema().then( schema => {
  // schema.models and schema.db available here
})
.catch( err => {
  // throwing error out of the promise
  setTimeout( () => { throw err });
});

Model Definition , file models/User.js

module.exports = {

  // Following http://docs.sequelizejs.com/en/latest/docs/models-definition/
  tableName : "user",

  attributes : {
    name : {
      type : "string"
    },
    last_name : {
      type : "string"
    },
    born_date : {
      type : "date"
    }
  },


  // Associations -> http://docs.sequelizejs.com/en/latest/docs/scopes/#associations
  associations : [{
    type    : "belongsTo",
    target  : "Profile",
    options : {
      foreignKey : "profile_id"
    }
  }],

  validate : {},
  indexes  : []
};

Contributing

Feel free to submit a PR or create an issue for any bug fixes or feature requests, just remember if you add new features or fix a bug, please provide the respective tests for the case.

Build and open code documentation

$ npm install -g gulp && gulp docs

Run Tests

You need edit test/mysql/config.js and test/psql/config.js with your own databases connection params, before run the steps below which are assuming that you will create a database with the name sequelize_test on each database.

$ npm install gulp -g && npm install

# Create and start development docker databases (needs docker  & docker-compose installed)
$ npm run db:up

# create mysql config files
$ gulp config-mysql

# test data for mysql
$ ./node_modules/sequelize-cli/bin/sequelize db:migrate

# create psql config files
$ gulp config-psql

# test data for postgres
$ ./node_modules/sequelize-cli/bin/sequelize db:migrate

# run test
$ gulp test

License

MIT