Skip to content

nbppp2/connect-session-knex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connect Session Knex

Build Status

connect-session-knex is a session store using knex.js, which is a SQL query builder for Postgres, MySQL, MariaDB and SQLite3.

Installation

$ npm install connect-session-knex

Usage

With express 4.x and the default sqlite3 DB:

var session = require('express-session');
var KnexSessionStore = require('connect-session-knex')(session);
var store = new KnexSessionStore(/* options here */);

app.use(session({
  store: store,
  secret: 'your secret',
  cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
}));

With express 4.x and PostgreSQL:

var session = require('express-session');
var KnexSessionStore = require('connect-session-knex')(session);
var knexPg = require('knex')({
  client: 'pg',
  connection: {
    host: '127.0.0.1',
    user: 'postgres',
    password: '',
    database: 'travis_ci_test'
  }
});
var store = new KnexSessionStore({
  knex: knexPg,
  tablename: 'sessions'
});

app.use(session({
  store: store,
  secret: 'your secret',
  cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
}));

With express 3.x:

var express = require('express')
var KnexSessionStore = require('connect-session-knex')(express);
var store = new KnexSessionStore(/* options here */);

app.configure(function() {
  app.use(express.session({
    store: store,
    secret: 'your secret',
    cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
  }));
});

With connect:

var connect = require('connect'),
var KnexSessionStore = require('connect-session-knex')(connect);
var store = new KnexSessionStore(/* options here */);

connect.createServer(
  connect.cookieParser(),
  connect.session({
    store: store,
    secret: 'your secret'
  })
);

Options

  • tablename='sessions' Tablename to use. Defaults to 'sessions'.
  • knex knex instance to use. Defaults to a new knex instance, using sqlite3 with a file named 'connect-session-knex.sqlite'

Benchmarks

https://github.com/llambda/express-session-benchmarks

About

A knex.js session store for express.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%