connect-mysql
This is a simple MySQL backed session store for connect.
It uses the node-mysql module already installed in your project to establish and pool connections.
Upgrading
Changes introduced in v2.2 mean sessions stored in earlier versions are not backwards compatible with v2.2. It it recommended that you clear the session table; alternately sessions will be discarded with a warning message.
Options
table
: the name of the database table that should be used for storing sessions. Defaults to'sessions'
pool
: a node-mysql connection pool ortrue
if the store should instantiate its own poolconfig
: the configuration that will be passed tocreateConnection()
orcreatePool()
if pool istrue
retries
: how many times to retry connecting to the database before failing. Defaults to3
keepalive
: keep pooled connections open by periodically pinging them. Set totrue
to use the default interval of30000
ms or provide a positive number to set your own. Defaults totrue
.cleanup
: a boolean specifying whether to enable the cleanup events. note that if this is disabled, cleanup will not take place at all and should be done externally. Sessions with an expiration time of0
will always be ignored and should also be cleaned up externally.secret
: key that will be used to encrypt session data. If this option is not provided then data will be stored in plain textalgorithm
: the algorithm that should be used to encrypt session data. Defaults to'aes-256-ctr'
Examples
Here are some example use cases to get your application up and running.
Default use case
Simple use case using the express
framework & connect-session
middleware with connect-mysql
as the data store.
var express = // express framework session = // session middleware cookieParser = // cookie middleware MySQLStore = session // mysql session store options = config: user: 'username' password: 'password' database: 'databasename' app = ; app; app; app; app;
Connection pooling example
For those MySQL installations that make use of pools the following examples are available.
var mysql = options = pool: mysql ;
Or
var options = pool: true config: user: 'dbuser' password: 'dbpassword' database: 'db' ;
Ssession encryption example
This option enables transparent session encryption assisting
var options = secret: 'thesessionsecret' config: user: 'dbuser' password: 'dbpassword' database: 'db' ;
contributing
Contributions are welcome & appreciated. Refer to the contributing document to help facilitate pull requests.
license
This software is licensed under the MIT License.
Nathan LaFreniere, Copyright (c) 2012 &Yet