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

k7-sequelize

v1.1.0

Published

K7 adapter for Sequelize ORM

Downloads

5

Readme

k7-sequelize

k7 adapter for sequelize ORM

Build Status Dependencies Status DevDependencies Status Known Vulnerabilities js-semistandard-style

K7-Sequelize is an Adapter for using Sequelize (SQL ORM) in Hapi by K7 connector

Usage

For example:

const Hapi = require('hapi');
const Server = new Hapi.Server();

Server.connection({host: 'localhost'});

let options = {
    adapter: require('k7-sequelize'),
    connectionString: 'postgresql://k7:k7@localhost:5432/K7Sequelize'
};

Server.register({
    register: require('k7'),
    options: options
}, (err) => {
    if (err) {
        throw err;
    }
    
    Server.start((err) => {
        if (err) {
            throw err;
        }
        
        Server.log('info', 'Server running at: ' + Server.info.uri);
    });
});

This example does:

  1. Setting the k7-sequelize adapter
  2. Setting the connectionString for sequelize connect (postgre)
  3. Register the k7 to Hapi.js

Options

All the options available in Sequelize can be setted in connectionOptions. You can see more about that in tests.

Models

For defining your models you will need folowing this example:

module.exports = (sequelize, DataType) => {
  return sequelize.define('User', {});
};

##About Migrations When you want to run migrations with sequelize, we strong recomend using Umzug and you can do that like this:

const Umzug = require('umzug');
const K7Sequelize = require('k7-sequelize');
const k7 = new K7Sequelize();
const Sequelize = k7.db.Sequelize;

const config = {
  username: process.env.DB_USERNAME || 'postgres',
  password: process.env.DB_PASSWORD || 'postgres',
  database: process.env.DB_NAME || 'cart',
  host: process.env.DB_HOST || '127.0.0.1',
  port: process.env.DB_PORT || 5432,
  dialect: process.env.DB_DIALECT || 'postgres'
};

const sequelize = new Sequelize(config.database, config.username, config.password, config);

let db = {sequelize, Sequelize};
// Instantiate Umzug
let options = {
  storage: 'sequelize',
  storageOptions: {
    sequelize: sequelize,
    modelName: 'MigrationSchema',
    tableName: 'migration_table'
  },
  logging: false,   // TODO: Create new logger to migration function receive a message parameter.
  upName: 'up',
  downName: 'down',
  migrations: {
    params: [db],
    path: 'migrations',
    pattern: /(migrations.js)$/
  }
};

const umzug = new Umzug(options);

const type = process.argv[2];
run(type);

function run (type) {
  type = type === 'down' ? 'down' : 'up';

  return umzug[type]()
    .then((migrations) => {
      migrations.map((migration) => {
        console.log('Executed ' + type.toUpperCase() + ': ', migration.file);
      });
    })
    .then(() => {
      console.log('Migration Success');
      process.exit();
    })
    .catch((err) => {
      console.log('Error executing migrations: ', err);
      process.exit(1);
    });
}

This is required, because when the load function will try to require the Models the instance of Sequelize will be injected in your models.

Examples

You can see k7 and k7-sequelize in action in the repo: Cart.

Testing

For testing you just need clone this repo and run npm install && npm test inside root folder of this project.;