An express-session store for Sequelize.js
Sequelize session store for Connect and Express
Compatibility
- Support Express
4.x
and5.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 = ;const SequelStore = session; app;
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 = ; // Basic usageconst database = config; app;
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 = sequelize; app;
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 { return sequelize;};
Using a custom session model
Use the sessionModel
option for custom integration.
store = database sessionModel: dbmodelsFooModel;
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;
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;
Disable expired sessions cleaning
You are in production environment and/or you manage the TTL index elsewhere.
app;
More options
fallbackMemory
Fallback toMemoryStore
. Useful if you want to use MemoryStore in some case, like in development environment.transform
Default isJSON.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