/**
 * from https://github.com/koajs/generic-session/blob/master/example/app.js
 */ 

var session = require('koa-generic-session');
var SQLiteStore = require('..');
var koa = require('koa');

var app = koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
  store: new SQLiteStore('sqlite.db')
}));

app.use(function *() {
  switch (this.path) {
  case '/get':
    get.call(this);
    break;
  case '/remove':
    remove.call(this);
    break;
  case '/regenerate':
    yield regenerate.call(this);
    break;
  }
});

function get() {
  var session = this.session;
  session.count = session.count || 0;
  session.count++;
  this.body = session.count;
}

function remove() {
  this.session = null;
  this.body = 0;
}

function *regenerate() {
  get.call(this);
  yield this.regenerateSession();
  get.call(this);
}

app.listen(8080);
/**
 * from https://github.com/koajs/generic-session/blob/master/example/app.js
 */ 

const session = require('koa-generic-session');
const SQLiteStore = require('..');
const Koa = require('koa');

const app = new Koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
  store: new SQLiteStore('sqlite.db')
}));

app.use(async (ctx) => {
  switch (ctx.path) {
  case '/get':
    get(ctx);
    break;
  case '/remove':
    remove(ctx);
    break;
  case '/regenerate':
    await regenerate(ctx);
    break;
  }
});

function get(ctx) {
  const { session } = ctx
  session.count = session.count || 0;
  session.count++;
  ctx.body = session.count;
}

function remove(ctx) {
  ctx.session = null;
  ctx.body = 0;
}

async function regenerate(ctx) {
  get(ctx);
  await ctx.regenerateSession();
  get(ctx);
}

app.listen(8080);
update example