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

sequelstore-connect

v1.1.5

Published

An express-session store for Sequelize.js

Downloads

17

Readme

An express-session store for Sequelize.js

npm Travis Coverage Status

Sequelize session store for Connect and Express

Compatibility

  • Support Express 4.x and 5.0
  • Support Node.js 0.10, 0.12, 4.x, 5.x and all io.js versions
  • Support for Sequelize up to version 3.15

Express or Connect integration

Express 4.x, 5.0 and Connect 3.x:

const session = require('express-session');
const SequelStore = require('sequelstore-connect')(session);

app.use(session({
    secret: 'foo',
    store: new SequelStore(options)
}));

Connection to Sequelize

sequelstore-connect can be used in three different ways, depending on your architecture, you should pick one which fits your requirements and architecture the best.

  • Usage with your existing database by adding a specific model.

  • Usage with your existing database by passing a custom model into it.

  • Or it can create the model for you.

const Sequelize = require('sequelize');

// Basic usage
const database = new Sequelize(config);

app.use(session({
    store: new SequelizeStore({database})
}));

Re-use your Sequelize instance.

In this case, you just have to give your Db instance to sequelstore-connect. If the connection is not opened, sequelstore-connect will do it for you.

/*
** There are many ways to create an instance.
** You should refer to the ORM documentation
** http://docs.sequelizejs.com/en/latest/
*/



const database = require ('./models').sequelize;

app.use(session({
    store: new MongoStore({ database })
}));

Using your own session models

Automatically use your db by creating a Model named ConnectSession

/*
 * IF this model exists anywhere in your db then
 * it will be used for session storage. It must be named "ConnectSession"
 */
module.exports = (sequelize, DataTypes) => {
  return sequelize.define('ConnectSession', {
    sid: {
      type: DataTypes.STRING,
      primaryKey: true
    },
    expires: DataTypes.DATE
  });
};

Using a custom session model

Use the sessionModel option for custom integration.

store = new SequelStore({
  database,
  sessionModel: db.models.FooModel
});

Session expiration

When the session cookie has an expiration date, sequelstore-connect will use it.

Otherwise, it will create a new one, using ttl option.

app.use(session({
    store: new MongoStore({
      database: db,
      ttl: 14 * 24 * 60 * 60 // = 14 days. Default
    })
}));

Note: Each time an user interacts with the server, its session expiration date is refreshed.

Remove expired sessions

Expired session are removed from the database every 15 minutes by default. You can change it by setting autoRemoveInterval

app.use(session({
    store: new MongoStore({
      database,
      autoRemoveInterval: 15 * 60 * 1000 // = 15 minutes. Default.
    })
}));

Disable expired sessions cleaning

You are in production environment and/or you manage the TTL index elsewhere.

app.use(session({
    store: new MongoStore({
      url: 'mongodb://localhost/test-app',
      autoRemoveInterval: 0
    })
}));

More options

  • fallbackMemory Fallback to MemoryStore. Useful if you want to use MemoryStore in some case, like in development environment.
  • transform Default is JSON.stringify - you can change the function that handles the session data.

Tests

npm install && npm test

Contributing

After cloning this repo, ensure dependencies are installed by running:

npm install

This library is written in ES6 and uses Babel for ES5 transpilation and Flow for type safety. Widely consumable JavaScript can be produced by running:

npm run build

Once npm run build has run, you may import or require() directly from node.

After developing, the full test suite can be evaluated by running:

npm test

While actively developing, we recommend running

npm run watch

in a terminal. This will watch the file system run lint, tests, and type checking automatically whenever you save a js file.

To lint the JS files and run type interface checks run npm run lint.

Acknowledgements

The following sources were heavily studied and/or used to product this library.

  • connect-session-sequelize.js
    • https://github.com/mweibel/connect-session-sequelize
    • by Michael Weibel
    • MIT Licensed
  • connect-mongo
    • https://github.com/kcbanner/connect-mongo/
    • by Casey Banner
    • by Jerome Desboeufs
    • MIT Licensed
  • connect-redis
    • https://github.com/tj/connect-redis
    • by TJ Holowaychuk
    • MIT Licensed

License

The MIT License