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

hapi-sequelize-load

v1.2.3

Published

load the sequelize models/associates for hapi

Downloads

3

Readme

hapi-sequelize-load

load the sequelize models/associates for hapi

When registering this module, it loads model files, handles model associations, and sync to the DB.
The sequelize-load object is attached to the server/request object.

Installation

npm install --save hapi-sequelize-load

npm install --save sequelize

# And one of the following:
npm install --save pg pg-hstore
npm install --save mysql2
npm install --save sqlite3
npm install --save tedious // MSSQL

HISTORY

1.2.3 only ever create one instance per database 1.2.2 db.getModels is attached to the server.app object.
1.1.0 uses sequelize-load@^0.4.0: associates is no longer an object, but an array.
option logging changed.

Register Plugin

server.register(
  {
    register: require( "hapi-sequlize-load" ),
    options: {
      dialect: 'postgres',
      host: 'localhost',
      port: 5432,
      database: 'mydb',
      username: 'xxxx',
      password: 'xxxx',
      define: {
        freezeTableName: true,
      },
      operatorsAliases: false,
      // ... other sequelize options
      syncData: __dirname + "/data/sync1.json",
      pattern: __dirname + "/**/*.model.js"
    }
  },
  function ( err ){
    if ( err ){
      console.log( err );
    }
  }
);

This plugin can connect to different databases.

server.register(
  {
    register: require( "hapi-sequlize-load" ),
    options: [
      {
        dialect: 'postgres',
        // ... sequelize options
        syncData: __dirname + "/data/pgsync.json",
        pattern: __dirname + "/**/*.pg.js",
        loaderName: "dbA"
      },
      {
        dialect: 'mysql',
        // ... sequelize options
        syncData: __dirname + "/data/mysync.json",
        pattern: __dirname + "/**/*.my.js",
        loaderName: "dbB"
      },
      {
        dialect: 'mysql',
        // ... sequelize options
        syncData: __dirname + "/data/mysync2.json",
        pattern: __dirname + "/**/*.my2.js"
        // loaderName == "db2"
      },
    ]
  },
  function ( err ){
    if ( err ){
      console.log( err );
    }
  }
);

Options

The multiple option defaults to false, which means only ever create one instance per database.

The syncData option is a file path, which is used to save the sync information and must be writable. Each connection must specify a different file.

The pattern option is a string or array that specifies the model file path. Using the glob format.

The loaderName option indicates the request property name.
If not specified, the single database defaults to "db", and multiple databases default to the "db" + options array index.

The sequelize option logging values are extended (insensitive): "SERVER", "CON", "BOTH" , or a function.
"SERVER"|true : uses server.log.
"CON" : uses console.log.
"BOTH" : using both server.log and console.log output.
"benchmark" : uses console.log, and set options.benchmark = true

Usage

An instance of sequelize-load is not created until getModels runs.

function ( request, reply ){
  return reply({
    // request.dbA.sequelize.foo(); ERROR
    var Users = request.dbA.getModels( "users" );
    // request.dbA.sequelize.foo(); OK
    var [Foo1, Foo2] = request.dbB.getModels( "foo1", "foo2" );
  });
});